This is an automated email from the ASF dual-hosted git repository.

zachjsh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git


The following commit(s) were added to refs/heads/master by this push:
     new cb09b572e62 Fix Druid  table schema resolution when table defined in 
catalog and has schema manager (#16869)
cb09b572e62 is described below

commit cb09b572e620aac83ed02c8e3a1832dcf68771fb
Author: zachjsh <[email protected]>
AuthorDate: Thu Aug 8 21:21:03 2024 -0400

    Fix Druid  table schema resolution when table defined in catalog and has 
schema manager (#16869)
    
    * SQL syntax error should target USER persona
    
    * * revert change to queryHandler and related tests, based on review 
comments
    
    * * add test
    
    * Properly handle Druid schema blending with catalog definition and segment 
metadata
    
    * * add javadocs
---
 .../org/apache/druid/sql/calcite/schema/DruidSchema.java     | 12 +++++++++---
 .../apache/druid/sql/calcite/schema/DruidSchemaManager.java  | 11 ++++++++++-
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git 
a/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java 
b/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java
index 4e8431cd5c6..5a8ae5ba9a8 100644
--- a/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java
+++ b/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java
@@ -22,6 +22,7 @@ package org.apache.druid.sql.calcite.schema;
 import org.apache.calcite.schema.Table;
 import org.apache.druid.sql.calcite.planner.CatalogResolver;
 import org.apache.druid.sql.calcite.table.DatasourceTable;
+import org.apache.druid.sql.calcite.table.DruidTable;
 
 import javax.inject.Inject;
 import java.util.Set;
@@ -56,11 +57,16 @@ public class DruidSchema extends AbstractTableSchema
   @Override
   public Table getTable(String name)
   {
-    if (druidSchemaManager != null) {
-      return druidSchemaManager.getTable(name);
-    } else {
+    DruidTable schemaMgrTable = null;
+    DruidTable catalogTable = catalogResolver.resolveDatasource(name, null);
+    if (catalogTable == null && druidSchemaManager != null) {
+      schemaMgrTable = druidSchemaManager.getTable(name, segmentMetadataCache);
+    }
+    if (schemaMgrTable == null) {
       DatasourceTable.PhysicalDatasourceMetadata dsMetadata = 
segmentMetadataCache.getDatasource(name);
       return catalogResolver.resolveDatasource(name, dsMetadata);
+    } else {
+      return schemaMgrTable;
     }
   }
 
diff --git 
a/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchemaManager.java 
b/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchemaManager.java
index c203ab18825..85808bb1af4 100644
--- 
a/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchemaManager.java
+++ 
b/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchemaManager.java
@@ -21,6 +21,7 @@ package org.apache.druid.sql.calcite.schema;
 
 import org.apache.druid.guice.annotations.ExtensionPoint;
 import org.apache.druid.guice.annotations.UnstableApi;
+import org.apache.druid.sql.calcite.planner.CatalogResolver;
 import org.apache.druid.sql.calcite.table.DruidTable;
 
 import java.util.Map;
@@ -29,7 +30,10 @@ import java.util.Set;
 /**
  * This interface provides a map of datasource names to {@link DruidTable}
  * objects, used by the {@link DruidSchema} class as the SQL planner's
- * view of Druid datasource schemas. If a non-default implementation is
+ * view of Druid datasource schemas. If a mapping is found for the
+ * datasource name in {@link CatalogResolver}, then it is preferred during
+ * resolution time, to the entry found in this manager. See
+ * {@link DruidSchema#getTable(String)}. If a non-default implementation is
  * provided, the segment metadata polling-based view of the Druid tables
  * will not be built in DruidSchema.
  */
@@ -56,6 +60,11 @@ public interface DruidSchemaManager
     return getTables().get(name);
   }
 
+  default DruidTable getTable(String name, BrokerSegmentMetadataCache 
segmentMetadataCache)
+  {
+    return getTables().get(name);
+  }
+
   default Set<String> getTableNames()
   {
     return getTables().keySet();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to