[GitHub] [spark] cloud-fan commented on a diff in pull request #38924: [SPARK-41398][SQL] Relax constraints on Storage-Partitioned Join when partition keys after runtime filtering do not match

2022-12-07 Thread GitBox


cloud-fan commented on code in PR #38924:
URL: https://github.com/apache/spark/pull/38924#discussion_r1041876441


##
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExec.scala:
##
@@ -114,8 +117,21 @@ case class BatchScanExec(
   // return an empty RDD with 1 partition if dynamic filtering removed the 
only split
   sparkContext.parallelize(Array.empty[InternalRow], 1)
 } else {
+  var finalPartitions = filteredPartitions
+
+  outputPartitioning match {
+case p: KeyGroupedPartitioning =>
+  val partitionMapping = finalPartitions.map(s =>
+s.head.asInstanceOf[HasPartitionKey].partitionKey() -> s).toMap
+  finalPartitions = p.partitionValuesOpt.get.map { partKey =>

Review Comment:
   ah then it makes sense to keep it here.



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] cloud-fan commented on a diff in pull request #38924: [SPARK-41398][SQL] Relax constraints on Storage-Partitioned Join when partition keys after runtime filtering do not match

2022-12-06 Thread GitBox


cloud-fan commented on code in PR #38924:
URL: https://github.com/apache/spark/pull/38924#discussion_r1041775153


##
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExec.scala:
##
@@ -114,8 +117,21 @@ case class BatchScanExec(
   // return an empty RDD with 1 partition if dynamic filtering removed the 
only split
   sparkContext.parallelize(Array.empty[InternalRow], 1)
 } else {
+  var finalPartitions = filteredPartitions
+
+  outputPartitioning match {
+case p: KeyGroupedPartitioning =>
+  val partitionMapping = finalPartitions.map(s =>
+s.head.asInstanceOf[HasPartitionKey].partitionKey() -> s).toMap
+  finalPartitions = p.partitionValuesOpt.get.map { partKey =>

Review Comment:
   It's better to centralize the related code.
   
   This empty filling is quite related to the `if (oldRows.size < 
newRows.size)` check. We should put them together if possible



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] cloud-fan commented on a diff in pull request #38924: [SPARK-41398][SQL] Relax constraints on Storage-Partitioned Join when partition keys after runtime filtering do not match

2022-12-06 Thread GitBox


cloud-fan commented on code in PR #38924:
URL: https://github.com/apache/spark/pull/38924#discussion_r1041775153


##
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExec.scala:
##
@@ -114,8 +117,21 @@ case class BatchScanExec(
   // return an empty RDD with 1 partition if dynamic filtering removed the 
only split
   sparkContext.parallelize(Array.empty[InternalRow], 1)
 } else {
+  var finalPartitions = filteredPartitions
+
+  outputPartitioning match {
+case p: KeyGroupedPartitioning =>
+  val partitionMapping = finalPartitions.map(s =>
+s.head.asInstanceOf[HasPartitionKey].partitionKey() -> s).toMap
+  finalPartitions = p.partitionValuesOpt.get.map { partKey =>

Review Comment:
   It's better to centralize the related code.



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] cloud-fan commented on a diff in pull request #38924: [SPARK-41398][SQL] Relax constraints on Storage-Partitioned Join when partition keys after runtime filtering do not match

2022-12-06 Thread GitBox


cloud-fan commented on code in PR #38924:
URL: https://github.com/apache/spark/pull/38924#discussion_r1041721325


##
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExec.scala:
##
@@ -114,8 +117,21 @@ case class BatchScanExec(
   // return an empty RDD with 1 partition if dynamic filtering removed the 
only split
   sparkContext.parallelize(Array.empty[InternalRow], 1)
 } else {
+  var finalPartitions = filteredPartitions
+
+  outputPartitioning match {
+case p: KeyGroupedPartitioning =>
+  val partitionMapping = finalPartitions.map(s =>
+s.head.asInstanceOf[HasPartitionKey].partitionKey() -> s).toMap
+  finalPartitions = p.partitionValuesOpt.get.map { partKey =>

Review Comment:
   shall we move this logic to `lazy val filteredPartitions`?



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] cloud-fan commented on a diff in pull request #38924: [SPARK-41398][SQL] Relax constraints on Storage-Partitioned Join when partition keys after runtime filtering do not match

2022-12-06 Thread GitBox


cloud-fan commented on code in PR #38924:
URL: https://github.com/apache/spark/pull/38924#discussion_r1041671515


##
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/BatchScanExec.scala:
##
@@ -81,18 +81,21 @@ case class BatchScanExec(
 
   val newRows = new InternalRowSet(p.expressions.map(_.dataType))
   newRows ++= 
newPartitions.map(_.asInstanceOf[HasPartitionKey].partitionKey())
-  val oldRows = p.partitionValuesOpt.get
 
-  if (oldRows.size != newRows.size) {
-throw new SparkException("Data source must have preserved the 
original partitioning " +
-"during runtime filtering: the number of unique partition 
values obtained " +
-s"through HasPartitionKey changed: before ${oldRows.size}, 
after ${newRows.size}")
+  val oldRows = p.partitionValuesOpt.get.toSet

Review Comment:
   shall we use `InternalRowSet`?



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org