trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hzel...@apache.org
Subject [4/6] trafodion git commit: OSIM changes and comment fix for JDBCUDR
Date Thu, 11 Jan 2018 17:45:46 GMT
OSIM changes and comment fix for JDBCUDR

Two small changes w/o JIRA.

Fixes in the OSIM tool related to external Hive tables. Issue an
unregister command before creating a new Hive table in OSIM simulation
mode.  Also get the REGISTER commands from the OSIM files and send
them to Trafodion, not to Hive, as before. Finally, make some minor
changes to showddl (avoid extra commas, fix comments that showed
REGISTER as a Hive command).

Cosmetic changes in the JDBC UDR (fix sandbox location in comment and
use a utility method to get to the sandbox location instead of
hard-coding it.).


Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/40b17734
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/40b17734
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/40b17734

Branch: refs/heads/master
Commit: 40b1773401ac7bb323114f3cf180ccbfec1e8caa
Parents: 4d521af
Author: Hans Zeller <hzeller@apache.org>
Authored: Tue Jan 9 22:11:37 2018 +0000
Committer: Hans Zeller <hzeller@apache.org>
Committed: Tue Jan 9 22:11:37 2018 +0000

----------------------------------------------------------------------
 core/sql/optimizer/OptimizerSimulator.cpp       | 36 ++++++++++++++++----
 core/sql/sqlcomp/CmpDescribe.cpp                | 10 +++---
 .../org/trafodion/sql/udr/predef/JDBCUDR.java   | 10 +++---
 3 files changed, 40 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/40b17734/core/sql/optimizer/OptimizerSimulator.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/OptimizerSimulator.cpp b/core/sql/optimizer/OptimizerSimulator.cpp
index 7b7fa38..53af84d 100644
--- a/core/sql/optimizer/OptimizerSimulator.cpp
+++ b/core/sql/optimizer/OptimizerSimulator.cpp
@@ -947,6 +947,18 @@ void OptimizerSimulator::dropObjects()
               CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
               raiseOsimException("drop external table: %d", retcode);
           }
+          //unregister hive table
+          NAString unregisterStmt = "UNREGISTER HIVE TABLE IF EXISTS ";
+          unregisterStmt += name;
+          debugMessage("%s\n", unregisterStmt.data());
+          retcode = executeFromMetaContext(unregisterStmt.data());
+          if(retcode < 0)
+          {
+              //suppress errors for now, even with IF EXISTS this will
+              //give an error if the Hive table does not exist
+              //CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+              //raiseOsimException("unregister hive table: %d", retcode);
+          }
           //drop hive table
           NAString hiveSchemaName;
           qualName->getHiveSchemaName(hiveSchemaName);
@@ -1048,10 +1060,12 @@ static const char* extractAsComment(const char* header, const NAString
& stmt)
     {
         int end = stmt.index('\n', begin);
         if(end > begin)
-        {
-            stmt.extract(begin, end-1, tmp);
-            return tmp.data();
-        }
+          end -= 1;
+        else
+          end = stmt.length()-1;
+
+        stmt.extract(begin, end, tmp);
+        return tmp.data();
     }
     return NULL;
 }
@@ -1156,7 +1170,14 @@ void OptimizerSimulator::loadHiveDDLs()
     while(readHiveStmt(hiveCreateExternalTableSql, statement, comment))
    {
         if(statement.length() > 0) {
-            debugMessage("%s\n", extractAsComment("CREATE EXTERNAL TABLE", statement));
+            // this could be a create external table or just a register table
+            // if this Hive table just has stats but no external table
+            const char *stmtText = extractAsComment("CREATE EXTERNAL TABLE", statement);
+
+            if (!stmtText)
+              stmtText = extractAsComment("REGISTER  HIVE TABLE", statement);
+            debugMessage("%s\n", stmtText);
+
             retcode = executeFromMetaContext(statement.data()); //create hive external table
             if(retcode < 0)
             {
@@ -2943,8 +2964,9 @@ void OptimizerSimulator::dumpHiveTableDDLs()
             for (int i = 0; i < outQueue->numEntries(); i++) {
                 OutputInfo * vi = (OutputInfo*)outQueue->getNext();
                 char * ptr = vi->get(0);
-                //write "CREATE EXTERNAL TABLE" DDL to another file.
-                if(strstr(ptr, "CREATE EXTERNAL TABLE"))
+                //write "CREATE EXTERNAL TABLE" and "REGISTER" DDL to another file.
+                if(strstr(ptr, "CREATE EXTERNAL TABLE") ||
+                   strstr(ptr, "REGISTER /*INTERNAL*/ HIVE TABLE"))
                     inExtDDL = TRUE;
                 if(inExtDDL){
                     (*writeLogStreams_[HIVE_CREATE_EXTERNAL_TABLE]) << ptr <<
endl;

http://git-wip-us.apache.org/repos/asf/trafodion/blob/40b17734/core/sql/sqlcomp/CmpDescribe.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpDescribe.cpp b/core/sql/sqlcomp/CmpDescribe.cpp
index 28590f4..26b9b3c 100644
--- a/core/sql/sqlcomp/CmpDescribe.cpp
+++ b/core/sql/sqlcomp/CmpDescribe.cpp
@@ -2411,7 +2411,12 @@ short CmpDescribeHiveTable (
     }
 
   if (type == 2)
-    outputShortLine(space, ";");
+    {
+      outputShortLine(space, ";");
+
+      outputShortLine(space," ");
+      outputShortLine(space,"/* Trafodion DDL */");
+    }
 
   // if this hive table is registered in traf metadata, show that.
   if ((type == 2) &&
@@ -2455,9 +2460,6 @@ short CmpDescribeHiveTable (
       QualifiedName qn(extName, 3);
       CorrName cn(qn);
 
-      outputShortLine(space," ");
-      outputShortLine(space,"/* Trafodion DDL */");
- 
       short rc = CmpDescribeSeabaseTable(cn, 
                                          type,
                                          dummyBuf, dummyLen, heap, 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/40b17734/core/sql/src/main/java/org/trafodion/sql/udr/predef/JDBCUDR.java
----------------------------------------------------------------------
diff --git a/core/sql/src/main/java/org/trafodion/sql/udr/predef/JDBCUDR.java b/core/sql/src/main/java/org/trafodion/sql/udr/predef/JDBCUDR.java
index 3cdd747..0c6936b 100644
--- a/core/sql/src/main/java/org/trafodion/sql/udr/predef/JDBCUDR.java
+++ b/core/sql/src/main/java/org/trafodion/sql/udr/predef/JDBCUDR.java
@@ -26,8 +26,8 @@ under the License.
  * Invocation (all arguments are strings):
  *
  * select ... from udf(JDBC(
- *    <name of JDBC driver jar>, // Not really needed if the jar is stored in
- *                               // $TRAF_HOME/udr/public/external_libs
+ *    <name of JDBC driver jar>, // file name of the JDBC driver jar, stored
+ *                               // in $TRAF_HOME/udr/public/external_libs
  *    <name of JDBC driver class in the jar>,
  *    <connection string>,
  *    <user name>,
@@ -98,7 +98,7 @@ class JDBCUDR extends UDR
             Path driverJarPath = Paths.get(driverJar_);
 
             // for security reasons, we sandbox the allowed driver jars
-            // into $TRAF_HOME/export/lib/udr/external_libs
+            // into $TRAF_HOME/udr/public/external_libs
             driverJarPath = driverJarPath.normalize();
             if (driverJarPath.isAbsolute())
               {
@@ -107,7 +107,7 @@ class JDBCUDR extends UDR
                   throw new UDRException(
                     38010,
                     "The jar name of the JDBC driver must be a name relative to %s, got %s",
-                    System.getenv("TRAF_HOME")+"/udr/external_libs",
+                    LmUtility.getSandboxRootForUser(null).toString(),
                     driverJar_);
               }
             else
@@ -141,7 +141,7 @@ class JDBCUDR extends UDR
                 38020,
                 "JDBC driver class %s not found. Please make sure the JDBC driver jar is
stored in %s. Message: %s",
                 driverClassName_,
-                System.getenv("TRAF_HOME") + "/udr/public/external_libs",
+                LmUtility.getSandboxRootForUser(null).toString(),
                 cnf.getMessage());
           }
           catch (SQLException se) {


Mime
View raw message