Jackie-Jiang commented on code in PR #20262:
URL: https://github.com/apache/pinot/pull/20262#discussion_r4595604148


##########
pinot-core/src/main/java/org/apache/pinot/core/query/executor/LogicalTableExecutionInfo.java:
##########
@@ -56,10 +64,11 @@ public static LogicalTableExecutionInfo 
create(InstanceDataManager instanceDataM
       SingleTableExecutionInfo singleTableExecutionInfo =
           SingleTableExecutionInfo.create(instanceDataManager, 
tableSegmentsContext.getTableName(),
               tableSegmentsContext.getSegments(), 
tableSegmentsContext.getOptionalSegments(), queryContext);
-      tableExecutionInfos.add(singleTableExecutionInfo);
+      if (singleTableExecutionInfo != null) {

Review Comment:
   Added `QueryExecutorTest#testLogicalTableWithPhysicalTableNotOnServer`. It 
sends logical-table requests through the real executor instead of mocking the 
data managers: a mix keeps the physical table that is present, a request whose 
only table is missing with just optional segments returns an empty result, and 
a missing table with a required segment fails the query.



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/plan/server/ServerPlanRequestUtils.java:
##########
@@ -161,59 +159,43 @@ public static List<InstanceRequest> 
constructServerQueryRequests(OpChainExecutio
     int numRequests = tableSegmentsMap.size();
     if (numRequests == 1) {
       Map.Entry<String, List<String>> entry = 
tableSegmentsMap.entrySet().iterator().next();
-      String tableType = entry.getKey();
-      List<String> segments = entry.getValue();
-      if (tableType.equals(TableType.OFFLINE.name())) {
-        String offlineTableName = 
TableNameBuilder.forType(TableType.OFFLINE).tableNameWithType(rawTableName);
-        TableDataManager tableDataManager = 
instanceDataManager.getTableDataManager(offlineTableName);
-        Preconditions.checkState(tableDataManager != null, "Failed to find 
data manager for table: %s",
-            offlineTableName);
-        Pair<TableConfig, Schema> tableConfigAndSchema = 
tableDataManager.getCachedTableConfigAndSchema();
-        return List.of(compileInstanceRequest(executionContext, pinotQuery, 
timeBoundary, TableType.OFFLINE,
-            tableDataManager.getTableName(), tableConfigAndSchema.getLeft(), 
tableConfigAndSchema.getRight(), segments,
-            null));
-      } else {
-        assert tableType.equals(TableType.REALTIME.name());
-        String realtimeTableName = 
TableNameBuilder.forType(TableType.REALTIME).tableNameWithType(rawTableName);
-        TableDataManager tableDataManager = 
instanceDataManager.getTableDataManager(realtimeTableName);
-        Preconditions.checkState(tableDataManager != null, "Failed to find 
data manager for table: %s",
-            realtimeTableName);
-        Pair<TableConfig, Schema> tableConfigAndSchema = 
tableDataManager.getCachedTableConfigAndSchema();
-        return List.of(compileInstanceRequest(executionContext, pinotQuery, 
timeBoundary, TableType.REALTIME,
-            tableDataManager.getTableName(), tableConfigAndSchema.getLeft(), 
tableConfigAndSchema.getRight(), segments,
-            null));
-      }
+      return List.of(compileInstanceRequest(executionContext, pinotQuery, 
timeBoundary,
+          TableType.valueOf(entry.getKey()), rawTableName, entry.getValue(), 
instanceDataManager));
     } else {
       assert numRequests == 2;
       List<String> offlineSegments = 
tableSegmentsMap.get(TableType.OFFLINE.name());
       List<String> realtimeSegments = 
tableSegmentsMap.get(TableType.REALTIME.name());
       assert offlineSegments != null && realtimeSegments != null;
-      String offlineTableName = 
TableNameBuilder.forType(TableType.OFFLINE).tableNameWithType(rawTableName);
-      TableDataManager offlineTableDataManager = 
instanceDataManager.getTableDataManager(offlineTableName);
-      Preconditions.checkState(offlineTableDataManager != null, "Failed to 
find data manager for table: %s",
-          offlineTableName);
-      Pair<TableConfig, Schema> offlineTableConfigAndSchema = 
offlineTableDataManager.getCachedTableConfigAndSchema();
-      String realtimeTableName = 
TableNameBuilder.forType(TableType.REALTIME).tableNameWithType(rawTableName);
-      TableDataManager realtimeTableDataManager = 
instanceDataManager.getTableDataManager(realtimeTableName);
-      Preconditions.checkState(realtimeTableDataManager != null, "Failed to 
find data manager for table: %s",
-          realtimeTableName);
-      Pair<TableConfig, Schema> realtimeTableConfigAndSchema =
-          realtimeTableDataManager.getCachedTableConfigAndSchema();
       // NOTE: Make a deep copy of PinotQuery for OFFLINE request.
       return List.of(
           compileInstanceRequest(executionContext, new PinotQuery(pinotQuery), 
timeBoundary, TableType.OFFLINE,
-              offlineTableDataManager.getTableName(), 
offlineTableConfigAndSchema.getLeft(),
-              offlineTableConfigAndSchema.getRight(), offlineSegments, null),
-          compileInstanceRequest(executionContext, pinotQuery, timeBoundary, 
TableType.REALTIME,
-              realtimeTableDataManager.getTableName(), 
realtimeTableConfigAndSchema.getLeft(),
-              realtimeTableConfigAndSchema.getRight(), realtimeSegments, 
null));
+              rawTableName, offlineSegments, instanceDataManager),
+          compileInstanceRequest(executionContext, pinotQuery, timeBoundary, 
TableType.REALTIME, rawTableName,
+              realtimeSegments, instanceDataManager));
     }
   }
 
-  /// Convert [PinotQuery] into an [InstanceRequest].
+  /// Converts [PinotQuery] into an [InstanceRequest] for one table type of a 
physical table.
+  ///
+  /// A server sets up a table when it adds the first segment of it, so a 
table that is not set up yet fails the query
+  /// only when the worker has a segment the server must have. Otherwise the 
request is built without the schema of
+  /// the table, and the leaf query executor answers it with an empty result.
   private static InstanceRequest 
compileInstanceRequest(OpChainExecutionContext executionContext, PinotQuery 
pinotQuery,
-      @Nullable TimeBoundaryInfo timeBoundaryInfo, TableType tableType,
-      String tableNameWithType, TableConfig tableConfig, Schema schema, 
@Nullable List<String> segmentList,
+      @Nullable TimeBoundaryInfo timeBoundaryInfo, TableType tableType, String 
rawTableName, List<String> segments,
+      InstanceDataManager instanceDataManager) {
+    String tableNameWithType = 
TableNameBuilder.forType(tableType).tableNameWithType(rawTableName);
+    TableDataManager tableDataManager = 
instanceDataManager.getTableDataManager(tableNameWithType);
+    Preconditions.checkState(tableDataManager != null || segments.isEmpty(),

Review Comment:
   Leaving this one out of this PR. No planner path on master hands a leaf 
worker a table type without segments on a server that has not set up the table, 
so the branch can only be reached here by mocking the whole execution context. 
The follow-up that sends optional segments in the multi-stage engine makes it 
reachable, and carries an end-to-end test for it: a join against a replicated 
table the server has not set up, run through the real planner and server.



-- 
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]

Reply via email to