Tutorial: Define CS.SPARK_XCALL UDF
Syntax: CS.SPARK_XCALL([folder name/service name], [input_location], [output_template, input_name_or_values], [input_name_or_values])
Spark services can be set up to call other Spark services. Any Spark service can become a function that can be called from any other Spark service. This feature is known as Xcall and is defined as a function within an Excel workbook.
This enables encapsulation and reuse of calculations and data. Instead of having all the formulas and data in one workbook, calculations can be split and managed separately, while being referenced and reused multiple times across Spark services.
Use cases include:
Model insurance product structures where each coverage is defined by separate Spark services. A "traffic director" upstream service assembles the coverage together for the policy.
Model insurance product structures that have variances across distribution channels or product versions across time. Each product can be a separate Spark service and a "traffic director" upstream service manages them with a common API interface.
Spark services where a complex part of a calculation like a solve needs to be run multiple times. The solve can be put into a separate file.
Prerequisites
Two Spark services are required:
The downstream service that has the encapsulated calculations and data. This can be any Spark service that includes Inputs and outputs (Xinput and Xoutput).
The upstream service that makes the API request and receives the response. This workbook must include the
CS.SPARK_XCALLuser-defined function to call the downstream service.
Both Spark services must be uploaded in the same tenant and accessible with the same credentials.
Coherent Assistant is required to define
CS.SPARK_XCALLuser-defined functions in Excel.
Use the right Xcall definition
There are many ways that the CS.SPARK_XCALL function can be defined. To understand how best to use this function, follow these steps.
Review the target downstream service. It should already be uploaded to Spark.
Identify the inputs you need to send to this service and the outputs that you want to receive. Depending on your use case you may not need all the inputs and outputs.
Categorize the inputs and outputs as either being single value or tables.
Assess the best
CS.SPARK_XCALLdefinition using the table below.Follow the step-by-step example for the definition.
Make multiple Xcall at a time with single value inputs only
1+ single value outputs
Xcall without output template
Any number of inputs and types
1 single value output
Example of Xcall without output template
In Spark, create a folder called
xcallsif it does not exist.Upload the Excel files for the downstream service and upstream service into the folder.
Use the API Tester to interact with the upstream service
matrix_math_single xcall. The key calculations are performed by the downstream servicematrix_math_single. The provisioned endpoint can be used for integration.Open the upstream file
matrix_math_single xcall.xlsxin Excel.Load Coherent Assistant and sign in to the same environment and tenant. Change the input fields and observe that the
CS.SPARK_XCALLfunction will recalculate.If you would like to make any changes to the upstream service, edit the Excel file and re-test the
CS.SPARK_XCALLfunction with Coherent Assistant. Upload the Excel file again to update the service.
Review all of the mappings in the Name Manager, either:
Select the Formulas tab and select Name Manager OR,
Use the keyboard shortcut
Ctrl+F3.
Xinput_scalar
Single value input.
Xinput_matrix
Table input with headings c1 and c2.
Xoutput_scalar_det
Single value output of the determinant
=det[scalar⋅matrix].
Review all of the mappings in the Name Manager, either:
Select the Formulas tab and select Name Manager OR,
Use the keyboard shortcut
Ctrl+F3.
Xinput_up_scalar
Single value input sent downstream as scalar.
C3
Xinput_up_matrix
Table input with headings c1 and c2 sent downstream as matrix.
C5:D7
Xoutput_up_double_det
Single value output derived from downstream response scalar_det then ×2.
C20
CS.SPARK_XCALL("xcalls/matrix_math_single", , "scalar_det", "scalar", C3, "matrix", C5:D7)

Xcall with output template
Any number of inputs and types
2+ single value output
OR
1+ table outputs
Example of Xcall with output template
The example is similar to Example of Xcall without output template except the downstream also includes a table response. An [output_template] is recommended for the CS.SPARK_XCALL function to properly layout the outputs returned by the downstream service.
In Spark, create a folder called
xcallsif it does not exist.Upload the Excel files for the downstream service and upstream service into the folder.
Use the API Tester to interact with the upstream service
matrix_math_w_table xcall. The key calculations are performed by the downstream servicematrix_math_w_table. The provisioned endpoint can be used for integration.Open the upstream file
matrix_math_single xcall.xlsxin Excel.Load Coherent Assistant and sign in to the same environment and tenant. Change the input fields and observe that the
CS.SPARK_XCALLfunction will recalculate.If you would like to make any changes to the upstream service, edit the Excel file and re-test the
CS.SPARK_XCALLfunction with Coherent Assistant. Upload the Excel file again to update the service.
Review all of the mappings in the Name Manager, either:
Select the Formulas tab and select Name Manager OR,
Use the keyboard shortcut
Ctrl+F3.
Xinput_scalar
Single value input.
Xinput_matrix
Table input with headings c1 and c2.
Xoutput_scalar_det
Single value output of the determinant
=det[scalar ⋅ matrix].
Xoutput_scalar_mult
Table input with headings c1 and c2
=scalar ⋅ matrix.
Review all of the mappings in the Name Manager, either:
Select the Formulas tab and select Name Manager OR,
Use the keyboard shortcut
Ctrl+F3.
Xinput_up_scalar
Single value input sent downstream as scalar.
C3
Xinput_up_matrix
Table input with headings c1 and c2 sent downstream as matrix.
C5:D7
Xoutput_up_double_det
Single value output derived from downstream response scalar_det then ×2.
C20
Xoutput_up_double_matrix
Table output with headings c1 and c2 derived from downstream response scalar_mult then ×2.
C22:D24
CS.SPARK_XCALL("xcalls/matrix_math_w_table", B9:D12, "scalar", C3, "matrix", C5:D7)

Array Xcall for scaling
Make multiple Xcall at a time with single value inputs only
1+ single value outputs
Example of array Xcall for scaling
If you need to perform multiple Xcall to a service at a time and downstream inputs and outputs are only single values, then you can make use of array Xcall. Array Xcall are easier to define many Xcall together and can be configured for higher synchronous Xcall performance.
In Spark, create a folder called
xcallsif it does not exist.Upload the Excel files for the downstream service and upstream service into the folder.
Use the API Tester to interact with the upstream service
ab_operations xcall. The key calculations are performed by the downstream serviceab_operations. The provisioned endpoint can be used for integration.Open the upstream file
ab_operations_xcall.xlsxin Excel.Load Coherent Assistant and sign in to the same environment and tenant. Change the input fields and observe that the
CS.SPARK_XCALLfunction will recalculate.If you would like to make any changes to the upstream service, edit the Excel file and re-test the
CS.SPARK_XCALLfunction with Coherent Assistant. Upload the Excel file again to update the service.
Review all of the mappings in the Name Manager, either:
Select the Formulas tab and select Name Manager OR,
Use the keyboard shortcut
Ctrl+F3.
Xinput_a
Single value input.
Xinput_b
Single value input.
Xoutput_sum
Single value output of SUM(a,b).
Xoutput_product
Single value output of PRODUCT(a,b).
Xoutput_sumsq
Single value output of SUMSQ(a,b).
Review all of the mappings in the Name Manager, either:
Select the Formulas tab and select Name Manager OR,
Use the keyboard shortcut
Ctrl+F3.
Xinput_table
Table with headings a and b . The table records will be sent downstream as a and b.
C3
Xoutput_table1
Table with columns concat, sum, product, sumsq derived from downstream response sum, product, sumsq.
The source CS.SPARK_XCALL references the data in Xinput_table as a single contiguous range
I10:L13
Xoutput_table2
Table with columns concat, sum, product, sumsq derived from downstream response sum, product, sumsq.
The source CS.SPARK_XCALL references the data in Xinput_table as separate columns.
I15:L18
For array Xcall, the input data can be referenced as a contiguous range or as separate columns depending on the layout of your worksheet. Both will work the same way.
CS.SPARK_XCALL("xcalls/ab_operations", , C10:E10, C3:D3, C4:D6)

CS.SPARK_XCALL("xcalls/ab_operations", ,C15:E15, C3, C4:C6, D3, D4:D6)

Next steps
Before making your first Xcall, review the CS.SPARK_XCALL UDF function reference. Many CS.SPARK_XCALL configurations are available. Review these configurations before implementing Xcall into your own upstream Spark service.
Last updated
