wangyum commented on code in PR #59027: URL: https://github.com/apache/spark/pull/59027#discussion_r4242044996
########## sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/planning/ExtractRangeJoinKeysSuite.scala: ########## @@ -0,0 +1,201 @@ +/* + * 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.planning + +import org.apache.spark.sql.catalyst.dsl.expressions._ +import org.apache.spark.sql.catalyst.expressions._ +import org.apache.spark.sql.catalyst.plans.{Inner, PlanTest} +import org.apache.spark.sql.catalyst.plans.logical.{Join, JoinHint, LocalRelation} +import org.apache.spark.sql.types.{DayTimeIntervalType, DoubleType, IntegerType} + +/** + * Plan-level coverage for [[ExtractRangeJoinKeys]]: which condition shapes are + * recognized, which `RangeJoin` tag is produced, and what residual remains. + */ +class ExtractRangeJoinKeysSuite extends PlanTest { + + private val points = LocalRelation($"p".int) + private val ranges = LocalRelation($"lo".int, $"hi".int) + private val intervalsA = LocalRelation($"lo".int, $"hi".int) + private val intervalsB = LocalRelation($"lo".int, $"hi".int) + + private val p = points.output.head + private val rLo = ranges.output(0) + private val rHi = ranges.output(1) + private val aLo = intervalsA.output(0) + private val aHi = intervalsA.output(1) + private val bLo = intervalsB.output(0) + private val bHi = intervalsB.output(1) + + private def join(left: LocalRelation, right: LocalRelation, cond: Expression): Join = + Join(left, right, Inner, Some(cond), JoinHint.NONE) + + private def assertKeys( + left: LocalRelation, + right: LocalRelation, + cond: Expression, + expected: RangeJoin, + leftKeys: Seq[Expression], + rightKeys: Seq[Expression]): Unit = { + join(left, right, cond) match { + case ExtractRangeJoinKeys(_, _, actualLeft, actualRight, _, rangeJoin) => + assert(rangeJoin === expected) + assert(actualLeft === leftKeys) + assert(actualRight === rightKeys) + case other => fail(s"expected $expected, got $other") + } + } + + private def assertUnrecognized(plan: Join): Unit = { + assert(ExtractRangeJoinKeys.unapply(plan).isEmpty) + } + + test("point-in-range keys are the point and the two bounds") { + // Inclusivity and conjunct order stay on the condition. BETWEEN is a With + // of the point when common expressions are not inlined; the ref has no Review Comment: Fixed. Clarified the comment to explain that `BETWEEN` lowers to a `With` whose deterministic common expression is inlined before range matching, substituting the reference back to the original point expression. -- 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]
