-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-31562][SQL] Update ExpressionDescription for substring, current_date, and current_timestamp #28342
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
[SPARK-31562][SQL] Update ExpressionDescription for substring, current_date, and current_timestamp #28342
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 |
|---|---|---|
|
|
@@ -28,7 +28,6 @@ import org.apache.commons.text.StringEscapeUtils | |
| import org.apache.spark.SparkUpgradeException | ||
| import org.apache.spark.sql.AnalysisException | ||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.catalyst.analysis.FunctionRegistry | ||
| import org.apache.spark.sql.catalyst.expressions.codegen._ | ||
| import org.apache.spark.sql.catalyst.expressions.codegen.Block._ | ||
| import org.apache.spark.sql.catalyst.util.{DateTimeUtils, LegacyDateFormats, TimestampFormatter} | ||
|
|
@@ -62,7 +61,21 @@ trait TimeZoneAwareExpression extends Expression { | |
| * There is no code generation since this expression should get constant folded by the optimizer. | ||
| */ | ||
| @ExpressionDescription( | ||
| usage = "_FUNC_() - Returns the current date at the start of query evaluation.", | ||
| usage = """ | ||
| _FUNC_() - Returns the current date at the start of query evaluation. | ||
|
|
||
| _FUNC_ - Returns the current date at the start of query evaluation. | ||
| """, | ||
| examples = """ | ||
| Examples: | ||
| > SELECT _FUNC_(); | ||
| 2020-04-25 | ||
| > SELECT _FUNC_; | ||
|
Member
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. Do you remember when we started to support this syntax? I roughly remember it was added relatively recently. If the added version is different, it might be best to note it 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. I found the PR to implement the syntax: #14442 |
||
| 2020-04-25 | ||
| """, | ||
| note = """ | ||
| The syntax without braces has been supported since 2.0.1. | ||
| """, | ||
| group = "datetime_funcs", | ||
| since = "1.5.0") | ||
| case class CurrentDate(timeZoneId: Option[String] = None) | ||
|
|
@@ -83,26 +96,52 @@ case class CurrentDate(timeZoneId: Option[String] = None) | |
| override def prettyName: String = "current_date" | ||
| } | ||
|
|
||
| abstract class CurrentTimestampLike() extends LeafExpression with CodegenFallback { | ||
| override def foldable: Boolean = true | ||
| override def nullable: Boolean = false | ||
| override def dataType: DataType = TimestampType | ||
| override def eval(input: InternalRow): Any = currentTimestamp() | ||
| } | ||
|
|
||
| /** | ||
| * Returns the current timestamp at the start of query evaluation. | ||
| * All calls of current_timestamp within the same query return the same value. | ||
| * | ||
| * There is no code generation since this expression should get constant folded by the optimizer. | ||
| */ | ||
| @ExpressionDescription( | ||
| usage = "_FUNC_() - Returns the current timestamp at the start of query evaluation.", | ||
| usage = """ | ||
| _FUNC_() - Returns the current timestamp at the start of query evaluation. | ||
|
|
||
| _FUNC_ - Returns the current timestamp at the start of query evaluation. | ||
| """, | ||
| examples = """ | ||
| Examples: | ||
| > SELECT _FUNC_(); | ||
| 2020-04-25 15:49:11.914 | ||
| > SELECT _FUNC_; | ||
| 2020-04-25 15:49:11.914 | ||
| """, | ||
| note = """ | ||
| The syntax without braces has been supported since 2.0.1. | ||
| """, | ||
| group = "datetime_funcs", | ||
| since = "1.5.0") | ||
| case class CurrentTimestamp() extends LeafExpression with CodegenFallback { | ||
| override def foldable: Boolean = true | ||
| override def nullable: Boolean = false | ||
|
|
||
| override def dataType: DataType = TimestampType | ||
|
|
||
| override def eval(input: InternalRow): Any = currentTimestamp() | ||
| case class CurrentTimestamp() extends CurrentTimestampLike { | ||
| override def prettyName: String = "current_timestamp" | ||
| } | ||
|
|
||
| override def prettyName: String = | ||
| getTagValue(FunctionRegistry.FUNC_ALIAS).getOrElse("current_timestamp") | ||
| @ExpressionDescription( | ||
| usage = "_FUNC_() - Returns the current timestamp at the start of query evaluation.", | ||
|
Member
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. nit. Do you think we can have
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. Ah I see. I'll add an example for |
||
| examples = """ | ||
| Examples: | ||
| > SELECT _FUNC_(); | ||
| 2020-04-25 15:49:11.914 | ||
| """, | ||
| group = "datetime_funcs", | ||
| since = "1.6.0") | ||
| case class Now() extends CurrentTimestampLike { | ||
| override def prettyName: String = "now" | ||
| } | ||
|
|
||
| /** | ||
|
|
||
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.
Since the usage is different between
nowandcurrent_timestamp, I added aNowexpr.Uh oh!
There was an error while loading. Please reload this page.
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.
btw, we don't need to add a version here where an alias added? For example,
current_timestampandnowhave been implemented in the different versions, 1.5 and 1.6.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.
What is the difference between
nowandcurrent_timestamp? ShouldnowextendNondeterministic, for example?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.
CURRENT_TIMESTAMPis a SQL syntax andNOWis not: https://github.com/apache/spark/blob/master/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4#L777