Data Serialization Functions

Serialization functions convert the data into the form expected by the query in which the interaction is inserted. For example, if the interaction is used in a compact-form query, use the asObject function to format the data into a one-dimensional object.

asDateRange Function 

Returns the date range filter condition as a string for a SAQL query. The date range is inclusive. Use the string as part of a filter based on dates.

The input data must be a one- or two-dimensional array. If the input data is a one-dimensional array with two elements, the function uses the first element as the minimum and the second element as the maximum. Null results in fieldName in all, which applies no filter.

To view an example of this function, see Date Range Filter Interaction.

Syntax 

1<input data>.asDateRange(fieldName)

Arguments 

ArgumentDescription
fieldName(Required) The name of the date field.

This example is based on the stepFoo source query. Assume that stepFoo.selection retrieves this row from the query.

1[{ "min": 1016504910000, "max": 1281655993000 }]

Example 

Function:

1row(stepFoo.selection, [0], ["min", "max"]).asDateRange("date(year, month, day)");

Output:

1date(year, month, day) in [dateRange([2002,3,19], [2010,8,12])]

See Also

asEquality Function 

Returns an equality or “in” filter condition as a string for a SAQL query. The input data must be a scalar, one-dimensional array, or a two-dimensional array.

If a single field name is provided, the returned string contains the in operator for a one-dimensional array, fieldName in ["foo", "bar"], or the equality operator for a scalar, fieldName == "foo".

If multiple field names are provided, the returned string contains a composite filter. For this case, a two-dimensional array is expected. The number of values in each array must match the number of specified fields.

If the input to this function is null, the function returns <fieldName> is null, where <fieldName> is the first field. For example, if cell(step1.selection, 0, "column1") evaluates to null, cell(step1.selection, 0, "column1").asEquality("field1") evaluates to 'field1' is null. If there are no selected rows, cell(step1.selection, "column1"), the function evaluates to <fieldName> in all.

Note

Syntax 

1<input data>.asEquality(fieldName)

Arguments 

ArgumentDescription
fieldName(Required) The name of the field.

These examples are based on the myStep source query. Assume that myStep.selection is:

1[
2    {grouping: "first", measure: 19}
3    {grouping: "second", measure: 32}
4]

Examples 

Function:

1cell(myStep.selection, 1, "measure").asEquality("bar");

Output:

1bar == 32

Function:

1column(myStep.selection, ["grouping"]).asEquality("bar");

Output:

1bar in ['first','second']

This example illustrates how a lack of input data is handled. Imagine that myStep.selection resolves as

1[]

Function:

1cell(myStep.selection, 0, "value").asEquality("bar");

Output:

1'bar' in all

The next examples illustrate how null values and empty arrays are evaluated when present in the myStep.selection.

1[
2  { "grouping": "first", "measure": null },
3  { "grouping": "second", "measure": 32 }
4]

Function:

1cell(myStep.selection, 0, "measure").asEquality("bar");

Output:

1'bar' is null
1[
2    {label: "Bananas", value: []}
3]

Function:

1cell(myStep.selection, 0, "value").asEquality("bar");

Output

1'bar' in all

See Also

asGrouping Function 

Returns a grouping as a string. Can also return multiple groupings

The input data must be a scalar or one-dimensional array of groupings. Null results in a group by all.

To view an example of this function, see Group and Project Interaction.

Syntax 

1<input data>.asGrouping()

Let’s look at some examples where the selection determines the groupings in a SAQL-form query. These examples are based on the stepFoo source query. Assume that stepFoo.selection retrieves these rows from the query.

1[
2    {grouping: "first", alias: "foo"}
3    {grouping: "second", alias: "bar"}
4]

Examples 

Function:

1cell(stepFoo.selection, 1, "grouping").asGrouping();

Output:

1'second'

Function:

To make the interaction return multiple fields for the grouping, replace the cell interaction function with a column function and update the arguments.

1column(stepFoo.selection, ["grouping"]).asGrouping();

Output:

1('first', 'second')

See Also

asObject Function 

Passes data through with no serialization. Returns data as an object that is an array of strings.

Syntax 

1<input data>.asObject()

Examples 

Function:

1column(StaticMeasureNamesStep.selection, [\"value\"]).asObject()

Function:

1cell(static_1.selection, 0, \"value\").asObject()

See Also

asProjection Function 

Returns the query expression and alias as a string that you can use to project a field in a query. The query expression determines the value of the field. The alias is the field label.

Use this function to write a foreach statement for a field projection. The function concatenates the query expression as and the field label in this format.

1<`query_expression`> as <`field_label`>

Here’s a sample projection that rounds the price to two decimals and stores the result in the SalesPrice field.

1q = foreach q generate round(Price, 2) as SalesPrice;

In this sample, round(Price, 2) is the expression and SalesPrice is the field label.

Syntax 

1<input data>.asProjection()

This example is based on the stepFoo source query. Assume that stepFoo.selection retrieves these rows from the query.

1[
2    {expression: "first", alias: "foo"}
3    {expression: "second", alias: "bar"}
4]

Examples 

Function:

1stepFoo.selection, [0], ["expression", "alias"]).asProjection()

Output:

1first as 'foo'

Function:

1stepFoo.selection, [], ["expression", "alias"]).asProjection()

Output:

1first as 'foo', second as 'bar'

See Also

asRange Function 

Returns a range filter condition as a string for a SAQL query. The range is inclusive.

The input data must be a one-dimensional array with at least two elements. The function uses the first as the minimum and the second as the maximum. Null results in fieldName in all, which applies no filter.

To view an example of this function, see Range Filter Interaction.

Syntax 

1<input data>.asRange(fieldName)

Arguments 

ArgumentDescription
fieldName(Required) The name of the field.

This example is based on the myStep source query. Assume that myStep.selection retrieves these rows from the query.

1[
2    {grouping: "first", measure: 19}
3    {grouping: "second", measure: 32}
4]

Example 

Function:

1row(myStep.selection, [0], ["min", "max"]).asRange("bar");

Output:

1bar >= 19 && bar <= 32

See Also

asString Function 

Serializes a scalar, one-dimensional array, or a two-dimensional array as a string. Escapes double quotes in strings.

Syntax 

1<input data>.asString()

Examples 

Function:

1cell(stepOpportunity.selection, 1, "measure").asString();

Function:

1cell(color_1.result, 0, "color").asString();

See Also