xiangfu0 commented on code in PR #20389:
URL: https://github.com/apache/pinot/pull/20389#discussion_r4762324401
##########
pinot-query-planner/src/main/java/org/apache/pinot/query/routing/WorkerManager.java:
##########
@@ -1033,6 +1043,25 @@ private void
assignWorkersToNonPartitionedLeafFragment(PlanFragment fragment, Di
metadata.setWorkerIdToSegmentsMap(workerIdToSegmentsMap);
}
+ private RoutingTable pruneGroupByRoute(RoutingTable route, PlanFragment
fragment, String tableName,
+ DispatchablePlanContext context) {
+ Set<String> pruned = getPrunedSegments(fragment, tableName, context);
+ if (pruned == null || pruned.isEmpty()) {
+ return route;
+ }
+ Map<ServerInstance, SegmentsToQuery> remaining = new HashMap<>();
+ int removed = 0;
+ for (var entry : route.getServerInstanceToSegmentsMap().entrySet()) {
+ List<String> segments = entry.getValue().getSegments();
+ List<String> kept = segments.stream().filter(segment ->
!pruned.contains(segment)).toList();
+ removed += segments.size() - kept.size();
+ if (!kept.isEmpty()) {
+ remaining.put(entry.getKey(), new SegmentsToQuery(kept, null));
+ }
+ }
Review Comment:
Added `WorkerManagerTest` coverage in `32829c6d03` for REALTIME and hybrid
tables, unavailable and optional segments, and actual pruning. The filtered
scan checks the surviving segment and the broker's pruned count. An unfiltered
scan verifies that both original segments are still present.
##########
pinot-query-planner/src/main/java/org/apache/pinot/query/routing/WorkerManager.java:
##########
@@ -1033,6 +1043,25 @@ private void
assignWorkersToNonPartitionedLeafFragment(PlanFragment fragment, Di
metadata.setWorkerIdToSegmentsMap(workerIdToSegmentsMap);
}
+ private RoutingTable pruneGroupByRoute(RoutingTable route, PlanFragment
fragment, String tableName,
+ DispatchablePlanContext context) {
+ Set<String> pruned = getPrunedSegments(fragment, tableName, context);
+ if (pruned == null || pruned.isEmpty()) {
+ return route;
Review Comment:
Fixed in `32829c6d03`. Both the required and optional lists are copied for
each pinned scan, including the unfiltered path. The test clears the scan's
required list and appends to its optional list, then verifies that both lists
in the cached routing table still have their original contents.
##########
pinot-query-planner/src/main/java/org/apache/pinot/query/routing/WorkerManager.java:
##########
@@ -1882,6 +1911,59 @@ static void checkLeafWorkerAssignment(String tableName,
@Nullable int[] partitio
}
}
+ /// Checks the ordinary selector's segment assignment. When every partition
has just one server, a group that
+ /// contains the partition key can finish there. Pin this route so dispatch
uses the same replica choices.
+ public boolean hasPartitionedGroupByRoute(String tableName, Set<String>
groupColumns, PlannerContext planner) {
+ PlannerContext.GroupByRoute checked =
planner.getGroupByRoutes().get(tableName);
+ if (checked != null) {
+ return groupColumns.contains(checked.partitionColumn());
+ }
+ TableType type = TableNameBuilder.getTableTypeFromTableName(tableName);
+ if (type == TableType.REALTIME || (type == null
+ &&
_routingManager.routingExists(TableNameBuilder.REALTIME.tableNameWithType(tableName))))
{
+ return false;
+ }
+ String offline = TableNameBuilder.OFFLINE.tableNameWithType(tableName);
+ TablePartitionInfo partitions =
_routingManager.getTablePartitionInfo(offline);
+ if (partitions == null || !partitions.hasConsistentPartitionFunction()
+ || !groupColumns.contains(partitions.getPartitionColumn())) {
+ return false;
+ }
+ RoutingTable route = getRoutingTableHelper(offline,
planner.getEnvConfig().getRequestId(), planner.getOptions());
Review Comment:
Fixed in `32829c6d03`. The planner caches a failed table-wide route check
for the lifetime of one query. If an aggregate simply lacks the partition
column, the next aggregate can still qualify. The routing test exercises both
conditions and verifies that the selector runs once.
##########
pinot-broker/src/main/java/org/apache/pinot/broker/routing/segmentpartition/SegmentPartitionMetadataManager.java:
##########
@@ -477,24 +479,59 @@ private void computeTablePartitionInfo() {
}
_tablePartitionInfo =
new TablePartitionInfo(_tableNameWithType, _partitionColumn,
_partitionFunctionName, _numPartitions,
- segmentsByPartition, segmentsWithInvalidPartition);
+ segmentsByPartition, segmentsWithInvalidPartition, consistent &&
segmentsWithInvalidPartition.isEmpty());
}
private static class SegmentInfo {
int _partitionId;
+ @Nullable
+ PartitionFunction _partitionFunction;
long _creationTimeMs;
List<String> _onlineServers;
/// Servers the ideal state assigns the segment to in ONLINE or CONSUMING
state; empty when the ideal state does
/// not list it, or lists it only in other states (e.g. OFFLINE while it
is being dropped).
List<String> _assignedServers;
- SegmentInfo(int partitionId, long creationTimeMs, List<String>
onlineServers, List<String> assignedServers) {
- _partitionId = partitionId;
- _creationTimeMs = creationTimeMs;
+ SegmentInfo(SegmentPartitionInfo partitionInfo, long creationTimeMs,
List<String> onlineServers,
+ List<String> assignedServers) {
+ updateMetadata(partitionInfo, creationTimeMs);
_onlineServers = onlineServers;
_assignedServers = assignedServers;
}
+ private boolean updateMetadata(SegmentPartitionInfo info, long
creationTimeMs) {
+ int partitionId = info == SegmentPartitionUtils.INVALID_PARTITION_INFO
+ ? INVALID_PARTITION_ID
+ : info.getPartitions().iterator().next();
+ PartitionFunction function =
comparableFunction(info.getPartitionFunction());
+ boolean changed = _partitionId != partitionId || _creationTimeMs !=
creationTimeMs
+ || !Objects.equals(_partitionFunction, function);
+ _partitionId = partitionId;
+ _partitionFunction = function;
+ _creationTimeMs = creationTimeMs;
+ return changed;
+ }
+
+ /// These built-ins persist their hash settings and implement value
equality. HashCode, Modulo and ByteArray
+ /// historically omitted their normalizer from segment metadata. For at
most two partitions every normalizer
+ /// gives the same valid id (parity for two), so that missing setting
cannot change group placement.
+ @Nullable
+ private static PartitionFunction comparableFunction(@Nullable
PartitionFunction function) {
+ if (function == null) {
+ return null;
+ }
+ Class<?> type = function.getClass();
+ if (type == MurmurPartitionFunction.class || type ==
Murmur3PartitionFunction.class
+ || type == FnvPartitionFunction.class) {
+ return function;
+ }
+ if (function.getNumPartitions() <= 2 && (type ==
HashCodePartitionFunction.class
+ || type == ModuloPartitionFunction.class || type ==
ByteArrayPartitionFunction.class)) {
+ return function;
+ }
Review Comment:
Leaving plugin opt-in for a follow-up as suggested. The required contract
covers settings actually recorded by historical segments and whether
partitioning preserves equality of stored group keys. Comparing two
reconstructed function instances alone cannot establish either property. I
documented that boundary in `32829c6d03`. Unrecognized plugins continue to use
the distributed merge.
##########
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`. The planner keeps the existing aggregate layout
whenever a join, set operation, or another aggregate consumes its output. Group
ownership for one table is insufficient to establish a common worker mapping
across inputs. With partitions on opposite servers, the grouped join now
returns `(0,2,1)` and `(1,1,2)` with either flag setting. The flag-on and
flag-off controls also agree for a colocated dynamic semi-join (one row), a
join above UNION ALL (eight rows), and INTERSECT (one row).
--
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]