Create DrillConfig.createClient() which gives a smaller and faster config 
object used in client-only situations.


Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/2fdb1a13
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/2fdb1a13
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/2fdb1a13

Branch: refs/heads/master
Commit: 2fdb1a1392253506c04b797783cf52c418f80e7f
Parents: c0927ea
Author: Jacques Nadeau <[email protected]>
Authored: Tue May 6 14:41:32 2014 -0700
Committer: Jacques Nadeau <[email protected]>
Committed: Tue May 6 14:41:32 2014 -0700

----------------------------------------------------------------------
 .../apache/drill/common/config/DrillConfig.java | 41 +++++++++++++-------
 .../apache/drill/jdbc/DrillConnectionImpl.java  | 30 +++++++-------
 .../main/java/org/apache/drill/jdbc/Driver.java | 10 +----
 3 files changed, 45 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2fdb1a13/common/src/main/java/org/apache/drill/common/config/DrillConfig.java
----------------------------------------------------------------------
diff --git 
a/common/src/main/java/org/apache/drill/common/config/DrillConfig.java 
b/common/src/main/java/org/apache/drill/common/config/DrillConfig.java
index 7fb0e39..8a67d60 100644
--- a/common/src/main/java/org/apache/drill/common/config/DrillConfig.java
+++ b/common/src/main/java/org/apache/drill/common/config/DrillConfig.java
@@ -56,23 +56,27 @@ public final class DrillConfig extends NestedConfig{
 
   @SuppressWarnings("restriction")
   @VisibleForTesting
-  public DrillConfig(Config config) {
+  public DrillConfig(Config config, boolean enableServer) {
     super(config);
 
     mapper = new ObjectMapper();
-    SimpleModule deserModule = new 
SimpleModule("LogicalExpressionDeserializationModule")
-      .addDeserializer(LogicalExpression.class, new LogicalExpression.De(this))
-      .addDeserializer(SchemaPath.class, new SchemaPath.De(this));
 
+    if(enableServer){
+      SimpleModule deserModule = new 
SimpleModule("LogicalExpressionDeserializationModule")
+        .addDeserializer(LogicalExpression.class, new 
LogicalExpression.De(this))
+        .addDeserializer(SchemaPath.class, new SchemaPath.De(this));
+
+
+      mapper.registerModule(deserModule);
+      mapper.enable(SerializationFeature.INDENT_OUTPUT);
+      mapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
+      mapper.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, true);
+      mapper.configure(Feature.ALLOW_COMMENTS, true);
+      mapper.registerSubtypes(LogicalOperatorBase.getSubTypes(this));
+      mapper.registerSubtypes(StoragePluginConfigBase.getSubTypes(this));
+      mapper.registerSubtypes(FormatPluginConfigBase.getSubTypes(this));
+    }
 
-    mapper.registerModule(deserModule);
-    mapper.enable(SerializationFeature.INDENT_OUTPUT);
-    mapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
-    mapper.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, true);
-    mapper.configure(Feature.ALLOW_COMMENTS, true);
-    mapper.registerSubtypes(LogicalOperatorBase.getSubTypes(this));
-    mapper.registerSubtypes(StoragePluginConfigBase.getSubTypes(this));
-    mapper.registerSubtypes(FormatPluginConfigBase.getSubTypes(this));
 
     RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
     this.startupArguments = ImmutableList.copyOf(bean.getInputArguments());
@@ -90,7 +94,11 @@ public final class DrillConfig extends NestedConfig{
    * @return The new DrillConfig object.
    */
   public static DrillConfig create() {
-    return create(null);
+    return create(null, true);
+  }
+
+  public static DrillConfig createClient(){
+    return create(null, false);
   }
 
   /**
@@ -114,6 +122,11 @@ public final class DrillConfig extends NestedConfig{
    *  @return A merged Config object.
    */
   public static DrillConfig create(String overrideFileName) {
+    return create(overrideFileName, true);
+  }
+
+
+  public static DrillConfig create(String overrideFileName, boolean 
enableServerConfigs) {
 
     overrideFileName = overrideFileName == null ? 
CommonConstants.CONFIG_OVERRIDE : overrideFileName;
 
@@ -126,7 +139,7 @@ public final class DrillConfig extends NestedConfig{
     }
 
     Config c = 
ConfigFactory.load(overrideFileName).withFallback(fallback).resolve();
-    return new DrillConfig(c);
+    return new DrillConfig(c, enableServerConfigs);
   }
 
   public <T> Class<T> getClassAt(String location, Class<T> clazz) throws 
DrillConfigurationException{

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2fdb1a13/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillConnectionImpl.java
----------------------------------------------------------------------
diff --git 
a/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillConnectionImpl.java 
b/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillConnectionImpl.java
index 3c7bd0b..337477e 100644
--- a/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillConnectionImpl.java
+++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/DrillConnectionImpl.java
@@ -29,6 +29,7 @@ import net.hydromatic.avatica.Helper;
 import net.hydromatic.avatica.Meta;
 import net.hydromatic.avatica.UnregisteredDriver;
 
+import org.apache.drill.common.config.DrillConfig;
 import org.apache.drill.exec.client.DrillClient;
 import org.apache.drill.exec.memory.BufferAllocator;
 import org.apache.drill.exec.memory.TopLevelAllocator;
@@ -38,7 +39,7 @@ import org.apache.drill.exec.server.RemoteServiceSet;
 
 /**
  * Implementation of JDBC connection in Drill.
- * 
+ *
  * <p>
  * Abstract to allow newer versions of JDBC to add methods.
  * </p>
@@ -46,30 +47,31 @@ import org.apache.drill.exec.server.RemoteServiceSet;
 abstract class DrillConnectionImpl extends AvaticaConnection implements 
org.apache.drill.jdbc.DrillConnection {
   public final DrillStatementRegistry registry = new DrillStatementRegistry();
   final DrillConnectionConfig config;
-  
-  
+
+
   static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(DrillConnection.class);
 
   private final DrillClient client;
   private final BufferAllocator allocator;
   private Drillbit bit;
   private RemoteServiceSet serviceSet;
-  
+
   protected DrillConnectionImpl(Driver driver, AvaticaFactory factory, String 
url, Properties info)  throws SQLException{
     super(driver, factory, url, info);
     this.config = new DrillConnectionConfig(info);
-  
+
   this.allocator = new TopLevelAllocator();
-    
+
     try{
       if(config.isLocal()){
+        DrillConfig dConfig = DrillConfig.create();
         RemoteServiceSet set = GlobalServiceSetReference.SETS.get();
         if(set == null){
           // we're embedded, start a local drill bit.
           serviceSet = RemoteServiceSet.getLocalServiceSet();
           set = serviceSet;
           try{
-          bit = new Drillbit(driver.getConfig(), serviceSet);
+          bit = new Drillbit(dConfig, serviceSet);
           bit.run();
           }catch(Exception e){
             throw new SQLException("Failure while attempting to start Drillbit 
in embedded mode.", e);
@@ -78,18 +80,18 @@ abstract class DrillConnectionImpl extends 
AvaticaConnection implements org.apac
           serviceSet = null;
           bit = null;
         }
-        this.client = new DrillClient(driver.getConfig(), 
set.getCoordinator());
+        this.client = new DrillClient(dConfig, set.getCoordinator());
         this.client.connect(null, info);
       }else{
-        this.client = new DrillClient();
+        this.client = new DrillClient(DrillConfig.createClient());
         this.client.connect(config.getZookeeperConnectionString(), info);
       }
     }catch(RpcException e){
       throw new SQLException("Failure while attempting to connect to Drill.", 
e);
     }
   }
-  
-  
+
+
   public DrillConnectionConfig config(){
     return config;
   }
@@ -106,11 +108,11 @@ abstract class DrillConnectionImpl extends 
AvaticaConnection implements org.apac
   BufferAllocator getAllocator(){
     return allocator;
   }
-  
+
   public DrillClient getClient(){
     return client;
   }
-  
+
   @Override
   public DrillStatement createStatement(int resultSetType, int 
resultSetConcurrency, int resultSetHoldability)
       throws SQLException {
@@ -154,7 +156,7 @@ abstract class DrillConnectionImpl extends 
AvaticaConnection implements org.apac
     client.close();
     allocator.close();
     if(bit != null) bit.close();
-    
+
     if(serviceSet != null){
       try{
         serviceSet.close();

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2fdb1a13/exec/jdbc/src/main/java/org/apache/drill/jdbc/Driver.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/main/java/org/apache/drill/jdbc/Driver.java 
b/exec/jdbc/src/main/java/org/apache/drill/jdbc/Driver.java
index 9ac913b..696ef26 100644
--- a/exec/jdbc/src/main/java/org/apache/drill/jdbc/Driver.java
+++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/Driver.java
@@ -32,18 +32,15 @@ public class Driver extends UnregisteredDriver {
 
 
 
-  final DrillConfig config;
-  
   public Driver() {
     super();
-    config = DrillConfig.create();
   }
 
 
   public static boolean load(){
     return true;
   }
-  
+
   @Override
   protected String getConnectStringPrefix() {
     return CONNECT_STRING_PREFIX;
@@ -72,10 +69,7 @@ public class Driver extends UnregisteredDriver {
         "unknown version");
   }
 
-  DrillConfig getConfig(){
-    return config;
-  }
-  
+
   @Override
   protected Handler createHandler() {
     return new HandlerImpl();

Reply via email to