net.snowflake.client.jdbc.SnowflakeSQLException: SQL access control error: Insufficient privileges to operate on schema 'PUBLIC'
net.snowflake.client.jdbc.SnowflakeSQLException: SQL access control error: Insufficient privileges to operate on schema 'PUBLIC'
我在尝试使用数据框时遇到错误。
这是我在 pyspark 的 databricks notebook 中 运行 从 snowflake
获取数据的代码片段
query = "SELECT * FROM TEST_TABLE LIMIT 10"
SNOWFLAKE_SOURCE_NAME = "net.snowflake.spark.snowflake"
df = spark.read.format(SNOWFLAKE_SOURCE_NAME).options(**sfOptions).option("query", query).load()
print(type(df))
print(df.count())
print((df.count(), len(df.columns)))
数据框的大小和列数正确。
当我做的时候
df.show()
我低于错误
Py4JJavaError: An error occurred while calling o1263.showString.
: net.snowflake.client.jdbc.SnowflakeSQLException: SQL access control error:
Insufficient privileges to operate on schema 'PUBLIC'
at net.snowflake.client.jdbc.SnowflakeUtil.checkErrorAndThrowExceptionSub(SnowflakeUtil.java:152)
at net.snowflake.client.jdbc.SnowflakeUtil.checkErrorAndThrowException(SnowflakeUtil.java:77)
at net.snowflake.client.core.StmtUtil.pollForOutput(StmtUtil.java:495)
at net.snowflake.client.core.StmtUtil.execute(StmtUtil.java:372)
at net.snowflake.client.core.SFStatement.executeHelper(SFStatement.java:575)
at net.snowflake.client.core.SFStatement.executeQueryInternal(SFStatement.java:265)
at net.snowflake.client.core.SFStatement.executeQuery(SFStatement.java:203)
at net.snowflake.client.core.SFStatement.execute(SFStatement.java:874)
at net.snowflake.client.jdbc.SnowflakeStatementV1.executeQueryInternal(SnowflakeStatementV1.java:259)
at net.snowflake.client.jdbc.SnowflakePreparedStatementV1.executeQuery(SnowflakePreparedStatementV1.java:181)
at net.snowflake.spark.snowflake.JDBCWrapper$$anonfun$executePreparedQueryInterruptibly.apply(SnowflakeJDBCWrapper.scala:317)
at net.snowflake.spark.snowflake.JDBCWrapper$$anonfun$executePreparedQueryInterruptibly.apply(SnowflakeJDBCWrapper.scala:315)
at net.snowflake.spark.snowflake.JDBCWrapper$$anonfun.apply(SnowflakeJDBCWrapper.scala:355)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
提前致谢。请帮助我。
编辑: 问题是因为当 运行 通过 spark 在雪花中查询时,我无权创建临时阶段。
当我像下面这样更改雪花客户端选项时,问题已解决:
sfOptions = {
"sfURL": "xxx.snowflakecomputing.com",
"sfUser": "xxxx",
"sfDatabase": "TEMP", <- changed this to TEMP from PUBLIC
"sfSchema": "PUBLIC",
"sfWarehouse": "xxx",
"sfRole": "xxxx",
"pem_private_key": private_key
}
他们授权开发人员仅在 TEMP 数据库中创建临时阶段。
也许执行以下语句来授予访问权限对您有所帮助。原因可能是您向 table 对象授予了 select 权限,但未授予对数据库 and/or 模式级别的使用权限。
GRANT USAGE ON DATABASE [database] TO ROLE [role];
GRANT USAGE ON SCHEMA [database].PUBLIC TO ROLE [role];
GRANT SELECT ON TABLE [database].PUBLIC.[table] TO ROLE [role];
文档:https://docs.snowflake.com/en/sql-reference/sql/grant-privilege.html
我在尝试使用数据框时遇到错误。
这是我在 pyspark 的 databricks notebook 中 运行 从 snowflake
获取数据的代码片段query = "SELECT * FROM TEST_TABLE LIMIT 10"
SNOWFLAKE_SOURCE_NAME = "net.snowflake.spark.snowflake"
df = spark.read.format(SNOWFLAKE_SOURCE_NAME).options(**sfOptions).option("query", query).load()
print(type(df))
print(df.count())
print((df.count(), len(df.columns)))
数据框的大小和列数正确。
当我做的时候
df.show()
我低于错误
Py4JJavaError: An error occurred while calling o1263.showString.
: net.snowflake.client.jdbc.SnowflakeSQLException: SQL access control error:
Insufficient privileges to operate on schema 'PUBLIC'
at net.snowflake.client.jdbc.SnowflakeUtil.checkErrorAndThrowExceptionSub(SnowflakeUtil.java:152)
at net.snowflake.client.jdbc.SnowflakeUtil.checkErrorAndThrowException(SnowflakeUtil.java:77)
at net.snowflake.client.core.StmtUtil.pollForOutput(StmtUtil.java:495)
at net.snowflake.client.core.StmtUtil.execute(StmtUtil.java:372)
at net.snowflake.client.core.SFStatement.executeHelper(SFStatement.java:575)
at net.snowflake.client.core.SFStatement.executeQueryInternal(SFStatement.java:265)
at net.snowflake.client.core.SFStatement.executeQuery(SFStatement.java:203)
at net.snowflake.client.core.SFStatement.execute(SFStatement.java:874)
at net.snowflake.client.jdbc.SnowflakeStatementV1.executeQueryInternal(SnowflakeStatementV1.java:259)
at net.snowflake.client.jdbc.SnowflakePreparedStatementV1.executeQuery(SnowflakePreparedStatementV1.java:181)
at net.snowflake.spark.snowflake.JDBCWrapper$$anonfun$executePreparedQueryInterruptibly.apply(SnowflakeJDBCWrapper.scala:317)
at net.snowflake.spark.snowflake.JDBCWrapper$$anonfun$executePreparedQueryInterruptibly.apply(SnowflakeJDBCWrapper.scala:315)
at net.snowflake.spark.snowflake.JDBCWrapper$$anonfun.apply(SnowflakeJDBCWrapper.scala:355)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
提前致谢。请帮助我。
编辑: 问题是因为当 运行 通过 spark 在雪花中查询时,我无权创建临时阶段。
当我像下面这样更改雪花客户端选项时,问题已解决:
sfOptions = {
"sfURL": "xxx.snowflakecomputing.com",
"sfUser": "xxxx",
"sfDatabase": "TEMP", <- changed this to TEMP from PUBLIC
"sfSchema": "PUBLIC",
"sfWarehouse": "xxx",
"sfRole": "xxxx",
"pem_private_key": private_key
}
他们授权开发人员仅在 TEMP 数据库中创建临时阶段。
也许执行以下语句来授予访问权限对您有所帮助。原因可能是您向 table 对象授予了 select 权限,但未授予对数据库 and/or 模式级别的使用权限。
GRANT USAGE ON DATABASE [database] TO ROLE [role];
GRANT USAGE ON SCHEMA [database].PUBLIC TO ROLE [role];
GRANT SELECT ON TABLE [database].PUBLIC.[table] TO ROLE [role];
文档:https://docs.snowflake.com/en/sql-reference/sql/grant-privilege.html