You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Junqing Li (Jira)" <ji...@apache.org> on 2024/06/07 07:17:00 UTC
[jira] [Updated] (SPARK-48562) Writing to JDBC Temporary View Failed
[ https://issues.apache.org/jira/browse/SPARK-48562?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Junqing Li updated SPARK-48562:
-------------------------------
Description:
When creating a JDBC temporary view, `ApplyCharTypePadding` would add a Project before LogicalRelation if CHAR/VARCHAR column exists and Spark would save it as a view plan. Then if we try to write this view, Spark would put this view plan to `InsertintoStatement` in `ResolveRelations` which would fall `PrewriteCheck`.
Adding the following code to `JDBCTableCatalogSuite` would meet this problem.
{code:java}
test("test writing temporary jdbc view") {
withConnection { conn =>
conn.prepareStatement("""CREATE TABLE "test"."to_drop" (id CHAR)""").executeUpdate()
}
sql(
s"""
CREATE TEMPORARY TABLE jdbcTable
USING jdbc
OPTIONS (
url='$url',
dbtable='"test"."to_drop"');""")
sql("INSERT INTO jdbcTable values(1),(2)")
sql("select * from test.to_drop").show()
withConnection { conn =>
conn.prepareStatement("""DROP TABLE "test"."to_drop"""").executeUpdate()
}
} {code}
was:
When creating a JDBC temporary view, `ApplyCharTypePadding` would add a Project before LogicalRelation if CHAR/VARCHAR column exists and Spark would save it as a view plan. Then if we try to write this view, Spark would put this view plan to `InsertintoStatement` in `ResolveRelations` which would fall `PrewriteCheck`.
Adding the following code to `JDBCTableCatalogSuite` would meet this problem.
```
test("test writing temporary jdbc view") {
withConnection { conn =>
conn.prepareStatement("""CREATE TABLE "test"."to_drop" (id CHAR)""").executeUpdate()
}
sql(
s"""
CREATE TEMPORARY TABLE jdbcTable
USING jdbc
OPTIONS (
url='$url',
dbtable='"test"."to_drop"');""")
sql("INSERT INTO jdbcTable values(1),(2)")
sql("select * from test.to_drop").show()
withConnection { conn =>
conn.prepareStatement("""DROP TABLE "test"."to_drop"""").executeUpdate()
}
}
```
> Writing to JDBC Temporary View Failed
> -------------------------------------
>
> Key: SPARK-48562
> URL: https://issues.apache.org/jira/browse/SPARK-48562
> Project: Spark
> Issue Type: Bug
> Components: SQL
> Affects Versions: 3.4.2, 3.4.0, 3.4.1, 3.5.0, 4.0.0, 3.5.1, 3.4.3
> Reporter: Junqing Li
> Priority: Major
>
> When creating a JDBC temporary view, `ApplyCharTypePadding` would add a Project before LogicalRelation if CHAR/VARCHAR column exists and Spark would save it as a view plan. Then if we try to write this view, Spark would put this view plan to `InsertintoStatement` in `ResolveRelations` which would fall `PrewriteCheck`.
> Adding the following code to `JDBCTableCatalogSuite` would meet this problem.
> {code:java}
> test("test writing temporary jdbc view") {
> withConnection { conn =>
> conn.prepareStatement("""CREATE TABLE "test"."to_drop" (id CHAR)""").executeUpdate()
> }
> sql(
> s"""
> CREATE TEMPORARY TABLE jdbcTable
> USING jdbc
> OPTIONS (
> url='$url',
> dbtable='"test"."to_drop"');""")
> sql("INSERT INTO jdbcTable values(1),(2)")
> sql("select * from test.to_drop").show()
> withConnection { conn =>
> conn.prepareStatement("""DROP TABLE "test"."to_drop"""").executeUpdate()
> }
> } {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org