You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by am...@apache.org on 2014/11/13 12:50:05 UTC

[38/50] incubator-lens git commit: Fix Hive client conf in ColumnarSQLRewriter

Fix Hive client conf in ColumnarSQLRewriter


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

Branch: refs/heads/toapache
Commit: af8dfc40f98c73ecfe061b8c9ddea86472df4707
Parents: e21f750
Author: Amareshwari Sriramdasu <am...@inmobi.com>
Authored: Thu Nov 13 12:34:36 2014 +0530
Committer: Amareshwari Sriramdasu <am...@inmobi.com>
Committed: Thu Nov 13 12:34:36 2014 +0530

----------------------------------------------------------------------
 .../lens/driver/jdbc/ColumnarSQLRewriter.java   | 24 +++++---------------
 .../org/apache/lens/driver/jdbc/JDBCDriver.java |  9 ++++++--
 .../apache/lens/driver/jdbc/QueryRewriter.java  |  7 ++++++
 3 files changed, 20 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/af8dfc40/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/ColumnarSQLRewriter.java
----------------------------------------------------------------------
diff --git a/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/ColumnarSQLRewriter.java b/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/ColumnarSQLRewriter.java
index 6110895..7961b39 100644
--- a/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/ColumnarSQLRewriter.java
+++ b/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/ColumnarSQLRewriter.java
@@ -45,7 +45,7 @@ import static org.apache.hadoop.hive.ql.parse.HiveParser.*;
 public class ColumnarSQLRewriter implements QueryRewriter {
 
   /** The conf. */
-  private Configuration conf;
+  private HiveConf conf;
 
   /** The clause name. */
   private String clauseName = null;
@@ -151,23 +151,12 @@ public class ColumnarSQLRewriter implements QueryRewriter {
 
   /**
    * Instantiates a new columnar sql rewriter.
-   *
-   * @param conf
-   *          the conf
-   * @param query
-   *          the query
    */
-  public ColumnarSQLRewriter(HiveConf conf, String query) {
-    // super(conf);
-    this.conf = conf;
-    this.query = query;
+  public ColumnarSQLRewriter() {
   }
 
-  /**
-   * Instantiates a new columnar sql rewriter.
-   */
-  public ColumnarSQLRewriter() {
-    // super(conf);
+  public void setConf(Configuration conf) {
+    this.conf = new HiveConf(conf, ColumnarSQLRewriter.class);
   }
 
   public String getClause() {
@@ -794,7 +783,6 @@ public class ColumnarSQLRewriter implements QueryRewriter {
   @Override
   public synchronized String rewrite(Configuration conf, String query) throws LensException {
     this.query = query;
-    this.conf = conf;
     StringBuilder mergedQuery = new StringBuilder();
     rewrittenQuery.setLength(0);
     String queryReplacedUdf = "";
@@ -909,7 +897,7 @@ public class ColumnarSQLRewriter implements QueryRewriter {
    *           the hive exception
    */
   String getUnderlyingDBName(String table) throws HiveException {
-    Table tbl = Hive.get().getTable(table);
+    Table tbl = Hive.get(this.conf).getTable(table);
     return tbl == null ? null : tbl.getProperty(LensConfConstants.NATIVE_DB_NAME);
   }
 
@@ -925,7 +913,7 @@ public class ColumnarSQLRewriter implements QueryRewriter {
    *           the hive exception
    */
   String getUnderlyingTableName(String table) throws HiveException {
-    Table tbl = Hive.get().getTable(table);
+    Table tbl = Hive.get(this.conf).getTable(table);
     return tbl == null ? null : tbl.getProperty(LensConfConstants.NATIVE_TABLE_NAME);
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/af8dfc40/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/JDBCDriver.java
----------------------------------------------------------------------
diff --git a/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/JDBCDriver.java b/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/JDBCDriver.java
index 585de38..6e79a01 100644
--- a/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/JDBCDriver.java
+++ b/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/JDBCDriver.java
@@ -352,6 +352,10 @@ public class JDBCDriver implements LensDriver {
     public String rewrite(Configuration conf, String query) throws LensException {
       return query;
     }
+
+    @Override
+    public void setConf(Configuration conf) {      
+    }
   }
 
   /**
@@ -441,7 +445,7 @@ public class JDBCDriver implements LensDriver {
    * @throws LensException
    *           the lens exception
    */
-  protected synchronized QueryRewriter getQueryRewriter(Configuration conf) throws LensException {
+  protected synchronized QueryRewriter getQueryRewriter() throws LensException {
     QueryRewriter rewriter;
     Class<? extends QueryRewriter> queryRewriterClass = conf.getClass(JDBC_QUERY_REWRITER_CLASS,
         DummyQueryRewriter.class, QueryRewriter.class);
@@ -455,6 +459,7 @@ public class JDBCDriver implements LensDriver {
         LOG.error("Unable to create rewriter object", e);
         throw new LensException(e);
       }
+      rewriter.setConf(conf);
       rewriterCache.put(queryRewriterClass, rewriter);
     }
     return rewriter;
@@ -505,7 +510,7 @@ public class JDBCDriver implements LensDriver {
       throw new LensException(e);
     }
 
-    QueryRewriter rewriter = getQueryRewriter(conf);
+    QueryRewriter rewriter = getQueryRewriter();
     String rewrittenQuery = rewriter.rewrite(conf, query);
     if (LOG.isDebugEnabled()) {
       LOG.debug("Query: " + query + " rewrittenQuery: " + rewrittenQuery);

http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/af8dfc40/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/QueryRewriter.java
----------------------------------------------------------------------
diff --git a/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/QueryRewriter.java b/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/QueryRewriter.java
index dbe0e80..1c319ab 100644
--- a/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/QueryRewriter.java
+++ b/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/QueryRewriter.java
@@ -38,4 +38,11 @@ public interface QueryRewriter {
    *           the lens exception
    */
   public String rewrite(Configuration conf, String query) throws LensException;
+
+  /**
+   * Set conf for the rewriter
+   * 
+   * @param conf
+   */
+  public void setConf(Configuration conf);
 }