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/16 10:01:00 UTC

[jira] [Updated] (SPARK-37021) JDBC option "sessionInitStatement" is ignored in resolveTable

     [ https://issues.apache.org/jira/browse/SPARK-37021?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Valery Meleshkin updated SPARK-37021:
-------------------------------------
    Summary: JDBC option "sessionInitStatement" is ignored in resolveTable  (was: JDBC option "sessionInitStatement" does not execute set sql statement when resolving a table)

> JDBC option "sessionInitStatement" is ignored in resolveTable
> -------------------------------------------------------------
>
>                 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" -> "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 might sound like an artificial example, in a simple case like the one above it's easy enough to specify {{"BOB.FOO"}} as {{dbtable}}. But when {{sessionInitStatement}} contains a more complicated setup it might not be as straightforward.



--
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