Step: SQL query
Overview
Redivis supports direct SQL queries for advanced functionality and for users who prefer to work in a programmatic interface. You can add one or more SQL query steps to any transform.
This step accepts SQL code and will execute in the order it has been placed within the rest of the steps.

Query syntax
SQL Dialect
Redivis supports the BigQuery Standard SQL Syntax and features, with certain limitations.
Referencing the source table
All queries must reference the SQL step's source, represented as _source_ in the query. If the SQL step is the first step in the transform, the source represents the transform's source table. Otherwise, the source represents the output of the previous step in the transform.
For example:
Referencing other tables
You can also reference any other table in the current workflow from your SQL step, following the same reference rules as those in the Redivis API. Start typing a table's name to select it from the autocomplete options.
For example:
The query editor will automatically qualify referenced tables and parameters as you reference them, which ensures your query will continue to work if tables or parameters get renamed. In most cases, you can just reference the table by name, and the fully qualified reference will be inserted for you.
Referencing parameters
You may also use parameters in your query as a SQL parameter, prefixed with the @ symbol. Note that all parameters are arrays of a given type, and you will need to cast the parameters if there is a type mismatch.
For example:
Referencing upstream variables
You can mix and match SQL steps with other step types within your transform. If you choose to do so, this may introduce additional semantics, since transforms allow variables with the same name to co-exist at any given step, delineated in the UI with the t0, t1, ... and v prefixes. The v prefix denotes any newly created variable, while the t# prefix denotes variables that have been joined from other tables.
If there is a name conflict with an upstream variable, you must reference that variable with its source prefix; e.g., t0_id or v_myvar. If there is no conflict, you may reference the variable using its source prefix, though the prefix can also be omitted (e.g., id, myvar).
For example:
Syntax errors
If your query is invalid, you will see an invalid icon and the error message displayed above your code, as well as the relevant part of your SQL query highlighted. Hover over any of the invalid indicators to see the full error message.
Transforms can't be run while any step is invalid.

Limitations
DDL / DML queries are not supported
All queries must return fields of a valid Redivis type. The following BigQuery types are not supported in the result set, though they may be used internally within the query:
TIMESTAMP
NUMERIC
BIGNUMERIC
BYTES
INTERVAL
JSON
ARRAY
STRUCT
BigQuery ML syntax is not supported
BigQuery scripting language is not supported
Recursive CTEs can only exist in transforms with a single SQL step
Statements may only reference tables that exist in your workflow
Unnamed variables in the result are not supported
Duplicate variable names in the result are not supported
Last updated
Was this helpful?

