Github user JoshRosen commented on a diff in the pull request:
https://github.com/apache/spark/pull/7985#discussion_r36394613
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/execution/joins/InnerJoinSuite.scala
---
@@ -0,0 +1,166 @@
+/*
+ * 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.execution.joins
+
+import org.apache.spark.sql.catalyst.planning.ExtractEquiJoinKeys
+import org.apache.spark.sql.catalyst.plans.Inner
+import org.apache.spark.sql.catalyst.plans.logical.Join
+import org.apache.spark.sql.{execution, Row, DataFrame}
+import org.apache.spark.sql.catalyst.expressions.Expression
+import org.apache.spark.sql.execution._
+
+class InnerJoinSuite extends SparkPlanTest {
+
+ private def testInnerJoin(
+ testName: String,
+ leftRows: DataFrame,
+ rightRows: DataFrame,
+ condition: Expression,
+ expectedAnswer: Seq[Product]): Unit = {
+ val join = Join(leftRows.logicalPlan, rightRows.logicalPlan, Inner,
Some(condition))
+ ExtractEquiJoinKeys.unapply(join).foreach {
+ case (joinType, leftKeys, rightKeys, boundCondition, leftChild,
rightChild) =>
+
+ def makeBroadcastHashJoin(left: SparkPlan, right: SparkPlan, side:
BuildSide) = {
+ val broadcastHashJoin =
+ execution.joins.BroadcastHashJoin(leftKeys, rightKeys, side,
left, right)
+ boundCondition.map(Filter(_,
broadcastHashJoin)).getOrElse(broadcastHashJoin)
+ }
+
+ def makeShuffledHashJoin(left: SparkPlan, right: SparkPlan, side:
BuildSide) = {
+ val shuffledHashJoin =
+ execution.joins.ShuffledHashJoin(leftKeys, rightKeys, side,
left, right)
+ val filteredJoin =
+ boundCondition.map(Filter(_,
shuffledHashJoin)).getOrElse(shuffledHashJoin)
+ EnsureRequirements(filteredJoin.sqlContext).apply(filteredJoin)
+ }
+
+ def makeSortMergeJoin(left: SparkPlan, right: SparkPlan) = {
+ val sortMergeJoin =
+ execution.joins.SortMergeJoin(leftKeys, rightKeys, left, right)
+ val filteredJoin = boundCondition.map(Filter(_,
sortMergeJoin)).getOrElse(sortMergeJoin)
+ EnsureRequirements(filteredJoin.sqlContext).apply(filteredJoin)
--- End diff --
Open question of whether I should be using `EnsureRequirements` here or
not. On the one hand, this allows us to test whether these operators properly
declare their requirements / input preconditions in a way that the optimizer
can satisfy them.
On the other hand, this makes it harder to exercise precise control over
the input iterators that the physical operators see, leaving certain parts of
the test orchestration a little more "up to coincidence." For instance, let's
say that I want to precisely control the input: I can create left and right
plans with single partitions and just trust that the Exchange is not going to
unnecessarily re-shuffle before sorting, but that's brittle if someone breaks
Exchange to mis-handle this case (see #7988, which specifically fixes an issue
that would have broken this strategy).
I guess the way forward is to state the Exchange / EnsureRequirements
behavior requirements here, add unit tests for them in PlannerSuite, then
assume those requirements here and build on top of them.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]