sotikoug83 commented on code in PR #56481:
URL: https://github.com/apache/spark/pull/56481#discussion_r3487884982
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala:
##########
@@ -2634,13 +2640,83 @@ class AstBuilder extends DataTypeAstBuilder
* Create an aliased table reference. This is typically used in FROM clauses.
*/
override def visitTableName(ctx: TableNameContext): LogicalPlan =
withOrigin(ctx) {
- val relation = createUnresolvedRelation(ctx.identifierReference,
Option(ctx.optionsClause))
+ val ttCtx = ctx.temporalTableIdentifierReference
+ val (atTimestamp, atVersion) = temporalSpec(ttCtx, ttCtx.timestamp,
ttCtx.version)
+ val hasAtSpec = atTimestamp.isDefined || atVersion.isDefined
+ if (hasAtSpec && ctx.temporalClause != null) {
+ withOrigin(ctx.temporalClause) {
+ throw QueryParsingErrors.multipleTimeTravelSpec(ctx.temporalClause)
+ }
+ }
+ val relation = createUnresolvedRelation(ttCtx.identifierReference,
Option(ctx.optionsClause))
+ val withAtSpec = if (hasAtSpec) {
+ RelationTimeTravel(relation, atTimestamp, atVersion)
+ } else {
+ relation
+ }
val table = mayApplyAliasPlan(
- ctx.tableAlias, relation.optionalMap(ctx.temporalClause)(withTimeTravel))
+ ctx.tableAlias,
withAtSpec.optionalMap(ctx.temporalClause)(withTimeTravel))
val sample = table.optionalMap(ctx.sample)(withSample)
sample.optionalMap(ctx.watermarkClause)(withWatermark)
}
+ override def visitTemporalTableIdentifier(
+ ctx: TemporalTableIdentifierContext): TemporalIdentifier =
withOrigin(ctx) {
+ val (timestamp, version) = temporalSpec(ctx, ctx.timestamp, ctx.version)
+ TemporalIdentifier(visitMultipartIdentifier(ctx.id), timestamp, version)
+ }
+
+ private val atSyntaxTimestampFormat = "yyyyMMddHHmmssSSS"
Review Comment:
Moved but could not find existing constant to use.
##########
sql/api/src/main/scala/org/apache/spark/sql/errors/QueryParsingErrors.scala:
##########
@@ -869,6 +869,28 @@ private[sql] object QueryParsingErrors extends
DataTypeErrorsBase {
ctx)
}
+ def invalidAtSyntaxTimestamp(
+ timestamp: String, format: String, ctx: ParserRuleContext): Throwable = {
+ new ParseException(
+ errorClass = "INVALID_TIMESTAMP_FORMAT",
Review Comment:
Good idea, using a dedicated `INVALID_TIME_TRAVEL_TIMESTAMP_FORMAT`
--
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]