You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "goutamadwant (via GitHub)" <gi...@apache.org> on 2026/08/29 03:59:18 UTC

[PR] feat: allow scaling RangePartitioning [datafusion]

goutamadwant opened a new pull request, #24766:
URL: https://github.com/apache/datafusion/pull/24766

   ## Which issue does this PR close?
   
   - Closes #24712.
   
   ## Rationale for this change
   
   Distributed and adaptive planners need to lower a range-partitioned plan's task count without discarding its higher-resolution boundary sample. Today scaling loses the range layout and falls back to unknown partitioning.
   
   ## What changes are included in this PR?
   
   - Add validated sample-backed construction, fallible scaling, and sample/current/max partition-count accessors while preserving existing exact construction and the borrowed `split_points()` API.
   - Cache deterministic effective split points and retain the shared maximum-resolution sample through projection, repartition, and join partitioning rewrites.
   - Preserve sample metadata through physical protobuf and FFI round trips.
   - Keep protobuf field 2 as the effective split points for older readers, while new readers validate the sample/count representation against it.
   
   ## Are these changes tested?
   
   Yes. Tests cover deterministic scaling and invalid counts, equality by effective boundaries, projection and plan rewrites, legacy/current/malformed protobuf payloads, and FFI unit and cross-library round trips. The full required workspace test suite and workspace-wide clippy with all targets and features passed. After refreshing the unchanged patch to current `main`, the focused `RangePartitioning` tests passed again.
   
   ## Are there any user-facing changes?
   
   Yes. `RangePartitioning` gains `try_new_with_samples`, `samples`, `max_partition_count`, and `scale`. Existing exact construction and `split_points()` callers remain source-compatible.
   
   `FFI_RangePartitioning` now carries samples and the current partition count, so this PR requires the `api change` label.


-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "goutamadwant (via GitHub)" <gi...@apache.org>.
goutamadwant commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4079721602


##########
datafusion/physical-optimizer/src/ensure_requirements/enforce_distribution.rs:
##########
@@ -1154,7 +1157,8 @@ fn enforce_distribution_relationships(
                 let partitioning = plan.output_partitioning();
                 match partitioning {
                     Partitioning::Range(_) | Partitioning::Hash(_, _) => {
-                        let is_native = !plan.is::<RepartitionExec>();
+                        let is_native =
+                            !plan.is::<RepartitionExec>() || child.scaled_native_range;

Review Comment:
   done @stuhood thanks for this input.



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "goutamadwant (via GitHub)" <gi...@apache.org>.
goutamadwant commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4079726001


##########
datafusion/physical-optimizer/src/ensure_requirements/enforce_distribution.rs:
##########
@@ -1194,11 +1198,9 @@ fn enforce_distribution_relationships(
                         })
                         .collect();
 
-                    // Only select a reference candidate if there is a unique, strictly
-                    // larger winner (`size_a > size_b`). If candidates have equal or
-                    // incomparable sizes (e.g. non-overlapping metrics), return None
-                    // so the optimizer avoids arbitrary tie-breaking and falls back to
-                    // standard distribution.
+                    // Prefer a unique, strictly larger winner (`size_a > size_b`).
+                    // Otherwise avoid arbitrary tie-breaking, except for the new
+                    // preserved-range case below.

Review Comment:
   right @stuhood.i removed the stale preserved-range exception from that comment. It now describes the actual choice: use a uniquely larger reference when one exists; otherwise use standard distribution.



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "stuhood (via GitHub)" <gi...@apache.org>.
stuhood commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4009549520


##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -234,19 +248,75 @@ impl RangePartitioning {
         Ok(Self::new(ordering, split_points))
     }
 
+    /// Creates sample-backed range partitioning and validates the sample shape,
+    /// ordering, and target partition count.
+    ///
+    /// `partition_count` must be at least one and no larger than
+    /// `samples.len() + 1`. When it is smaller than that maximum, the samples
+    /// are evenly down-sampled to derive the effective split points.
+    pub fn try_new_with_samples(
+        ordering: LexOrdering,
+        samples: Vec<SplitPoint>,
+        partition_count: usize,
+    ) -> Result<Self> {
+        validate_range_split_points(
+            &samples,
+            &ordering
+                .iter()
+                .map(|sort_expr| sort_expr.options)
+                .collect::<Vec<_>>(),
+        )?;
+        validate_range_partition_count(partition_count, samples.len() + 1)?;
+        let samples: Arc<[SplitPoint]> = Arc::from(samples);
+        let split_points = downsample_split_points(&samples, partition_count);
+        Ok(Self {
+            ordering,
+            samples,
+            split_points,
+            partition_count,
+        })
+    }
+
     /// Returns the ordering that defines the range key.
     pub fn ordering(&self) -> &LexOrdering {
         &self.ordering
     }
 
-    /// Returns the ordered split points between partitions.
+    /// Returns the maximum-resolution sample points.
+    pub fn samples(&self) -> &[SplitPoint] {
+        &self.samples
+    }
+
+    /// Returns the effective split points between partitions.
     pub fn split_points(&self) -> &[SplitPoint] {
         &self.split_points
     }
 
     /// Returns the number of partitions.
     pub fn partition_count(&self) -> usize {
-        self.split_points.len() + 1
+        self.partition_count
+    }
+
+    /// Returns the largest partition count supported by the stored samples.
+    pub fn max_partition_count(&self) -> usize {
+        self.samples.len() + 1
+    }
+
+    /// Returns this range partitioning scaled to `target_partitions`.
+    ///
+    /// Scaling retains the original samples, so a range partitioning that was
+    /// scaled down can later be scaled back up to [`Self::max_partition_count`].
+    pub fn scale(&self, target_partitions: usize) -> Result<Self> {
+        validate_range_partition_count(target_partitions, self.max_partition_count())?;
+        if target_partitions == self.partition_count {
+            return Ok(self.clone());
+        }
+        Ok(Self {
+            ordering: self.ordering.clone(),
+            samples: Arc::clone(&self.samples),
+            split_points: downsample_split_points(&self.samples, target_partitions),
+            partition_count: target_partitions,
+        })
     }

Review Comment:
   So, the case where we don't have enough samples to scale up to a particular `target_partition` count should be treated more like an expected case rather than a failure. Ideally we would always have enough samples to do this... but in cases where we don't (small tables, etc), it is definitely a recoverable case, and callers should convert the `Partitioning::Range` into something else... e.g. `Partitioning::Unknown`.
   
   So rather than returning `Result<Self>`, maybe this should return `Option<Self>`? Alternatively, it could return a `Result<Self, ScalingError>` (name TBD) that allows the caller to differentiate failure cases.



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#issuecomment-5460310566

   ## [Codecov](https://app.codecov.io/gh/apache/datafusion/pull/24766?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `80.74074%` with `78 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 81.50%. Comparing base ([`c56a7ab`](https://app.codecov.io/gh/apache/datafusion/commit/c56a7ab824bc70635344d38208c7139145fd00b0?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`afb7b33`](https://app.codecov.io/gh/apache/datafusion/commit/afb7b33f93b6842a60cbe7257a31aaa2229f669c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 6 commits behind head on main.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/datafusion/pull/24766?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [datafusion/physical-expr/src/partitioning.rs](https://app.codecov.io/gh/apache/datafusion/pull/24766?src=pr&el=tree&filepath=datafusion%2Fphysical-expr%2Fsrc%2Fpartitioning.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9waHlzaWNhbC1leHByL3NyYy9wYXJ0aXRpb25pbmcucnM=) | 86.26% | [15 Missing and 24 partials :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/24766?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [datafusion/proto-models/src/generated/pbjson.rs](https://app.codecov.io/gh/apache/datafusion/pull/24766?src=pr&el=tree&filepath=datafusion%2Fproto-models%2Fsrc%2Fgenerated%2Fpbjson.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9wcm90by1tb2RlbHMvc3JjL2dlbmVyYXRlZC9wYmpzb24ucnM=) | 0.00% | [26 Missing :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/24766?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [datafusion/ffi/src/physical\_expr/partitioning.rs](https://app.codecov.io/gh/apache/datafusion/pull/24766?src=pr&el=tree&filepath=datafusion%2Fffi%2Fsrc%2Fphysical_expr%2Fpartitioning.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9mZmkvc3JjL3BoeXNpY2FsX2V4cHIvcGFydGl0aW9uaW5nLnJz) | 82.05% | [3 Missing and 4 partials :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/24766?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [datafusion/ffi/src/plan\_properties.rs](https://app.codecov.io/gh/apache/datafusion/pull/24766?src=pr&el=tree&filepath=datafusion%2Fffi%2Fsrc%2Fplan_properties.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9mZmkvc3JjL3BsYW5fcHJvcGVydGllcy5ycw==) | 75.00% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/24766?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [datafusion/physical-plan/src/joins/utils.rs](https://app.codecov.io/gh/apache/datafusion/pull/24766?src=pr&el=tree&filepath=datafusion%2Fphysical-plan%2Fsrc%2Fjoins%2Futils.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9waHlzaWNhbC1wbGFuL3NyYy9qb2lucy91dGlscy5ycw==) | 92.85% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/24766?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [datafusion/physical-plan/src/repartition/mod.rs](https://app.codecov.io/gh/apache/datafusion/pull/24766?src=pr&el=tree&filepath=datafusion%2Fphysical-plan%2Fsrc%2Frepartition%2Fmod.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9waHlzaWNhbC1wbGFuL3NyYy9yZXBhcnRpdGlvbi9tb2QucnM=) | 86.66% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/24766?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@            Coverage Diff             @@
   ##             main   #24766      +/-   ##
   ==========================================
   + Coverage   81.47%   81.50%   +0.03%     
   ==========================================
     Files        1122     1123       +1     
     Lines      404140   405437    +1297     
     Branches   404140   405437    +1297     
   ==========================================
   + Hits       329284   330470    +1186     
   - Misses      55546    55616      +70     
   - Partials    19310    19351      +41     
   ```
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/datafusion/pull/24766?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "stuhood (via GitHub)" <gi...@apache.org>.
stuhood commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4009816931


##########
datafusion/physical-expr/src/partitioning.rs:
##########


Review Comment:
   The fact that `PartialEq` is derived here is going to confuse callers: `enforce_distribution_relationships` uses equality to check whether two `RangePartitioning` instances are compatible. The `samples` should not actually be included in that equality check: only the `split_points`.
   
   There are two schools of thought on that, and I don't know which DataFusion prefers:
   * School 1: `PartialEq` should always represent structural equality, and so should basically always be derived. Other definitions of equality should be provided by other methods.
   * School 2: `PartialEq` should be the most useful definition of equality, even if that is not structural.
   
   I expect that @gene-bordegaray has an opinion on this one.



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r3888208431


##########
datafusion/physical-expr/src/partitioning.rs:
##########


Review Comment:
   Range([a@0 ASC], [(30), (50), (70)], 4) is identical for a partitioning that can scale to 10 and one that can't scale past 4. Since EXPLAIN output is the primary debugging surface for partitioning bugs, appending the max when it differs (e.g. , max 10) would pay for itself.



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "stuhood (via GitHub)" <gi...@apache.org>.
stuhood commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4009549520


##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -234,19 +248,75 @@ impl RangePartitioning {
         Ok(Self::new(ordering, split_points))
     }
 
+    /// Creates sample-backed range partitioning and validates the sample shape,
+    /// ordering, and target partition count.
+    ///
+    /// `partition_count` must be at least one and no larger than
+    /// `samples.len() + 1`. When it is smaller than that maximum, the samples
+    /// are evenly down-sampled to derive the effective split points.
+    pub fn try_new_with_samples(
+        ordering: LexOrdering,
+        samples: Vec<SplitPoint>,
+        partition_count: usize,
+    ) -> Result<Self> {
+        validate_range_split_points(
+            &samples,
+            &ordering
+                .iter()
+                .map(|sort_expr| sort_expr.options)
+                .collect::<Vec<_>>(),
+        )?;
+        validate_range_partition_count(partition_count, samples.len() + 1)?;
+        let samples: Arc<[SplitPoint]> = Arc::from(samples);
+        let split_points = downsample_split_points(&samples, partition_count);
+        Ok(Self {
+            ordering,
+            samples,
+            split_points,
+            partition_count,
+        })
+    }
+
     /// Returns the ordering that defines the range key.
     pub fn ordering(&self) -> &LexOrdering {
         &self.ordering
     }
 
-    /// Returns the ordered split points between partitions.
+    /// Returns the maximum-resolution sample points.
+    pub fn samples(&self) -> &[SplitPoint] {
+        &self.samples
+    }
+
+    /// Returns the effective split points between partitions.
     pub fn split_points(&self) -> &[SplitPoint] {
         &self.split_points
     }
 
     /// Returns the number of partitions.
     pub fn partition_count(&self) -> usize {
-        self.split_points.len() + 1
+        self.partition_count
+    }
+
+    /// Returns the largest partition count supported by the stored samples.
+    pub fn max_partition_count(&self) -> usize {
+        self.samples.len() + 1
+    }
+
+    /// Returns this range partitioning scaled to `target_partitions`.
+    ///
+    /// Scaling retains the original samples, so a range partitioning that was
+    /// scaled down can later be scaled back up to [`Self::max_partition_count`].
+    pub fn scale(&self, target_partitions: usize) -> Result<Self> {
+        validate_range_partition_count(target_partitions, self.max_partition_count())?;
+        if target_partitions == self.partition_count {
+            return Ok(self.clone());
+        }
+        Ok(Self {
+            ordering: self.ordering.clone(),
+            samples: Arc::clone(&self.samples),
+            split_points: downsample_split_points(&self.samples, target_partitions),
+            partition_count: target_partitions,
+        })
     }

Review Comment:
   So, the case where we don't have enough samples to scale up to a particular `target_partition` count should be treated more like an expected case rather than a failure. Ideally we would always have enough samples to do this... but in cases where we don't (small tables, etc), it is definitely a recoverable case, and callers should convert the `Partitioning::Range` into something else... e.g. `Partitioning::Unknown`.
   
   So rather than returning `Result<Self>`, maybe this should return `Option<Self>`? Alternatively, it could return a `Result<Self, ScalingError>` that allows the caller to differentiate failure cases.



##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -234,19 +248,75 @@ impl RangePartitioning {
         Ok(Self::new(ordering, split_points))
     }
 
+    /// Creates sample-backed range partitioning and validates the sample shape,
+    /// ordering, and target partition count.
+    ///
+    /// `partition_count` must be at least one and no larger than
+    /// `samples.len() + 1`. When it is smaller than that maximum, the samples
+    /// are evenly down-sampled to derive the effective split points.
+    pub fn try_new_with_samples(
+        ordering: LexOrdering,
+        samples: Vec<SplitPoint>,
+        partition_count: usize,
+    ) -> Result<Self> {

Review Comment:
   This looks good. But I think that we should go ahead and deprecate the old constructor, and have all existing callers switch to a method like `RangePartitioning::try_new_with_samples`. `RangePartitioning::new` will create something which cannot be scaled, and that's much less useful.
   
   In terms of the number of samples for callers to provide to `try_new_with_samples`: we might want to recommend something like `K * target_partitions`, where `K` is some value that we expect will give us enough flexibility to actually scale things for the relevant number of partitions.



##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -205,8 +211,12 @@ impl Display for Partitioning {
 pub struct RangePartitioning {
     /// Ordered partitioning key.
     ordering: LexOrdering,
-    /// Boundaries between adjacent partitions.
-    split_points: Vec<SplitPoint>,
+    /// Maximum-resolution boundaries used to derive split points.
+    samples: Arc<[SplitPoint]>,
+    /// Effective boundaries for the current partition count.
+    split_points: Arc<[SplitPoint]>,
+    /// Number of effective partitions.
+    partition_count: usize,

Review Comment:
   The `partition_count` can be derived from `split_points.len() + 1`, so it doesn't need to be stored.



##########
datafusion/physical-expr/src/partitioning.rs:
##########


Review Comment:
   The fact that `PartialEq` is derived here is going to confuse callers: `enforce_distribution_relationships` uses equality to check whether two `RangePartitioning` instances are compatible. The `samples` should not actually be included in that equality check: only the `split_points`.
   
   There are two schools of though on that, and I don't know which DataFusion prefers:
   * School 1: `PartialEq` should always represent structural equality, and so should basically always be derived. Other definitions of equality should be provided by other methods.
   * School 2: `PartialEq` should be the most useful definition of equality, even if that is not structural.
   
   I expect that @gene-bordegaray has an opinion on this one.



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "goutamadwant (via GitHub)" <gi...@apache.org>.
goutamadwant commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4011135687


##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -234,19 +248,75 @@ impl RangePartitioning {
         Ok(Self::new(ordering, split_points))
     }
 
+    /// Creates sample-backed range partitioning and validates the sample shape,
+    /// ordering, and target partition count.
+    ///
+    /// `partition_count` must be at least one and no larger than
+    /// `samples.len() + 1`. When it is smaller than that maximum, the samples
+    /// are evenly down-sampled to derive the effective split points.
+    pub fn try_new_with_samples(
+        ordering: LexOrdering,
+        samples: Vec<SplitPoint>,
+        partition_count: usize,
+    ) -> Result<Self> {
+        validate_range_split_points(
+            &samples,
+            &ordering
+                .iter()
+                .map(|sort_expr| sort_expr.options)
+                .collect::<Vec<_>>(),
+        )?;
+        validate_range_partition_count(partition_count, samples.len() + 1)?;
+        let samples: Arc<[SplitPoint]> = Arc::from(samples);
+        let split_points = downsample_split_points(&samples, partition_count);
+        Ok(Self {
+            ordering,
+            samples,
+            split_points,
+            partition_count,
+        })
+    }
+
     /// Returns the ordering that defines the range key.
     pub fn ordering(&self) -> &LexOrdering {
         &self.ordering
     }
 
-    /// Returns the ordered split points between partitions.
+    /// Returns the maximum-resolution sample points.
+    pub fn samples(&self) -> &[SplitPoint] {
+        &self.samples
+    }
+
+    /// Returns the effective split points between partitions.
     pub fn split_points(&self) -> &[SplitPoint] {
         &self.split_points
     }
 
     /// Returns the number of partitions.
     pub fn partition_count(&self) -> usize {
-        self.split_points.len() + 1
+        self.partition_count
+    }
+
+    /// Returns the largest partition count supported by the stored samples.
+    pub fn max_partition_count(&self) -> usize {
+        self.samples.len() + 1
+    }
+
+    /// Returns this range partitioning scaled to `target_partitions`.
+    ///
+    /// Scaling retains the original samples, so a range partitioning that was
+    /// scaled down can later be scaled back up to [`Self::max_partition_count`].
+    pub fn scale(&self, target_partitions: usize) -> Result<Self> {
+        validate_range_partition_count(target_partitions, self.max_partition_count())?;
+        if target_partitions == self.partition_count {
+            return Ok(self.clone());
+        }
+        Ok(Self {
+            ordering: self.ordering.clone(),
+            samples: Arc::clone(&self.samples),
+            split_points: downsample_split_points(&self.samples, target_partitions),
+            partition_count: target_partitions,
+        })
     }

Review Comment:
   @stuhood changed scale to return a typed RangePartitioningScaleError, distinguishing InsufficientSamples from ZeroPartitions. EnsureRequirements retains a satisfying range when capacity is insufficient; other callers can choose their own fallback without parsing error strings.



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "goutamadwant (via GitHub)" <gi...@apache.org>.
goutamadwant commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4011146518


##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -205,8 +211,12 @@ impl Display for Partitioning {
 pub struct RangePartitioning {
     /// Ordered partitioning key.
     ordering: LexOrdering,
-    /// Boundaries between adjacent partitions.
-    split_points: Vec<SplitPoint>,
+    /// Maximum-resolution boundaries used to derive split points.
+    samples: Arc<[SplitPoint]>,
+    /// Effective boundaries for the current partition count.
+    split_points: Arc<[SplitPoint]>,
+    /// Number of effective partitions.
+    partition_count: usize,

Review Comment:
   makes sense @stuhood removed the stored partition_count field; it is now derived from split_points.len() + 1. Protobuf and FFI still retain the effective count needed to reconstruct the selected layout from the stored samples.



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "stuhood (via GitHub)" <gi...@apache.org>.
stuhood commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4067528351


##########
datafusion/physical-optimizer/src/ensure_requirements/enforce_distribution.rs:
##########
@@ -1154,7 +1157,8 @@ fn enforce_distribution_relationships(
                 let partitioning = plan.output_partitioning();
                 match partitioning {
                     Partitioning::Range(_) | Partitioning::Hash(_, _) => {
-                        let is_native = !plan.is::<RepartitionExec>();
+                        let is_native =
+                            !plan.is::<RepartitionExec>() || child.scaled_native_range;

Review Comment:
   We shouldn't treat a node which has been scaled with `RepartitionExec` as "natively partitioned": this pass is about finding sources which already satisfy the constraints, without the addition of a `RepartitionExec`.
   
   Unless a node can be scaled with `ExecutionPlan::repartitioned`, we shouldn't consider it to be natively partitioned here, as that will prioritize adapting some other data source to match this one.
   
   It's possible that after #25483 we might consider a `Range` which has been scaled with `Range` to be preferable to something that has been hashed... but right now I don't think that makes sense.
   
   So probably `scaled_native_range` should be removed entirely.



##########
datafusion/physical-optimizer/src/ensure_requirements/enforce_distribution.rs:
##########
@@ -1194,11 +1198,9 @@ fn enforce_distribution_relationships(
                         })
                         .collect();
 
-                    // Only select a reference candidate if there is a unique, strictly
-                    // larger winner (`size_a > size_b`). If candidates have equal or
-                    // incomparable sizes (e.g. non-overlapping metrics), return None
-                    // so the optimizer avoids arbitrary tie-breaking and falls back to
-                    // standard distribution.
+                    // Prefer a unique, strictly larger winner (`size_a > size_b`).
+                    // Otherwise avoid arbitrary tie-breaking, except for the new
+                    // preserved-range case below.

Review Comment:
   Stale I think.



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "gene-bordegaray (via GitHub)" <gi...@apache.org>.
gene-bordegaray commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4094836864


##########
datafusion/ffi/src/physical_expr/partitioning.rs:
##########
@@ -174,13 +180,28 @@ mod tests {
         )?))
     }
 
+    fn sampled_range_partitioning() -> Result<Partitioning> {
+        let ordering = LexOrdering::new([PhysicalSortExpr::new_default(Arc::new(
+            Column::new("a", 0),
+        ))])
+        .expect("non-empty ordering");
+        let samples = [10, 20, 30, 40, 50]
+            .into_iter()
+            .map(|value| SplitPoint::new(vec![ScalarValue::Int64(Some(value))]))
+            .collect();
+        Ok(Partitioning::Range(
+            RangePartitioning::try_new_with_samples(ordering, samples, 3)?,
+        ))
+    }

Review Comment:
   is this needed with the test below?



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#issuecomment-5460231454

   <!-- semver-check-comment -->
   Thank you for opening this pull request!
   
   Reviewer note: [cargo-semver-checks](https://github.com/obi1kenobi/cargo-semver-checks) reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch).
   
   <details>
   <summary>Details</summary>
   
   ```
        Cloning apache/main
       Building datafusion-ffi v55.0.0 (current)
          Built [  55.303s] (current)
        Parsing datafusion-ffi v55.0.0 (current)
         Parsed [   0.062s] (current)
       Building datafusion-ffi v55.0.0 (baseline)
          Built [  55.068s] (baseline)
        Parsing datafusion-ffi v55.0.0 (baseline)
         Parsed [   0.061s] (baseline)
       Checking datafusion-ffi v55.0.0 -> v55.0.0 (no change; assume patch)
        Checked [   0.262s] 223 checks: 221 pass, 1 fail, 1 warn, 31 skip
   
   --- failure constructible_struct_adds_field: struct exhaustively constructible through public API adds field ---
   
   Description:
   A pub struct that could be exhaustively constructed with a literal using only public API has a new pub field, breaking existing exhaustive literals.
           ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
          impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.50.0/src/lints/constructible_struct_adds_field.ron
   
   Failed in:
     field ForeignLibraryModule.create_exec_with_range_partitioning in /home/runner/work/datafusion/datafusion/datafusion/ffi/src/tests/mod.rs:126
   
   --- warning repr_c_plain_struct_fields_reordered: struct fields reordered in repr(C) struct ---
   
   Description:
   A public repr(C) struct had its fields reordered. This can change the struct's memory layout, possibly breaking FFI use cases that depend on field position and order.
           ref: https://doc.rust-lang.org/reference/type-layout.html#reprc-structs
          impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.50.0/src/lints/repr_c_plain_struct_fields_reordered.ron
   
   Failed in:
     ForeignLibraryModule.create_table_with_statistics moved from position 18 to 19, in /home/runner/work/datafusion/datafusion/datafusion/ffi/src/tests/mod.rs:128
     ForeignLibraryModule.create_physical_optimizer_rule moved from position 19 to 20, in /home/runner/work/datafusion/datafusion/datafusion/ffi/src/tests/mod.rs:131
     ForeignLibraryModule.create_context_aware_optimizer_rule moved from position 20 to 21, in /home/runner/work/datafusion/datafusion/datafusion/ffi/src/tests/mod.rs:133
     ForeignLibraryModule.create_query_planner moved from position 21 to 22, in /home/runner/work/datafusion/datafusion/datafusion/ffi/src/tests/mod.rs:137
     ForeignLibraryModule.version moved from position 22 to 23, in /home/runner/work/datafusion/datafusion/datafusion/ffi/src/tests/mod.rs:143
     ForeignLibraryModule.create_first_value_udaf moved from position 23 to 24, in /home/runner/work/datafusion/datafusion/datafusion/ffi/src/tests/mod.rs:146
   
        Summary semver requires new major version: 1 major and 0 minor checks failed
        Warning produced 1 major and 0 minor level warnings
       Finished [ 113.258s] datafusion-ffi
       Building datafusion-physical-expr v55.0.0 (current)
          Built [  29.959s] (current)
        Parsing datafusion-physical-expr v55.0.0 (current)
         Parsed [   0.049s] (current)
       Building datafusion-physical-expr v55.0.0 (baseline)
          Built [  29.991s] (baseline)
        Parsing datafusion-physical-expr v55.0.0 (baseline)
         Parsed [   0.050s] (baseline)
       Checking datafusion-physical-expr v55.0.0 -> v55.0.0 (no change; assume patch)
        Checked [   0.332s] 223 checks: 223 pass, 31 skip
        Summary no semver update required
       Finished [  61.509s] datafusion-physical-expr
       Building datafusion-physical-plan v55.0.0 (current)
          Built [  40.188s] (current)
        Parsing datafusion-physical-plan v55.0.0 (current)
         Parsed [   0.156s] (current)
       Building datafusion-physical-plan v55.0.0 (baseline)
          Built [  39.722s] (baseline)
        Parsing datafusion-physical-plan v55.0.0 (baseline)
         Parsed [   0.153s] (baseline)
       Checking datafusion-physical-plan v55.0.0 -> v55.0.0 (no change; assume patch)
        Checked [   0.668s] 223 checks: 223 pass, 31 skip
        Summary no semver update required
       Finished [  82.256s] datafusion-physical-plan
       Building datafusion-proto-models v55.0.0 (current)
          Built [  26.110s] (current)
        Parsing datafusion-proto-models v55.0.0 (current)
         Parsed [   0.133s] (current)
       Building datafusion-proto-models v55.0.0 (baseline)
          Built [  25.783s] (baseline)
        Parsing datafusion-proto-models v55.0.0 (baseline)
         Parsed [   0.132s] (baseline)
       Checking datafusion-proto-models v55.0.0 -> v55.0.0 (no change; assume patch)
        Checked [   1.749s] 223 checks: 222 pass, 1 fail, 0 warn, 31 skip
   
   --- failure constructible_struct_adds_field: struct exhaustively constructible through public API adds field ---
   
   Description:
   A pub struct that could be exhaustively constructed with a literal using only public API has a new pub field, breaking existing exhaustive literals.
           ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
          impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.50.0/src/lints/constructible_struct_adds_field.ron
   
   Failed in:
     field PhysicalRangePartitioning.sample_point in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:2371
     field PhysicalRangePartitioning.partition_count in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:2374
     field PhysicalRangePartitioning.sample_point in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:2371
     field PhysicalRangePartitioning.partition_count in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:2374
   
        Summary semver requires new major version: 1 major and 0 minor checks failed
       Finished [  55.523s] datafusion-proto-models
   ```
   
   </details>


-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "stuhood (via GitHub)" <gi...@apache.org>.
stuhood commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4033306103


##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -234,19 +248,75 @@ impl RangePartitioning {
         Ok(Self::new(ordering, split_points))
     }
 
+    /// Creates sample-backed range partitioning and validates the sample shape,
+    /// ordering, and target partition count.
+    ///
+    /// `partition_count` must be at least one and no larger than
+    /// `samples.len() + 1`. When it is smaller than that maximum, the samples
+    /// are evenly down-sampled to derive the effective split points.
+    pub fn try_new_with_samples(
+        ordering: LexOrdering,
+        samples: Vec<SplitPoint>,
+        partition_count: usize,
+    ) -> Result<Self> {

Review Comment:
   > @stuhood do you think there is a use case for having a contructor that does not return a `Result`? I could see it if a use case vlaidated themselves and is really trying to squeeze perf
   
   Hm, maybe... but I can't think of any cases where you'd be creating `RangePartitioning` instances in a tight loop.



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "goutamadwant (via GitHub)" <gi...@apache.org>.
goutamadwant commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4090361225


##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -198,48 +206,97 @@ impl Display for Partitioning {
 /// partition 2: keys at/after (2023, Allston)
 /// ```
 ///
-/// NOTE: Optimizer and execution behavior for this partitioning is intentionally
-/// not implemented and will be introduced incrementally. See
-/// <https://github.com/apache/datafusion/issues/22395>.
+/// Equality includes retained samples, since they determine which future scales
+/// are possible. Use [`Self::has_same_layout`] to compare only the current layout.
 #[derive(Debug, Clone, PartialEq)]
 pub struct RangePartitioning {
     /// Ordered partitioning key.
     ordering: LexOrdering,
-    /// Boundaries between adjacent partitions.
-    split_points: Vec<SplitPoint>,
+    /// Caller-supplied maximum-resolution split points used to derive the
+    /// effective boundaries.
+    samples: Arc<[SplitPoint]>,
+    /// Effective boundaries for the current partition count.
+    split_points: Arc<[SplitPoint]>,
 }
 
 impl RangePartitioning {
     /// Creates range partitioning metadata without validating split points.
     ///
-    /// Use [`Self::try_new`] to validate the contract documented on
-    /// [`RangePartitioning`].
+    /// Prefer [`Self::try_new_with_samples`] to validate the boundaries and retain
+    /// additional samples for scaling up. [`Self::try_new`] remains available for
+    /// validated exact boundaries.
+    #[deprecated(
+        since = "56.0.0",
+        note = "Use RangePartitioning::try_new_with_samples instead"
+    )]
     pub fn new(ordering: LexOrdering, split_points: Vec<SplitPoint>) -> Self {
+        let split_points: Arc<[SplitPoint]> = Arc::from(split_points);
         Self {
             ordering,
+            samples: Arc::clone(&split_points),
             split_points,
         }
     }
 
     /// Creates range partitioning metadata and validates split point shape and
     /// ordering.
+    ///
+    /// The exact boundaries are also the retained samples. This allows scaling
+    /// down and back up to the original count, but not beyond it. Prefer
+    /// [`Self::try_new_with_samples`] when additional sample points are available.
     pub fn try_new(ordering: LexOrdering, split_points: Vec<SplitPoint>) -> Result<Self> {
+        let partition_count = split_points.len() + 1;
+        Self::try_new_with_samples(ordering, split_points, partition_count)
+    }
+
+    /// Creates sample-backed range partitioning and validates the sample shape,
+    /// ordering, and target partition count.
+    ///
+    /// `partition_count` must be at least one and no larger than
+    /// `samples.len() + 1`. When it is smaller than that maximum, the samples
+    /// are evenly down-sampled to derive the effective split points.
+    ///
+    /// Retain at least `maximum_expected_partitions - 1` samples to support that

Review Comment:
   thanks for the example @gene-bordegaray updated it to match the main range-partitioning docs lmk if this looks good now. 



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#issuecomment-5853532818

   Thanks @goutamadwant @gene-bordegaray @stuhood 🚀 


-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r3888208431


##########
datafusion/physical-expr/src/partitioning.rs:
##########


Review Comment:
   nit: Range([a@0 ASC], [(30), (50), (70)], 4) is identical for a partitioning that can scale to 10 and one that can't scale past 4. Since EXPLAIN output is the primary debugging surface for partitioning bugs, appending the max when it differs (e.g. , max 10) would pay for itself.



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "goutamadwant (via GitHub)" <gi...@apache.org>.
goutamadwant commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4011143563


##########
datafusion/physical-expr/src/partitioning.rs:
##########


Review Comment:
   sure @stuhood cc @gene-bordegaray kept structural PartialEq for InterleaveExec safety and added has_same_layout to compare ordering and effective boundaries. The optimizer now uses that comparison. A three-input regression fails before the change and passes afterward in both sampled/exact orientations: compatible inputs retain their own samples without another exchange. 



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "gene-bordegaray (via GitHub)" <gi...@apache.org>.
gene-bordegaray commented on PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#issuecomment-5833149652

   will bump @jayzhan211 I think this is good for another pass


-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "gene-bordegaray (via GitHub)" <gi...@apache.org>.
gene-bordegaray commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4084094720


##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -198,48 +206,97 @@ impl Display for Partitioning {
 /// partition 2: keys at/after (2023, Allston)
 /// ```
 ///
-/// NOTE: Optimizer and execution behavior for this partitioning is intentionally
-/// not implemented and will be introduced incrementally. See
-/// <https://github.com/apache/datafusion/issues/22395>.
+/// Equality includes retained samples, since they determine which future scales
+/// are possible. Use [`Self::has_same_layout`] to compare only the current layout.
 #[derive(Debug, Clone, PartialEq)]
 pub struct RangePartitioning {
     /// Ordered partitioning key.
     ordering: LexOrdering,
-    /// Boundaries between adjacent partitions.
-    split_points: Vec<SplitPoint>,
+    /// Caller-supplied maximum-resolution split points used to derive the
+    /// effective boundaries.
+    samples: Arc<[SplitPoint]>,
+    /// Effective boundaries for the current partition count.
+    split_points: Arc<[SplitPoint]>,
 }
 
 impl RangePartitioning {
     /// Creates range partitioning metadata without validating split points.
     ///
-    /// Use [`Self::try_new`] to validate the contract documented on
-    /// [`RangePartitioning`].
+    /// Prefer [`Self::try_new_with_samples`] to validate the boundaries and retain
+    /// additional samples for scaling up. [`Self::try_new`] remains available for
+    /// validated exact boundaries.
+    #[deprecated(
+        since = "56.0.0",
+        note = "Use RangePartitioning::try_new_with_samples instead"
+    )]
     pub fn new(ordering: LexOrdering, split_points: Vec<SplitPoint>) -> Self {
+        let split_points: Arc<[SplitPoint]> = Arc::from(split_points);
         Self {
             ordering,
+            samples: Arc::clone(&split_points),
             split_points,
         }
     }
 
     /// Creates range partitioning metadata and validates split point shape and
     /// ordering.
+    ///
+    /// The exact boundaries are also the retained samples. This allows scaling
+    /// down and back up to the original count, but not beyond it. Prefer
+    /// [`Self::try_new_with_samples`] when additional sample points are available.
     pub fn try_new(ordering: LexOrdering, split_points: Vec<SplitPoint>) -> Result<Self> {
+        let partition_count = split_points.len() + 1;
+        Self::try_new_with_samples(ordering, split_points, partition_count)
+    }
+
+    /// Creates sample-backed range partitioning and validates the sample shape,

Review Comment:
   can we point to try_new when appropriate in docs



##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -198,48 +206,97 @@ impl Display for Partitioning {
 /// partition 2: keys at/after (2023, Allston)
 /// ```
 ///
-/// NOTE: Optimizer and execution behavior for this partitioning is intentionally
-/// not implemented and will be introduced incrementally. See
-/// <https://github.com/apache/datafusion/issues/22395>.
+/// Equality includes retained samples, since they determine which future scales
+/// are possible. Use [`Self::has_same_layout`] to compare only the current layout.
 #[derive(Debug, Clone, PartialEq)]
 pub struct RangePartitioning {
     /// Ordered partitioning key.
     ordering: LexOrdering,
-    /// Boundaries between adjacent partitions.
-    split_points: Vec<SplitPoint>,
+    /// Caller-supplied maximum-resolution split points used to derive the
+    /// effective boundaries.
+    samples: Arc<[SplitPoint]>,
+    /// Effective boundaries for the current partition count.
+    split_points: Arc<[SplitPoint]>,
 }
 
 impl RangePartitioning {
     /// Creates range partitioning metadata without validating split points.
     ///
-    /// Use [`Self::try_new`] to validate the contract documented on
-    /// [`RangePartitioning`].
+    /// Prefer [`Self::try_new_with_samples`] to validate the boundaries and retain
+    /// additional samples for scaling up. [`Self::try_new`] remains available for
+    /// validated exact boundaries.
+    #[deprecated(
+        since = "56.0.0",
+        note = "Use RangePartitioning::try_new_with_samples instead"
+    )]
     pub fn new(ordering: LexOrdering, split_points: Vec<SplitPoint>) -> Self {
+        let split_points: Arc<[SplitPoint]> = Arc::from(split_points);
         Self {
             ordering,
+            samples: Arc::clone(&split_points),
             split_points,
         }
     }
 
     /// Creates range partitioning metadata and validates split point shape and
     /// ordering.
+    ///
+    /// The exact boundaries are also the retained samples. This allows scaling
+    /// down and back up to the original count, but not beyond it. Prefer
+    /// [`Self::try_new_with_samples`] when additional sample points are available.
     pub fn try_new(ordering: LexOrdering, split_points: Vec<SplitPoint>) -> Result<Self> {
+        let partition_count = split_points.len() + 1;
+        Self::try_new_with_samples(ordering, split_points, partition_count)
+    }
+
+    /// Creates sample-backed range partitioning and validates the sample shape,
+    /// ordering, and target partition count.
+    ///
+    /// `partition_count` must be at least one and no larger than
+    /// `samples.len() + 1`. When it is smaller than that maximum, the samples
+    /// are evenly down-sampled to derive the effective split points.
+    ///
+    /// Retain at least `maximum_expected_partitions - 1` samples to support that

Review Comment:
   this is very wordy I was thinking something more like the range partitionig main docs. Here is the example there as reference:
   
   ```text
   /// For a single range key:
   ///
   /// ```text
   /// ordering = [date ASC NULLS LAST]
   /// split_points = [
   ///   (2022-01-01),
   ///   (2023-01-01),
   /// ]
   ///
   /// partition 0: date before 2022-01-01
   /// partition 1: date between 2022-01-01 (inclusive) and 2023-01-01 (exclusive)
   /// partition 2: date at/after 2023-01-01
   /// ```
   ```



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "goutamadwant (via GitHub)" <gi...@apache.org>.
goutamadwant commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4011139478


##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -234,19 +248,75 @@ impl RangePartitioning {
         Ok(Self::new(ordering, split_points))
     }
 
+    /// Creates sample-backed range partitioning and validates the sample shape,
+    /// ordering, and target partition count.
+    ///
+    /// `partition_count` must be at least one and no larger than
+    /// `samples.len() + 1`. When it is smaller than that maximum, the samples
+    /// are evenly down-sampled to derive the effective split points.
+    pub fn try_new_with_samples(
+        ordering: LexOrdering,
+        samples: Vec<SplitPoint>,
+        partition_count: usize,
+    ) -> Result<Self> {

Review Comment:
   @stuhood deprecated the unchecked new constructor for 56.0.0 and migrated its internal callers to try_new_with_samples. Validated try_new remains supported and delegates to the sample-backed constructor. Added capacity-sizing guidance and an oversampling example, including the small-input limitation.



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "goutamadwant (via GitHub)" <gi...@apache.org>.
goutamadwant commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4101295092


##########
datafusion/ffi/src/physical_expr/partitioning.rs:
##########
@@ -174,13 +180,28 @@ mod tests {
         )?))
     }
 
+    fn sampled_range_partitioning() -> Result<Partitioning> {
+        let ordering = LexOrdering::new([PhysicalSortExpr::new_default(Arc::new(
+            Column::new("a", 0),
+        ))])
+        .expect("non-empty ordering");
+        let samples = [10, 20, 30, 40, 50]
+            .into_iter()
+            .map(|value| SplitPoint::new(vec![ScalarValue::Int64(Some(value))]))
+            .collect();
+        Ok(Partitioning::Range(
+            RangePartitioning::try_new_with_samples(ordering, samples, 3)?,
+        ))
+    }

Review Comment:
   @gene-bordegaray I removed the sampled-range case from the generic FFI round-trip test and moved its setup into the dedicated sampled-range test. let me know if this looks good now. thanks for checking



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4026787414


##########
datafusion/physical-optimizer/src/ensure_requirements/enforce_distribution.rs:
##########
@@ -1548,37 +1577,78 @@ pub fn ensure_distribution(
                             && target_partitions > child_partitions;
 
                     // When subset satisfaction is enabled, preserve an
-                    // already-satisfying partitioning. Otherwise, hash
+                    // already-satisfying partitioning. Otherwise,
                     // repartition may also increase parallelism.
-                    let needs_hash_repartition = if allow_subset_satisfy_partitioning {
+                    let needs_repartition = if allow_subset_satisfy_partitioning {
                         !partitioning_satisfied
                     } else {
                         !partitioning_satisfied
                             || (target_partitions > child_partitions
                                 && !preserve_satisfying_file_partitioning)
                     };
-                    let should_add_hash_repartition =
-                        hash_necessary && needs_hash_repartition;
+                    let should_add_repartition = hash_necessary && needs_repartition;
 
                     // See https://github.com/apache/datafusion/issues/18341#issuecomment-3503238325 for background
-                    // When inserting hash is necessary to satisfy hash requirement, insert hash repartition.
-                    if should_add_hash_repartition {
+                    // Enforce unmet requirements, or increase parallelism when beneficial.
+                    if should_add_repartition {
+                        let partitioning = match child.plan.output_partitioning() {
+                            Partitioning::Range(range) if partitioning_satisfied => {
+                                // A satisfying range layout remains useful to the
+                                // co-partitioning pass even when its samples cannot
+                                // support the preferred degree of parallelism.
+                                match range.scale(target_partitions) {
+                                    Ok(range) => {
+                                        let scaled = Partitioning::Range(range);
+                                        // A single partition satisfies any key requirement,
+                                        // but scaling it must still use compatible keys.
+                                        if scaled
+                                            .satisfaction(
+                                                &requirement,
+                                                child.plan.equivalence_properties(),
+                                                false,
+                                            )
+                                            .is_satisfied()
+                                        {
+                                            scaled_native_range =
+                                                !child.plan.is::<RepartitionExec>();
+                                            Some(scaled)
+                                        } else {
+                                            Some(
+                                                requirement
+                                                    .clone()
+                                                    .create_partitioning(target_partitions),
+                                            )
+                                        }
+                                    }
+                                    Err(RangePartitioningScaleError::InsufficientSamples { .. }) => {
+                                        preserved_unscalable_range = true;
+                                        None

Review Comment:
   On `InsufficientSamples` the Range input keeps its partition count even with `preserve_file_partitions = 0`, and even for single-input requirements (e.g. an aggregate) where nothing needs to line up. Range sources today are built with `try_new` (max == current count), so all existing Range users lose parallelism. `range_satisfaction_config_matrix` `(NOT_MET, DISABLED, GREATER)` flips `Hash` → `Reuse`, and sqllogictest TEST 13 now joins at 4 partitions with `target_partitions = 5`. Please keep the layout only when the inputs are co-partitioned (and confirm on #24712 whether joins should also require `preserve_file_partitions`):
   
   ```diff
   -                                    Err(RangePartitioningScaleError::InsufficientSamples { .. }) => {
   +                                    Err(RangePartitioningScaleError::InsufficientSamples { .. })
   +                                        if input_distributions.is_co_partitioned() =>
   +                                    {
                                            preserved_unscalable_range = true;
                                            None
                                        }
   +                                    Err(RangePartitioningScaleError::InsufficientSamples { .. }) => Some(
   +                                        requirement
   +                                            .clone()
   +                                            .create_partitioning(target_partitions),
   +                                    ),
                                        Err(error) => return Err(error.into()),
   ```



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#issuecomment-5682601631

   @goutamadwant,
   
   This changes planning policy beyond the feature. When `scale()` returns `InsufficientSamples`, the child is now left at its current partition count instead of being key-repartitioned to `target_partitions` as on main. That applies to every key requirement, not only co-partitioned ones, so e.g. an aggregate over a 3-way exact range source now runs 3-way on a 16-core machine (`range_requirement_scales_within_sample_resolution` pins target 7 -> 3 partitions with no exchange).
   
   We already have a knob for "keep a satisfying layout instead of increasing parallelism": `preserve_file_partitions` / `preserve_satisfying_file_partitioning` a few lines above. This change makes the disabled setting a no-op for range sources, which is why `range_satisfaction_config_matrix` had to flip `(NOT_MET, DISABLED, GREATER)` from `[Hash, Hash, Hash]` to `[Reuse, Hash, Hash]` and slt TEST 13 lost both exchanges and its 5-way parallelism.
   
   It can also be strictly worse than main for joins. In `range_preservation_prefers_larger_unscalable_input` the larger side is a 3-way exact range and the other side is already a native 4-way range at target. main: one Range(4) exchange, 4-way join. This PR: one Range(3) exchange, 3-way join. Same exchange count, less parallelism. The `.or_else` tie-break only covers the unknown-size tie, not the strictly-larger case.
   
   Suggest keeping main's behaviour on `InsufficientSamples` and dropping `preserved_unscalable_range` plus the tie-break:
   
   ```rust
   -                                    Err(RangePartitioningScaleError::InsufficientSamples { .. }) => {
   -                                        preserved_unscalable_range = true;
   -                                        None
   -                                    }
   +                                    // Samples cannot support the target parallelism:
   +                                    // fall back to key repartitioning as before.
   +                                    Err(RangePartitioningScaleError::InsufficientSamples { .. }) => Some(
   +                                        requirement
   +                                            .clone()
   +                                            .create_partitioning(target_partitions),
   +                                    ),
   ```
   and restoring the matrix / TEST 13 expectations. If retaining an unscalable range for the co-partitioning pass is desirable, it should be gated on the existing preserve_file_partitions threshold rather than unconditional, and the reference selection must never let a preserved range beat a candidate that already provides target_partitions.


-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "gene-bordegaray (via GitHub)" <gi...@apache.org>.
gene-bordegaray commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4024690131


##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -198,48 +204,133 @@ impl Display for Partitioning {
 /// partition 2: keys at/after (2023, Allston)
 /// ```
 ///
-/// NOTE: Optimizer and execution behavior for this partitioning is intentionally
-/// not implemented and will be introduced incrementally. See
-/// <https://github.com/apache/datafusion/issues/22395>.
+/// Equality includes retained samples, since they determine which future scales
+/// are possible. Use [`Self::has_same_layout`] to compare only the current layout.
 #[derive(Debug, Clone, PartialEq)]
 pub struct RangePartitioning {
     /// Ordered partitioning key.
     ordering: LexOrdering,
-    /// Boundaries between adjacent partitions.
-    split_points: Vec<SplitPoint>,
+    /// Maximum-resolution boundaries used to derive split points.
+    samples: Arc<[SplitPoint]>,
+    /// Effective boundaries for the current partition count.
+    split_points: Arc<[SplitPoint]>,
+}
+
+/// Why a [`RangePartitioning`] cannot be scaled to a requested partition count.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum RangePartitioningScaleError {

Review Comment:
   I dont think eposing a public error type is the best path here. Most likely could be a datafusion internal error and have some private enum if needed



##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -153,15 +153,21 @@ impl Display for Partitioning {
 
 /// Physical range partitioning.
 ///
-/// [`RangePartitioning`] describes an ordered key space with split points.
+/// [`RangePartitioning`] describes an ordered key space with sampled split points.
 ///
 /// - `ordering` defines the partitioning key and ordering.
-/// - `split_points` define the boundaries between adjacent partitions.
+/// - `samples` define the maximum-resolution boundaries.
+/// - `partition_count` selects how many ranges to derive from those samples.

Review Comment:
   isnt split points still in the struct?



##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -153,15 +153,21 @@ impl Display for Partitioning {
 
 /// Physical range partitioning.
 ///
-/// [`RangePartitioning`] describes an ordered key space with split points.
+/// [`RangePartitioning`] describes an ordered key space with sampled split points.
 ///
 /// - `ordering` defines the partitioning key and ordering.
-/// - `split_points` define the boundaries between adjacent partitions.
+/// - `samples` define the maximum-resolution boundaries.
+/// - `partition_count` selects how many ranges to derive from those samples.

Review Comment:
   I also am not seeing `partition_count` but may be missing



##########
datafusion/physical-optimizer/src/ensure_requirements/enforce_distribution.rs:
##########
@@ -1783,3 +1857,83 @@ fn update_children(mut dist_context: DistributionContext) -> Result<Distribution
 }
 
 // See tests in datafusion/core/tests/physical_optimizer
+

Review Comment:
   tests for this go in that file above: `datafusion/core/tests/physical_optimizer`



##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -198,48 +204,133 @@ impl Display for Partitioning {
 /// partition 2: keys at/after (2023, Allston)
 /// ```
 ///
-/// NOTE: Optimizer and execution behavior for this partitioning is intentionally
-/// not implemented and will be introduced incrementally. See
-/// <https://github.com/apache/datafusion/issues/22395>.
+/// Equality includes retained samples, since they determine which future scales
+/// are possible. Use [`Self::has_same_layout`] to compare only the current layout.
 #[derive(Debug, Clone, PartialEq)]
 pub struct RangePartitioning {
     /// Ordered partitioning key.
     ordering: LexOrdering,
-    /// Boundaries between adjacent partitions.
-    split_points: Vec<SplitPoint>,
+    /// Maximum-resolution boundaries used to derive split points.
+    samples: Arc<[SplitPoint]>,
+    /// Effective boundaries for the current partition count.
+    split_points: Arc<[SplitPoint]>,
+}
+
+/// Why a [`RangePartitioning`] cannot be scaled to a requested partition count.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum RangePartitioningScaleError {
+    /// A partitioning must contain at least one partition.
+    ZeroPartitions,
+    /// The retained samples cannot support the requested number of partitions.
+    /// Callers may retain the current layout or choose another partitioning.
+    InsufficientSamples {
+        /// Requested number of partitions.
+        target_partitions: usize,
+        /// Largest partition count supported by the retained samples.
+        max_partitions: usize,
+    },
+}
+
+impl Display for RangePartitioningScaleError {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        match self {
+            Self::ZeroPartitions => {
+                write!(f, "Range partitioning partition count must be at least 1")
+            }
+            Self::InsufficientSamples {
+                target_partitions,
+                max_partitions,
+            } => write!(
+                f,
+                "Range partitioning partition count {target_partitions} exceeds maximum {max_partitions}"
+            ),
+        }
+    }
+}
+
+impl std::error::Error for RangePartitioningScaleError {}
+
+impl From<RangePartitioningScaleError> for DataFusionError {
+    fn from(error: RangePartitioningScaleError) -> Self {
+        Self::Plan(error.to_string())
+    }
 }
 
 impl RangePartitioning {
     /// Creates range partitioning metadata without validating split points.
     ///
-    /// Use [`Self::try_new`] to validate the contract documented on
-    /// [`RangePartitioning`].
+    /// Prefer [`Self::try_new_with_samples`] to validate the boundaries and retain
+    /// additional samples for scaling up. [`Self::try_new`] remains available for
+    /// validated exact boundaries.
+    #[deprecated(
+        since = "56.0.0",
+        note = "Use RangePartitioning::try_new_with_samples instead"
+    )]
     pub fn new(ordering: LexOrdering, split_points: Vec<SplitPoint>) -> Self {
+        let split_points: Arc<[SplitPoint]> = Arc::from(split_points);
         Self {
             ordering,
+            samples: Arc::clone(&split_points),
             split_points,
         }
     }
 
     /// Creates range partitioning metadata and validates split point shape and
     /// ordering.
+    ///
+    /// The exact boundaries are also the retained samples. This allows scaling

Review Comment:
   I would clearly state that the `samples` are derived from teh split points provided



##########
datafusion/sqllogictest/test_files/range_partitioning.slt:
##########
@@ -541,10 +541,9 @@ ORDER BY l.range_key;
 35 350
 
 ##########
-# TEST 13: Compatible Range Join Repartitions to Increase Parallelism
-# Co-partitioning satisfaction does not prevent a repartition that increases
-# parallelism. With target_partitions larger than the Range partition count,
-# both sides are hash repartitioned.
+# TEST 13: Compatible Range Join Preserves Unscalable Partitioning

Review Comment:
   is this the inteded behavior we want though? What if we would benefit more from a repartition to 5 for more parallelism. We should make this configurable to the user in some way. Maybe a threshold of some type



##########
datafusion/physical-optimizer/src/ensure_requirements/enforce_distribution.rs:
##########
@@ -1548,37 +1577,78 @@ pub fn ensure_distribution(
                             && target_partitions > child_partitions;
 
                     // When subset satisfaction is enabled, preserve an
-                    // already-satisfying partitioning. Otherwise, hash
+                    // already-satisfying partitioning. Otherwise,
                     // repartition may also increase parallelism.
-                    let needs_hash_repartition = if allow_subset_satisfy_partitioning {
+                    let needs_repartition = if allow_subset_satisfy_partitioning {
                         !partitioning_satisfied
                     } else {
                         !partitioning_satisfied
                             || (target_partitions > child_partitions
                                 && !preserve_satisfying_file_partitioning)
                     };
-                    let should_add_hash_repartition =
-                        hash_necessary && needs_hash_repartition;
+                    let should_add_repartition = hash_necessary && needs_repartition;
 
                     // See https://github.com/apache/datafusion/issues/18341#issuecomment-3503238325 for background
-                    // When inserting hash is necessary to satisfy hash requirement, insert hash repartition.
-                    if should_add_hash_repartition {
+                    // Enforce unmet requirements, or increase parallelism when beneficial.
+                    if should_add_repartition {
+                        let partitioning = match child.plan.output_partitioning() {
+                            Partitioning::Range(range) if partitioning_satisfied => {
+                                // A satisfying range layout remains useful to the
+                                // co-partitioning pass even when its samples cannot
+                                // support the preferred degree of parallelism.
+                                match range.scale(target_partitions) {
+                                    Ok(range) => {
+                                        let scaled = Partitioning::Range(range);
+                                        // A single partition satisfies any key requirement,
+                                        // but scaling it must still use compatible keys.
+                                        if scaled
+                                            .satisfaction(
+                                                &requirement,
+                                                child.plan.equivalence_properties(),
+                                                false,
+                                            )
+                                            .is_satisfied()
+                                        {
+                                            scaled_native_range =
+                                                !child.plan.is::<RepartitionExec>();
+                                            Some(scaled)
+                                        } else {
+                                            Some(
+                                                requirement
+                                                    .clone()
+                                                    .create_partitioning(target_partitions),
+                                            )
+                                        }
+                                    }
+                                    Err(RangePartitioningScaleError::InsufficientSamples { .. }) => {
+                                        preserved_unscalable_range = true;
+                                        None

Review Comment:
   this returns None which I have tracked as meaning “keep the current range partitioning” and this happens even when preserve_file_partitions is disabled so I think this shouldnt happen



##########
datafusion/physical-plan/src/repartition/mod.rs:
##########


Review Comment:
   are we intentionally rejecting here?



##########
datafusion/sqllogictest/test_files/range_partitioning.slt:
##########
@@ -557,10 +556,8 @@ JOIN range_partitioned r ON l.range_key = r.range_key;
 ----
 physical_plan
 01)HashJoinExec: mode=Partitioned, join_type=Inner, on=[(range_key@0, range_key@0)], projection=[range_key@0, value@1, value@3]
-02)--RepartitionExec: partitioning=Hash([range_key@0], 5), input_partitions=4

Review Comment:
   I am very confused here, we are showing that we are not repartitioning but we are not doing this due to scaling. This was intentional to show that if we can increase parallelism in the system we should. I think a better test here would be showing increasing parallelism by repartitioning on range and scaling the points correctly



##########
datafusion/physical-optimizer/src/ensure_requirements/enforce_distribution.rs:
##########
@@ -1548,37 +1577,78 @@ pub fn ensure_distribution(
                             && target_partitions > child_partitions;
 
                     // When subset satisfaction is enabled, preserve an
-                    // already-satisfying partitioning. Otherwise, hash
+                    // already-satisfying partitioning. Otherwise,
                     // repartition may also increase parallelism.
-                    let needs_hash_repartition = if allow_subset_satisfy_partitioning {
+                    let needs_repartition = if allow_subset_satisfy_partitioning {
                         !partitioning_satisfied
                     } else {
                         !partitioning_satisfied
                             || (target_partitions > child_partitions
                                 && !preserve_satisfying_file_partitioning)
                     };
-                    let should_add_hash_repartition =
-                        hash_necessary && needs_hash_repartition;
+                    let should_add_repartition = hash_necessary && needs_repartition;
 
                     // See https://github.com/apache/datafusion/issues/18341#issuecomment-3503238325 for background
-                    // When inserting hash is necessary to satisfy hash requirement, insert hash repartition.
-                    if should_add_hash_repartition {
+                    // Enforce unmet requirements, or increase parallelism when beneficial.
+                    if should_add_repartition {
+                        let partitioning = match child.plan.output_partitioning() {

Review Comment:
   I think using an option here too is pretty confusing. Could we make it more explicit what the variants are like Keep or Repartition on Range



##########
datafusion/physical-plan/src/repartition/mod.rs:
##########


Review Comment:
   shouldn't we attempt to scale



##########
datafusion/physical-optimizer/src/ensure_requirements/enforce_distribution.rs:
##########
@@ -1548,37 +1577,78 @@ pub fn ensure_distribution(
                             && target_partitions > child_partitions;
 
                     // When subset satisfaction is enabled, preserve an
-                    // already-satisfying partitioning. Otherwise, hash
+                    // already-satisfying partitioning. Otherwise,
                     // repartition may also increase parallelism.
-                    let needs_hash_repartition = if allow_subset_satisfy_partitioning {
+                    let needs_repartition = if allow_subset_satisfy_partitioning {
                         !partitioning_satisfied
                     } else {
                         !partitioning_satisfied
                             || (target_partitions > child_partitions
                                 && !preserve_satisfying_file_partitioning)
                     };
-                    let should_add_hash_repartition =
-                        hash_necessary && needs_hash_repartition;
+                    let should_add_repartition = hash_necessary && needs_repartition;
 
                     // See https://github.com/apache/datafusion/issues/18341#issuecomment-3503238325 for background
-                    // When inserting hash is necessary to satisfy hash requirement, insert hash repartition.
-                    if should_add_hash_repartition {
+                    // Enforce unmet requirements, or increase parallelism when beneficial.
+                    if should_add_repartition {
+                        let partitioning = match child.plan.output_partitioning() {
+                            Partitioning::Range(range) if partitioning_satisfied => {
+                                // A satisfying range layout remains useful to the
+                                // co-partitioning pass even when its samples cannot
+                                // support the preferred degree of parallelism.
+                                match range.scale(target_partitions) {
+                                    Ok(range) => {
+                                        let scaled = Partitioning::Range(range);
+                                        // A single partition satisfies any key requirement,
+                                        // but scaling it must still use compatible keys.
+                                        if scaled
+                                            .satisfaction(
+                                                &requirement,
+                                                child.plan.equivalence_properties(),
+                                                false,
+                                            )
+                                            .is_satisfied()
+                                        {
+                                            scaled_native_range =
+                                                !child.plan.is::<RepartitionExec>();
+                                            Some(scaled)
+                                        } else {
+                                            Some(
+                                                requirement
+                                                    .clone()
+                                                    .create_partitioning(target_partitions),
+                                            )
+                                        }
+                                    }
+                                    Err(RangePartitioningScaleError::InsufficientSamples { .. }) => {
+                                        preserved_unscalable_range = true;
+                                        None

Review Comment:
   so like a 3 partiitoned range merging with a 8 partitioned hash, I would think if the user doesn't opt in we should decide to use more parallelism



##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -198,48 +204,133 @@ impl Display for Partitioning {
 /// partition 2: keys at/after (2023, Allston)
 /// ```
 ///
-/// NOTE: Optimizer and execution behavior for this partitioning is intentionally
-/// not implemented and will be introduced incrementally. See
-/// <https://github.com/apache/datafusion/issues/22395>.
+/// Equality includes retained samples, since they determine which future scales
+/// are possible. Use [`Self::has_same_layout`] to compare only the current layout.
 #[derive(Debug, Clone, PartialEq)]
 pub struct RangePartitioning {
     /// Ordered partitioning key.
     ordering: LexOrdering,
-    /// Boundaries between adjacent partitions.
-    split_points: Vec<SplitPoint>,
+    /// Maximum-resolution boundaries used to derive split points.
+    samples: Arc<[SplitPoint]>,
+    /// Effective boundaries for the current partition count.
+    split_points: Arc<[SplitPoint]>,
+}
+
+/// Why a [`RangePartitioning`] cannot be scaled to a requested partition count.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum RangePartitioningScaleError {
+    /// A partitioning must contain at least one partition.
+    ZeroPartitions,
+    /// The retained samples cannot support the requested number of partitions.
+    /// Callers may retain the current layout or choose another partitioning.
+    InsufficientSamples {
+        /// Requested number of partitions.
+        target_partitions: usize,
+        /// Largest partition count supported by the retained samples.
+        max_partitions: usize,
+    },
+}
+
+impl Display for RangePartitioningScaleError {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        match self {
+            Self::ZeroPartitions => {
+                write!(f, "Range partitioning partition count must be at least 1")
+            }
+            Self::InsufficientSamples {
+                target_partitions,
+                max_partitions,
+            } => write!(
+                f,
+                "Range partitioning partition count {target_partitions} exceeds maximum {max_partitions}"
+            ),
+        }
+    }
+}
+
+impl std::error::Error for RangePartitioningScaleError {}
+
+impl From<RangePartitioningScaleError> for DataFusionError {
+    fn from(error: RangePartitioningScaleError) -> Self {
+        Self::Plan(error.to_string())
+    }
 }
 
 impl RangePartitioning {
     /// Creates range partitioning metadata without validating split points.
     ///
-    /// Use [`Self::try_new`] to validate the contract documented on
-    /// [`RangePartitioning`].
+    /// Prefer [`Self::try_new_with_samples`] to validate the boundaries and retain
+    /// additional samples for scaling up. [`Self::try_new`] remains available for
+    /// validated exact boundaries.
+    #[deprecated(
+        since = "56.0.0",
+        note = "Use RangePartitioning::try_new_with_samples instead"
+    )]
     pub fn new(ordering: LexOrdering, split_points: Vec<SplitPoint>) -> Self {
+        let split_points: Arc<[SplitPoint]> = Arc::from(split_points);
         Self {
             ordering,
+            samples: Arc::clone(&split_points),
             split_points,
         }
     }
 
     /// Creates range partitioning metadata and validates split point shape and
     /// ordering.
+    ///
+    /// The exact boundaries are also the retained samples. This allows scaling
+    /// down and back up to the original count, but not beyond it. Prefer
+    /// [`Self::try_new_with_samples`] when additional sample points are available.
     pub fn try_new(ordering: LexOrdering, split_points: Vec<SplitPoint>) -> Result<Self> {
+        let partition_count = split_points.len() + 1;
+        Self::try_new_with_samples(ordering, split_points, partition_count)
+    }
+
+    /// Creates sample-backed range partitioning and validates the sample shape,
+    /// ordering, and target partition count.
+    ///
+    /// `partition_count` must be at least one and no larger than
+    /// `samples.len() + 1`. When it is smaller than that maximum, the samples
+    /// are evenly down-sampled to derive the effective split points.
+    ///
+    /// Retain at least `maximum_expected_partitions - 1` samples to support that
+    /// many partitions later. For example, supplying `4 * partition_count`
+    /// samples provides capacity for up to `4 * partition_count + 1` partitions.
+    /// Choose the sampling factor for the workload; small inputs may not have
+    /// enough distinct values, and callers must handle insufficient capacity.
+    pub fn try_new_with_samples(

Review Comment:
   I would love to see a concrete example of samles and split points relationship being shown. Like what an actual scaling would look like and the contract it enforces, like not exceeding the max samples.
   
   This also makes me think, samples is not the most telling name for a public facing property. Maybe something like max_partition_bounds?



##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -234,19 +248,75 @@ impl RangePartitioning {
         Ok(Self::new(ordering, split_points))
     }
 
+    /// Creates sample-backed range partitioning and validates the sample shape,
+    /// ordering, and target partition count.
+    ///
+    /// `partition_count` must be at least one and no larger than
+    /// `samples.len() + 1`. When it is smaller than that maximum, the samples
+    /// are evenly down-sampled to derive the effective split points.
+    pub fn try_new_with_samples(
+        ordering: LexOrdering,
+        samples: Vec<SplitPoint>,
+        partition_count: usize,
+    ) -> Result<Self> {

Review Comment:
   I don't know if deprecating is needed rather than it jsut being an invariant. It seems we can alsways derive the samples form split points.
   
   @stuhood do you think there is a use case for having a contructor that does not return a `Result`? I could see it if a use case vlaidated themselves and is really trying to squeeze perf



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "stuhood (via GitHub)" <gi...@apache.org>.
stuhood commented on PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#issuecomment-5471427979

   Thanks for working on this!
   
   Before we actually land this, there is a little bit more work that I should do to prove that https://github.com/apache/datafusion/issues/24712 is actually sufficient to solve the case that I'm examining... could we hold off for a few days, so that I can update the ticket if needed?


-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "goutamadwant (via GitHub)" <gi...@apache.org>.
goutamadwant commented on PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#issuecomment-5658940972

   > Thanks @goutamadwant, there is a suggestion:
   > 
   > `RangePartitioning::PartialEq` compares only `ordering` + effective `split_points`, but `samples` is not derivable from `split_points` and is exactly the state `scale()` reads. So `a == b` does not imply `a.scale(k) == b.scale(k)`, and doesn't even imply both succeed — your own test asserts `try_new_with_samples(ord, [10..90], 4) == try_new(ord, [30,50,70])`, yet the first scales to 10 and the second errors at 4.
   > 
   > There's already a consumer that turns this into wrong results. `can_interleave` gates on `partition == *reference`:
   > 
   > ```rust
   > // datafusion/physical-plan/src/union.rs:931
   > matches!(reference, Partitioning::Hash(_, _) | Partitioning::Range(_))
   >     && inputs
   >         .map(|plan| plan.borrow().output_partitioning().clone())
   >         .all(|partition| partition == *reference)
   > ```
   > 
   > and `InterleaveExec::compute_properties` then adopts one input's metadata for the whole output:
   > 
   > ```rust
   > // datafusion/physical-plan/src/union.rs:698
   > let output_partitioning = inputs[0].output_partitioning().clone();
   > ```
   > 
   > Concretely: input A = `try_new_with_samples(ord, [10,20,...,90], 4)`, input B = `try_new(ord, [30,50,70])`. They compare equal, interleaving is allowed (correct — the effective boundaries do match), and the `InterleaveExec` output now advertises `max_partition_count() == 10`. A distributed planner — the use case this PR is for — calls `scale(10)` on that output and gets `[10,20,...,90]`, boundaries B's rows were never placed against. Because range partitioning is a declared, unvalidated property, that's silently wrong rows per partition, not an error.
   > 
   > Suggest making equality structural:
   > 
   > ```diff
   > -#[derive(Debug, Clone)]
   > +#[derive(Debug, Clone, PartialEq)]
   >  pub struct RangePartitioning {
   >      ordering: LexOrdering,
   >      samples: Arc<[SplitPoint]>,
   >      split_points: Arc<[SplitPoint]>,
   >      partition_count: usize,
   >  }
   > @@
   > -impl PartialEq for RangePartitioning {
   > -    fn eq(&self, other: &Self) -> bool {
   > -        self.ordering == other.ordering && self.split_points == other.split_points
   > -    }
   > -}
   > ```
   > 
   > The one place that genuinely wants effective-boundary comparison already spells it out and is unaffected:
   > 
   > ```rust
   > // datafusion/physical-plan/src/distribution_requirements.rs:348
   > (Partitioning::Range(left), Partitioning::Range(right)) => {
   >     left.split_points() == right.split_points()
   >         && ...
   > }
   > ```
   > 
   > so co-partitioned joins keep the permissive behavior; only `can_interleave` gets stricter, which is the conservative direction. `test_range_partitioning_equality_uses_effective_split_points` would then need to flip to `assert_ne!`.
   > 
   > If you'd rather keep permissive equality, the alternative is for `InterleaveExec::compute_properties` to reduce the output to the coarsest sample set common to all inputs rather than inheriting `inputs[0]`'s — but that's more machinery for the same guarantee.
   
   @jayzhan211 Switched RangePartitioning to structural equality and added an interleave regression for matching effective boundaries with different retained samples. Both input orders are covered, so interleave cannot inherit unsupported scaling capacity from either input.


-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "stuhood (via GitHub)" <gi...@apache.org>.
stuhood commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4033322589


##########
datafusion/sqllogictest/test_files/range_partitioning.slt:
##########
@@ -541,10 +541,9 @@ ORDER BY l.range_key;
 35 350
 
 ##########
-# TEST 13: Compatible Range Join Repartitions to Increase Parallelism
-# Co-partitioning satisfaction does not prevent a repartition that increases
-# parallelism. With target_partitions larger than the Range partition count,
-# both sides are hash repartitioned.
+# TEST 13: Compatible Range Join Preserves Unscalable Partitioning

Review Comment:
   No, this is not intended. See https://github.com/apache/datafusion/pull/24766#issuecomment-5682601631



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "stuhood (via GitHub)" <gi...@apache.org>.
stuhood commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4067528351


##########
datafusion/physical-optimizer/src/ensure_requirements/enforce_distribution.rs:
##########
@@ -1154,7 +1157,8 @@ fn enforce_distribution_relationships(
                 let partitioning = plan.output_partitioning();
                 match partitioning {
                     Partitioning::Range(_) | Partitioning::Hash(_, _) => {
-                        let is_native = !plan.is::<RepartitionExec>();
+                        let is_native =
+                            !plan.is::<RepartitionExec>() || child.scaled_native_range;

Review Comment:
   We shouldn't treat a node which has been scaled with `RepartitionExec` as "natively partitioned": this pass is about finding sources which already satisfy the constraints, without the addition of a `RepartitionExec`.
   
   Unless a node can be scaled with `ExecutionPlan::repartitioned`, we shouldn't consider it to be natively partitioned here, as that will prioritize adapting some other data source to match this one.
   
   It's possible that after #25483 we might consider a `Range` which has been scaled with `RangePartitioning::scale` to be preferable to something that has been hashed... but right now I don't think that that makes sense.
   
   So probably `scaled_native_range` should be removed entirely.



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "goutamadwant (via GitHub)" <gi...@apache.org>.
goutamadwant commented on code in PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#discussion_r4090282380


##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -198,48 +206,97 @@ impl Display for Partitioning {
 /// partition 2: keys at/after (2023, Allston)
 /// ```
 ///
-/// NOTE: Optimizer and execution behavior for this partitioning is intentionally
-/// not implemented and will be introduced incrementally. See
-/// <https://github.com/apache/datafusion/issues/22395>.
+/// Equality includes retained samples, since they determine which future scales
+/// are possible. Use [`Self::has_same_layout`] to compare only the current layout.
 #[derive(Debug, Clone, PartialEq)]
 pub struct RangePartitioning {
     /// Ordered partitioning key.
     ordering: LexOrdering,
-    /// Boundaries between adjacent partitions.
-    split_points: Vec<SplitPoint>,
+    /// Caller-supplied maximum-resolution split points used to derive the
+    /// effective boundaries.
+    samples: Arc<[SplitPoint]>,
+    /// Effective boundaries for the current partition count.
+    split_points: Arc<[SplitPoint]>,
 }
 
 impl RangePartitioning {
     /// Creates range partitioning metadata without validating split points.
     ///
-    /// Use [`Self::try_new`] to validate the contract documented on
-    /// [`RangePartitioning`].
+    /// Prefer [`Self::try_new_with_samples`] to validate the boundaries and retain
+    /// additional samples for scaling up. [`Self::try_new`] remains available for
+    /// validated exact boundaries.
+    #[deprecated(
+        since = "56.0.0",
+        note = "Use RangePartitioning::try_new_with_samples instead"
+    )]
     pub fn new(ordering: LexOrdering, split_points: Vec<SplitPoint>) -> Self {
+        let split_points: Arc<[SplitPoint]> = Arc::from(split_points);
         Self {
             ordering,
+            samples: Arc::clone(&split_points),
             split_points,
         }
     }
 
     /// Creates range partitioning metadata and validates split point shape and
     /// ordering.
+    ///
+    /// The exact boundaries are also the retained samples. This allows scaling
+    /// down and back up to the original count, but not beyond it. Prefer
+    /// [`Self::try_new_with_samples`] when additional sample points are available.
     pub fn try_new(ordering: LexOrdering, split_points: Vec<SplitPoint>) -> Result<Self> {
+        let partition_count = split_points.len() + 1;
+        Self::try_new_with_samples(ordering, split_points, partition_count)
+    }
+
+    /// Creates sample-backed range partitioning and validates the sample shape,

Review Comment:
   Sure. updated the constructor docs and deprecation note to recommend try_new for validated exact boundaries, or `try_new_with_samples` when retaining extra samples for scaling.



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 merged PR #24766:
URL: https://github.com/apache/datafusion/pull/24766


-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "stuhood (via GitHub)" <gi...@apache.org>.
stuhood commented on PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#issuecomment-5722971290

   Thanks again for working on this @goutamadwant!
   
   Some more breadcrumbs here: I've integrated this in https://github.com/datafusion-contrib/datafusion-distributed/pull/730 and https://github.com/paradedb/paradedb/pull/6342, and did not find any problems with the API other than those already mentioned here.
   
   Let me know if we can help get this landed.


-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: allow scaling RangePartitioning [datafusion]

Posted by "stuhood (via GitHub)" <gi...@apache.org>.
stuhood commented on PR #24766:
URL: https://github.com/apache/datafusion/pull/24766#issuecomment-5685173645

   > If retaining an unscalable range for the co-partitioning pass is desirable, it should be gated on the existing `preserve_file_partitions` threshold rather than unconditional, and the reference selection must never let a preserved range beat a candidate that already provides target_partitions.
   
   Agreed.
   
   Thanks!


-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org