This is an automated email from the ASF dual-hosted git repository.
Jackie-Jiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new 14d03a704d7 Do not fail the query when the server has not set up the
table and all segments are optional (#20262)
14d03a704d7 is described below
commit 14d03a704d7819a371abc144072478c76f0901a1
Author: Xiaotian (Jackie) Jiang <[email protected]>
AuthorDate: Tue Nov 17 15:59:38 2026 -0800
Do not fail the query when the server has not set up the table and all
segments are optional (#20262)
---
.../query/executor/EmptyTableExecutionInfo.java | 119 +++++++++++++++++++++
.../query/executor/LogicalTableExecutionInfo.java | 15 ++-
.../query/executor/ServerQueryExecutorV1Impl.java | 4 +
.../query/executor/SingleTableExecutionInfo.java | 12 +++
.../core/query/executor/TableExecutionInfo.java | 3 +-
.../core/query/executor/QueryExecutorTest.java | 63 ++++++++++-
.../executor/SingleTableExecutionInfoTest.java | 19 +++-
.../plan/server/ServerPlanRequestUtils.java | 80 +++++---------
8 files changed, 255 insertions(+), 60 deletions(-)
diff --git
a/pinot-core/src/main/java/org/apache/pinot/core/query/executor/EmptyTableExecutionInfo.java
b/pinot-core/src/main/java/org/apache/pinot/core/query/executor/EmptyTableExecutionInfo.java
new file mode 100644
index 00000000000..e78a9f71583
--- /dev/null
+++
b/pinot-core/src/main/java/org/apache/pinot/core/query/executor/EmptyTableExecutionInfo.java
@@ -0,0 +1,119 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.query.executor;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import javax.annotation.Nullable;
+import org.apache.pinot.core.query.pruner.SegmentPrunerService;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.apache.pinot.core.query.request.context.TimerContext;
+import org.apache.pinot.segment.local.data.manager.SegmentDataManager;
+import org.apache.pinot.segment.spi.IndexSegment;
+import org.apache.pinot.segment.spi.SegmentContext;
+import org.apache.pinot.spi.data.Schema;
+
+
+/// The [TableExecutionInfo] of a query that has nothing to query on the
server: the table is not set up on the server
+/// yet, and the query has no segment the server must have.
+///
+/// A server sets up a table when it adds the first segment of it, so a server
without the table has not loaded any of
+/// the optional segments it is asked for. The query runs the way it does over
a table whose segments are all skipped.
+///
+/// Stateless, and thus thread safe.
+public final class EmptyTableExecutionInfo implements TableExecutionInfo {
+ public static final EmptyTableExecutionInfo INSTANCE = new
EmptyTableExecutionInfo();
+
+ private EmptyTableExecutionInfo() {
+ }
+
+ @Nullable
+ @Override
+ public Schema getSchema() {
+ return null;
+ }
+
+ @Override
+ public boolean hasRealtime() {
+ return false;
+ }
+
+ @Override
+ public List<IndexSegment> getIndexSegments() {
+ return List.of();
+ }
+
+ @Nullable
+ @Override
+ public Map<IndexSegment, SegmentContext> getProvidedSegmentContexts() {
+ return null;
+ }
+
+ @Override
+ public List<String> getSegmentsToQuery() {
+ return List.of();
+ }
+
+ @Override
+ public List<String> getOptionalSegments() {
+ return List.of();
+ }
+
+ @Override
+ public List<SegmentDataManager> getSegmentDataManagers() {
+ return List.of();
+ }
+
+ @Override
+ public void releaseSegmentDataManagers() {
+ }
+
+ @Override
+ public List<SegmentContext> getSegmentContexts(List<IndexSegment>
selectedSegments,
+ Map<String, String> queryOptions) {
+ return List.of();
+ }
+
+ @Override
+ public List<String> getNotAcquiredSegments() {
+ return List.of();
+ }
+
+ @Override
+ public List<String> getMissingSegments() {
+ return List.of();
+ }
+
+ @Override
+ public int getNumSegmentsAcquired() {
+ return 0;
+ }
+
+ @Override
+ public SelectedSegmentsInfo getSelectedSegmentsInfo(QueryContext
queryContext, TimerContext timerContext,
+ ExecutorService executorService, SegmentPrunerService
segmentPrunerService) {
+ return new SelectedSegmentsInfo();
+ }
+
+ @Override
+ public ConsumingSegmentsInfo getConsumingSegmentsInfo() {
+ return new ConsumingSegmentsInfo(0, 0, 0, 0);
+ }
+}
diff --git
a/pinot-core/src/main/java/org/apache/pinot/core/query/executor/LogicalTableExecutionInfo.java
b/pinot-core/src/main/java/org/apache/pinot/core/query/executor/LogicalTableExecutionInfo.java
index 022935b11b1..187f52c16b3 100644
---
a/pinot-core/src/main/java/org/apache/pinot/core/query/executor/LogicalTableExecutionInfo.java
+++
b/pinot-core/src/main/java/org/apache/pinot/core/query/executor/LogicalTableExecutionInfo.java
@@ -46,6 +46,14 @@ import org.slf4j.LoggerFactory;
public class LogicalTableExecutionInfo implements TableExecutionInfo {
private static final Logger LOGGER =
LoggerFactory.getLogger(LogicalTableExecutionInfo.class);
+ /// Creates the execution info of the physical tables of the given request,
acquiring the segments to query.
+ ///
+ /// A physical table that is not set up on the server yet is left out when
the query has no segment of it the server
+ /// must have (see [SingleTableExecutionInfo#create]). Returns `null` when
no physical table is left.
+ ///
+ /// @throws TableNotFoundException when a physical table is not set up on
the server and the query has a segment of
+ /// it the server must have
+ @Nullable
public static LogicalTableExecutionInfo create(InstanceDataManager
instanceDataManager,
ServerQueryRequest queryRequest, QueryContext queryContext)
throws TableNotFoundException {
@@ -56,10 +64,11 @@ public class LogicalTableExecutionInfo implements
TableExecutionInfo {
SingleTableExecutionInfo singleTableExecutionInfo =
SingleTableExecutionInfo.create(instanceDataManager,
tableSegmentsContext.getTableName(),
tableSegmentsContext.getSegments(),
tableSegmentsContext.getOptionalSegments(), queryContext);
- tableExecutionInfos.add(singleTableExecutionInfo);
+ if (singleTableExecutionInfo != null) {
+ tableExecutionInfos.add(singleTableExecutionInfo);
+ }
}
-
- return new LogicalTableExecutionInfo(tableExecutionInfos);
+ return !tableExecutionInfos.isEmpty() ? new
LogicalTableExecutionInfo(tableExecutionInfos) : null;
}
private final List<SingleTableExecutionInfo> _tableExecutionInfos;
diff --git
a/pinot-core/src/main/java/org/apache/pinot/core/query/executor/ServerQueryExecutorV1Impl.java
b/pinot-core/src/main/java/org/apache/pinot/core/query/executor/ServerQueryExecutorV1Impl.java
index 5f53acedadb..6e1db5c46f5 100644
---
a/pinot-core/src/main/java/org/apache/pinot/core/query/executor/ServerQueryExecutorV1Impl.java
+++
b/pinot-core/src/main/java/org/apache/pinot/core/query/executor/ServerQueryExecutorV1Impl.java
@@ -298,6 +298,10 @@ public class ServerQueryExecutorV1Impl implements
QueryExecutor {
LOGGER.error("{} while processing requestId: {}", errorMessage,
requestId);
return instanceResponse;
}
+ if (executionInfo == null) {
+ // The table is not set up on the server yet, and all the segments to
query are optional
+ executionInfo = EmptyTableExecutionInfo.INSTANCE;
+ }
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Processing requestId: {} with segmentsToQuery: {},
optionalSegments: {} and acquiredSegments: {}",
diff --git
a/pinot-core/src/main/java/org/apache/pinot/core/query/executor/SingleTableExecutionInfo.java
b/pinot-core/src/main/java/org/apache/pinot/core/query/executor/SingleTableExecutionInfo.java
index df484ea40d0..2132e86dec6 100644
---
a/pinot-core/src/main/java/org/apache/pinot/core/query/executor/SingleTableExecutionInfo.java
+++
b/pinot-core/src/main/java/org/apache/pinot/core/query/executor/SingleTableExecutionInfo.java
@@ -60,11 +60,23 @@ public class SingleTableExecutionInfo implements
TableExecutionInfo {
private final List<String> _optionalSegments;
private final List<String> _notAcquiredSegments;
+ /// Creates the execution info of the given table, acquiring the segments to
query.
+ ///
+ /// Returns `null` when the table is not set up on the server yet and the
query has no segment the server must have,
+ /// i.e. all of its segments are optional. A server sets up a table when it
adds the first segment of it, so it has
+ /// not loaded any of them and there is nothing to query.
+ ///
+ /// @throws TableNotFoundException when the table is not set up on the
server and the query has a segment the server
+ /// must have
+ @Nullable
public static SingleTableExecutionInfo create(InstanceDataManager
instanceDataManager, String tableNameWithType,
List<String> segmentsToQuery, List<String> optionalSegments,
QueryContext queryContext)
throws TableNotFoundException {
TableDataManager tableDataManager =
instanceDataManager.getTableDataManager(tableNameWithType);
if (tableDataManager == null) {
+ if (segmentsToQuery.isEmpty()) {
+ return null;
+ }
throw new TableNotFoundException(tableNameWithType);
}
diff --git
a/pinot-core/src/main/java/org/apache/pinot/core/query/executor/TableExecutionInfo.java
b/pinot-core/src/main/java/org/apache/pinot/core/query/executor/TableExecutionInfo.java
index c80b8e99e45..2c11e65493a 100644
---
a/pinot-core/src/main/java/org/apache/pinot/core/query/executor/TableExecutionInfo.java
+++
b/pinot-core/src/main/java/org/apache/pinot/core/query/executor/TableExecutionInfo.java
@@ -36,7 +36,8 @@ import org.apache.pinot.spi.data.Schema;
public interface TableExecutionInfo {
- /// Returns the latest [Schema] for the table.
+ /// Returns the latest [Schema] for the table, or `null` when the table is
not set up on the server.
+ @Nullable
Schema getSchema();
/// Check if consuming segments are being queried.
diff --git
a/pinot-core/src/test/java/org/apache/pinot/core/query/executor/QueryExecutorTest.java
b/pinot-core/src/test/java/org/apache/pinot/core/query/executor/QueryExecutorTest.java
index 8fc7296a7e5..3fff14d219f 100644
---
a/pinot-core/src/test/java/org/apache/pinot/core/query/executor/QueryExecutorTest.java
+++
b/pinot-core/src/test/java/org/apache/pinot/core/query/executor/QueryExecutorTest.java
@@ -45,6 +45,7 @@ import org.apache.pinot.common.metrics.ServerTimer;
import org.apache.pinot.common.request.BrokerRequest;
import org.apache.pinot.common.request.Expression;
import org.apache.pinot.common.request.InstanceRequest;
+import org.apache.pinot.common.request.TableSegmentsInfo;
import org.apache.pinot.common.request.context.ExpressionContext;
import org.apache.pinot.common.request.context.RequestContextUtils;
import org.apache.pinot.core.data.manager.InstanceDataManager;
@@ -245,6 +246,55 @@ public class QueryExecutorTest {
assertEquals(((AggregationResultsBlock)
instanceResponse.getResultsBlock()).getResults().get(0), 0.0);
}
+ /// A server sets up a table when it adds the first segment of it. Until
then it has no optional segment of the table
+ /// to query, and a segment it must have is missing along with the table.
+ @Test
+ public void testTableNotOnServer() {
+ String query = "SELECT COUNT(*) FROM otherTable_OFFLINE";
+ InstanceRequest instanceRequest = new InstanceRequest(0L,
CalciteSqlCompiler.compileToBrokerRequest(query));
+ instanceRequest.setSearchSegments(List.of());
+ instanceRequest.setOptionalSegments(List.of("newSegment"));
+ InstanceResponseBlock instanceResponse = execute(instanceRequest);
+ assertTrue(instanceResponse.getExceptions().isEmpty(),
instanceResponse.getExceptions().toString());
+ assertTrue(instanceResponse.getResultsBlock() instanceof
AggregationResultsBlock);
+ assertEquals(((AggregationResultsBlock)
instanceResponse.getResultsBlock()).getResults().get(0), 0L);
+
assertEquals(instanceResponse.getResponseMetadata().get(MetadataKey.NUM_SEGMENTS_QUERIED.getName()),
"0");
+
+ String error = executeExpectingFailure(query, null);
+ assertTrue(error.contains("Failed to find table: otherTable_OFFLINE"),
error);
+ }
+
+ /// A logical table leaves out a physical table the server has not set up
when all the segments of that table are
+ /// optional, and fails the query when one of them is a segment the server
must have.
+ @Test
+ public void testLogicalTableWithPhysicalTableNotOnServer() {
+ String query = "SELECT COUNT(*) FROM logicalTable_OFFLINE";
+ Object numRows = aggregate("SELECT COUNT(*) FROM " + OFFLINE_TABLE_NAME,
null);
+ TableSegmentsInfo tableOnServer = newTableSegmentsInfo(OFFLINE_TABLE_NAME,
_segmentNames, null);
+ TableSegmentsInfo tableNotOnServer =
newTableSegmentsInfo("otherTable_OFFLINE", List.of(), List.of("newSegment"));
+ assertEquals(aggregate(newLogicalTableRequest(query, tableOnServer,
tableNotOnServer)), numRows);
+ assertEquals(aggregate(newLogicalTableRequest(query, tableNotOnServer)),
0L);
+
+ tableNotOnServer.setSegments(List.of("segment"));
+ String error = executeExpectingFailure(newLogicalTableRequest(query,
tableNotOnServer));
+ assertTrue(error.contains("Failed to find table: otherTable_OFFLINE"),
error);
+ }
+
+ private static TableSegmentsInfo newTableSegmentsInfo(String
tableNameWithType, List<String> segments,
+ @Nullable List<String> optionalSegments) {
+ TableSegmentsInfo tableSegmentsInfo = new TableSegmentsInfo();
+ tableSegmentsInfo.setTableName(tableNameWithType);
+ tableSegmentsInfo.setSegments(segments);
+ tableSegmentsInfo.setOptionalSegments(optionalSegments);
+ return tableSegmentsInfo;
+ }
+
+ private static InstanceRequest newLogicalTableRequest(String query,
TableSegmentsInfo... tableSegmentsInfos) {
+ InstanceRequest instanceRequest = new InstanceRequest(0L,
CalciteSqlCompiler.compileToBrokerRequest(query));
+ instanceRequest.setTableSegmentsInfoList(List.of(tableSegmentsInfos));
+ return instanceRequest;
+ }
+
/// The broker rejects IN_PARTITIONED_SUBQUERY for a principal with row
filters. A server behind an older broker,
/// which stamps the row filters in the query options but lets the function
through, fails the query instead: the
/// subquery reaches it as a string literal the filters do not cover, so it
would build its ID_SET from every row.
@@ -265,7 +315,11 @@ public class QueryExecutorTest {
}
private Object aggregate(String query, @Nullable Map<String, String>
queryOptions) {
- InstanceResponseBlock instanceResponse = execute(newInstanceRequest(query,
queryOptions));
+ return aggregate(newInstanceRequest(query, queryOptions));
+ }
+
+ private Object aggregate(InstanceRequest instanceRequest) {
+ InstanceResponseBlock instanceResponse = execute(instanceRequest);
assertTrue(instanceResponse.getExceptions().isEmpty(),
instanceResponse.getExceptions().toString());
assertTrue(instanceResponse.getResultsBlock() instanceof
AggregationResultsBlock);
return ((AggregationResultsBlock)
instanceResponse.getResultsBlock()).getResults().get(0);
@@ -273,7 +327,12 @@ public class QueryExecutorTest {
/// Runs the query and returns the text of the exceptions it fails with.
private String executeExpectingFailure(String query, @Nullable Map<String,
String> queryOptions) {
- InstanceResponseBlock instanceResponse = execute(newInstanceRequest(query,
queryOptions));
+ return executeExpectingFailure(newInstanceRequest(query, queryOptions));
+ }
+
+ /// Runs the request and returns the text of the exceptions it fails with.
+ private String executeExpectingFailure(InstanceRequest instanceRequest) {
+ InstanceResponseBlock instanceResponse = execute(instanceRequest);
assertFalse(instanceResponse.getExceptions().isEmpty(), "Expected the
query to fail");
return String.join("\n", instanceResponse.getExceptions().values());
}
diff --git
a/pinot-core/src/test/java/org/apache/pinot/core/query/executor/SingleTableExecutionInfoTest.java
b/pinot-core/src/test/java/org/apache/pinot/core/query/executor/SingleTableExecutionInfoTest.java
index 630e3724164..2831cb846c3 100644
---
a/pinot-core/src/test/java/org/apache/pinot/core/query/executor/SingleTableExecutionInfoTest.java
+++
b/pinot-core/src/test/java/org/apache/pinot/core/query/executor/SingleTableExecutionInfoTest.java
@@ -39,6 +39,7 @@ import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertSame;
import static org.testng.Assert.expectThrows;
@@ -128,8 +129,8 @@ public class SingleTableExecutionInfoTest {
assertSame(indexSegments.get(1), seg2);
}
- /// [SingleTableExecutionInfo#create] throws [TableNotFoundException] when
the requested table
- /// is not registered with the instance data manager.
+ /// [SingleTableExecutionInfo#create] throws [TableNotFoundException] when
the requested table is not registered with
+ /// the instance data manager and the query has a segment the server must
have.
@Test
public void testCreateThrowsTableNotFoundWhenTableMissing() {
InstanceDataManager instanceDataManager = mock(InstanceDataManager.class);
@@ -137,7 +138,19 @@ public class SingleTableExecutionInfoTest {
expectThrows(TableNotFoundException.class,
() -> SingleTableExecutionInfo.create(instanceDataManager,
TABLE_NAME_WITH_TYPE,
- List.of(), null, mock(QueryContext.class)));
+ List.of("seg01"), List.of("seg02"), mock(QueryContext.class)));
+ }
+
+ /// [SingleTableExecutionInfo#create] returns `null` when the requested
table is not registered with the instance
+ /// data manager and all the segments to query are optional.
+ @Test
+ public void testCreateReturnsNullWhenTableMissingAndAllSegmentsOptional()
+ throws TableNotFoundException {
+ InstanceDataManager instanceDataManager = mock(InstanceDataManager.class);
+
when(instanceDataManager.getTableDataManager(TABLE_NAME_WITH_TYPE)).thenReturn(null);
+
+ assertNull(SingleTableExecutionInfo.create(instanceDataManager,
TABLE_NAME_WITH_TYPE, List.of(), List.of("seg01"),
+ mock(QueryContext.class)));
}
private static InstanceDataManager
mockInstanceDataManager(List<SegmentDataManager> acquired,
diff --git
a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/plan/server/ServerPlanRequestUtils.java
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/plan/server/ServerPlanRequestUtils.java
index 8c35aa5442f..37a29140c07 100644
---
a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/plan/server/ServerPlanRequestUtils.java
+++
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/plan/server/ServerPlanRequestUtils.java
@@ -28,7 +28,6 @@ import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.function.BiConsumer;
import javax.annotation.Nullable;
-import org.apache.commons.lang3.tuple.Pair;
import org.apache.pinot.common.metrics.ServerMetrics;
import org.apache.pinot.common.request.BrokerRequest;
import org.apache.pinot.common.request.Expression;
@@ -53,7 +52,6 @@ import org.apache.pinot.query.runtime.operator.OpChain;
import org.apache.pinot.query.runtime.plan.OpChainConverterDispatcher;
import org.apache.pinot.query.runtime.plan.OpChainExecutionContext;
import org.apache.pinot.segment.local.data.manager.TableDataManager;
-import org.apache.pinot.spi.config.table.TableConfig;
import org.apache.pinot.spi.config.table.TableType;
import org.apache.pinot.spi.data.FieldSpec;
import org.apache.pinot.spi.data.Schema;
@@ -161,59 +159,43 @@ public class ServerPlanRequestUtils {
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(),
+ "Failed to find data manager for table: %s", tableNameWithType);
+ Schema schema = tableDataManager != null ?
tableDataManager.getCachedTableConfigAndSchema().getRight() : null;
+ return compileInstanceRequest(executionContext, pinotQuery,
timeBoundaryInfo, tableType, tableNameWithType, schema,
+ segments, null);
+ }
+
+ /// Converts [PinotQuery] into an [InstanceRequest]. The schema is `null`
when the table is not set up on the server.
+ private static InstanceRequest
compileInstanceRequest(OpChainExecutionContext executionContext, PinotQuery
pinotQuery,
+ @Nullable TimeBoundaryInfo timeBoundaryInfo, TableType tableType, String
tableNameWithType,
+ @Nullable Schema schema, @Nullable List<String> segmentList,
@Nullable List<TableSegmentsInfo> tableRouteInfoList) {
Preconditions.checkArgument(segmentList == null || tableRouteInfoList ==
null,
"Either segmentList OR tableRouteInfoList should be set");
@@ -447,15 +429,13 @@ public class ServerPlanRequestUtils {
String offlineTableName =
TableNameBuilder.forType(TableType.OFFLINE).tableNameWithType(logicalTableName);
return List.of(
compileInstanceRequest(executionContext, pinotQuery,
timeBoundaryInfo, TableType.OFFLINE, offlineTableName,
- logicalTableContext.getRefOfflineTableConfig(),
logicalTableContext.getLogicalTableSchema(), null,
- routeInfoList));
+ logicalTableContext.getLogicalTableSchema(), null,
routeInfoList));
} else {
Preconditions.checkNotNull(logicalTableContext.getRefRealtimeTableConfig());
String realtimeTableName =
TableNameBuilder.forType(TableType.REALTIME).tableNameWithType(logicalTableName);
return List.of(
compileInstanceRequest(executionContext, pinotQuery,
timeBoundaryInfo, TableType.REALTIME,
- realtimeTableName,
logicalTableContext.getRefRealtimeTableConfig(),
- logicalTableContext.getLogicalTableSchema(), null,
routeInfoList));
+ realtimeTableName,
logicalTableContext.getLogicalTableSchema(), null, routeInfoList));
}
} else {
Preconditions.checkNotNull(logicalTableContext.getRefOfflineTableConfig());
@@ -466,11 +446,9 @@ public class ServerPlanRequestUtils {
PinotQuery realtimePinotQuery = pinotQuery.deepCopy();
return List.of(
compileInstanceRequest(executionContext, offlinePinotQuery,
timeBoundaryInfo, TableType.OFFLINE,
- offlineTableName, logicalTableContext.getRefOfflineTableConfig(),
- logicalTableContext.getLogicalTableSchema(), null,
offlineTableRouteInfoList),
+ offlineTableName, logicalTableContext.getLogicalTableSchema(),
null, offlineTableRouteInfoList),
compileInstanceRequest(executionContext, realtimePinotQuery,
timeBoundaryInfo, TableType.REALTIME,
- realtimeTableName,
logicalTableContext.getRefRealtimeTableConfig(),
- logicalTableContext.getLogicalTableSchema(), null,
realtimeTableRouteInfoList));
+ realtimeTableName, logicalTableContext.getLogicalTableSchema(),
null, realtimeTableRouteInfoList));
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]