comphead commented on PR #2258:
URL:
https://github.com/apache/datafusion-comet/pull/2258#issuecomment-3316131986
For Spark it can be something like
```
val schema = StructType(Seq(
StructField("region", StringType, true),
StructField("user_id", IntegerType, true),
StructField("age", IntegerType, true)
))
// Data with duplicates
val data = Seq(
Row("us", 1: Integer, 30: Integer),
Row("us", 2: Integer, 30: Integer),
Row("us", 3: Integer, 30: Integer),
Row("eu", 4: Integer, 20: Integer),
Row("eu", 5: Integer, 20: Integer),
Row("apac", 6: Integer, 25: Integer),
Row("apac", 7: Integer, 25: Integer),
Row("apac", 8: Integer, 25: Integer),
Row("apac", 9: Integer, 25: Integer)
)
val df = spark.createDataFrame(
spark.sparkContext.parallelize(data),
schema
)
// Range repartition into 3 partitions
val repartitioned = df.repartitionByRange(
3,
df("region").asc,
df("age").asc
)
// Print partition contents
repartitioned.rdd.mapPartitionsWithIndex { case (i, iter) =>
Iterator(s"--- Partition $i ---\n" + iter.mkString("\n"))
}.collect().foreach(println) <---- here we can assert
```
To check data distribution including duplicates
--
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]