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:00:12 UTC

[jira] [Created] (SPARK-37021) JDBC option "sessionInitStatement" does not execute set sql statement when resolving a table

Valery Meleshkin created SPARK-37021:
----------------------------------------

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


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



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