trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [1/2] trafodion git commit: [TRAFODION-3009] Streamline error handling in Executor utility commands
Date Thu, 19 Apr 2018 23:19:20 GMT
Repository: trafodion
Updated Branches:
  refs/heads/master 8af8b959a -> 9ebcfba5a


[TRAFODION-3009] Streamline error handling in Executor utility commands

ComDiagsArea is now allocated only when there are warnings or errors in
all the utility commands.

This requires all the executor utility commands to use a new version of
ExRaiseSqlError to populate diagnostics area.


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

Branch: refs/heads/master
Commit: 7eaf88d3d74b78af20d845d7f717068e3a5db66c
Parents: c29ebc6
Author: selvaganesang <selva.govindarajan@esgyn.com>
Authored: Thu Apr 19 18:47:04 2018 +0000
Committer: selvaganesang <selva.govindarajan@esgyn.com>
Committed: Thu Apr 19 18:47:04 2018 +0000

----------------------------------------------------------------------
 core/sql/cli/Context.cpp                        |   1 -
 core/sql/executor/ExExeUtil.h                   |   6 +-
 core/sql/executor/ExExeUtilCli.cpp              |   2 +
 core/sql/executor/ExExeUtilCli.h                |   1 +
 core/sql/executor/ExExeUtilCommon.cpp           |   2 +-
 core/sql/executor/ExExeUtilExplain.cpp          |  10 +-
 core/sql/executor/ExExeUtilGet.cpp              |   6 +-
 core/sql/executor/ExExeUtilLoad.cpp             |  21 +--
 core/sql/executor/ExExeUtilMisc.cpp             |  52 ++------
 core/sql/executor/HiveClient_JNI.cpp            | 133 ++++++++++++++-----
 core/sql/executor/HiveClient_JNI.h              |  11 +-
 core/sql/exp/ExpHbaseInterface.cpp              |   1 -
 core/sql/exp/ExpHbaseInterface.h                |   1 +
 core/sql/sqlcomp/CmpSeabaseDDLauth.cpp          |   1 -
 .../main/java/org/trafodion/sql/HiveClient.java | 114 +++++++++-------
 15 files changed, 204 insertions(+), 158 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/7eaf88d3/core/sql/cli/Context.cpp
----------------------------------------------------------------------
diff --git a/core/sql/cli/Context.cpp b/core/sql/cli/Context.cpp
index c4dd6c7..7aee780 100644
--- a/core/sql/cli/Context.cpp
+++ b/core/sql/cli/Context.cpp
@@ -4768,5 +4768,4 @@ void ContextCli::disconnectHdfsConnections()
           hdfsDisconnect(entry->hdfsHandle_);         
         }
     }
-  
 }

http://git-wip-us.apache.org/repos/asf/trafodion/blob/7eaf88d3/core/sql/executor/ExExeUtil.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtil.h b/core/sql/executor/ExExeUtil.h
index 3615c10..a3f197d 100644
--- a/core/sql/executor/ExExeUtil.h
+++ b/core/sql/executor/ExExeUtil.h
@@ -280,6 +280,7 @@ class ExExeUtilTcb : public ex_tcb
 
   short holdAndSetCQD(const char * defaultName, const char * defaultValue,
                       ComDiagsArea * globalDiags = NULL);
+
   short restoreCQD(const char * defaultName, ComDiagsArea * globalDiags = NULL);
 
   short setCS(const char * csName, char * csValue,
@@ -290,8 +291,9 @@ class ExExeUtilTcb : public ex_tcb
   void restoreMaintainControlTableTimeout(char * catalog);
 
   static Lng32 holdAndSetCQD(const char * defaultName, const char * defaultValue,
-                            ExeCliInterface * cliInterface,
-                            ComDiagsArea * globalDiags = NULL);
+                         ExeCliInterface * cliInterface,
+                         ComDiagsArea * globalDiags = NULL);
+
   static Lng32 restoreCQD(const char * defaultName,
                          ExeCliInterface * cliInterface,
                          ComDiagsArea * globalDiags = NULL);

http://git-wip-us.apache.org/repos/asf/trafodion/blob/7eaf88d3/core/sql/executor/ExExeUtilCli.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilCli.cpp b/core/sql/executor/ExExeUtilCli.cpp
index eb7ae04..f71a8ff 100644
--- a/core/sql/executor/ExExeUtilCli.cpp
+++ b/core/sql/executor/ExExeUtilCli.cpp
@@ -2211,6 +2211,7 @@ Lng32 ExeCliInterface::holdAndSetCQD(const char * defaultName, const
char * defa
   return 0;
 }
 
+
 Lng32 ExeCliInterface::restoreCQD(const char * defaultName, ComDiagsArea *globalDiags)
 {
   Lng32 cliRC;
@@ -2243,6 +2244,7 @@ Lng32 ExeCliInterface::restoreCQD(const char * defaultName, ComDiagsArea
*global
 Lng32 ExeCliInterface::getCQDval(const char * defaultName, 
 				 char * val,
 				 ComDiagsArea *globalDiags)
+
 {
   Lng32 cliRC;
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/7eaf88d3/core/sql/executor/ExExeUtilCli.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilCli.h b/core/sql/executor/ExExeUtilCli.h
index 963b567..859c852 100644
--- a/core/sql/executor/ExExeUtilCli.h
+++ b/core/sql/executor/ExExeUtilCli.h
@@ -264,6 +264,7 @@ private:
   Lng32 GetRowsAffected(Int64 *rowsAffected);
 
   Lng32 holdAndSetCQD(const char * defaultName, const char * defaultValue, ComDiagsArea *globalDiags
= NULL);
+
   Lng32 restoreCQD(const char * defaultName, ComDiagsArea *globalDiags = NULL);
 
   Lng32 getCQDval(const char * defaultName,

http://git-wip-us.apache.org/repos/asf/trafodion/blob/7eaf88d3/core/sql/executor/ExExeUtilCommon.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilCommon.cpp b/core/sql/executor/ExExeUtilCommon.cpp
index d6af9a7..b623ee3 100644
--- a/core/sql/executor/ExExeUtilCommon.cpp
+++ b/core/sql/executor/ExExeUtilCommon.cpp
@@ -1621,7 +1621,7 @@ Lng32 ExExeUtilTcb::extractParts
   if ((rc = extractedPartsObj_->extractParts(numParts, parts)) != 0 ||
       (numParts != 3))
     {
-      *getDiagsArea() << DgSqlCode(-CLI_INTERNAL_ERROR);
+      ExRaiseSqlError(getHeap(), &diagsArea_, -CLI_INTERNAL_ERROR);
       return -1;
     }
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/7eaf88d3/core/sql/executor/ExExeUtilExplain.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilExplain.cpp b/core/sql/executor/ExExeUtilExplain.cpp
index 7e12a27..4bf3d9b 100644
--- a/core/sql/executor/ExExeUtilExplain.cpp
+++ b/core/sql/executor/ExExeUtilExplain.cpp
@@ -399,8 +399,7 @@ short ExExeUtilDisplayExplainTcb::work()
 		// no rows found.
 		// Either no explain information was available or statement
 		// was not found.
-		ComDiagsArea * da = getDiagsArea();
-		ExRaiseSqlError(getMyHeap(), &da,
+		ExRaiseSqlError(getMyHeap(), &diagsArea_,
 				(((exeUtilTdb().getModuleName()) ||
 				  (exeUtilTdb().getStmtName())) ?
 				 (ExeErrorCode)CLI_STMT_NOT_EXISTS :
@@ -472,13 +471,11 @@ short ExExeUtilDisplayExplainTcb::work()
 	    if (rc != 0)	//means we got an EXE_EXPLAIN_BAD_DATA
 	      //or an error from getPtrAndLen()
 	      {
-		ComDiagsArea * da = getDiagsArea();
-		ExRaiseSqlError(getMyHeap(), &da,
+		ExRaiseSqlError(getMyHeap(), &diagsArea_,
 				(((exeUtilTdb().getModuleName()) ||
 				  (exeUtilTdb().getStmtName())) ?
 				 (ExeErrorCode)CLI_STMT_NOT_EXISTS :
 				 (ExeErrorCode)EXE_NO_EXPLAIN_INFO));
-
 		pstate.step_ = HANDLE_ERROR_;
 	      }
 	    else
@@ -3928,8 +3925,7 @@ short ExExeUtilDisplayExplainComplexTcb::work()
 		    // Return error.
 		    // Do not do 'DROP_AND_ERROR' as we don't want to drop
 		    // an existing table.
-		    ComDiagsArea * da = getDiagsArea();
-		    ExRaiseSqlError(getHeap(), &da,
+		    ExRaiseSqlError(getHeap(), &diagsArea_,
 				    EXE_NO_EXPLAIN_INFO, NULL);
 
 		    step_ = ERROR_;

http://git-wip-us.apache.org/repos/asf/trafodion/blob/7eaf88d3/core/sql/executor/ExExeUtilGet.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilGet.cpp b/core/sql/executor/ExExeUtilGet.cpp
index 3fdf07a..33865fa 100644
--- a/core/sql/executor/ExExeUtilGet.cpp
+++ b/core/sql/executor/ExExeUtilGet.cpp
@@ -6116,11 +6116,11 @@ short ExExeUtilHiveMDaccessTcb::work()
                         (hcd ? hcd->type_ : hpd->type_),
                         (hcd ? hcd->name_ : hpd->name_),
                         hiveCat_, hiveSch_, htd->tblName_);
-		ExRaiseSqlError(getHeap(), &diagsArea_, CLI_GET_METADATA_INFO_ERROR,
+                ExRaiseSqlError(getHeap(), &diagsArea_, CLI_GET_METADATA_INFO_ERROR,
                       NULL, NULL, NULL,
                       strP);
-                step_ = ADVANCE_ROW_;
-                break;
+		step_ = ADVANCE_ROW_;
+		break;
 	      }
 	    
             infoCol->fsDatatype = fstype;

http://git-wip-us.apache.org/repos/asf/trafodion/blob/7eaf88d3/core/sql/executor/ExExeUtilLoad.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilLoad.cpp b/core/sql/executor/ExExeUtilLoad.cpp
index 5024f8c..67d0bc9 100644
--- a/core/sql/executor/ExExeUtilLoad.cpp
+++ b/core/sql/executor/ExExeUtilLoad.cpp
@@ -2705,8 +2705,7 @@ short ExExeUtilLobExtractTcb::work()
 		      
 		      Lng32 intParam1 = 0;
 		      ExRaiseSqlError(getHeap(), &diagsArea_, 
-				      (ExeErrorCode)(8444), NULL, &intParam1, 
-				      &cliError, NULL, NULL);
+				      -8448, &intParam1, &cliError, NULL, NULL);
 		      step_ = HANDLE_ERROR_;
 		    }
 		}
@@ -2738,11 +2737,9 @@ short ExExeUtilLobExtractTcb::work()
 		  ex_queue_entry * up_entry = qparent_.up->getTailEntry();
 
 		  // invalid state, should not be reached.
-		  ComDiagsArea *diagsArea = up_entry->getDiagsArea();
 		  ExRaiseSqlError(getMyHeap(),
-				  &diagsArea,
+				  &diagsArea_,
 				  (ExeErrorCode)(EXE_INTERNAL_ERROR));
-                  setDiagsArea(diagsArea);
 		  step_ = CANCEL_;
 		}
 		break;
@@ -2895,12 +2892,9 @@ short ExExeUtilLobExtractTcb::work()
 	      else
 		{
 		  // invalid "toType"
-		  ex_queue_entry * up_entry = qparent_.up->getTailEntry();
-		  ComDiagsArea *diagsArea = up_entry->getDiagsArea();
 		  ExRaiseSqlError(getMyHeap(),
-				  &diagsArea,
+				  &diagsArea_,
 				  (ExeErrorCode)(EXE_INTERNAL_ERROR));
-                  setDiagsArea(diagsArea);
 		  step_ = CANCEL_;
 		
 		break;
@@ -3211,12 +3205,9 @@ short ExExeUtilLobExtractTcb::work()
 	    else
 	      {
 		// No other "toType" shoudl reach here - i.e TO_FILE_ or TO_STRING
-		ex_queue_entry * up_entry = qparent_.up->getTailEntry();
-		ComDiagsArea *diagsArea = up_entry->getDiagsArea();
 		ExRaiseSqlError(getMyHeap(),
-				&diagsArea,
+				&diagsArea_,
 				(ExeErrorCode)(EXE_INTERNAL_ERROR));
-                setDiagsArea(diagsArea);
 		step_ = CANCEL_;
 		
 		break;
@@ -3462,10 +3453,8 @@ short ExExeUtilLobUpdateTcb::work()
             else
 		{
 		  // invalid "fromType"
-		  ex_queue_entry * up_entry = qparent_.up->getTailEntry();
-		  ComDiagsArea * da = up_entry->getDiagsArea();
 		  ExRaiseSqlError(getMyHeap(),
-				  &da,
+				  &diagsArea_,
 				  (ExeErrorCode)(EXE_INTERNAL_ERROR));
 		  step_ = CANCEL_;
 		

http://git-wip-us.apache.org/repos/asf/trafodion/blob/7eaf88d3/core/sql/executor/ExExeUtilMisc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilMisc.cpp b/core/sql/executor/ExExeUtilMisc.cpp
index 8ae7124..6568f12 100644
--- a/core/sql/executor/ExExeUtilMisc.cpp
+++ b/core/sql/executor/ExExeUtilMisc.cpp
@@ -2323,8 +2323,7 @@ short ExExeUtilHiveTruncateTcb::work()
           Lng32 cliError = 0;
           
           Lng32 intParam1 = -cliRC;
-          ComDiagsArea * diagsArea = NULL;
-          ExRaiseSqlError(getHeap(), &diagsArea, 
+          ExRaiseSqlError(getHeap(), &diagsArea_, 
                           (ExeErrorCode)(EXE_ERROR_FROM_LOB_INTERFACE),
                           NULL, &intParam1, 
                           &cliError, 
@@ -2332,7 +2331,6 @@ short ExExeUtilHiveTruncateTcb::work()
                           "HDFS",
                           (char*)"ExpLOBInterfaceEmptyDirectory",
                           getLobErrStr(intParam1));
-          pentry_down->setDiagsArea(diagsArea);
           step_ = ERROR_;
           break;
         }
@@ -2343,13 +2341,10 @@ short ExExeUtilHiveTruncateTcb::work()
           str_sprintf(errStr, "genModTS = %ld, failedModTS = %ld", 
                       htTdb().getModTS(), failedModTS);
           
-          ComDiagsArea * diagsArea = NULL;
-          ExRaiseSqlError(getHeap(), &diagsArea, 
+          ExRaiseSqlError(getHeap(), &diagsArea_, 
                           (ExeErrorCode)(EXE_HIVE_DATA_MOD_CHECK_ERROR), NULL,
                           NULL, NULL, NULL,
                           errStr);
-          pentry_down->setDiagsArea(diagsArea);
-          
           step_ = ERROR_;
           break;
         }
@@ -2377,8 +2372,7 @@ short ExExeUtilHiveTruncateTcb::work()
           Lng32 cliError = 0;
           
           Lng32 intParam1 = -cliRC;
-          ComDiagsArea * diagsArea = NULL;
-          ExRaiseSqlError(getHeap(), &diagsArea, 
+          ExRaiseSqlError(getHeap(), &diagsArea_, 
                           (ExeErrorCode)(EXE_ERROR_FROM_LOB_INTERFACE),
                           NULL, &intParam1, 
                           &cliError, 
@@ -2402,12 +2396,11 @@ short ExExeUtilHiveTruncateTcb::work()
               strcpy(reason, "Reason: error occurred during deletion of one or more files
at the specified location");
             }
           
-          ExRaiseSqlError(getHeap(), &diagsArea, 
+          ExRaiseSqlError(getHeap(), &diagsArea_, 
                           (ExeErrorCode)(EXE_HIVE_TRUNCATE_ERROR), NULL,
                           NULL, NULL, NULL,
                           reason,
                           NULL, NULL);
-          pentry_down->setDiagsArea(diagsArea);
           step_ = ERROR_;
         }
         else
@@ -2419,48 +2412,21 @@ short ExExeUtilHiveTruncateTcb::work()
 
       case ERROR_:
       {
-        if (qparent_.up->isFull())
-          return WORK_OK;
-
-        // Return Error 
-        ex_queue_entry * up_entry = qparent_.up->getTailEntry();
-        up_entry->copyAtp(pentry_down);
-
-        up_entry->upState.parentIndex = pentry_down->downState.parentIndex;
-
-        up_entry->upState.setMatchNo(0);
-        up_entry->upState.status = ex_queue::Q_SQLERROR;
-
-        // insert into parent
-        qparent_.up->insert();
-
+        if (handleError())
+           return WORK_OK;
         step_ = DONE_;
       }
       break;
 
       case DONE_:
       {
-        if (qparent_.up->isFull())
-          return WORK_OK;
-
-        // Return EOF.
-        ex_queue_entry * up_entry = qparent_.up->getTailEntry();
-
-        up_entry->upState.parentIndex = pentry_down->downState.parentIndex;
-
-        up_entry->upState.setMatchNo(0);
-        up_entry->upState.status = ex_queue::Q_NO_DATA;
-
-        // insert into parent
-        qparent_.up->insert();
-
-        //pstate.matches_ = 0;
+        if (handleDone())
+           return WORK_OK;
         step_ = INITIAL_;
-        qparent_.down->removeHead();
 
         return WORK_OK;
       }
-        break;
+      break;
 
     } // switch
   } // while

http://git-wip-us.apache.org/repos/asf/trafodion/blob/7eaf88d3/core/sql/executor/HiveClient_JNI.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/HiveClient_JNI.cpp b/core/sql/executor/HiveClient_JNI.cpp
index 3db5ce8..9c09b97 100644
--- a/core/sql/executor/HiveClient_JNI.cpp
+++ b/core/sql/executor/HiveClient_JNI.cpp
@@ -38,12 +38,14 @@ pthread_mutex_t HiveClient_JNI::javaMethodsInitMutex_ = PTHREAD_MUTEX_INITIALIZE
 
 static const char* const hvcErrorEnumStr[] = 
 {
-  "Java exception while initializing HiveClient"
+  "Preparing parameters for HiveClient."
  ,"Java exception in close()."
  ,"Preparing parameters for exists()."
  ,"Java exception in exists()."
  ,"Preparing parameters for getHiveTableStr()."
  ,"Java exception in getHiveTableStr()."
+ ,"Preparing parameters for getHiveTableParameters()."
+ ,"Java exception in getHiveTableParameters()."
  ,"Preparing parameters for getRedefTime()."
  ,"Java exception in getRedefTime()."
  ,"Java exception in getAllSchemas()."
@@ -106,8 +108,8 @@ void HiveClient_JNI::deleteInstance()
 //////////////////////////////////////////////////////////////////////////////
 HiveClient_JNI::~HiveClient_JNI()
 {
-   if (isInitialized())
-      close(); // error handling?
+   if (isInitialized())	
+      close(); // error handling
 }
 
 //////////////////////////////////////////////////////////////////////////////
@@ -135,12 +137,14 @@ HVC_RetCode HiveClient_JNI::init()
     
     JavaMethods_[JM_CTOR       ].jm_name      = "<init>";
     JavaMethods_[JM_CTOR       ].jm_signature = "()V";
-    JavaMethods_[JM_CLOSE      ].jm_name      = "close";
+    JavaMethods_[JM_CLOSE      ].jm_name      = "close";	
     JavaMethods_[JM_CLOSE      ].jm_signature = "()Z";
     JavaMethods_[JM_EXISTS     ].jm_name      = "exists";
     JavaMethods_[JM_EXISTS     ].jm_signature = "(Ljava/lang/String;Ljava/lang/String;)Z";
     JavaMethods_[JM_GET_HVT    ].jm_name      = "getHiveTableString";
     JavaMethods_[JM_GET_HVT    ].jm_signature = "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;";
+    JavaMethods_[JM_GET_HVP    ].jm_name      = "getHiveTableParameters";
+    JavaMethods_[JM_GET_HVP    ].jm_signature = "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;";
     JavaMethods_[JM_GET_RDT    ].jm_name      = "getRedefTime";
     JavaMethods_[JM_GET_RDT    ].jm_signature = "(Ljava/lang/String;Ljava/lang/String;)J";
     JavaMethods_[JM_GET_ASH     ].jm_name      = "getAllSchemas";
@@ -149,6 +153,7 @@ HVC_RetCode HiveClient_JNI::init()
     JavaMethods_[JM_GET_ATL    ].jm_signature = "(Ljava/lang/String;)[Ljava/lang/Object;";
     JavaMethods_[JM_EXEC_HIVE_SQL].jm_name = "executeHiveSQL";
     JavaMethods_[JM_EXEC_HIVE_SQL].jm_signature = "(Ljava/lang/String;)V";
+
     rc = (HVC_RetCode)JavaObjectInterface::init(className, javaClass_, JavaMethods_, (Int32)JM_LAST,
javaMethodsInitialized_);
     if (rc == HVC_OK)
        javaMethodsInitialized_ = TRUE;
@@ -160,37 +165,6 @@ HVC_RetCode HiveClient_JNI::init()
 //////////////////////////////////////////////////////////////////////////////
 // 
 //////////////////////////////////////////////////////////////////////////////
-HVC_RetCode HiveClient_JNI::close()
-{
-  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "HiveClient_JNI::close() called.");
-
-  if (initJNIEnv() != JOI_OK)
-     return HVC_ERROR_INIT_PARAM;
-
-  // boolean close();
-  tsRecentJMFromJNI = JavaMethods_[JM_CLOSE].jm_full_name;
-  jboolean jresult = jenv_->CallStaticBooleanMethod(javaClass_, JavaMethods_[JM_CLOSE].methodID);
-  if (jenv_->ExceptionCheck())
-  {
-    getExceptionDetails(__FILE__, __LINE__, "HiveClient_JNI::close()");
-    jenv_->PopLocalFrame(NULL);
-    return HVC_ERROR_CLOSE_EXCEPTION;
-  }
-  
-  if (jresult == false) 
-  {
-    logError(CAT_SQL_HBASE, "HiveClient_JNI::close()", getLastError());
-    jenv_->PopLocalFrame(NULL);
-    return HVC_ERROR_CLOSE_EXCEPTION;
-  }
-
-  jenv_->PopLocalFrame(NULL);
-  return HVC_OK;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// 
-//////////////////////////////////////////////////////////////////////////////
 HVC_RetCode HiveClient_JNI::exists(const char* schName, const char* tabName)
 {
   QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "HiveClient_JNI::exists(%s, %s) called.", schName,
tabName);
@@ -294,6 +268,64 @@ HVC_RetCode HiveClient_JNI::getHiveTableStr(const char* schName,
 
 //////////////////////////////////////////////////////////////////////////////
 // 
+//////////////////////////////////////////////////////////////////////////////
+HVC_RetCode HiveClient_JNI::getHiveTableParameters(const char *schName, const char *tabName,
Text& hiveParamsStr)
+{
+  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "Enter HiveClient_JNI::getHiveTableParameters(%s).",
hiveParamsStr.data());
+  if (initJNIEnv() != JOI_OK)
+     return HVC_ERROR_INIT_PARAM;
+  if (getInstance() == NULL)
+     return HVC_ERROR_INIT_PARAM;
+  jstring js_schName = jenv_->NewStringUTF(schName);
+  if (js_schName == NULL) 
+  {
+    GetCliGlobals()->setJniErrorStr(getErrorText(HVC_ERROR_GET_HVT_PARAM));
+    jenv_->PopLocalFrame(NULL);
+    return HVC_ERROR_GET_HVP_PARAM;
+  }
+  jstring js_tabName = jenv_->NewStringUTF(tabName);
+  if (js_tabName == NULL) 
+  {
+    GetCliGlobals()->setJniErrorStr(getErrorText(HVC_ERROR_GET_HVT_PARAM));
+    jenv_->PopLocalFrame(NULL);
+    return HVC_ERROR_GET_HVP_PARAM;
+  }
+
+  // java.lang.String getHiveTableParameters();
+  tsRecentJMFromJNI = JavaMethods_[JM_GET_HVP].jm_full_name;
+  jstring jresult = (jstring)jenv_->CallStaticObjectMethod(javaClass_, 
+                                                     JavaMethods_[JM_GET_HVP].methodID, js_schName,
js_tabName);
+
+  if (jenv_->ExceptionCheck())
+  {
+    getExceptionDetails(__FILE__, __LINE__, "HiveClient_JNI::getHiveTableParameters()");
+    jenv_->PopLocalFrame(NULL);
+    return HVC_ERROR_GET_HVT_EXCEPTION;
+  }
+ 
+  if (jresult == NULL) {
+     jenv_->PopLocalFrame(NULL);
+     return HVC_DONE;
+  }
+  if (jenv_->GetStringLength(jresult) <= 0)
+  { 
+     jenv_->PopLocalFrame(NULL);
+     return HVC_DONE; // Table does not exist
+  }
+    
+  // Not using UFTchars and NAWString for now.
+  const char* char_result = jenv_->GetStringUTFChars(jresult, 0);
+  hiveParamsStr += char_result ; // deep copy. hiveParamsStr is assumed to be empty.
+  jenv_->ReleaseStringUTFChars(jresult, char_result);
+
+  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "Exit HiveClient_JNI::getHiveTableParameters(%s).",
hiveParamsStr.data());
+  jenv_->PopLocalFrame(NULL);
+  return HVC_OK;  // Table exists.
+}
+
+
+//////////////////////////////////////////////////////////////////////////////
+// 
 //////////////////////////////////////////////////////////////////////////////  
 HVC_RetCode HiveClient_JNI::getRedefTime(const char* schName, 
                                          const char* tabName, 
@@ -464,6 +496,37 @@ HVC_RetCode HiveClient_JNI::getAllTables(NAHeap *heap, const char* schName,
   return HVC_OK;
 }
 
+//////////////////////////////////////////////////////////////////////////////	
+// 	
+//////////////////////////////////////////////////////////////////////////////	
+HVC_RetCode HiveClient_JNI::close()	
+{	
+  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "HiveClient_JNI::close() called.");	
+	
+  if (initJNIEnv() != JOI_OK)	
+     return HVC_ERROR_INIT_PARAM;	
+	
+  // boolean close();	
+  tsRecentJMFromJNI = JavaMethods_[JM_CLOSE].jm_full_name;	
+  jboolean jresult = jenv_->CallStaticBooleanMethod(javaClass_, JavaMethods_[JM_CLOSE].methodID);

+  if (jenv_->ExceptionCheck())	
+  {	
+    getExceptionDetails(__FILE__, __LINE__, "HiveClient_JNI::close()");	
+    jenv_->PopLocalFrame(NULL);	
+    return HVC_ERROR_CLOSE_EXCEPTION;	
+  }	
+  	
+  if (jresult == false) 	
+  {	
+    logError(CAT_SQL_HBASE, "HiveClient_JNI::close()", getLastError());	
+    jenv_->PopLocalFrame(NULL);	
+    return HVC_ERROR_CLOSE_EXCEPTION;	
+  }	
+	
+  jenv_->PopLocalFrame(NULL);	
+  return HVC_OK;	
+}
+
 //////////////////////////////////////////////////////////////////////////////
 // 
 //////////////////////////////////////////////////////////////////////////////  

http://git-wip-us.apache.org/repos/asf/trafodion/blob/7eaf88d3/core/sql/executor/HiveClient_JNI.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/HiveClient_JNI.h b/core/sql/executor/HiveClient_JNI.h
index 32c8c33..3d6dfe8 100644
--- a/core/sql/executor/HiveClient_JNI.h
+++ b/core/sql/executor/HiveClient_JNI.h
@@ -28,6 +28,7 @@
 #ifndef HIVE_CLIENT_H
 #define HIVE_CLIENT_H
 
+#include <list>
 #include "JavaObjectInterface.h"
 
 typedef enum {
@@ -40,6 +41,8 @@ typedef enum {
  ,HVC_ERROR_EXISTS_EXCEPTION
  ,HVC_ERROR_GET_HVT_PARAM
  ,HVC_ERROR_GET_HVT_EXCEPTION
+ ,HVC_ERROR_GET_HVP_PARAM
+ ,HVC_ERROR_GET_HVP_EXCEPTION
  ,HVC_ERROR_GET_REDEFTIME_PARAM
  ,HVC_ERROR_GET_REDEFTIME_EXCEPTION
  ,HVC_ERROR_GET_ALLSCH_EXCEPTION
@@ -53,7 +56,6 @@ typedef enum {
 class HiveClient_JNI : public JavaObjectInterface
 {
 public:
-  
   static HiveClient_JNI* getInstance();
   static void deleteInstance();
 
@@ -63,11 +65,13 @@ public:
   // Initialize JVM and all the JNI configuration.
   // Must be called.
   HVC_RetCode init();
-  
+
   HVC_RetCode close();
   static HVC_RetCode exists(const char* schName, const char* tabName);
   static HVC_RetCode getHiveTableStr(const char* schName, const char* tabName, 
                               Text& hiveTblStr);
+  static HVC_RetCode getHiveTableParameters(const char *schName, const char *tabName, 
+                              Text& hiveParamsStr);
   static HVC_RetCode getRedefTime(const char* schName, const char* tabName, 
                            Int64& redefTime);
   static HVC_RetCode getAllSchemas(NAHeap *heap, LIST(Text *)& schNames);
@@ -83,6 +87,7 @@ private:
   // Private Default constructor		
   HiveClient_JNI(NAHeap *heap)
   :  JavaObjectInterface(heap)
+  , isConnected_(FALSE)
   {}
 
 private:  
@@ -91,6 +96,7 @@ private:
    ,JM_CLOSE
    ,JM_EXISTS     
    ,JM_GET_HVT
+   ,JM_GET_HVP
    ,JM_GET_RDT
    ,JM_GET_ASH
    ,JM_GET_ATL
@@ -102,5 +108,6 @@ private:
   static bool javaMethodsInitialized_;
   // this mutex protects both JaveMethods_ and javaClass_ initialization
   static pthread_mutex_t javaMethodsInitMutex_;
+  bool isConnected_;
 };
 #endif

http://git-wip-us.apache.org/repos/asf/trafodion/blob/7eaf88d3/core/sql/exp/ExpHbaseInterface.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpHbaseInterface.cpp b/core/sql/exp/ExpHbaseInterface.cpp
index b824a9d..51899ec 100644
--- a/core/sql/exp/ExpHbaseInterface.cpp
+++ b/core/sql/exp/ExpHbaseInterface.cpp
@@ -1515,7 +1515,6 @@ NAArray<HbaseStr> * ExpHbaseInterface_JNI::getRegionStats(const
HbaseStr& tblNam
   NAArray<HbaseStr>* regionStats = client_->getRegionStats((NAHeap *)heap_, tblName.val);
   if (regionStats == NULL)
     return NULL;
-
   return regionStats;
 }
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/7eaf88d3/core/sql/exp/ExpHbaseInterface.h
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpHbaseInterface.h b/core/sql/exp/ExpHbaseInterface.h
index adc76f9..c9583e5 100644
--- a/core/sql/exp/ExpHbaseInterface.h
+++ b/core/sql/exp/ExpHbaseInterface.h
@@ -54,6 +54,7 @@
 
 #include "HBaseClient_JNI.h"
 #include "HiveClient_JNI.h"
+#include "HiveClient_JNI.h"
 
 #define INLINE_COLNAME_LEN 256
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/7eaf88d3/core/sql/sqlcomp/CmpSeabaseDDLauth.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLauth.cpp b/core/sql/sqlcomp/CmpSeabaseDDLauth.cpp
index 8f3a10d..18b1865 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLauth.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLauth.cpp
@@ -2093,4 +2093,3 @@ CmpSeabaseDDLauth::AuthStatus authStatus = getAuthDetails(roleName,false);
     return true;
     
 }
-

http://git-wip-us.apache.org/repos/asf/trafodion/blob/7eaf88d3/core/sql/src/main/java/org/trafodion/sql/HiveClient.java
----------------------------------------------------------------------
diff --git a/core/sql/src/main/java/org/trafodion/sql/HiveClient.java b/core/sql/src/main/java/org/trafodion/sql/HiveClient.java
index d86ce25..fb77f58 100644
--- a/core/sql/src/main/java/org/trafodion/sql/HiveClient.java
+++ b/core/sql/src/main/java/org/trafodion/sql/HiveClient.java
@@ -57,46 +57,47 @@ import java.sql.DriverManager;
 
 
 public class HiveClient {
-    static Logger logger = Logger.getLogger(HiveClient.class.getName());
-    static HiveConf hiveConf = null;
-    static HiveMetaStoreClient hmsClient  ;
-    static String ddlTimeConst = null;
-    public HiveClient() {
-   
-    }
+    private static Logger logger = Logger.getLogger(HiveClient.class.getName());
+    private final String lockPath="/trafodion/traflock";
 
+    private static HiveConf hiveConf = null;
+    private static HiveMetaStoreClient hmsClient  ;
+    private static String ddlTimeConst = null;
     static {
-      String confFile = System.getProperty("trafodion.log4j.configFile");
-      System.setProperty("trafodion.root", System.getenv("TRAF_HOME"));
-      if (confFile == null) {
+         String confFile = System.getProperty("trafodion.log4j.configFile");
+         System.setProperty("trafodion.root", System.getenv("TRAF_HOME"));
+         if (confFile == null) 
          confFile = System.getenv("TRAF_CONF") + "/log4j.sql.config";
-      }
-      PropertyConfigurator.configure(confFile);
-      hiveConf = new HiveConf();
-      try {
-          hmsClient = new HiveMetaStoreClient(hiveConf, null);
-          ddlTimeConst = getDDLTimeConstant();
-      } catch (MetaException me)
-      {
-          throw new RuntimeException("Checked MetaException from HiveClient static block");
-      }
+         PropertyConfigurator.configure(confFile);
+         hiveConf = new HiveConf();
+         try {
+             hmsClient = new HiveMetaStoreClient(hiveConf, null);
+             ddlTimeConst = getDDLTimeConstant();
+         } catch (MetaException me)
+         {
+             throw new RuntimeException("Checked MetaException from HiveClient static block");
+         }
     }
 
-    public static boolean close() {
-        hmsClient.close();
-        return true;
+    public static boolean close() 
+    {	
+        hmsClient.close();	
+        return true;	
     }
-
+ 
     public static boolean exists(String schName, String tblName)  
-        throws MetaException, TException, UnknownDBException {
-            if (logger.isDebugEnabled()) logger.debug("HiveClient.exists(" + schName + "
, " + tblName + ") called.");
-            boolean result = hmsClient.tableExists(schName, tblName);
-            return result;
+        throws MetaException, TException, UnknownDBException 
+    {
+        if (logger.isDebugEnabled()) logger.debug("HiveClient.exists(" + schName + " , "
+ tblName + ") called.");
+        boolean result = hmsClient.tableExists(schName, tblName);
+        return result;
     }
 
     public static String getHiveTableString(String schName, String tblName)
-        throws MetaException, TException {
+        throws MetaException, TException 
+    {
         Table table;
+
         if (logger.isDebugEnabled()) logger.debug("HiveClient.getHiveTableString(" + schName
+ " , " + 
                      tblName + ") called.");
         try {
@@ -107,11 +108,29 @@ public class HiveClient {
             return new String("");
         }
         if (logger.isDebugEnabled()) logger.debug("HiveTable is " + table.toString());
-        return table.toString() ;
+        return table.toString();
     }
 
+    public static String getHiveTableParameters(String schName, String tblName)
+        throws MetaException, TException 
+    {
+        Table table;
+        if (logger.isDebugEnabled()) logger.debug("HiveClient.getHiveTableParameters(" +
schName + " , " + 
+                     tblName + ") called.");
+        try {
+            table = hmsClient.getTable(schName, tblName);
+        }
+        catch (NoSuchObjectException x) {
+            if (logger.isDebugEnabled()) logger.debug("HiveTable not found");
+            return new String("");
+        }
+        String tableParams = new String();
+        return tableParams.toString();
+    }
+    
     public static long getRedefTime(String schName, String tblName)
-        throws MetaException, TException, ClassCastException, NullPointerException, NumberFormatException
{
+        throws MetaException, TException, ClassCastException, NullPointerException, NumberFormatException

+    {
         Table table;
         if (logger.isDebugEnabled()) logger.debug("HiveClient.getRedefTime(" + schName +
" , " + 
                      tblName + ") called.");
@@ -140,7 +159,8 @@ public class HiveClient {
         return redefTime ;
     }
 
-    public static Object[] getAllSchemas() throws MetaException {
+    public static Object[] getAllSchemas() throws MetaException 
+    {
         List<String> schemaList = (hmsClient.getAllDatabases());
         if (schemaList != null)
            return schemaList.toArray();
@@ -149,7 +169,8 @@ public class HiveClient {
     }
 
     public static Object[] getAllTables(String schName) 
-        throws MetaException, TException {
+        throws MetaException, TException 
+    {
         try {
         Database db = hmsClient.getDatabase(schName);
         if (db == null)
@@ -220,23 +241,24 @@ public class HiveClient {
         return fieldVal.toString();
   }
 
-  public static boolean hdfsCreateFile(String fname) throws IOException
-  {
-    if (logger.isDebugEnabled()) logger.debug("HiveClient.hdfsCreateFile() - started" );
-    Path filePath = new Path(fname);
-    FileSystem fs = FileSystem.get(filePath.toUri(),hiveConf);
-    fs.create(filePath, true);
-    
-    if (logger.isDebugEnabled()) logger.debug("HiveClient.hdfsCreateFile() - file created"
);
-
-    return true;
-  }
-  
   public static void executeHiveSQL(String ddl) throws ClassNotFoundException, SQLException
   {
       Class.forName("org.apache.hive.jdbc.HiveDriver");
-      Connection con = DriverManager.getConnection("jdbc:hive2://", "hive", "");
+      Connection con = null;
+      String isSecureHadoop = System.getenv("SECURE_HADOOP");
+      //If Kerberos is enabled, then we need to connect to remote hiveserver2 using hive
principal
+      if(isSecureHadoop != null && isSecureHadoop.equalsIgnoreCase("Y")){
+         String hiveServer2Url = System.getenv("HIVESERVER2_URL");
+         if(hiveServer2Url == null || hiveServer2Url.isEmpty()){
+            hiveServer2Url = "localhost:10000";
+         }
+         String hivePrincipal = System.getenv("HIVE_PRINCIPAL");
+         con = DriverManager.getConnection("jdbc:hive2://" + hiveServer2Url+"/;principal="
+ hivePrincipal, "hive", "");
+      }else{
+         con = DriverManager.getConnection("jdbc:hive2://", "hive", "");
+      }
       Statement stmt = con.createStatement();
       stmt.execute(ddl);
   }
+
 }


Mime
View raw message