You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2020/02/03 23:54:38 UTC

[GitHub] [druid] gianm commented on a change in pull request #9279: Guicify druid sql module

gianm commented on a change in pull request #9279: Guicify druid sql module
URL: https://github.com/apache/druid/pull/9279#discussion_r374400132
 
 

 ##########
 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:
   This is a bit gross. The binding setup and method signatures suggest that the complete root schema is built using an incomplete root schema as input. But this method actually modifies the incomplete schema and they end up being the exact same object. And in fact, that grossness is required for the InformationSchema to work properly, because it needs to be able to see itself in the root schema!
   
   Maybe we could give the InformationSchema a root schema provider instead of the actual root schema? Would that work? It'd be cleaner, if so.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org