You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by se...@apache.org on 2015/12/01 03:08:25 UTC

hive git commit: HIVE-12490 : Metastore: Mysql ANSI_QUOTES is not there for some cases (Sergey Shelukhin, reviewed by Ashutosh Chauhan)

Repository: hive
Updated Branches:
  refs/heads/branch-1 f3fa4e46a -> 9c0d09134


HIVE-12490 : Metastore: Mysql ANSI_QUOTES is not there for some cases (Sergey Shelukhin, reviewed by Ashutosh Chauhan)

Conflicts:
	metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/9c0d0913
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/9c0d0913
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/9c0d0913

Branch: refs/heads/branch-1
Commit: 9c0d09134d6f508e4485026a80bc0e8727258fa2
Parents: f3fa4e4
Author: Sergey Shelukhin <se...@apache.org>
Authored: Mon Nov 30 17:46:58 2015 -0800
Committer: Sergey Shelukhin <se...@apache.org>
Committed: Mon Nov 30 18:05:15 2015 -0800

----------------------------------------------------------------------
 .../hive/metastore/MetaStoreDirectSql.java      | 37 ++++++++++----------
 .../hadoop/hive/metastore/ObjectStore.java      |  1 +
 2 files changed, 19 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/9c0d0913/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java
----------------------------------------------------------------------
diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java b/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java
index f598c58..3ba7d64 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java
@@ -217,6 +217,7 @@ class MetaStoreDirectSql {
     // Run a self-test query. If it doesn't work, we will self-disable. What a PITA...
     String selfTestQuery = "select \"DB_ID\" from \"DBS\"";
     try {
+      prepareTxn();
       query = pm.newQuery("javax.jdo.query.SQL", selfTestQuery);
       query.execute();
       tx.commit();
@@ -237,21 +238,6 @@ class MetaStoreDirectSql {
     return isCompatibleDatastore;
   }
 
-  /**
-   * This function is intended to be called by functions before they put together a query
-   * Thus, any query-specific instantiation to be done from within the transaction is done
-   * here - for eg., for MySQL, we signal that we want to use ANSI SQL quoting behaviour
-   */
-  private void doDbSpecificInitializationsBeforeQuery() throws MetaException {
-    if (dbType != DB.MYSQL) return;
-    try {
-      assert pm.currentTransaction().isActive(); // must be inside tx together with queries
-      executeNoResult("SET @@session.sql_mode=ANSI_QUOTES");
-    } catch (SQLException sqlEx) {
-      throw new MetaException("Error setting ansi quotes: " + sqlEx.getMessage());
-    }
-  }
-
   private void executeNoResult(final String queryText) throws SQLException {
     JDOConnection jdoConn = pm.getDataStoreConnection();
     boolean doTrace = LOG.isDebugEnabled();
@@ -270,8 +256,6 @@ class MetaStoreDirectSql {
     try {
       dbName = dbName.toLowerCase();
 
-      doDbSpecificInitializationsBeforeQuery();
-
       String queryTextDbSelector= "select "
           + "\"DB_ID\", \"NAME\", \"DB_LOCATION_URI\", \"DESC\", "
           + "\"OWNER_NAME\", \"OWNER_TYPE\" "
@@ -443,8 +427,6 @@ class MetaStoreDirectSql {
     // We have to be mindful of order during filtering if we are not returning all partitions.
     String orderForFilter = (max != null) ? " order by \"PART_NAME\" asc" : "";
 
-    doDbSpecificInitializationsBeforeQuery();
-
     // Get all simple fields for partitions and related objects, which we can map one-on-one.
     // We will do this in 2 queries to use different existing indices for each one.
     // We do not get table and DB name, assuming they are the same as we are using to filter.
@@ -1641,4 +1623,21 @@ class MetaStoreDirectSql {
       throw new MetaException("See previous errors; " + ex.getMessage());
     }
   }
+
+  /**
+   * This run the necessary logic to prepare for queries. It should be called once, after the
+   * txn on DataNucleus connection is opened, and before any queries are issued. What it does
+   * currently is run db-specific logic, e.g. setting ansi quotes mode for MySQL. The reason it
+   * must be used inside of the txn is connection pooling; there's no way to guarantee that the
+   * effect will apply to the connection that is executing the queries otherwise.
+   */
+  public void prepareTxn() throws MetaException {
+    if (dbType != DB.MYSQL) return;
+    try {
+      assert pm.currentTransaction().isActive(); // must be inside tx together with queries
+      executeNoResult("SET @@session.sql_mode=ANSI_QUOTES");
+    } catch (SQLException sqlEx) {
+      throw new MetaException("Error setting ansi quotes: " + sqlEx.getMessage());
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/hive/blob/9c0d0913/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
----------------------------------------------------------------------
diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
index c830d4f..260f51a 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
@@ -2449,6 +2449,7 @@ public class ObjectStore implements RawStore, Configurable {
         start(initTable);
         if (doUseDirectSql) {
           try {
+            directSql.prepareTxn();
             setResult(getSqlResult(this));
           } catch (Exception ex) {
             handleDirectSqlError(ex);