Snowpark 执行 ALTER SESSION 语句时出现错误

问题描述 投票:0回答:1

当我在Snowpark中执行以下语句时:

session.sql("ALTER SESSION SET query_tag = 'test';").collect()

我收到以下错误

SnowparkSQLException: (1304): 01b90062-0205-27a9-0000-01915ca148da: 090236 (42601): Stored procedure execution error: Unsupported statement type 'ALTER_SESSION'.

如何执行该语句而不出错?

snowflake-cloud-data-platform
1个回答
0
投票

我们无法使用

session.sql("ALTER SESSION SET query_tag = 'test';")
更改会话并使用
collect
获取有关会话收集的详细信息,因为我们没有任何可返回的内容。

我们可以使用连接属性设置query_tag并使用

SHOW PARAMETERS

获取参数
    connection_parameters = {
    "account": "test",
    "user": "test",
    "password": "test",
    "role": "test", # optional
    "warehouse": "test_wh",  # optional
    "database": "test",  # optional
    "schema": "public", # optional
    "timezone": "UTC",
    "query_tag": "test"
   }

    session = Session.builder.configs(connection_parameters).create()
    session.sql("SHOW PARAMETERS LIKE 'TIMEZONE%' IN SESSION").show()
    session.sql("SHOW PARAMETERS LIKE 'query_tag%' IN SESSION").show()

-------------------------------------------------------------------------------
|"key"     |"value"  |"default"            |"level"  |"description"  |"type"  |
-------------------------------------------------------------------------------
|TIMEZONE  |UTC      |America/Los_Angeles  |SESSION  |time zone      |STRING  |
-------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------
|"key"      |"value"  |"default"  |"level"  |"description"                                       |"type"  |
-----------------------------------------------------------------------------------------------------------
|QUERY_TAG  |test     |           |SESSION  |String (up to 2000 characters) used to tag stat...  |STRING  |
-----------------------------------------------------------------------------------------------------------

使用 app_name 的另一种方法

session = Session.builder.configs(connection_parameters).app_name("test_2").create() 
session.sql("SHOW PARAMETERS LIKE 'query_tag' IN SESSION").show()

------------------------------------------------------------------------------------------------------------------
|"key"      |"value"         |"default"  |"level"  |"description"                                       |"type"  |
------------------------------------------------------------------------------------------------------------------
|QUERY_TAG  |APPNAME=test_2  |           |SESSION  |String (up to 2000 characters) used to tag stat...  |STRING  |
------------------------------------------------------------------------------------------------------------------
© www.soinside.com 2019 - 2024. All rights reserved.