FrankChen021 commented on code in PR #20183:
URL: https://github.com/apache/druid/pull/20183#discussion_r3969307620


##########
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:
   [P2] [P2] Handle nested system-table datasources before casting the root
   
   `QueryLifecycle.findDataSourceQueryHandler` deliberately selects this 
handler when a registered datasource appears below the root, and 
`DataSourceQueryHandler` documents that the handler receives the complete 
query. A native `ScanQuery` such as a join or `QueryDataSource` containing 
`SystemTableDataSource` therefore reaches this method with a composite root and 
throws `ClassCastException` at this cast. The Router also forwards a composite 
query carrying `X-Druid-Native-Query-Route: local` to the Broker, whose local 
handler takes this same path. Native system-table joins are advertised as 
supported; either recursively replace local system-table leaves here or 
reject/route composite local requests before selecting this handler.



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