-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-53687][SQL][SS][SDP] Introduce WATERMARK clause in SQL statement #52428
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 all commits
d229cee
01eab25
f06846a
a2db250
92dd249
150e9ef
fc092b6
c451b1b
5fd9cf5
b1c8619
ff96c94
c2ec240
107f7b3
9206997
31ddd57
27e4de3
855c453
8805a58
bba84a9
d09b56e
b06efdc
6a40983
35cd9ed
66d4578
612df08
c556393
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 |
|---|---|---|
|
|
@@ -382,8 +382,10 @@ createPipelineDatasetHeader | |
| ; | ||
|
|
||
| streamRelationPrimary | ||
| : STREAM multipartIdentifier optionsClause? tableAlias #streamTableName | ||
| | STREAM LEFT_PAREN multipartIdentifier RIGHT_PAREN optionsClause? tableAlias #streamTableName | ||
| : STREAM multipartIdentifier optionsClause? watermarkClause? | ||
| tableAlias #streamTableName | ||
| | STREAM LEFT_PAREN multipartIdentifier RIGHT_PAREN | ||
| optionsClause? watermarkClause? tableAlias #streamTableName | ||
| ; | ||
|
|
||
| setResetStatement | ||
|
|
@@ -927,6 +929,10 @@ lateralView | |
| : LATERAL VIEW (OUTER)? qualifiedName LEFT_PAREN (expression (COMMA expression)*)? RIGHT_PAREN tblName=identifier (AS? colName+=identifier (COMMA colName+=identifier)*)? | ||
| ; | ||
|
|
||
| watermarkClause | ||
| : WATERMARK colName=namedExpression DELAY OF delay=interval | ||
| ; | ||
|
|
||
| setQuantifier | ||
| : DISTINCT | ||
| | ALL | ||
|
|
@@ -1001,9 +1007,11 @@ identifierComment | |
| relationPrimary | ||
| : streamRelationPrimary #streamRelation | ||
| | identifierReference temporalClause? | ||
| optionsClause? sample? tableAlias #tableName | ||
| | LEFT_PAREN query RIGHT_PAREN sample? tableAlias #aliasedQuery | ||
| | LEFT_PAREN relation RIGHT_PAREN sample? tableAlias #aliasedRelation | ||
| optionsClause? sample? watermarkClause? tableAlias #tableName | ||
|
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.
Contributor
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. relation here can be a temp view which could be technically streaming without STREAM keyword |
||
| | LEFT_PAREN query RIGHT_PAREN sample? watermarkClause? | ||
| tableAlias #aliasedQuery | ||
| | LEFT_PAREN relation RIGHT_PAREN sample? | ||
| watermarkClause? tableAlias #aliasedRelation | ||
| | inlineTable #inlineTableDefault2 | ||
| | functionTable #tableValuedFunction | ||
| ; | ||
|
|
@@ -1012,6 +1020,8 @@ optionsClause | |
| : WITH options=propertyList | ||
| ; | ||
|
|
||
| // Unlike all other types of expression for relation, we do not support watermarkClause for | ||
| // inlineTable. | ||
| inlineTable | ||
| : VALUES expression (COMMA expression)* tableAlias | ||
| ; | ||
|
|
@@ -1048,10 +1058,13 @@ functionTableArgument | |
| | functionArgument | ||
| ; | ||
|
|
||
| // This is only used in relationPrimary where having watermarkClause makes sense. If this becomes | ||
| // referred by other clause, please check wheter watermarkClause makes sense to the clause. | ||
| // If not, consider separate this rule. | ||
| functionTable | ||
| : funcName=functionName LEFT_PAREN | ||
| (functionTableArgument (COMMA functionTableArgument)*)? | ||
| RIGHT_PAREN tableAlias | ||
| RIGHT_PAREN watermarkClause? tableAlias | ||
|
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. From the doc https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-select-watermark, it looks like
Contributor
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. Ouch I think it's missed in that doc. |
||
| ; | ||
|
|
||
| tableAlias | ||
|
|
@@ -1819,6 +1832,7 @@ ansiNonReserved | |
| | DEFAULT | ||
| | DEFINED | ||
| | DEFINER | ||
| | DELAY | ||
| | DELETE | ||
| | DELIMITED | ||
| | DESC | ||
|
|
@@ -2063,6 +2077,7 @@ ansiNonReserved | |
| | WEEK | ||
| | WEEKS | ||
| | WHILE | ||
| | WATERMARK | ||
| | WINDOW | ||
| | WITHOUT | ||
| | YEAR | ||
|
|
@@ -2188,6 +2203,7 @@ nonReserved | |
| | DEFAULT | ||
| | DEFINED | ||
| | DEFINER | ||
| | DELAY | ||
| | DELETE | ||
| | DELIMITED | ||
| | DESC | ||
|
|
@@ -2469,6 +2485,7 @@ nonReserved | |
| | VIEW | ||
| | VIEWS | ||
| | VOID | ||
| | WATERMARK | ||
| | WEEK | ||
| | WEEKS | ||
| | WHILE | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.catalyst.analysis | ||
|
|
||
| import org.apache.spark.sql.AnalysisException | ||
| import org.apache.spark.sql.catalyst.plans.logical.{EventTimeWatermark, LogicalPlan, Project} | ||
| import org.apache.spark.sql.catalyst.rules.Rule | ||
| import org.apache.spark.sql.catalyst.trees.TreePattern | ||
| import org.apache.spark.sql.catalyst.util.AUTO_GENERATED_ALIAS | ||
|
|
||
| /** | ||
| * Resolve [[UnresolvedEventTimeWatermark]] to [[EventTimeWatermark]]. | ||
| */ | ||
| object ResolveEventTimeWatermark extends Rule[LogicalPlan] { | ||
| override def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperatorsUpWithPruning( | ||
| _.containsPattern(TreePattern.UNRESOLVED_EVENT_TIME_WATERMARK), ruleId) { | ||
|
|
||
| case u: UnresolvedEventTimeWatermark if u.eventTimeColExpr.resolved && u.childrenResolved => | ||
| if (u.eventTimeColExpr.metadata.contains(AUTO_GENERATED_ALIAS) && | ||
| u.eventTimeColExpr.metadata.getString(AUTO_GENERATED_ALIAS) == "true") { | ||
| throw new AnalysisException( | ||
| errorClass = "REQUIRES_EXPLICIT_NAME_IN_WATERMARK_CLAUSE", | ||
| messageParameters = Map("sqlExpr" -> u.eventTimeColExpr.sql) | ||
| ) | ||
| } | ||
|
|
||
| val uuid = java.util.UUID.randomUUID() | ||
|
|
||
| val attrRef = u.eventTimeColExpr.toAttribute | ||
| if (u.child.outputSet.contains(u.eventTimeColExpr)) { | ||
| // We don't need to have projection since the attribute being referenced will be available. | ||
| EventTimeWatermark(uuid, attrRef, u.delay, u.child) | ||
| } else { | ||
| // We need to inject projection as we can't find the matching column directly in the | ||
| // child output. | ||
| val proj = Project(Seq(u.eventTimeColExpr) ++ u.child.output, u.child) | ||
| EventTimeWatermark(uuid, attrRef, u.delay, proj) | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.