Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16228#discussion_r100904151
  
    --- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/statsEstimation/JoinEstimationSuite.scala
 ---
    @@ -0,0 +1,314 @@
    +/*
    + * 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.statsEstimation
    +
    +import java.sql.{Date, Timestamp}
    +
    +import scala.collection.mutable
    +
    +import org.apache.spark.sql.catalyst.expressions.{And, Attribute, 
AttributeMap, AttributeReference, EqualTo}
    +import org.apache.spark.sql.catalyst.plans._
    +import org.apache.spark.sql.catalyst.plans.logical.{ColumnStat, Join, 
Project, Statistics}
    +import org.apache.spark.sql.types.{DateType, TimestampType, _}
    +
    +
    +class JoinEstimationSuite extends StatsEstimationTestBase {
    +
    +  /** Set up tables and its columns for testing */
    +  private val columnInfo: AttributeMap[ColumnStat] = AttributeMap(Seq(
    +    attr("key11") -> ColumnStat(distinctCount = 5, min = Some(1), max = 
Some(5), nullCount = 0,
    +      avgLen = 4, maxLen = 4),
    +    attr("key12") -> ColumnStat(distinctCount = 5, min = Some(5), max = 
Some(9), nullCount = 0,
    +      avgLen = 4, maxLen = 4),
    +    attr("key21") -> ColumnStat(distinctCount = 2, min = Some(1), max = 
Some(2), nullCount = 0,
    +      avgLen = 4, maxLen = 4),
    +    attr("key22") -> ColumnStat(distinctCount = 3, min = Some(2), max = 
Some(4), nullCount = 0,
    +      avgLen = 4, maxLen = 4),
    +    attr("key31") -> ColumnStat(distinctCount = 2, min = Some(1), max = 
Some(2), nullCount = 0,
    +      avgLen = 4, maxLen = 4),
    +    attr("key32") -> ColumnStat(distinctCount = 2, min = Some(2), max = 
Some(3), nullCount = 0,
    +      avgLen = 4, maxLen = 4)
    +  ))
    +
    +  private val nameToAttr: Map[String, Attribute] = columnInfo.map(kv => 
kv._1.name -> kv._1)
    +  private val nameToColInfo: Map[String, (Attribute, ColumnStat)] =
    +    columnInfo.map(kv => kv._1.name -> kv)
    +
    +  // Suppose table1 (key11 int, key12 int) has 5 records: (1, 9), (2, 8), 
(3, 7), (4, 6), (5, 5)
    +  private val table1 = StatsTestPlan(
    +    outputList = Seq("key11", "key12").map(nameToAttr),
    +    rowCount = 5,
    +    attributeStats = AttributeMap(Seq("key11", 
"key12").map(nameToColInfo)))
    +
    +  // Suppose table2 (key21 int, key22 int) has 3 records: (1, 2), (2, 3), 
(2, 4)
    +  private val table2 = StatsTestPlan(
    +    outputList = Seq("key21", "key22").map(nameToAttr),
    +    rowCount = 3,
    +    attributeStats = AttributeMap(Seq("key21", 
"key22").map(nameToColInfo)))
    +
    +  // Suppose table3 (key31 int, key32 int) has 2 records: (1, 2), (2, 3)
    +  private val table3 = StatsTestPlan(
    +    outputList = Seq("key31", "key32").map(nameToAttr),
    +    rowCount = 2,
    +    attributeStats = AttributeMap(Seq("key31", 
"key32").map(nameToColInfo)))
    +
    +  test("cross join") {
    +    // table1 (key11 int, key12 int): (1, 9), (2, 8), (3, 7), (4, 6), (5, 
5)
    +    // table2 (key21 int, key22 int): (1, 2), (2, 3), (2, 4)
    +    val join = Join(table1, table2, Cross, None)
    +    val expectedStats = Statistics(
    +      sizeInBytes = 5 * 3 * (8 + 4 * 4),
    +      rowCount = Some(5 * 3),
    +      // Keep the column stat from both sides unchanged.
    +      attributeStats = AttributeMap(Seq("key11", "key12", "key21", 
"key22").map(nameToColInfo)))
    +    assert(join.stats(conf) == expectedStats)
    +  }
    +
    +  test("disjoint inner join") {
    +    // table1 (key11 int, key12 int): (1, 9), (2, 8), (3, 7), (4, 6), (5, 
5)
    +    // table2 (key21 int, key22 int): (1, 2), (2, 3), (2, 4)
    +    // key12 and key22 are disjoint
    +    val join = Join(table1, table2, Inner, Some(
    +      And(EqualTo(nameToAttr("key11"), nameToAttr("key21")),
    --- End diff --
    
    actually we can just use `key12 = key22`, so that it's more different from 
the test `inner join with multiple equi-join keys`


---
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]

Reply via email to