QueryNode Class

Define each node of the query - such as projection, groups, order, filters. Execute the query.

Namespace

wave

Usage

Refer to the QueryBuilder example.

QueryNode Methods

The following are methods for QueryNode.

build(streamName)

Build the query string represented by this QueryNode and assign it to a stream name.

Signature

public String build(String streamName)

Parameters

  • streamName:

    Type: String

    The identifier for the stream - for example, “q”.

Return Value

Type: String

The SAQL query string represented by the QueryNode.

foreach(projections)

Applies a set of expressions to every row in a dataset. This action is often referred to as projection.

Signature

public wave.QueryNode foreach(List<wave.ProjectionNode> projections)

Parameters

  • projections:

    Type: List<wave.ProjectionNode>

    A list of ProjectionNodes to be added to this QueryNode.

Return Value

Type: wave.QueryNode

group(groups)

Groups matched records (group by specific dataset attributes).

Signature

public wave.QueryNode group(List<String> groups)

Parameters

  • groups:

    Type: List<String>

    A list of expressions.

Return Value

Type: wave.QueryNode

Example

1Wave.ProjectionNode[] projs = new Wave.ProjectionNode[]{Wave.QueryBuilder.get('Name'), Wave.QueryBuilder.get('Revenue').sum().alias('REVENUE_SUM')};
2ConnectApi.LiteralJson result = Wave.QueryBuilder.load('datasetId', 'datasetVersionId').group(new String[]{'Name'}).foreach(projs).build('q');

group()

Groups matched records (group by all).

Signature

public wave.QueryNode group()

Return Value

Type: wave.QueryNode

Example

1String query = Wave.QueryBuilder.load('datasetId', 'datasetVersionId').group().foreach(projs).build('q');

order(orders)

Sorts in ascending or descending order on one or more fields.

Signature

public wave.QueryNode order(List<List<String>> orders)

Parameters

  • orders: Type: List<List<String>> A list of column names and associated ascending or descending keywords, for example
    1List<List<String>>{new List<String>{'Name', 'asc'}, new List<String>{'Revenue', 'desc'}}

Return Value

Type: wave.QueryNode

cap(cap)

Limits the number of results that are returned.

Signature

global Wave.QueryNode cap(Integer cap)

Parameters

  • cap:

    Type: Integer

    The maximum number of rows to return.

Return Value

Type: wave.QueryNode

filter(filterCondition)

Selects rows from a dataset based on a filter condition (a predicate).

Signature

public wave.QueryNode filter(String filterCondition)

Parameters

  • filterCondition:

    Type: String

    For example: filter('Name != \'My Name\'')

Return Value

Type: wave.QueryNode

filter(filterConditions)

Selects rows from a dataset based on multiple filter conditions (predicates).

Signature

public wave.QueryNode filter(List<String> filterCondition)

Parameters

  • filterCondition:

    Type: List<String>

    A list of filter conditions.

Return Value

Type: wave.QueryNode

execute(streamName)

Execute the query and return rows as JSON.

Signature

global ConnectApi.LiteralJson execute(String streamName)

Parameters

  • streamName:

    Type: String

    The query stream to execute. For example:
    1ConnectApi.LiteralJson result = Wave.QueryBuilder.load('datasetId',
    2      'datasetVersionId').group().foreach(projs).execute('q');

Return Value

Type: ConnectApi.LiteralJson