Skip to content

[SPARK-51987][SPARK-52235][SQL][FOLLOW-UP] Add ANSI mode check for new tests #51092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -676,104 +676,107 @@ class DataSourceV2DataFrameSuite

test("create/replace table default value expression should have a cast") {
val tableName = "testcat.ns1.ns2.tbl"
withTable(tableName) {

val createExec = executeAndKeepPhysicalPlan[CreateTableExec] {
sql(
s"""
|CREATE TABLE $tableName (
| col1 int,
| col2 timestamp DEFAULT '2018-11-17 13:33:33',
| col3 double DEFAULT 1)
|""".stripMargin)
}
checkDefaultValues(
createExec.columns,
Array(
null,
new ColumnDefaultValue(
"'2018-11-17 13:33:33'",
new LiteralValue(1542490413000000L, TimestampType),
new LiteralValue(1542490413000000L, TimestampType)),
new ColumnDefaultValue(
"1",
new V2Cast(LiteralValue(1, IntegerType), IntegerType, DoubleType),
LiteralValue(1.0, DoubleType))))
withSQLConf(SQLConf.ANSI_ENABLED.key -> "true") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid similar issues in the future, can we turn on ANSI for the entire test suite? we can override def sparkConf like https://github.com/apache/spark/blob/master/sql/core/src/test/scala/org/apache/spark/sql/TPCDSQuerySuite.scala#L32

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea let me do that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm it didnt work, i think this goes to another sparkconf that's not used by this suite? I guess that's why there's a separate before to override the conf, i put it there.

withTable(tableName) {
val createExec = executeAndKeepPhysicalPlan[CreateTableExec] {
sql(
s"""
|CREATE TABLE $tableName (
| col1 int,
| col2 timestamp DEFAULT '2018-11-17 13:33:33',
| col3 double DEFAULT 1)
|""".stripMargin)
}
checkDefaultValues(
createExec.columns,
Array(
null,
new ColumnDefaultValue(
"'2018-11-17 13:33:33'",
new LiteralValue(1542490413000000L, TimestampType),
new LiteralValue(1542490413000000L, TimestampType)),
new ColumnDefaultValue(
"1",
new V2Cast(LiteralValue(1, IntegerType), IntegerType, DoubleType),
LiteralValue(1.0, DoubleType))))

val replaceExec = executeAndKeepPhysicalPlan[ReplaceTableExec] {
sql(
s"""
|REPLACE TABLE $tableName (
| col1 int,
| col2 timestamp DEFAULT '2022-02-23 05:55:55',
| col3 double DEFAULT (1 + 1))
|""".stripMargin)
val replaceExec = executeAndKeepPhysicalPlan[ReplaceTableExec] {
sql(
s"""
|REPLACE TABLE $tableName (
| col1 int,
| col2 timestamp DEFAULT '2022-02-23 05:55:55',
| col3 double DEFAULT (1 + 1))
|""".stripMargin)
}
checkDefaultValues(
replaceExec.columns,
Array(
null,
new ColumnDefaultValue(
"'2022-02-23 05:55:55'",
LiteralValue(1645624555000000L, TimestampType),
LiteralValue(1645624555000000L, TimestampType)),
new ColumnDefaultValue(
"(1 + 1)",
new V2Cast(
new GeneralScalarExpression("+", Array(LiteralValue(1, IntegerType),
LiteralValue(1, IntegerType))),
IntegerType,
DoubleType),
LiteralValue(2.0, DoubleType))))
}
checkDefaultValues(
replaceExec.columns,
Array(
null,
new ColumnDefaultValue(
"'2022-02-23 05:55:55'",
LiteralValue(1645624555000000L, TimestampType),
LiteralValue(1645624555000000L, TimestampType)),
new ColumnDefaultValue(
"(1 + 1)",
new V2Cast(
new GeneralScalarExpression("+", Array(LiteralValue(1, IntegerType),
LiteralValue(1, IntegerType))),
IntegerType,
DoubleType),
LiteralValue(2.0, DoubleType))))
}
}

test("alter table default value expression should have a cast") {
val tableName = "testcat.ns1.ns2.tbl"
withTable(tableName) {
withSQLConf(SQLConf.ANSI_ENABLED.key -> "true") {
withTable(tableName) {

sql(s"CREATE TABLE $tableName (col1 int) using foo")
val alterExec = executeAndKeepPhysicalPlan[AlterTableExec] {
sql(
s"""
|ALTER TABLE $tableName ADD COLUMNS (
| col2 timestamp DEFAULT '2018-11-17 13:33:33',
| col3 double DEFAULT 1)
|""".stripMargin)
}
sql(s"CREATE TABLE $tableName (col1 int) using foo")
val alterExec = executeAndKeepPhysicalPlan[AlterTableExec] {
sql(
s"""
|ALTER TABLE $tableName ADD COLUMNS (
| col2 timestamp DEFAULT '2018-11-17 13:33:33',
| col3 double DEFAULT 1)
|""".stripMargin)
}

checkDefaultValues(
alterExec.changes.map(_.asInstanceOf[AddColumn]).toArray,
Array(
new ColumnDefaultValue(
"'2018-11-17 13:33:33'",
LiteralValue(1542490413000000L, TimestampType),
LiteralValue(1542490413000000L, TimestampType)),
new ColumnDefaultValue(
"1",
new V2Cast(LiteralValue(1, IntegerType), IntegerType, DoubleType),
LiteralValue(1.0, DoubleType))))
checkDefaultValues(
alterExec.changes.map(_.asInstanceOf[AddColumn]).toArray,
Array(
new ColumnDefaultValue(
"'2018-11-17 13:33:33'",
LiteralValue(1542490413000000L, TimestampType),
LiteralValue(1542490413000000L, TimestampType)),
new ColumnDefaultValue(
"1",
new V2Cast(LiteralValue(1, IntegerType), IntegerType, DoubleType),
LiteralValue(1.0, DoubleType))))

val alterCol1 = executeAndKeepPhysicalPlan[AlterTableExec] {
sql(
s"""
|ALTER TABLE $tableName ALTER COLUMN
| col2 SET DEFAULT '2022-02-23 05:55:55',
| col3 SET DEFAULT (1 + 1)
|""".stripMargin)
val alterCol1 = executeAndKeepPhysicalPlan[AlterTableExec] {
sql(
s"""
|ALTER TABLE $tableName ALTER COLUMN
| col2 SET DEFAULT '2022-02-23 05:55:55',
| col3 SET DEFAULT (1 + 1)
|""".stripMargin)
}
checkDefaultValues(
alterCol1.changes.map(_.asInstanceOf[UpdateColumnDefaultValue]).toArray,
Array(
new DefaultValue("'2022-02-23 05:55:55'",
LiteralValue(1645624555000000L, TimestampType)),
new DefaultValue(
"(1 + 1)",
new V2Cast(
new GeneralScalarExpression("+", Array(LiteralValue(1, IntegerType),
LiteralValue(1, IntegerType))),
IntegerType,
DoubleType))))
}
checkDefaultValues(
alterCol1.changes.map(_.asInstanceOf[UpdateColumnDefaultValue]).toArray,
Array(
new DefaultValue("'2022-02-23 05:55:55'",
LiteralValue(1645624555000000L, TimestampType)),
new DefaultValue(
"(1 + 1)",
new V2Cast(
new GeneralScalarExpression("+", Array(LiteralValue(1, IntegerType),
LiteralValue(1, IntegerType))),
IntegerType,
DoubleType))))
}
}

Expand Down