Quick reference: Snowpark Scala APIs for SQL commands¶
This topic provides a quick reference of some of the Snowpark APIs that correspond to SQL commands.
(Note that this is not a complete list of the APIs that correspond to SQL commands.)
Performing queries¶
Selecting columns¶
To select specific columns, use DataFrame.select.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Renaming columns¶
To rename a column, use Column.as, Column.alias, or Column.name.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Filtering data¶
To filter data, use DataFrame.filter or DataFrame.where.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Sorting data¶
To sort data, use DataFrame.sort.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Limiting the number of rows returned¶
To limit the number of rows returned, use DataFrame.limit. See Limiting the Number of Rows in a DataFrame.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Performing joins¶
To perform a join, use DataFrame.join or DataFrame.naturalJoin. See Joining DataFrames.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Querying semi-structured data¶
To traverse semi-structured data, use Column.apply(“<field_name>”) and Column.apply(<index>). See Working with Semi-Structured Data.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Grouping and aggregating data¶
To group data, use DataFrame.groupBy. This returns a RelationalGroupedDataFrame object, which you can use to perform the aggregations.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Calling window functions¶
To call a window function, use the Window object methods to build a WindowSpec object, which in turn you can use for windowing functions (similar to using ‘<function> OVER … PARTITION BY … ORDER BY’).
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Updating, deleting, and merging rows¶
To update, delete, and merge rows in a table, use Updatable. See Updating, Deleting, and Merging Rows in a Table.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Working with stages¶
For more information on working with stages, see Working With Files in a Stage.
Uploading and downloading files from a stage¶
To upload and download files from a stage, use FileOperation. See Uploading and Downloading Files in a Stage.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Reading data from files in a stage¶
To read data from files in a stage, use DataFrameReader to create a DataFrame for the data. See Setting Up a DataFrame for Files in a Stage.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Copying data from files in a stage to a table¶
To copy data from files in a stage to a table, use DataFrameReader to create a CopyableDataFrame for the data, and use the CopyableDataFrame.copyInto method to copy the data to the table. See Copying Data from Files into a Table.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Saving a DataFrame to files on a stage¶
To save a DataFrame to files on a stage, use the DataFrameWriter method named after the format of the files that you want to use. See Saving a DataFrame to Files on a Stage.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Creating and calling user-defined functions (UDFs)¶
To create a Scala function that serves as a UDF (an anonymous UDF), use udf.
To create a temporary or permanent UDF that you can call by name, use UDFRegistration.registerTemporary or UDFRegistration.registerPermanent.
To call a permanent UDF by name, use callUDF.
For details, see Creating User-Defined Functions (UDFs) for DataFrames in Scala and Calling scalar user-defined functions (UDFs).
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Creating and calling stored procedures¶
For a guide on creating stored procedures with Snowpark, see Creating stored procedures for DataFrames in Scala.
To create an anonymous or named temporary procedure, use a
registerTemporarymethods of com.snowflake.snowpark.SProcRegistration.To create a named permanent procedure, use a
registerPermanentmethod of the com.snowflake.snowpark.SProcRegistration class.To call a procedure, use the
storedProceduremethod of the com.snowflake.snowpark.Session class.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|