xiangfu0 commented on code in PR #20389:
URL: https://github.com/apache/pinot/pull/20389#discussion_r4762322709
##########
pinot-query-planner/src/main/java/org/apache/pinot/query/routing/WorkerManager.java:
##########
@@ -935,7 +938,14 @@ private void
assignWorkersToNonPartitionedLeafFragment(PlanFragment fragment, Di
// When broker pruning is enabled, routingPinotQuery carries the leaf
stage filter so that segment pruners can
// eliminate segments. When disabled (null), fall back to an unfiltered
SELECT * routing request.
Map<String, RoutingTable> routingTableMap = null;
- if (routingPinotQuery != null) {
+ if (metadata.getTableOptions() != null
+ &&
metadata.getTableOptions().containsKey(PinotHintStrategyTable.GROUP_BY_ROUTE)) {
+ PlannerContext.GroupByRoute checked =
context.getPlannerContext().getGroupByRoutes().get(tableName);
+ Preconditions.checkState(checked != null, "Missing verified GROUP BY
route for table: %s", tableName);
+ routingTableMap =
+ Map.of(TableType.OFFLINE.name(), pruneGroupByRoute(checked.route(),
fragment, tableName, context));
+ }
Review Comment:
Fixed in `32829c6d03`. Before the fix, the reversed-placement fixture
returned two joined rows with the flag off and zero with it on. The planner now
limits automatic leaf finalization to a terminal GROUP BY. An aggregate feeding
a join retains its original hash exchange and FINAL stage, so enabling the flag
preserves the worker mapping expected by the join. Both flag settings return
the two H2 rows.
##########
pinot-query-planner/src/main/java/org/apache/pinot/calcite/rel/rules/PinotAggregateExchangeNodeInsertRule.java:
##########
@@ -295,15 +306,91 @@ private static RelNode createPlan(RelOptRuleCall call,
Aggregate aggRel, boolean
if (withinGroupCollation != null || (hasGroupBy && Boolean.parseBoolean(
hintOptions.get(PinotHintOptions.AggregateOptions.IS_SKIP_LEAF_STAGE_GROUP_BY))))
{
return createPlanWithExchangeDirectAggregation(call, aggRel,
withinGroupCollation, collations, limit);
- } else if (hasGroupBy && Boolean.parseBoolean(
+ }
+ RelNode directInput = null;
+ if (hasGroupBy && Boolean.parseBoolean(
hintOptions.get(PinotHintOptions.AggregateOptions.IS_PARTITIONED_BY_GROUP_BY_KEYS)))
{
- return new PinotLogicalAggregate(aggRel, aggRel.getInput(),
buildAggCalls(aggRel, AggType.DIRECT, false),
+ directInput = aggRel.getInput();
+ } else if (hasGroupBy && hintOptions.isEmpty()) {
+ Context context = call.getPlanner().getContext();
+ PlannerContext planner = context != null ?
context.unwrap(PlannerContext.class) : null;
+ if (planner != null &&
QueryOptionsUtils.isServerReturnFinalResult(planner.getOptions())
+ &&
!QueryOptionsUtils.isMultiClusterRoutingEnabled(planner.getOptions(), false)
+ &&
!planner.getOptions().containsKey(QueryOptionKey.MULTI_STAGE_LEAF_LIMIT)
+ && !planner.getOptions().containsKey(QueryOptionKey.TABLE_SAMPLER)
+ && !planner.getOptions().containsKey(QueryOptionKey.ROUTING_OPTIONS)
+ && planner.getEnvConfig().getWorkerManager() != null) {
+ directInput = partitionedGroupByInput(aggRel.getInput(),
aggRel.getGroupSet(), planner);
+ }
+ }
+ if (directInput != null) {
+ return new PinotLogicalAggregate(aggRel, directInput,
buildAggCalls(aggRel, AggType.DIRECT, false),
AggType.DIRECT, false, collations, limit);
- } else {
- boolean leafReturnFinalResult =
-
Boolean.parseBoolean(hintOptions.get(PinotHintOptions.AggregateOptions.IS_LEAF_RETURN_FINAL_RESULT));
- return createPlanWithLeafExchangeFinalAggregate(aggRel,
leafReturnFinalResult, collations, limit);
}
+ boolean leafReturnFinalResult =
+
Boolean.parseBoolean(hintOptions.get(PinotHintOptions.AggregateOptions.IS_LEAF_RETURN_FINAL_RESULT));
+ return createPlanWithLeafExchangeFinalAggregate(aggRel,
leafReturnFinalResult, collations, limit);
+ }
+
+ /// Trace unmodified grouping columns through the leaf and give its scan the
exact partition routing that
+ /// makes the aggregate direct. Grouping on a transformation of the
partition column cannot establish colocation.
+ @Nullable
+ private static RelNode partitionedGroupByInput(RelNode input,
ImmutableBitSet keys, PlannerContext planner) {
+ RelNode node = PinotRuleUtils.unboxRel(input);
+ if (node instanceof Project project) {
+ ImmutableBitSet.Builder refs = ImmutableBitSet.builder();
+ for (int key : keys) {
+ if (project.getProjects().get(key) instanceof RexInputRef ref) {
+ refs.set(ref.getIndex());
+ }
+ }
+ keys = refs.build();
+ } else if (node instanceof TableScan scan) {
+ if (PinotHintStrategyTable.getHint(scan,
PinotHintOptions.TABLE_HINT_OPTIONS) != null) {
+ return null;
+ }
+ String tableName = planner.getEnvConfig().getTableCache()
+
.getActualTableName(RelToPlanNodeConverter.getTableNameFromTableScan(scan));
+ if (tableName == null) {
+ return null;
+ }
+ Schema schema =
planner.getEnvConfig().getTableCache().getSchema(TableNameBuilder.extractRawTableName(tableName));
+ if (schema == null) {
+ return null;
+ }
+ // Hashing the ingested value must agree with grouping the stored value.
Null sentinels and decimal
+ // representations can differ between segments even when SQL considers
the group keys equal.
+ Set<String> groupColumns = new HashSet<>();
+ for (int key : keys) {
+ String column = scan.getRowType().getFieldNames().get(key);
+ FieldSpec field = schema.getFieldSpecFor(column);
+ if (field != null && field.isSingleValueField() && field.isNotNull()
Review Comment:
Changed the gate in `32829c6d03` to use the query's effective
`enableNullHandling` setting. With null handling disabled, the planner can
certify a supported single-value partition key even when its field has the
default `notNull=false`. With null handling enabled it keeps FINAL because even
a current column-based non-null declaration cannot establish the contents of
older segments. The planner tests cover both schema modes.
##########
pinot-query-planner/src/main/java/org/apache/pinot/calcite/rel/rules/PinotAggregateExchangeNodeInsertRule.java:
##########
@@ -295,15 +306,91 @@ private static RelNode createPlan(RelOptRuleCall call,
Aggregate aggRel, boolean
if (withinGroupCollation != null || (hasGroupBy && Boolean.parseBoolean(
hintOptions.get(PinotHintOptions.AggregateOptions.IS_SKIP_LEAF_STAGE_GROUP_BY))))
{
return createPlanWithExchangeDirectAggregation(call, aggRel,
withinGroupCollation, collations, limit);
- } else if (hasGroupBy && Boolean.parseBoolean(
+ }
+ RelNode directInput = null;
+ if (hasGroupBy && Boolean.parseBoolean(
hintOptions.get(PinotHintOptions.AggregateOptions.IS_PARTITIONED_BY_GROUP_BY_KEYS)))
{
- return new PinotLogicalAggregate(aggRel, aggRel.getInput(),
buildAggCalls(aggRel, AggType.DIRECT, false),
+ directInput = aggRel.getInput();
+ } else if (hasGroupBy && hintOptions.isEmpty()) {
+ Context context = call.getPlanner().getContext();
+ PlannerContext planner = context != null ?
context.unwrap(PlannerContext.class) : null;
+ if (planner != null &&
QueryOptionsUtils.isServerReturnFinalResult(planner.getOptions())
+ &&
!QueryOptionsUtils.isMultiClusterRoutingEnabled(planner.getOptions(), false)
+ &&
!planner.getOptions().containsKey(QueryOptionKey.MULTI_STAGE_LEAF_LIMIT)
+ && !planner.getOptions().containsKey(QueryOptionKey.TABLE_SAMPLER)
+ && !planner.getOptions().containsKey(QueryOptionKey.ROUTING_OPTIONS)
+ && planner.getEnvConfig().getWorkerManager() != null) {
+ directInput = partitionedGroupByInput(aggRel.getInput(),
aggRel.getGroupSet(), planner);
+ }
+ }
+ if (directInput != null) {
+ return new PinotLogicalAggregate(aggRel, directInput,
buildAggCalls(aggRel, AggType.DIRECT, false),
AggType.DIRECT, false, collations, limit);
- } else {
- boolean leafReturnFinalResult =
-
Boolean.parseBoolean(hintOptions.get(PinotHintOptions.AggregateOptions.IS_LEAF_RETURN_FINAL_RESULT));
- return createPlanWithLeafExchangeFinalAggregate(aggRel,
leafReturnFinalResult, collations, limit);
}
+ boolean leafReturnFinalResult =
+
Boolean.parseBoolean(hintOptions.get(PinotHintOptions.AggregateOptions.IS_LEAF_RETURN_FINAL_RESULT));
+ return createPlanWithLeafExchangeFinalAggregate(aggRel,
leafReturnFinalResult, collations, limit);
+ }
+
+ /// Trace unmodified grouping columns through the leaf and give its scan the
exact partition routing that
+ /// makes the aggregate direct. Grouping on a transformation of the
partition column cannot establish colocation.
+ @Nullable
+ private static RelNode partitionedGroupByInput(RelNode input,
ImmutableBitSet keys, PlannerContext planner) {
+ RelNode node = PinotRuleUtils.unboxRel(input);
+ if (node instanceof Project project) {
+ ImmutableBitSet.Builder refs = ImmutableBitSet.builder();
+ for (int key : keys) {
+ if (project.getProjects().get(key) instanceof RexInputRef ref) {
+ refs.set(ref.getIndex());
+ }
+ }
+ keys = refs.build();
+ } else if (node instanceof TableScan scan) {
+ if (PinotHintStrategyTable.getHint(scan,
PinotHintOptions.TABLE_HINT_OPTIONS) != null) {
+ return null;
+ }
+ String tableName = planner.getEnvConfig().getTableCache()
+
.getActualTableName(RelToPlanNodeConverter.getTableNameFromTableScan(scan));
+ if (tableName == null) {
+ return null;
+ }
+ Schema schema =
planner.getEnvConfig().getTableCache().getSchema(TableNameBuilder.extractRawTableName(tableName));
+ if (schema == null) {
+ return null;
+ }
+ // Hashing the ingested value must agree with grouping the stored value.
Null sentinels and decimal
+ // representations can differ between segments even when SQL considers
the group keys equal.
+ Set<String> groupColumns = new HashSet<>();
+ for (int key : keys) {
+ String column = scan.getRowType().getFieldNames().get(key);
+ FieldSpec field = schema.getFieldSpecFor(column);
+ if (field != null && field.isSingleValueField() && field.isNotNull()
+ && (field.getDataType() == FieldSpec.DataType.INT ||
field.getDataType() == FieldSpec.DataType.LONG
+ || field.getDataType() == FieldSpec.DataType.STRING)) {
+ groupColumns.add(column);
+ }
+ }
+ if (groupColumns.isEmpty()) {
+ return null;
+ }
+ WorkerManager workerManager = planner.getEnvConfig().getWorkerManager();
+ try {
+ if (!workerManager.hasPartitionedGroupByRoute(tableName, groupColumns,
planner)) {
+ return null;
+ }
+ } catch (RuntimeException e) {
+ LOGGER.debug("Could not verify GROUP BY routing for {}", tableName, e);
Review Comment:
Added DEBUG reasons to `WorkerManager.hasPartitionedGroupByRoute` and
documented the terminal GROUP BY, OFFLINE, null-handling, group-key and
worker-placement requirements on `serverReturnFinalResult` in `32829c6d03`. The
messages distinguish missing or inconsistent metadata, a split partition, an
unsupported HashCode string key, and an incomplete route.
--
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]