---
schema_version: "1"
id: 2cb9fdc98db32a34e4abc9bf8e28a0a1e3a450d20ea16ba173ef4f8c905398e3
title: QueryNode Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_class_wave_QueryNode.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_wave_QueryNode.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 9c75e1f58915a0b109b2eb334eb20670584f372fb35a94679e48d52d22aacf7c
description: Define each node of the query - such as projection, groups, order, filters. Execute the query.Build the query string represented by this QueryNode and assign it to a stream name.Applies a set of expressions to every row in a dataset. This action is often referred to as projection.Groups matched records (group by specific dataset attributes).Groups matched records (group by all).Sorts in ascending or descending order on one or more fields.Limits the number of results that are returned.Selects rows from a dataset based on a filter condition (a predicate).Selects rows from a dataset based on multiple filter conditions (predicates).Execute the query and return rows as JSON.
---
# 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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_wave_QueryNode.htm#apex_wave_QueryNode_methods)**

## QueryNode Methods

The following are methods for QueryNode.

- **[build(streamName)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_wave_QueryNode.htm#apex_wave_QueryNode_build)**  
    Build the query string represented by this QueryNode and assign it to a stream name.
- **[foreach(projections)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_wave_QueryNode.htm#apex_wave_QueryNode_foreach)**  
    Applies a set of expressions to every row in a dataset. This action is often referred to as projection.
- **[group(groups)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_wave_QueryNode.htm#apex_wave_QueryNode_group)**  
    Groups matched records (group by specific dataset attributes).
- **[group()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_wave_QueryNode.htm#apex_wave_QueryNode_group_2)**  
    Groups matched records (group by all).
- **[order(orders)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_wave_QueryNode.htm#unique_2144460913)**  
    Sorts in ascending or descending order on one or more fields.
- **[cap(cap)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_wave_QueryNode.htm#unique_906538190)**  
    Limits the number of results that are returned.
- **[filter(filterCondition)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_wave_QueryNode.htm#apex_wave_QueryNode_filter_2)**  
    Selects rows from a dataset based on a filter condition (a predicate).
- **[filter(filterConditions)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_wave_QueryNode.htm#apex_wave_QueryNode_filter)**  
    Selects rows from a dataset based on multiple filter conditions (predicates).
- **[execute(streamName)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_wave_QueryNode.htm#unique_117053492)**  
    Execute the query and return rows as JSON.

### 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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")
    
    The identifier for the stream - for example, “q”.

#### Return Value

Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_wave_ProjectionNode.htm#apex_class_wave_ProjectionNode "Add aggregate functions to the query, or define an alias.")\>
    
    A list of ProjectionNodes to be added to this QueryNode.

#### Return Value

Type: [wave.QueryNode](#apex_class_wave_QueryNode "Define each node of the query - such as projection, groups, order, filters. Execute the query.")

### group(groups)

Groups matched records (group by specific dataset attributes).

#### Signature

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

#### Parameters

- **groups**:
    
    Type: List<[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")\>
    
    A list of expressions.

#### Return Value

Type: [wave.QueryNode](#apex_class_wave_QueryNode "Define each node of the query - such as projection, groups, order, filters. Execute the query.")

#### Example

Wave.ProjectionNode\[\] projs = new Wave.ProjectionNode\[\]{Wave.QueryBuilder.get('Name'), Wave.QueryBuilder.get('Revenue').sum().alias('REVENUE\_SUM')};
String query = 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](#apex_class_wave_QueryNode "Define each node of the query - such as projection, groups, order, filters. Execute the query.")

#### Example

String 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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")\>> A list of column names and associated ascending or descending keywords, for example
    
    List<List<String\>>{new List<String\>{'Name', 'asc'}, new List<String\>{'Revenue', 'desc'}}

#### Return Value

Type: [wave.QueryNode](#apex_class_wave_QueryNode "Define each node of the query - such as projection, groups, order, filters. Execute the query.")

### cap(cap)

Limits the number of results that are returned.

#### Signature

global Wave.QueryNode cap(Integer cap)

#### Parameters

- **cap**:
    
    Type: [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")
    
    The maximum number of rows to return.

#### Return Value

Type: [wave.QueryNode](#apex_class_wave_QueryNode "Define each node of the query - such as projection, groups, order, filters. Execute the query.")

### 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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")
    
    For example: filter('Name != \\'My Name\\'')

#### Return Value

Type: [wave.QueryNode](#apex_class_wave_QueryNode "Define each node of the query - such as projection, groups, order, filters. Execute the query.")

### 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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")\>
    
    A list of filter conditions.

#### Return Value

Type: [wave.QueryNode](#apex_class_wave_QueryNode "Define each node of the query - such as projection, groups, order, filters. Execute the query.")

### execute(streamName)

Execute the query and return rows as JSON.

#### Signature

global ConnectApi.LiteralJson execute(String streamName)

#### Parameters

- **streamName**:
    
    Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")
    
    The query stream to execute. For example:
    
    ConnectApi.LiteralJson result = Wave.QueryBuilder.load('datasetId',
          'datasetVersionId').group().foreach(projs).execute('q');

#### Return Value

Type: ConnectApi.LiteralJson