[GitHub] [carbondata] ravipesala commented on a change in pull request #3182: [CARBONDATA-3343] Compaction for Range Sort

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] [carbondata] ravipesala commented on a change in pull request #3182: [CARBONDATA-3343] Compaction for Range Sort

GitBox
ravipesala commented on a change in pull request #3182: [CARBONDATA-3343] Compaction for Range Sort
URL: https://github.com/apache/carbondata/pull/3182#discussion_r277669012
 
 

 ##########
 File path: integration/spark-common/src/main/scala/org/apache/spark/DataSkewRangePartitioner.scala
 ##########
 @@ -129,47 +131,68 @@ class DataSkewRangePartitioner[K: Ordering : ClassTag, V](
           val weight = (1.0 / fraction).toFloat
           candidates ++= reSampled.map(x => (x, weight))
         }
-        determineBounds(candidates, partitions)
+        // In case of compaction we do not need the skew handled ranges so we use RangePartitioner,
+        // but we require the overall minmax for creating the separate ranges.
+        // withoutSkew = true for Compaction only
+        if (withoutSkew == false) {
+          determineBounds(candidates, partitions, false)
+        } else {
+          var ranges = RangePartitioner.determineBounds(candidates, partitions)
+          var otherRangeParams = determineBounds(candidates, partitions, true)
+          (ranges, otherRangeParams._2, otherRangeParams._3,
+            otherRangeParams._4, otherRangeParams._5)
+        }
       }
     }
   }
 
   def determineBounds(
       candidates: ArrayBuffer[(K, Float)],
-      partitions: Int): (Array[K], Int, Array[Int], Array[Int]) = {
+      partitions: Int,
+      withoutSkew: Boolean): (Array[K], Int, Array[Int], Array[Int], Array[K]) = {
     val ordered = candidates.sortBy(_._1)
     val numCandidates = ordered.size
-    val sumWeights = ordered.map(_._2.toDouble).sum
-    val step = sumWeights / partitions
-    var cumWeight = 0.0
-    var target = step
-    val bounds = ArrayBuffer.empty[K]
-    var i = 0
-    var j = 0
-    var previousBound = Option.empty[K]
-    while ((i < numCandidates) && (j < partitions - 1)) {
-      val (key, weight) = ordered(i)
-      cumWeight += weight
-      if (cumWeight >= target) {
-        // Skip duplicate values.
-        if (previousBound.isEmpty || ordering.gteq(key, previousBound.get)) {
-          bounds += key
-          target += step
-          j += 1
-          previousBound = Some(key)
+    var minMax = new Array[K](2)
+    if (numCandidates > 0) {
+      minMax(0) = ordered(0)._1
+      minMax(1) = ordered(numCandidates - 1)._1
+    }
+    if (withoutSkew == true) {
 
 Review comment:
   Just write `if (withoutSkew)`

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services