[ 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} Then we would get the following error. {code:java} [UNSUPPORTED_INSERT.RDD_BASED] Can't insert into the target. An RDD-based table is not allowed. SQLSTATE: 42809; 'InsertIntoStatement Project [staticinvoke(class org.apache.spark.sql.catalyst.util.CharVarcharCodegenUtils, StringType, readSidePadding, ID#0, 1, true, false, true) AS ID#1], false, false, false +- LocalRelation [col1#3] {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. {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} > 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} > > Then we would get the following error. > {code:java} > [UNSUPPORTED_INSERT.RDD_BASED] Can't insert into the target. An RDD-based > table is not allowed. SQLSTATE: 42809; > 'InsertIntoStatement Project [staticinvoke(class > org.apache.spark.sql.catalyst.util.CharVarcharCodegenUtils, StringType, > readSidePadding, ID#0, 1, true, false, true) AS ID#1], false, false, false > +- LocalRelation [col1#3] {code} -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org