Github user marmbrus commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1134#discussion_r14678203
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/joins.scala ---
    @@ -400,3 +401,73 @@ case class BroadcastNestedLoopJoin(
           streamedPlusMatches.flatMap(_._1), 
sqlContext.sparkContext.makeRDD(rightOuterMatches))
       }
     }
    +
    +/**
    + * :: DeveloperApi ::
    + * In some case ,data skew happens.SkewJoin  sample the table rdd to find 
the largest key,
    + * then make the largest key rows as a table rdd.The left rdd will be made 
 leftSkewedtable
    + * rdd without the largest key and the maxkeyskewedtable rdd with the 
largest key.
    + *  Then,join the two table  with the righttable.
    + * Finally,union the two result rdd.
    + */
    +@DeveloperApi
    +case class SkewJoinCartesianProduct(
    +    left: SparkPlan,
    +    right: SparkPlan,
    +    condition: Option[Expression])(@transient sc: SparkContext) extends 
BinaryNode {
    +  override def output = left.output ++ right.output
    +
    +  @transient lazy val boundCondition =
    +    InterpretedPredicate(
    +      condition
    +              .map(c => BindReferences.bindReference(c, left.output ++ 
right.output))
    +              .getOrElse(Literal(true)))
    +
    +  def execute() = {
    +
    +    val skewedTable = left.execute()
    +    //This will later write as configuration
    +    val sample = skewedTable.sample(false, 0.3, 9).collect()
    +    val sortedSample = sample.sortWith((row1, row2) => row1.hashCode() > 
row2.hashCode())
    +    var max = 0
    +    var num = sample.size - 1
    +    var temp = 0
    +    var maxrowKey = sortedSample(0)
    +    //find the largest key
    +    if (sortedSample.size > 1) {
    +      for (i <- 1 to num) {
    +        if (sortedSample(i - 1) == sortedSample(i)) {
    +          temp += 1
    +        }
    +        else {
    +          if (temp > max) {
    +            max = temp
    +            maxrowKey = sortedSample(i - 1)
    +          }
    +          temp = 0
    +        }
    +      }
    +    }
    +    // I also Send a Pull Request as RDD API span fun to offer the 
function 
    +    //split a RDD as two through span function
    +    // .https://github.com/apache/spark/pull/1306
    +    //    val (maxKeySkewedTable, mainSkewedTable) = skewedTable.span(row 
=> {
    +    //      
skewSideKeyGenerator(row).toString().equals(maxrowKey.toString())
    +    //    })
    +    val maxKeySkewedTable = skewedTable.filter(row => {
    +      row.toString().equals(maxrowKey.toString())
    --- End diff --
    
    Why are you comparing the strings of the rows instead of the rows 
themselves?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to