shivadarshan-devadiga commented on code in PR #18995:
URL: https://github.com/apache/iceberg/pull/18995#discussion_r4726843108
##########
spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/sql/TestStoragePartitionedJoins.java:
##########
@@ -777,6 +1009,121 @@ public void testJoinsHourToDays() throws
NoSuchTableException {
otherTableName);
}
+ private void checkBroadcastJoinOrdering(String direction) {
+ sql(
+ "CREATE TABLE %s (id BIGINT) USING iceberg " + "PARTITIONED BY (id)
TBLPROPERTIES (%s)",
+ tableName, tablePropsAsString(TABLE_PROPERTIES));
+ configurePlanningMode(planningMode);
+ sql("INSERT INTO %s VALUES (-3), (-2), (-1), (1), (2), (3)", tableName);
+
+ sql("CREATE TABLE %s (id BIGINT) USING iceberg",
tableName(OTHER_TABLE_NAME));
+ configurePlanningMode(tableName(OTHER_TABLE_NAME), planningMode);
+ sql("INSERT INTO %s VALUES (1), (2), (3)", tableName(OTHER_TABLE_NAME));
+
+ withSQLConf(
+ ImmutableMap.of(
+ SQLConf.V2_BUCKETING_SORTING_ENABLED().key(),
+ "true",
+ SQLConf.DYNAMIC_PARTITION_PRUNING_ENABLED().key(),
+ "false"),
+ () -> {
+ for (String joinKey : List.of("-p.id", "4 - p.id")) {
+ assertPartitioningAwarePlan(
+ 1,
+ 2,
+ "SELECT /*+ BROADCAST(p) */ p.id FROM %s i JOIN %s p "
+ + "ON i.id = %s ORDER BY %s %s",
+ tableName,
+ tableName(OTHER_TABLE_NAME),
+ joinKey,
+ joinKey,
+ direction);
+ }
+ });
+ }
+
+ @TestTemplate
+ void subsetJoinKeysWithMixedPartitionTypes() {
+ checkSubsetJoinKeysWithMixedPartitionTypes(false);
+ }
+
+ @TestTemplate
+ void partiallyClusteredSubsetJoinKeysWithMixedPartitionTypes() {
+ checkSubsetJoinKeysWithMixedPartitionTypes(true);
+ }
+
+ private void checkSubsetJoinKeysWithMixedPartitionTypes(boolean
partiallyClustered) {
+ sql(
+ "CREATE TABLE %s (id STRING, part STRING, data STRING) USING iceberg "
+ + "PARTITIONED BY (part, bucket(32, id), bucket(32, data))
TBLPROPERTIES (%s)",
+ tableName, tablePropsAsString(TABLE_PROPERTIES));
+ configurePlanningMode(tableName, planningMode);
+ sql(
+ "INSERT INTO %s VALUES ('a', '2026-05-01', 'aa'), ('a', '2026-05-02',
'cc'), "
+ + "('b', '2026-05-01', 'bb'), ('c', '2026-05-02', 'aa')",
+ tableName);
+ sql(
+ "CREATE TABLE %s (id STRING, part STRING, data STRING) USING iceberg "
+ + "PARTITIONED BY (bucket(32, id)) TBLPROPERTIES (%s)",
+ tableName(OTHER_TABLE_NAME), tablePropsAsString(TABLE_PROPERTIES));
+ configurePlanningMode(tableName(OTHER_TABLE_NAME), planningMode);
+ sql(
+ "INSERT INTO %s VALUES ('a', '2026-05-01', 'xx'), ('b', '2026-05-01',
'yy'), "
+ + "('d', '2026-05-01', 'zz')",
+ tableName(OTHER_TABLE_NAME));
+ String query =
+ String.format(
+ "SELECT /*+ MERGE(l, r) */ l.id, l.part, l.data, r.data FROM %s l
JOIN %s r "
+ + "ON l.id = r.id ORDER BY l.id, l.part, l.data, r.data",
+ tableName, tableName(OTHER_TABLE_NAME));
+ AtomicReference<List<Object[]>> expected = new AtomicReference<>();
+ withSQLConf(DISABLED_SPJ_SQL_CONF, () -> expected.set(sql(query)));
+ assertThat(expected.get()).hasSize(3);
+ withSQLConf(
+ ENABLED_SPJ_SQL_CONF,
+ () ->
+ withSQLConf(
+ ImmutableMap.of(
+ SQLConf.ADAPTIVE_EXECUTION_ENABLED().key(),
+ "true",
+ SQLConf.SKEW_JOIN_ENABLED().key(),
+ "true",
+
SQLConf.V2_BUCKETING_PARTIALLY_CLUSTERED_DISTRIBUTION_ENABLED().key(),
+ Boolean.toString(partiallyClustered)),
+ () -> {
+ SparkPlan plan = executeAndKeepPlan(query);
+ assertThat(plan.toString()).contains("SortMergeJoin");
+ assertThat(hasNonLeadingPartitionKeyProjection(plan))
Review Comment:
Thanks, done in
https://github.com/apache/iceberg/pull/18995/commits/e4a5249285748fa5ba08a59931af0d118f4ead41.
`hasNonLeadingPartitionKeyProjection` now takes `partiallyClustered` and
requires the scan that projects the trailing join key to have
`spjParams().applyPartialClustering() == partiallyClustered` in 4.0 and 4.1,
and the `GroupPartitionsExec` to have `distributePartitions() ==
partiallyClustered` in 4.2. Both variants pass, and with the comparison
flipped, both fail on 4.0 and 4.2.
--
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]