FrankChen021 commented on code in PR #20183: URL: https://github.com/apache/druid/pull/20183#discussion_r3989732312
########## server/src/main/java/org/apache/druid/server/system/handler/SystemTableQueryHandler.java: ########## @@ -0,0 +1,162 @@ +/* + * 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.server.system.handler; + +import com.google.inject.Inject; +import org.apache.druid.client.DirectDruidClient; +import org.apache.druid.java.util.common.IAE; +import org.apache.druid.java.util.common.ISE; +import org.apache.druid.java.util.common.JodaUtils; +import org.apache.druid.java.util.common.guava.Sequence; +import org.apache.druid.query.Druids; +import org.apache.druid.query.InlineDataSource; +import org.apache.druid.query.Query; +import org.apache.druid.query.QueryPlus; +import org.apache.druid.query.QueryRunner; +import org.apache.druid.query.SystemTableDataSource; +import org.apache.druid.query.context.ResponseContext; +import org.apache.druid.query.scan.ScanQuery; +import org.apache.druid.query.scan.ScanQueryEngine; +import org.apache.druid.segment.InlineSegmentWrangler; +import org.apache.druid.segment.Segment; +import org.apache.druid.server.DataSourceQueryHandler; +import org.apache.druid.server.security.AuthenticationResult; +import org.apache.druid.server.security.AuthorizerMapper; +import org.apache.druid.server.system.table.SystemTableDataProvider; +import org.apache.druid.server.system.table.SystemTableDescriptor; +import org.apache.druid.server.system.table.SystemTablePushdownFilter; + +import java.util.Map; + +/** Resolves one node-local system table and returns its rows through the standard native Scan stack. */ +public class SystemTableQueryHandler implements DataSourceQueryHandler +{ + private final Map<String, SystemTableDataProvider> dataSuppliers; + private final Map<String, SystemTableDescriptor> tableDescriptors; + private final ScanQueryEngine scanQueryEngine; + private final AuthorizerMapper authorizerMapper; + + @Inject + public SystemTableQueryHandler( + final Map<String, SystemTableDataProvider> dataSuppliers, + final Map<String, SystemTableDescriptor> tableDescriptors, + final ScanQueryEngine scanQueryEngine, + final AuthorizerMapper authorizerMapper + ) + { + this.dataSuppliers = dataSuppliers; + this.tableDescriptors = tableDescriptors; + this.scanQueryEngine = scanQueryEngine; + this.authorizerMapper = authorizerMapper; + } + + @Override + public <T> QueryRunner<T> createRunner( + final Query<T> query, + final AuthenticationResult requestAuthenticationResult, + final boolean executeLocally + ) + { + if (!(query instanceof ScanQuery)) { + throw new IAE("Local system table queries must be scan queries"); + } + + final SystemTableDataSource dataSource = (SystemTableDataSource) query.getDataSource(); Review Comment: Fixed in `922c82dcdd`. Local execution now requires a root `SystemTableDataSource`; a composite query carrying the local-route header is rejected with `BadQueryContextException` instead of reaching the unsafe cast. `SystemTableQueryHandler` also validates the datasource shape defensively. Composite queries without the local-route header continue through `SystemTableQueryClient`, which recursively resolves system-table leaves. Added regression coverage in `SystemTableBrokerQueryHandlerTest` and `SystemTableQueryHandlerTest`. The focused server run passed all 5 tests. <!-- mergelens:review --> -- 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]
