Write SQL queries
Transform data from the CDF staging area into a data model using built-in and custom Spark SQL queries. Select Switch to SQL editor on the Transform data page to create a transformation in Spark SQL. This article describes the queries and explains how you can load data incrementally.
The SQL editor offers built-in code completion and built-in Spark SQL functions and Cognite custom SQL functions.
Your changes won't be kept if you switch from the SQL editor to the mapping editor.
Read from a CDF staging table
To select data from a CDF staging table, use the syntax mydb.mytable
:
select
*
from
database-name.table-name
If your database or table name contains special characters, enclose the name in backticks, for example `my-db`.`my table`
.
Avoid schema inference
Transformations infer schemas in the CDF staging table, but this process only uses a subset of all the rows in the table. You can avoid schema inference and write a schema fitted your data.
To avoid schema inference:
select
*
from
cdf_raw("database-name", "table-name")