快速参考:适用于 SQL 命令的 Snowpark Java APIs¶
本主题供您快速参考与 SQL 命令对应的一些 Snowpark APIs
(请注意,此处未列出与 SQL 命令对应的完整 APIs 列表。)
执行查询
选择列
To select specific columns, use select.
| Example of a SQL Statement | Example of Snowpark Code |
|---|---|
重命名列
To rename a column, use as or alias.
| Example of a SQL Statement | Example of Snowpark Code |
|---|---|
筛选数据
To filter data, use filter or where.
| Example of a SQL Statement | Example of Snowpark Code |
|---|---|
对数据进行排序
To sort data, use sort.
| Example of a SQL Statement | Example of Snowpark Code |
|---|---|
限制返回的行数
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 |
|---|---|
执行联接
To perform a join, use join or naturalJoin. See Joining DataFrames.
| Example of a SQL Statement | Example of Snowpark Code |
|---|---|
查询半结构化数据
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 |
|---|---|
对数据进行分组和聚合
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 |
|---|---|
调用窗口函数
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 |
|---|---|
更新、删除和合并行
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 |
|---|---|
使用暂存区
For more information on working with stages, see Working With Files in 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 |
|---|---|
从暂存区的文件中读取数据
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 |
|---|---|
将暂存区文件中的数据复制到表中
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 |
|---|---|
将 DataFrame 保存到暂存区上的文件¶
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 |
|---|---|
创建和调用用户定义的函数 (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 |
|---|---|
创建和调用存储过程
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 |
|---|---|