Repository navigation
feat(sql): add native query support for system tables #20183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
FrankChen021
wants to merge
12
commits into
apache:master
Choose a base branch
from
FrankChen021:codex/native-sys-tasks-mvp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+7,357
−215
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a0ce486
feat(sql): add native system table execution
FrankChen021 40984db
revert: remove system table node query comment
FrankChen021 8035122
refactor: align task system table class names
FrankChen021 097f647
refactor(sql): split native tasks support into follow-up
FrankChen021 922c82d
fix(server): reject composite local system queries
FrankChen021 cb1c1ef
Merge remote-tracking branch 'offical/master' into codex/native-sys-t…
FrankChen021 0e70330
Merge remote-tracking branch 'offical/master' into codex/native-sys-t…
FrankChen021 fcc68cf
test: remove redundant native system table test cases
FrankChen021 7fc93df
perf: skip native query generation in system-table authorization check
FrankChen021 12d36e8
fix: do not push down filters on columns shadowed by virtual columns
FrankChen021 d4ddcf9
fix: handle null window leaf virtual columns in system table node que…
FrankChen021 24dee02
fix: allow window queries over filtered segments
FrankChen021 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 182 additions & 0 deletions
182
...test/java/org/apache/druid/testing/embedded/query/NativeSysServerPropertiesQueryTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| /* | ||
| * 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.druid.testing.embedded.query; | ||
|
|
||
| import org.apache.druid.query.QueryContexts; | ||
| import org.apache.druid.sql.calcite.planner.PlannerContext; | ||
| import org.apache.druid.sql.calcite.run.NativeSqlEngine; | ||
| import org.apache.druid.testing.embedded.EmbeddedBroker; | ||
| import org.apache.druid.testing.embedded.EmbeddedCoordinator; | ||
| import org.apache.druid.testing.embedded.EmbeddedDruidCluster; | ||
| import org.apache.druid.testing.embedded.EmbeddedHistorical; | ||
| import org.apache.druid.testing.embedded.EmbeddedIndexer; | ||
| import org.apache.druid.testing.embedded.EmbeddedOverlord; | ||
| import org.apache.druid.testing.embedded.EmbeddedRouter; | ||
| import org.apache.druid.testing.embedded.junit5.EmbeddedClusterTestBase; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public class NativeSysServerPropertiesQueryTest extends EmbeddedClusterTestBase | ||
| { | ||
| private static final String SERVICE_NAME = "native/mvp/broker"; | ||
| private static final String COORDINATOR_PROPERTY = "native.sys.server.properties.coordinator"; | ||
| private static final String OVERLORD_PROPERTY = "native.sys.server.properties.overlord"; | ||
| private static final String BROKER_PROPERTY = "native.sys.server.properties.broker"; | ||
| private static final String HISTORICAL_PROPERTY = "native.sys.server.properties.historical"; | ||
| private static final String INDEXER_PROPERTY = "native.sys.server.properties.indexer"; | ||
| private static final String ROUTER_PROPERTY = "native.sys.server.properties.router"; | ||
|
|
||
| private final EmbeddedCoordinator coordinator = new EmbeddedCoordinator() | ||
| .addProperty(COORDINATOR_PROPERTY, "enabled"); | ||
|
|
||
| private final EmbeddedOverlord overlord = new EmbeddedOverlord() | ||
| .addProperty(OVERLORD_PROPERTY, "enabled"); | ||
|
|
||
| private final EmbeddedBroker broker = new EmbeddedBroker() | ||
| .addProperty("druid.service", SERVICE_NAME) | ||
| .addProperty(BROKER_PROPERTY, "enabled"); | ||
|
|
||
| private final EmbeddedHistorical historical = new EmbeddedHistorical() | ||
| .addProperty(HISTORICAL_PROPERTY, "enabled"); | ||
|
|
||
| private final EmbeddedIndexer indexer = new EmbeddedIndexer() | ||
| .addProperty(INDEXER_PROPERTY, "enabled"); | ||
|
|
||
| private final EmbeddedRouter router = new EmbeddedRouter() | ||
| .addProperty(ROUTER_PROPERTY, "enabled"); | ||
|
|
||
| @Override | ||
| protected EmbeddedDruidCluster createCluster() | ||
| { | ||
| return EmbeddedDruidCluster.withEmbeddedDerbyAndZookeeper() | ||
| .useLatchableEmitter() | ||
| .addCommonProperty("druid.centralizedDatasourceSchema.enabled", "true") | ||
| .addServer(coordinator) | ||
| .addServer(overlord) | ||
| .addServer(broker) | ||
| .addServer(historical) | ||
| .addServer(indexer) | ||
| .addServer(router); | ||
| } | ||
|
|
||
| /** | ||
| * Verifies that a native query for {@code sys.server_properties} reaches every persistent node type in the | ||
| * embedded cluster. In particular, the Router row proves that the Broker's native request included | ||
| * {@code X-Druid-Native-Query-Route: local}: without that header the Router would forward the request back to the | ||
| * Broker instead of reading its local system-table provider. | ||
| */ | ||
| @ParameterizedTest(name = "plannerStrategy = {0}") | ||
| @ValueSource(strings = { | ||
| QueryContexts.NATIVE_QUERY_SQL_PLANNING_MODE_COUPLED, | ||
| QueryContexts.NATIVE_QUERY_SQL_PLANNING_MODE_DECOUPLED | ||
| }) | ||
| public void testServerPropertiesFansOutToAllNodes(final String plannerStrategy) | ||
| { | ||
| final String result = cluster.runSql( | ||
| "SELECT service_name, COUNT(*) " | ||
| + "FROM sys.server_properties " | ||
| + "WHERE property IN ('" + COORDINATOR_PROPERTY + "', '" + OVERLORD_PROPERTY + "', '" + BROKER_PROPERTY | ||
| + "', '" + HISTORICAL_PROPERTY + "', '" + INDEXER_PROPERTY + "', '" + ROUTER_PROPERTY + "') " | ||
| + "GROUP BY service_name ORDER BY service_name", | ||
| nativeQueryContext(plannerStrategy) | ||
| ); | ||
|
|
||
| Assertions.assertEquals( | ||
| String.join( | ||
| "\n", | ||
| "druid/coordinator,1", | ||
| "druid/historical,1", | ||
| "druid/indexer,1", | ||
| "druid/overlord,1", | ||
| "druid/router,1", | ||
| SERVICE_NAME + ",1" | ||
| ), | ||
| result | ||
| ); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "plannerStrategy = {0}") | ||
| @ValueSource(strings = { | ||
| QueryContexts.NATIVE_QUERY_SQL_PLANNING_MODE_COUPLED, | ||
| QueryContexts.NATIVE_QUERY_SQL_PLANNING_MODE_DECOUPLED | ||
| }) | ||
| public void testNativeAggregationsSupportDistinctCount(final String plannerStrategy) | ||
| { | ||
| final String result = cluster.runSql( | ||
| "SELECT COUNT(*), COUNT(DISTINCT service_name), COUNT(DISTINCT server), " | ||
| + "COUNT(DISTINCT property), SUM(1) " | ||
| + "FROM sys.server_properties " | ||
| + "WHERE property IN ('" + COORDINATOR_PROPERTY + "', '" + OVERLORD_PROPERTY + "', '" + BROKER_PROPERTY | ||
| + "', '" + HISTORICAL_PROPERTY + "', '" + INDEXER_PROPERTY + "', '" + ROUTER_PROPERTY + "')", | ||
| nativeQueryContext(plannerStrategy) | ||
| ); | ||
|
|
||
| Assertions.assertEquals("6,6,6,6,6", result); | ||
| } | ||
|
|
||
| /** | ||
| * A filtered window-function query is planned as a {@code WindowOperatorQuery} over a system-table Scan, whose | ||
| * filter is pushed into the node scans. | ||
| */ | ||
| @ParameterizedTest(name = "plannerStrategy = {0}") | ||
| @ValueSource(strings = { | ||
| QueryContexts.NATIVE_QUERY_SQL_PLANNING_MODE_COUPLED, | ||
| QueryContexts.NATIVE_QUERY_SQL_PLANNING_MODE_DECOUPLED | ||
| }) | ||
| public void testNativeWindowFunction(final String plannerStrategy) | ||
| { | ||
| final String result = cluster.runSql( | ||
| "SELECT service_name, ROW_NUMBER() OVER (ORDER BY service_name) " | ||
| + "FROM sys.server_properties " | ||
| + "WHERE property IN ('" + COORDINATOR_PROPERTY + "', '" + OVERLORD_PROPERTY + "', '" + BROKER_PROPERTY | ||
| + "', '" + HISTORICAL_PROPERTY + "', '" + INDEXER_PROPERTY + "', '" + ROUTER_PROPERTY + "') " | ||
| + "ORDER BY service_name", | ||
| nativeQueryContext(plannerStrategy) | ||
| ); | ||
|
|
||
| Assertions.assertEquals( | ||
| String.join( | ||
| "\n", | ||
| "druid/coordinator,1", | ||
| "druid/historical,2", | ||
| "druid/indexer,3", | ||
| "druid/overlord,4", | ||
| "druid/router,5", | ||
| SERVICE_NAME + ",6" | ||
| ), | ||
| result | ||
| ); | ||
| } | ||
|
|
||
| private static Map<String, Object> nativeQueryContext(final String plannerStrategy) | ||
| { | ||
| return Map.of( | ||
| QueryContexts.ENGINE, | ||
| NativeSqlEngine.NAME, | ||
| PlannerContext.CTX_USE_NATIVE_QUERY_FOR_SYSTEM_TABLES, | ||
| true, | ||
| QueryContexts.CTX_NATIVE_QUERY_SQL_PLANNING_MODE, | ||
| plannerStrategy | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, is this header required only for the
sys.server_propertiestable? I wonder if there's a better way to achieve this without passing in additional headers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's needed as the broker will send native query to router or itself to retrieve data. for router, we need to tell whether it acts as a proxy or execute the native query.
another way is by using query context, but I don't think the query context is better way because this value here is just an internal flag, not user-facing context parameter.