cloud-fan commented on code in PR #52428: URL: https://github.com/apache/spark/pull/52428#discussion_r2447436192
########## sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ResolveEventTimeWatermarkSuite.scala: ########## @@ -0,0 +1,105 @@ +/* + * 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.catalyst.analysis.TestRelations.streamingRelation +import org.apache.spark.sql.catalyst.dsl.expressions._ +import org.apache.spark.sql.catalyst.dsl.plans._ +import org.apache.spark.sql.catalyst.expressions.Alias +import org.apache.spark.sql.catalyst.plans.logical.{EventTimeWatermark, LogicalPlan} +import org.apache.spark.sql.catalyst.rules.Rule +import org.apache.spark.unsafe.types.CalendarInterval + +class ResolveEventTimeWatermarkSuite extends AnalysisTest { + override protected def extendedAnalysisRules: Seq[Rule[LogicalPlan]] = { + ResolveEventTimeWatermark +: super.extendedAnalysisRules + } + + test("event time column expr refers to the column in child") { + val planBeforeRule = streamingRelation + .watermarkUnresolved($"ts", new CalendarInterval(0, 0, 1000)) + + val analyzed = getAnalyzer.execute(planBeforeRule) + + // EventTimeWatermark node has UUID, hence we can't simply compare the plan + // with expected shape of plan as a whole. + val uuid = java.util.UUID.randomUUID() + + val uuidInjectedAnalyzed = analyzed.transform { + case e: EventTimeWatermark => e.copy(nodeId = uuid) + } + + comparePlans( + uuidInjectedAnalyzed, + EventTimeWatermark( + uuid, + streamingRelation.output.find(_.name == "ts").head, + new CalendarInterval(0, 0, 1000), + streamingRelation + ) Review Comment: ```suggestion EventTimeWatermark( uuid, $"ts", new CalendarInterval(0, 0, 1000), streamingRelation ).analyze ``` `.analyze` invokes the default analyzer and won't resolve watermarks, which is a perfect match for this test to construct the expected plan. -- 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]
