Quick reference: Snowpark Java 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 select.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Renaming columns¶
To rename a column, use as or alias.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Filtering data¶
To filter data, use filter or where.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Sorting data¶
To sort data, use sort.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Limiting the number of rows returned¶
To limit the number of rows returned, use 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 join or naturalJoin. See Joining DataFrames.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Querying semi-structured data¶
To traverse semi-structured data, use subField(“<field_name>”) and subField(<index>). See Working with Semi-Structured Data.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|
Grouping and aggregating data¶
To group data, use 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 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 an anonymous UDF, use Functions.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 Functions.callUDF.
For details, see Creating User-Defined Functions (UDFs) for DataFrames in Java 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 Java.
To create an anonymous or named temporary procedure, use a
registerTemporarymethod of com.snowflake.snowpark_java.SProcRegistration.To create a named permanent procedure, use a
registerPermanentmethod of the com.snowflake.snowpark_java.SProcRegistration class.To call a procedure, use the
storedProceduremethod of the com.snowflake.snowpark_java.Session class.
Example of a SQL Statement |
Example of Snowpark Code |
|---|---|