szehon-ho commented on code in PR #52504:
URL: https://github.com/apache/spark/pull/52504#discussion_r2415265113
##########
sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2SQLSuite.scala:
##########
@@ -3881,6 +3870,60 @@ class DataSourceV2SQLSuiteV1Filter
}
}
+ test("test default value special column name conflicting with real column
name") {
+ val t = "testcat.ns.t"
+ withTable("t") {
+ sql(s"""CREATE table $t (
+ c1 STRING,
+ current_date DATE DEFAULT CURRENT_DATE,
+ current_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ current_time time DEFAULT CURRENT_TIME,
+ current_user STRING DEFAULT CURRENT_USER,
+ session_user STRING DEFAULT SESSION_USER,
+ user STRING DEFAULT USER,
+ current_database STRING DEFAULT CURRENT_DATABASE(),
+ current_catalog STRING DEFAULT CURRENT_CATALOG())""")
+ sql(s"INSERT INTO $t (c1) VALUES ('a')")
+ val result = sql(s"SELECT * FROM $t").collect()
+ assert(result.length == 1)
Review Comment:
tried PlanResolutionSuite but FunctionRegistry is not populated so doesnt'
work. Added to DataSourceV2DataFrameSuite
##########
sql/core/src/test/scala/org/apache/spark/sql/connector/AlterTableTests.scala:
##########
@@ -1590,4 +1590,79 @@ trait AlterTableTests extends SharedSparkSession with
QueryErrorsBase {
Row(1, Map(Row(20, null) -> Row("d", null)), "sales")))
}
}
+
+ private def checkConflictSpecialColNameResult(table: String): Unit = {
+ val result = sql(s"SELECT * FROM $table").collect()
+ assert(result.length == 1)
+ assert(!result(0).getBoolean(0))
+ assert(result(0).get(1) != null)
+ }
+
+ test("Add column with special column name default value conflicting with
column name") {
+ withSQLConf(SQLConf.DEFAULT_COLUMN_ALLOWED_PROVIDERS.key -> s"$v2Format,
") {
+ val t = fullTableName("table_name")
+ // There is a default value that is a special column name
'current_timestamp'.
+ withTable(t) {
+ sql(s"CREATE TABLE $t (i boolean) USING $v2Format")
+ sql(s"ALTER TABLE $t ADD COLUMN s timestamp DEFAULT current_timestamp")
+ sql(s"INSERT INTO $t(i) VALUES(false)")
+ checkConflictSpecialColNameResult(t)
+ }
+ // There is a default value with special column name 'current_user' but
in uppercase.
+ withTable(t) {
+ sql(s"CREATE TABLE $t (i boolean) USING $v2Format")
+ sql(s"ALTER TABLE $t ADD COLUMN s string DEFAULT CURRENT_USER")
+ sql(s"INSERT INTO $t(i) VALUES(false)")
+ checkConflictSpecialColNameResult(t)
+ }
+ // There is a default value with special column name same as current
column name
+ withTable(t) {
+ sql(s"CREATE TABLE $t (b boolean) USING $v2Format")
+ sql(s"ALTER TABLE $t ADD COLUMN current_timestamp timestamp DEFAULT
current_timestamp")
+ sql(s"INSERT INTO $t(b) VALUES(false)")
+ checkConflictSpecialColNameResult(t)
+ }
+ // There is a default value with special column name same as another
column name
+ withTable(t) {
+ sql(s"CREATE TABLE $t (current_date boolean) USING $v2Format")
+ sql(s"ALTER TABLE $t ADD COLUMN s date DEFAULT current_date")
+ sql(s"INSERT INTO $t(current_date) VALUES(false)")
+ checkConflictSpecialColNameResult(t)
+ }
+ }
+ }
+
+ test("Set default value for existing column conflicting with special column
names") {
Review Comment:
done
--
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]