使用 Snowpark Java 分析查询和故障排除

本主题提供了一些有关在使用 Snowpark 库时分析查询和故障排除的指引。

在 Snowpark 中查看查询的执行计划

To inspect the evaluation plan of a DataFrame, call the explain method of the DataFrame. This prints the SQL statements used to evaluate the DataFrame. If there is only one SQL statement, the method also prints the logical plan for the statement.

----------DATAFRAME EXECUTION PLAN----------
Query List:
0.
SELECT
  "_1" AS "col %",
  "_2" AS "col *"
FROM
  (
    SELECT
      *
    FROM
      (
        VALUES
          (1 :: int, 2 :: int),
          (3 :: int, 4 :: int) AS SN_TEMP_OBJECT_639016133("_1", "_2")
      )
  )
Logical Execution Plan:
 GlobalStats:
    partitionsTotal=0
    partitionsAssigned=0
    bytesAssigned=0
Operations:
1:0     ->Result  SN_TEMP_OBJECT_639016133.COLUMN1, SN_TEMP_OBJECT_639016133.COLUMN2
1:1          ->ValuesClause  (1, 2), (3, 4)

--------------------------------------------

After the execution of a DataFrame has been triggered, you can check on the progress of the query in the Query History page in Snowsight.

In the Query Tag column, you can find the name of the function and the line number in your code that triggered this query.

Snowpark request in the Query History page

更改日志记录设置

By default, the Snowpark library logs INFO level messages to stdout. To change the logging settings, create a simplelogger.properties file, and configure the logger properties in that file. For example, to set the log level to DEBUG:

# simplelogger.properties file (a text file)
# Set the default log level for the SimpleLogger to DEBUG.
org.slf4j.simpleLogger.defaultLogLevel=debug

Put this file in your classpath. If you are using a Maven directory layout, put the file in the src/main/resources/ directory.

java.lang.OutOfMemoryError 异常

If a java.lang.OutOfMemoryError exception is thrown, increase the maximum heap size for the JVM (e.g. through the -J-Xmxmaximum_size flag).

Java 17 上的未命名模块错误

在 Java 17 上执行 Snowpark Java 或 Scala 客户端时,您可能会看到以下错误:

java.base does not "opens java.nio" to unnamed module

This is because Snowpark uses the Apache Arrow connector (https://arrow.apache.org/docs/java/install.html#id3), which depends on internal Java APIs that are not exposed by default after Java 9.

若要解决此错误,请在运行应用程序时或在系统的环境变量中将以下参数设置为命令行参数。

--add-opens=java.base/java.nio=ALL-UNNAMED

Note

Snowpark API 支持以下 Java 版本:

  • 11.x
  • 17.x

在运行应用程序时设置实参

您可以在运行应用程序时通过命令行设置此参数。

For example, when calling the java command, you can add --add-opens=java.base/java.nio=ALL-UNNAMED, as in the following:

java --add-opens=java.base/java.nio=ALL-UNNAMED -jar my-snowpark-app.jar.

If you are also using RSA private key authentication, you will also need to allow sun.security.util, as in the following example:

java --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/sun.security.util=ALL-UNNAMED -jar my-snowpark-app.jar

将参数设置为环境变量

您可以在系统的环境变量中设置参数。有关设置环境变量的说明,请参阅操作系统文档。

Create or update a JDK_JAVA_OPTIONS environment variable, as in the following Unix-based example:

export JDK_JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED"

If you are also using RSA private key authentication, you will also need to allow sun.security.util, as in the following example:

export JDK_JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/sun.security.util=ALL-UNNAMED"