gene-bordegaray commented on code in PR #22590:
URL: https://github.com/apache/datafusion/pull/22590#discussion_r3318030131
##########
datafusion/physical-expr/src/partitioning.rs:
##########
@@ -1267,6 +1369,157 @@ mod tests {
Ok(())
}
+ #[test]
+ fn test_range_partitioning_compatible_with() -> Result<()> {
+ let fixture = PartitioningTestFixture::int64(&["a", "b"])?;
+ let mut eq_properties = fixture.eq_properties.clone();
+ eq_properties.add_equal_conditions(fixture.col(0), fixture.col(1))?;
+
+ let split_points = vec![int_split_point([10]), int_split_point([20])];
+ let range_a = fixture.range([0], split_points.clone());
+ let range_a_same = fixture.range([0], split_points.clone());
+ let range_b_equivalent = fixture.range([1], split_points.clone());
+ let range_b_different_split = fixture.range([1],
vec![int_split_point([30])]);
+ let range_a_desc = RangePartitioning::try_new(
+ [fixture.range_sort_expr(0, SortOptions::new(true, false))].into(),
+ vec![int_split_point([10])],
+ )?;
+ let single_partition_range_a = fixture.range([0], vec![]);
+ let single_partition_range_b = fixture.range([1], vec![]);
+
+ assert!(range_a.compatible_with(&range_a_same,
&fixture.eq_properties));
+ assert!(range_a.compatible_with(&range_b_equivalent, &eq_properties));
+ assert!(!range_a.compatible_with(&range_b_equivalent,
&fixture.eq_properties));
+ assert!(!range_a.compatible_with(&range_b_different_split,
&eq_properties));
+ assert!(!range_a.compatible_with(&range_a_desc, &eq_properties));
+ assert!(
+ single_partition_range_a
+ .compatible_with(&single_partition_range_b,
&fixture.eq_properties)
+ );
+
+ assert!(
+ fixture
+ .range_partitioning([0], vec![int_split_point([10])])
+ .compatible_with(
+ &fixture.range_partitioning([1],
vec![int_split_point([10])]),
+ &eq_properties
+ )
+ );
+ assert!(
+ !fixture
+ .range_partitioning([0], vec![int_split_point([10])])
+ .compatible_with(
+ &fixture.range_partitioning([0],
vec![int_split_point([20])]),
+ &fixture.eq_properties
+ )
+ );
+ assert!(
+ !fixture
+ .range_partitioning([0], vec![int_split_point([10])])
+ .compatible_with(
+ &fixture.hash_partitioning([0], 2),
+ &fixture.eq_properties
+ )
+ );
+
+ Ok(())
+ }
+
+ #[test]
+ fn test_hash_partitioning_compatible_with() -> Result<()> {
+ let fixture = PartitioningTestFixture::int64(&["a", "b"])?;
+ let mut eq_properties = fixture.eq_properties.clone();
+ eq_properties.add_equal_conditions(fixture.col(0), fixture.col(1))?;
+
+ assert!(
+ fixture.hash_partitioning([0], 2).compatible_with(
+ &fixture.hash_partitioning([0], 2),
+ &fixture.eq_properties
+ )
+ );
+ assert!(
+ fixture
+ .hash_partitioning([0], 2)
+ .compatible_with(&fixture.hash_partitioning([1], 2),
&eq_properties)
+ );
+ assert!(
+ !fixture.hash_partitioning([0], 2).compatible_with(
+ &fixture.hash_partitioning([1], 2),
+ &fixture.eq_properties
+ )
+ );
+ assert!(
+ !fixture.hash_partitioning([0], 2).compatible_with(
+ &fixture.hash_partitioning([0], 3),
+ &fixture.eq_properties
+ )
+ );
+ assert!(!fixture.hash_partitioning([0], 2).compatible_with(
+ &fixture.hash_partitioning([0, 1], 2),
+ &fixture.eq_properties
+ ));
+ assert!(
+ !Partitioning::Hash(vec![], 2)
+ .compatible_with(&Partitioning::Hash(vec![], 2),
&fixture.eq_properties)
+ );
+ assert!(!fixture.hash_partitioning([0], 2).compatible_with(
+ &fixture.range_partitioning([0], vec![int_split_point([10])]),
+ &fixture.eq_properties
+ ));
+ assert!(
+ fixture.hash_partitioning([0], 1).compatible_with(
+ &Partitioning::RoundRobinBatch(1),
+ &fixture.eq_properties
+ )
+ );
+
+ Ok(())
+ }
+
+ #[test]
+ fn test_round_robin_partitioning_compatible_with() {
+ let eq_properties =
EquivalenceProperties::new(Arc::new(Schema::empty()));
+
+ assert!(
+ Partitioning::RoundRobinBatch(1)
+ .compatible_with(&Partitioning::RoundRobinBatch(1),
&eq_properties)
+ );
+ assert!(
+ !Partitioning::RoundRobinBatch(2)
+ .compatible_with(&Partitioning::RoundRobinBatch(2),
&eq_properties)
+ );
+ assert!(
+ Partitioning::RoundRobinBatch(1)
+ .compatible_with(&Partitioning::UnknownPartitioning(1),
&eq_properties)
+ );
+ assert!(
+ !Partitioning::RoundRobinBatch(2)
+ .compatible_with(&Partitioning::UnknownPartitioning(2),
&eq_properties)
+ );
+ }
+
+ #[test]
+ fn test_unknown_partitioning_compatible_with() {
Review Comment:
these might be too granular, we could collapse these as some of them test
the same case just flipped self and other. I just tried to make a test per type
of partitioning to keep the test scopes nice and understandable
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]