suneet-s commented on a change in pull request #9279: Guicify druid sql module
URL: https://github.com/apache/druid/pull/9279#discussion_r374433786
 
 

 ##########
 File path: 
sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidCalciteSchemaModule.java
 ##########
 @@ -0,0 +1,72 @@
+/*
+ * 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.sql.calcite.schema;
+
+import com.google.inject.Binder;
+import com.google.inject.Module;
+import com.google.inject.Provides;
+import com.google.inject.Scopes;
+import com.google.inject.Singleton;
+import com.google.inject.name.Named;
+import com.google.inject.name.Names;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.druid.guice.LifecycleModule;
+import org.apache.druid.sql.guice.SqlBindings;
+
+/**
+ * The module responsible for providing bindings
+ */
+public class DruidCalciteSchemaModule implements Module
+{
+  private static final String DRUID_SCHEMA_NAME = "druid";
+  static final String INCOMPLETE_SCHEMA = "INCOMPLETE_SCHEMA";
+
+  @Override
+  public void configure(Binder binder)
+  {
+    
binder.bind(String.class).annotatedWith(DruidSchemaName.class).toInstance(DRUID_SCHEMA_NAME);
+
+    // Should only be used by the information schema
+    binder.bind(SchemaPlus.class)
+          .annotatedWith(Names.named(INCOMPLETE_SCHEMA))
+          .toProvider(RootSchemaProvider.class)
+          .in(Scopes.SINGLETON);
+
+    // DruidSchema needs to listen to changes for incoming segments
+    LifecycleModule.register(binder, DruidSchema.class);
+    binder.bind(SystemSchema.class).in(Scopes.SINGLETON);
+    binder.bind(InformationSchema.class).in(Scopes.SINGLETON);
+    binder.bind(LookupSchema.class).in(Scopes.SINGLETON);
+
+    // Binder to inject different schema to Calcite
+    SqlBindings.addSchema(binder, DruidSqlSchema.class);
+    SqlBindings.addSchema(binder, SystemSqlSchema.class);
+    SqlBindings.addSchema(binder, LookupSqlSchema.class);
+  }
+
+  @Provides
+  @Singleton
+  private SchemaPlus getRootSchema(@Named(INCOMPLETE_SCHEMA) SchemaPlus 
rootSchema, InformationSchema informationSchema)
+  {
+    String name = "INFORMATION_SCHEMA";
+    rootSchema.add(name, informationSchema);
 
 Review comment:
   Agreed this is gross :( I tried for a while to get this set up correctly. 
Here's where I landed
   
   Unfortunately I'd still need to inject 2 `SchemaPlus`es - a Provider to an 
"incomplete" one that is needed by InformationSchema, and a complete one that's 
used by the PlannerFactory. It's unclear to me if any other classes would ever 
need to use the "complete" schema. So even though this is gross, I think this 
will prevent someone from accidentally injecting the wrong schema in another 
class.
   
   The grossness is also contained in this one method. I'll add more comments 
explaining this. Maybe someone else can make this better in a future patch. 🤞 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to