-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29774][SQL] Date and Timestamp type +/- null should be null as Postgres #26412
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
Changes from 31 commits
0b293db
f726297
e7225a3
b925517
cd49411
57b13e9
eab6a83
e8b75ba
02b3738
e89d806
0694e07
0f5618b
efab3ec
1c27be1
5df6980
9817d2d
9808b9c
b190612
e544137
83705fd
846802d
4af7edb
a67be30
9a1affd
ae70022
571225b
6052e5a
928fd86
254d2d2
5dd632c
c84d46e
a44948e
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 |
|---|---|---|
|
|
@@ -151,17 +151,18 @@ case class CurrentBatchTimestamp( | |
| """, | ||
| since = "1.5.0") | ||
| case class DateAdd(startDate: Expression, days: Expression) | ||
| extends BinaryExpression with ImplicitCastInputTypes { | ||
| extends BinaryExpression with ExpectsInputTypes { | ||
|
|
||
| override def left: Expression = startDate | ||
| override def right: Expression = days | ||
|
|
||
| override def inputTypes: Seq[AbstractDataType] = Seq(DateType, IntegerType) | ||
| override def inputTypes: Seq[AbstractDataType] = | ||
| Seq(DateType, TypeCollection(IntegerType, ShortType, ByteType)) | ||
|
|
||
| override def dataType: DataType = DateType | ||
|
|
||
| override def nullSafeEval(start: Any, d: Any): Any = { | ||
| start.asInstanceOf[Int] + d.asInstanceOf[Int] | ||
| start.asInstanceOf[Int] + d.asInstanceOf[Number].intValue() | ||
| } | ||
|
|
||
| override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = { | ||
|
|
@@ -185,16 +186,17 @@ case class DateAdd(startDate: Expression, days: Expression) | |
| """, | ||
| since = "1.5.0") | ||
| case class DateSub(startDate: Expression, days: Expression) | ||
| extends BinaryExpression with ImplicitCastInputTypes { | ||
| extends BinaryExpression with ExpectsInputTypes { | ||
| override def left: Expression = startDate | ||
| override def right: Expression = days | ||
|
|
||
| override def inputTypes: Seq[AbstractDataType] = Seq(DateType, IntegerType) | ||
| override def inputTypes: Seq[AbstractDataType] = | ||
| Seq(DateType, TypeCollection(IntegerType, ShortType, ByteType)) | ||
|
|
||
| override def dataType: DataType = DateType | ||
|
|
||
| override def nullSafeEval(start: Any, d: Any): Any = { | ||
| start.asInstanceOf[Int] - d.asInstanceOf[Int] | ||
| start.asInstanceOf[Int] - d.asInstanceOf[Number].intValue() | ||
|
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. can we add some UT in
Member
Author
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. done |
||
| } | ||
|
|
||
| override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = { | ||
|
|
@@ -1072,7 +1074,7 @@ case class NextDay(startDate: Expression, dayOfWeek: Expression) | |
| * Adds an interval to timestamp. | ||
| */ | ||
| case class TimeAdd(start: Expression, interval: Expression, timeZoneId: Option[String] = None) | ||
| extends BinaryExpression with TimeZoneAwareExpression with ImplicitCastInputTypes { | ||
| extends BinaryExpression with TimeZoneAwareExpression with ExpectsInputTypes { | ||
|
|
||
| def this(start: Expression, interval: Expression) = this(start, interval, None) | ||
|
|
||
|
|
@@ -1187,7 +1189,7 @@ case class FromUTCTimestamp(left: Expression, right: Expression) | |
| * Subtracts an interval from timestamp. | ||
| */ | ||
| case class TimeSub(start: Expression, interval: Expression, timeZoneId: Option[String] = None) | ||
| extends BinaryExpression with TimeZoneAwareExpression with ImplicitCastInputTypes { | ||
| extends BinaryExpression with TimeZoneAwareExpression with ExpectsInputTypes { | ||
|
|
||
| def this(start: Expression, interval: Expression) = this(start, interval, None) | ||
|
|
||
|
|
@@ -2127,7 +2129,7 @@ case class DatePart(field: Expression, source: Expression, child: Expression) | |
| * between the given timestamps. | ||
| */ | ||
| case class SubtractTimestamps(endTimestamp: Expression, startTimestamp: Expression) | ||
| extends BinaryExpression with ImplicitCastInputTypes { | ||
| extends BinaryExpression with ExpectsInputTypes { | ||
|
|
||
| override def left: Expression = endTimestamp | ||
| override def right: Expression = startTimestamp | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,9 +23,9 @@ import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | |
| * Test various parser errors. | ||
| */ | ||
| class ErrorParserSuite extends AnalysisTest { | ||
| import CatalystSqlParser._ | ||
| import org.apache.spark.sql.catalyst.dsl.expressions._ | ||
| import org.apache.spark.sql.catalyst.dsl.plans._ | ||
| import org.apache.spark.sql.catalyst.parser.CatalystSqlParser._ | ||
|
||
|
|
||
| private def assertEqual(sqlCommand: String, plan: LogicalPlan): Unit = { | ||
| assert(parsePlan(sqlCommand) == plan) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,9 +31,9 @@ import org.apache.spark.sql.types.IntegerType | |
| * There is also SparkSqlParserSuite in sql/core module for parser rules defined in sql/core module. | ||
| */ | ||
| class PlanParserSuite extends AnalysisTest { | ||
| import CatalystSqlParser._ | ||
| import org.apache.spark.sql.catalyst.dsl.expressions._ | ||
| import org.apache.spark.sql.catalyst.dsl.plans._ | ||
| import org.apache.spark.sql.catalyst.parser.CatalystSqlParser._ | ||
|
||
|
|
||
| private def assertEqual(sqlCommand: String, plan: LogicalPlan): Unit = { | ||
| comparePlans(parsePlan(sqlCommand), plan, checkAnalysis = false) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.