You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Valery Meleshkin (Jira)" <ji...@apache.org> on 2021/10/15 17:01:00 UTC
[jira] [Updated] (SPARK-37021) JDBC option "sessionInitStatement"
does not execute set sql statement when resolving a table
[ https://issues.apache.org/jira/browse/SPARK-37021?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Valery Meleshkin updated SPARK-37021:
-------------------------------------
Description:
If {{sessionInitStatement}} is required to grant permissions or resolve an ambiguity, schema resolution will fail when reading a JDBC table.
Consider the following example running against Oracle database:
{code:scala}
reader.format("jdbc").options(
Map(
"url" -> jdbcUrl,
"dbtable" -> "SELECT * FROM FOO",
"user" -> "BOB",
"sessionInitStatement" -> """ALTER SESSION SET CURRENT_SCHEMA = "BAR"""",
"password" -> password
)).load
{code}
Table {{FOO}} is in schema {{BAR}}, but default value for {{CURRENT_SCHEMA}} for the JDBC connection will be {{BOB}}. Therefore, the code above will fail with an error ({{ORA-00942: table or view does not exist}} if it's Oracle). It happens because [resolveTable |https://github.com/apache/spark/blob/9d061e3939a021c602c070fc13cef951a8f94c82/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JDBCRDD.scala#L67]
that is called during planning phase ignores {{sessionInitStatement}}.
was:
If {{sessionInitStatement}} is required to grant permissions or resolve an ambiguity, schema resolution will fail when reading a JDBC table.
Consider the following example running against Oracle database:
{code:scala}
reader.format("jdbc").options(
Map(
"url" -> jdbcUrl,
"dbtable" -> "SELECT * FROM FOO",
"user" -> "BOB",
"sessionInitStatement" -> """ALTER SESSION SET CURRENT_SCHEMA = "BAR"""",
"password" -> password
)).load
{code}
Table {{FOO}} is in schema {{BAR}}, but default value for {{CURRENT_SCHEMA}} for the JDBC connection will be {{BOB}}. Therefore, the code above will fail with an error ({{ORA-00942: table or view does not exist}} if it's Oracle). It happens because [resolveTable |resolveTable]
that is called during planning phase ignores `sessionInitStatement`.
> JDBC option "sessionInitStatement" does not execute set sql statement when resolving a table
> --------------------------------------------------------------------------------------------
>
> Key: SPARK-37021
> URL: https://issues.apache.org/jira/browse/SPARK-37021
> Project: Spark
> Issue Type: Bug
> Components: Spark Core
> Affects Versions: 3.0.2
> Reporter: Valery Meleshkin
> Priority: Major
>
> If {{sessionInitStatement}} is required to grant permissions or resolve an ambiguity, schema resolution will fail when reading a JDBC table.
> Consider the following example running against Oracle database:
> {code:scala}
> reader.format("jdbc").options(
> Map(
> "url" -> jdbcUrl,
> "dbtable" -> "SELECT * FROM FOO",
> "user" -> "BOB",
> "sessionInitStatement" -> """ALTER SESSION SET CURRENT_SCHEMA = "BAR"""",
> "password" -> password
> )).load
> {code}
> Table {{FOO}} is in schema {{BAR}}, but default value for {{CURRENT_SCHEMA}} for the JDBC connection will be {{BOB}}. Therefore, the code above will fail with an error ({{ORA-00942: table or view does not exist}} if it's Oracle). It happens because [resolveTable |https://github.com/apache/spark/blob/9d061e3939a021c602c070fc13cef951a8f94c82/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JDBCRDD.scala#L67]
> that is called during planning phase ignores {{sessionInitStatement}}.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org