dtenedor commented on code in PR #36212:
URL: https://github.com/apache/spark/pull/36212#discussion_r852289273
##########
sql/core/src/test/scala/org/apache/spark/sql/connector/InsertIntoTests.scala:
##########
@@ -118,16 +118,18 @@ abstract class InsertIntoTests(
}
test("insertInto: fails when missing a column") {
- val t1 = s"${catalogAndNamespace}tbl"
- sql(s"CREATE TABLE $t1 (id bigint, data string, missing string) USING
$v2Format")
- val df = Seq((1L, "a"), (2L, "b"), (3L, "c")).toDF("id", "data")
- val exc = intercept[AnalysisException] {
- doInsert(t1, df)
- }
+ withSQLConf(SQLConf.USE_NULLS_FOR_MISSING_DEFAULT_COLUMN_VALUES.key ->
"false") {
Review Comment:
Could we also add a version of this test with the conf set to "true" to show
that the intended behavior works? (This should be the same as the test code in
this case before this PR.)
##########
sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala:
##########
@@ -1078,11 +1101,13 @@ class InsertSuite extends DataSourceTest with
SharedSparkSession {
}
}
// There is one trailing default value referenced implicitly by the INSERT
INTO statement.
- withTable("t") {
- sql("create table t(i int, s bigint default 42, x bigint) using parquet")
- assert(intercept[AnalysisException] {
- sql("insert into t values(1)")
- }.getMessage.contains("expected 3 columns but found"))
+ withSQLConf(SQLConf.USE_NULLS_FOR_MISSING_DEFAULT_COLUMN_VALUES.key ->
"false") {
Review Comment:
Same as above, could we also add a version of this test with the conf set to
"true" to show that the intended behavior works? (This should be the same as
the test code in this case before this PR.)
##########
sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala:
##########
@@ -1467,10 +1494,12 @@ class InsertSuite extends DataSourceTest with
SharedSparkSession {
}
test("SPARK-36980: Insert support query with CTE") {
- withTable("t") {
- sql("CREATE TABLE t(i int, part1 int, part2 int) using parquet")
- sql("INSERT INTO t WITH v1(c1) as (values (1)) select 1, 2, 3 from v1")
- checkAnswer(spark.table("t"), Row(1, 2, 3))
+ withSQLConf(SQLConf.USE_NULLS_FOR_MISSING_DEFAULT_COLUMN_VALUES.key ->
"false") {
Review Comment:
Same as above, could we also add a version of this test with the conf set to
"true" to show that the intended behavior works? (This should be the same as
the test code in this case before this PR.)
##########
sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala:
##########
@@ -1178,34 +1205,34 @@ class InsertSuite extends DataSourceTest with
SharedSparkSession {
val addOneColButExpectedTwo = "target table has 2 column(s) but the
inserted data has 1 col"
val addTwoColButExpectedThree = "target table has 3 column(s) but the
inserted data has 2 col"
// The missing columns in these INSERT INTO commands do not have explicit
default values.
- withTable("t") {
- sql("create table t(i boolean, s bigint) using parquet")
- assert(intercept[AnalysisException] {
- sql("insert into t (i) values (true)")
- }.getMessage.contains(addOneColButExpectedTwo))
- }
- withTable("t") {
- sql("create table t(i boolean default true, s bigint) using parquet")
- assert(intercept[AnalysisException] {
- sql("insert into t (i) values (default)")
- }.getMessage.contains(addOneColButExpectedTwo))
- }
- withTable("t") {
- sql("create table t(i boolean, s bigint default 42) using parquet")
- assert(intercept[AnalysisException] {
- sql("insert into t (s) values (default)")
- }.getMessage.contains(addOneColButExpectedTwo))
- }
- withTable("t") {
- sql("create table t(i boolean, s bigint, q int default 43) using
parquet")
- assert(intercept[AnalysisException] {
- sql("insert into t (i, q) select true from (select 1)")
- }.getMessage.contains(addTwoColButExpectedThree))
- }
- // When the USE_NULLS_FOR_MISSING_DEFAULT_COLUMN_VALUES configuration is
disabled, and no
- // explicit DEFAULT value is available when the INSERT INTO statement
provides fewer
- // values than expected, the INSERT INTO command fails to execute.
withSQLConf(SQLConf.USE_NULLS_FOR_MISSING_DEFAULT_COLUMN_VALUES.key ->
"false") {
Review Comment:
Same as above, could we also add a version of this test with the conf set to
"true" to show that the intended behavior works?
##########
sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala:
##########
@@ -144,14 +144,16 @@ class InsertSuite extends DataSourceTest with
SharedSparkSession {
}
test("SELECT clause generating a different number of columns is not
allowed.") {
- val message = intercept[AnalysisException] {
- sql(
- s"""
- |INSERT OVERWRITE TABLE jsonTable SELECT a FROM jt
- """.stripMargin)
- }.getMessage
- assert(message.contains("target table has 2 column(s) but the inserted
data has 1 column(s)")
- )
+ withSQLConf(SQLConf.USE_NULLS_FOR_MISSING_DEFAULT_COLUMN_VALUES.key ->
"false") {
Review Comment:
Same as above, could we also add a version of this test with the conf set to
"true" to show that the intended behavior works? (This should be the same as
the test code in this case before this PR.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]