-
Notifications
You must be signed in to change notification settings - Fork 241
[AURON #2474] Fix make_date null and ANSI semantics #2479
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,6 @@ | |
| */ | ||
| package org.apache.auron | ||
|
|
||
| import java.sql.Date | ||
| import java.text.SimpleDateFormat | ||
|
|
||
| import org.apache.spark.sql.{AuronQueryTest, Row} | ||
|
|
@@ -1135,19 +1134,37 @@ class AuronFunctionSuite extends AuronQueryTest with BaseAuronSQLSuite { | |
| } | ||
|
|
||
| test("test function make_date") { | ||
| withTable("t1") { | ||
| sql( | ||
| "create table t1 using parquet as select '2025'" + | ||
| " as year, '03' as month, '01' as day") | ||
| val functions = | ||
| """ | ||
| |select | ||
| | make_date(year, month, day) | ||
| |from t1 | ||
| """.stripMargin | ||
| withSQLConf("spark.sql.ansi.enabled" -> "false") { | ||
| withTable("t1") { | ||
| sql("create table t1(year int, month int, day int) using parquet") | ||
| sql(""" | ||
| |insert into t1 values | ||
| | (2025, 3, 1), | ||
| | (2024, null, 2), | ||
| | (2024, 2, 30), | ||
| | (null, 7, 15), | ||
| | (2024, 7, null) | ||
| |""".stripMargin) | ||
| checkSparkAnswerAndOperator( | ||
| "select make_date(year, month, day), " + | ||
| "make_date(cast(null as int), month, day) from t1") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| val df = sql(functions) | ||
| checkAnswer(df, Seq(Row(Date.valueOf("2025-03-01")))) | ||
| test("make_date fails for invalid input in ANSI mode") { | ||
| withSQLConf("spark.sql.ansi.enabled" -> "true") { | ||
| withTable("t1") { | ||
| sql("create table t1(year int, month int, day int) using parquet") | ||
| sql("insert into t1 values (2024, 13, 1)") | ||
| val df = sql("select make_date(year, month, day) from t1") | ||
|
|
||
| val err = intercept[Exception] { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This expectation does not hold on spark 3.0. |
||
| df.collect() | ||
| } | ||
| assertPlanIsNative(df) | ||
| assert(allCauseMessages(err).toLowerCase.contains("invalid value for make_date")) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we build the result directly with a
Date32Builderhere?the current
Vecfollowed byDate32Array::from(result)requires a temporary allocation and a second full pass to pack the values and validity bitmap.appending values and nulls directly to a
Date32Builderin the existing loop would preserve the current behavior while avoiding the temporary vector and extra traversal.