You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by se...@apache.org on 2018/04/06 16:07:31 UTC

[1/7] trafodion git commit: [TRAFODION-3009] Streamline error handling in Executor utility commands

Repository: trafodion
Updated Branches:
  refs/heads/master 052f7faa4 -> ee2cff973


http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/HBaseClient_JNI.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/HBaseClient_JNI.cpp b/core/sql/executor/HBaseClient_JNI.cpp
index 88c3431..178043b 100644
--- a/core/sql/executor/HBaseClient_JNI.cpp
+++ b/core/sql/executor/HBaseClient_JNI.cpp
@@ -3510,478 +3510,6 @@ HTC_RetCode HTableClient_JNI::coProcAggr(Int64 transID,
   return HTC_OK;
 }
 
-// ===========================================================================
-// ===== Class HiveClient_JNI
-// ===========================================================================
-
-JavaMethodInit* HiveClient_JNI::JavaMethods_ = NULL;
-jclass HiveClient_JNI::javaClass_ = 0;
-bool HiveClient_JNI::javaMethodsInitialized_ = false;
-pthread_mutex_t HiveClient_JNI::javaMethodsInitMutex_ = PTHREAD_MUTEX_INITIALIZER;
-
-static const char* const hvcErrorEnumStr[] = 
-{
- "Preparing parameters for initConnection()."
- ,"Java exception in initConnection()."
- ,"Java exception in close()."
- ,"Preparing parameters for exists()."
- ,"Java exception in exists()."
- ,"Preparing parameters for getHiveTableStr()."
- ,"Java exception in getHiveTableStr()."
- ,"Preparing parameters for getRedefTime()."
- ,"Java exception in getRedefTime()."
- ,"Java exception in getAllSchemas()."
- ,"Preparing parameters for getAllTables()."
- ,"Java exception in getAllTables()."
- ,"Preparing parameters for executeHiveSQL()."
- ,"Java exception in executeHiveSQL()."
-};
-
-
-
-//////////////////////////////////////////////////////////////////////////////
-// 
-//////////////////////////////////////////////////////////////////////////////
-char* HiveClient_JNI::getErrorText(HVC_RetCode errEnum)
-{
-  if (errEnum < (HVC_RetCode)JOI_LAST)
-    return JavaObjectInterface::getErrorText((JOI_RetCode)errEnum);
-  else    
-    return (char*)hvcErrorEnumStr[errEnum-HVC_FIRST-1];
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// 
-//////////////////////////////////////////////////////////////////////////////
-HiveClient_JNI* HiveClient_JNI::getInstance()
-{
-    ContextCli *currContext = GetCliGlobals()->currContext();
-    HiveClient_JNI *hiveClient_JNI = currContext->getHiveClient();
-    if (hiveClient_JNI == NULL)
-    { 
-       NAHeap *heap = currContext->exHeap();
-       hiveClient_JNI = new (heap) HiveClient_JNI(heap);
-       currContext->setHiveClient(hiveClient_JNI);
-  }
-  return hiveClient_JNI;
-}
-
-void HiveClient_JNI::deleteInstance()
-{
-  ContextCli *currContext = GetCliGlobals()->currContext();
-  HiveClient_JNI *hiveClient_JNI = currContext->getHiveClient();
-  if (hiveClient_JNI != NULL)
-  {
-     NAHeap *heap = currContext->exHeap();
-     NADELETE(hiveClient_JNI, HiveClient_JNI, heap);
-     currContext->setHiveClient(NULL);
-  }
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// 
-//////////////////////////////////////////////////////////////////////////////
-HiveClient_JNI::~HiveClient_JNI()
-{
-  if (isConnected_)
-    close(); // error handling?
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// 
-//////////////////////////////////////////////////////////////////////////////
-HVC_RetCode HiveClient_JNI::init()
-{
-  static char className[]="org/trafodion/sql/HiveClient";
-  HVC_RetCode rc;
-  
-  if (isInitialized())
-    return HVC_OK;
-  
-  if (javaMethodsInitialized_)
-    return (HVC_RetCode)JavaObjectInterface::init(className, javaClass_, JavaMethods_, (Int32)JM_LAST, javaMethodsInitialized_);
-  else
-  {
-    pthread_mutex_lock(&javaMethodsInitMutex_);
-    if (javaMethodsInitialized_)
-    {
-      pthread_mutex_unlock(&javaMethodsInitMutex_);
-      return (HVC_RetCode)JavaObjectInterface::init(className, javaClass_, JavaMethods_, (Int32)JM_LAST, javaMethodsInitialized_);
-    }
-    JavaMethods_ = new JavaMethodInit[JM_LAST];
-    
-    JavaMethods_[JM_CTOR       ].jm_name      = "<init>";
-    JavaMethods_[JM_CTOR       ].jm_signature = "()V";
-    JavaMethods_[JM_INIT       ].jm_name      = "init";
-    JavaMethods_[JM_INIT       ].jm_signature = "(Ljava/lang/String;)Z";
-    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_RDT    ].jm_name      = "getRedefTime";
-    JavaMethods_[JM_GET_RDT    ].jm_signature = "(Ljava/lang/String;Ljava/lang/String;)J";
-    JavaMethods_[JM_GET_ASH     ].jm_name      = "getAllSchemas";
-    JavaMethods_[JM_GET_ASH     ].jm_signature = "()[Ljava/lang/Object;";
-    JavaMethods_[JM_GET_ATL    ].jm_name      = "getAllTables";
-    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;
-    pthread_mutex_unlock(&javaMethodsInitMutex_);
-  }
-  return rc;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// 
-//////////////////////////////////////////////////////////////////////////////
-HVC_RetCode HiveClient_JNI::initConnection(const char* metastoreURI)
-{
-  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "HiveClient_JNI::initConnection(%s) called.", metastoreURI);
-
-  if (initJNIEnv() != JOI_OK)
-     return HVC_ERROR_INIT_PARAM;
-
-  jstring js_metastoreURI = jenv_->NewStringUTF(metastoreURI);
-  if (js_metastoreURI == NULL) 
-  {
-    GetCliGlobals()->setJniErrorStr(getErrorText(HVC_ERROR_INIT_PARAM));
-    jenv_->PopLocalFrame(NULL);
-    return HVC_ERROR_INIT_PARAM;
-  }
-  
-
-  tsRecentJMFromJNI = JavaMethods_[JM_INIT].jm_full_name;
-  jboolean jresult = jenv_->CallBooleanMethod(javaObj_, JavaMethods_[JM_INIT].methodID, js_metastoreURI);
-
-  if (jenv_->ExceptionCheck())
-  {
-    getExceptionDetails(__FILE__, __LINE__, "HiveClient_JNI::initConnection()");
-    jenv_->PopLocalFrame(NULL);
-    return HVC_ERROR_INIT_EXCEPTION;
-  }
-
-  if (jresult == false) 
-  {
-    logError(CAT_SQL_HBASE, "HiveClient_JNI::initConnection()", getLastError());
-    jenv_->PopLocalFrame(NULL);
-    return HVC_ERROR_INIT_EXCEPTION;
-  }
-
-  isConnected_ = TRUE;
-  jenv_->PopLocalFrame(NULL);
-  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_->CallBooleanMethod(javaObj_, 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);
-  if (initJNIEnv() != JOI_OK)
-     return HVC_ERROR_INIT_PARAM;
-
-  jstring js_schName = jenv_->NewStringUTF(schName);
-  if (js_schName == NULL) 
-  {
-    GetCliGlobals()->setJniErrorStr(getErrorText(HVC_ERROR_EXISTS_PARAM));
-    jenv_->PopLocalFrame(NULL);
-    return HVC_ERROR_EXISTS_PARAM;
-  }
-  jstring js_tabName = jenv_->NewStringUTF(tabName);
-  if (js_tabName == NULL) 
-  {
-    GetCliGlobals()->setJniErrorStr(getErrorText(HVC_ERROR_EXISTS_PARAM));
-    jenv_->PopLocalFrame(NULL);
-    return HVC_ERROR_EXISTS_PARAM;
-  }
-
-  // boolean exists(java.lang.String, java.lang.String);
-  tsRecentJMFromJNI = JavaMethods_[JM_EXISTS].jm_full_name;
-  jboolean jresult = jenv_->CallBooleanMethod(javaObj_, JavaMethods_[JM_EXISTS].methodID, js_schName, js_tabName);
-
-  if (jenv_->ExceptionCheck())
-  {
-    getExceptionDetails(__FILE__, __LINE__, "HiveClient_JNI::exists()");
-    jenv_->PopLocalFrame(NULL);
-    return HVC_ERROR_EXISTS_EXCEPTION;
-  }
-
-  if (jresult == false) {
-     jenv_->PopLocalFrame(NULL);
-     return HVC_DONE;  // Table does not exist
-  }
-
-  jenv_->PopLocalFrame(NULL);
-  return HVC_OK;  // Table exists.
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// 
-//////////////////////////////////////////////////////////////////////////////
-HVC_RetCode HiveClient_JNI::getHiveTableStr(const char* schName, 
-                                            const char* tabName, 
-                                            Text& hiveTblStr)
-{
-  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "Enter HiveClient_JNI::getHiveTableStr(%s, %s, %s).", schName, tabName, hiveTblStr.data());
-  if (initJNIEnv() != JOI_OK)
-     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_HVT_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_HVT_PARAM;
-  }
-
-  // java.lang.String getHiveTableString(java.lang.String, java.lang.String);
-  tsRecentJMFromJNI = JavaMethods_[JM_GET_HVT].jm_full_name;
-  jstring jresult = (jstring)jenv_->CallObjectMethod(javaObj_, 
-                                            JavaMethods_[JM_GET_HVT].methodID, 
-                                            js_schName, js_tabName);
-  if (jenv_->ExceptionCheck())
-  {
-    getExceptionDetails(__FILE__, __LINE__, "HiveClient_JNI::getHiveTableStr()");
-    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);
-  hiveTblStr += char_result ; // deep copy. hiveTblStr is assumed to be empty.
-  jenv_->ReleaseStringUTFChars(jresult, char_result);
-
-  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "Exit HiveClient_JNI::getHiveTableStr(%s, %s, %s).", schName, tabName, hiveTblStr.data());
-  jenv_->PopLocalFrame(NULL);
-  return HVC_OK;  // Table exists.
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// 
-//////////////////////////////////////////////////////////////////////////////  
-HVC_RetCode HiveClient_JNI::getRedefTime(const char* schName, 
-                                         const char* tabName, 
-                                         Int64& redefTime)
-{
-  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "Enter HiveClient_JNI::getRedefTime(%s, %s, %lld).", schName, tabName, redefTime);
-  if (initJNIEnv() != JOI_OK)
-     return HVC_ERROR_INIT_PARAM;
-
-  jstring js_schName = jenv_->NewStringUTF(schName);
-  if (js_schName == NULL) 
-  {
-    GetCliGlobals()->setJniErrorStr(getErrorText(HVC_ERROR_GET_REDEFTIME_PARAM));
-    jenv_->PopLocalFrame(NULL);
-    return HVC_ERROR_GET_REDEFTIME_PARAM;
-  }
-  jstring js_tabName = jenv_->NewStringUTF(tabName);
-  if (js_tabName == NULL) 
-  {
-    GetCliGlobals()->setJniErrorStr(getErrorText(HVC_ERROR_GET_REDEFTIME_PARAM));
-    jenv_->PopLocalFrame(NULL);
-    return HVC_ERROR_GET_REDEFTIME_PARAM;
-  }
-
-  //  jlong getRedefTime(java.lang.String, java.lang.String);
-  tsRecentJMFromJNI = JavaMethods_[JM_GET_RDT].jm_full_name;
-  jlong jresult = jenv_->CallLongMethod(javaObj_, 
-                                        JavaMethods_[JM_GET_RDT].methodID, 
-                                        js_schName, js_tabName);
-
-  if (jenv_->ExceptionCheck())
-  {
-    getExceptionDetails(__FILE__, __LINE__, "HiveClient_JNI::getRedefTime()");
-    jenv_->PopLocalFrame(NULL);
-    return HVC_ERROR_GET_REDEFTIME_EXCEPTION;
-  }
-
-  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "Exit HiveClient_JNI::getRedefTime(%s, %s, %lld).", schName, tabName, redefTime);
-
-  if (jresult < 0) {
-    jenv_->PopLocalFrame(NULL);
-    return HVC_DONE; // Table does not exist
-  }
-
-  redefTime = jresult ;
-  jenv_->PopLocalFrame(NULL);
-  return HVC_OK;  // Table exists.
-  
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// 
-////////////////////////////////////////////////////////////////////////////// 
-HVC_RetCode HiveClient_JNI::getAllSchemas(LIST(Text *)& schNames)
-{
-  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "Enter HiveClient_JNI::getAllSchemas(%p) called.", (void *) &schNames);
-  if (initJNIEnv() != JOI_OK)
-     return HVC_ERROR_INIT_PARAM;
-
-  tsRecentJMFromJNI = JavaMethods_[JM_GET_ASH].jm_full_name;
-  jarray j_schNames= 
-     (jarray)jenv_->CallObjectMethod(javaObj_, JavaMethods_[JM_GET_ASH].methodID);
-
-  if (jenv_->ExceptionCheck())
-  {
-    getExceptionDetails(__FILE__, __LINE__, "HiveClient_JNI::getAllSchemas()");
-    jenv_->PopLocalFrame(NULL);
-    return HVC_ERROR_GET_ALLSCH_EXCEPTION;
-  }
-
-  int numSchemas = convertStringObjectArrayToList(heap_, j_schNames,
-                   schNames);           
-  if (numSchemas == 0) {
-     jenv_->PopLocalFrame(NULL);
-     return HVC_DONE;
-  }
-  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, 
-       "Exit HiveClient_JNI::getAllSchemas(%p) called.", (void *) &schNames);
-  jenv_->PopLocalFrame(NULL);
-  return HVC_OK;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// 
-////////////////////////////////////////////////////////////////////////////// 
-HVC_RetCode HiveClient_JNI::executeHiveSQL(const char* hiveSQL)
-{
-  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "Enter HiveClient_JNI::executeHiveSQL(%s) called.", hiveSQL);
-  if (initJNIEnv() != JOI_OK)
-     return HVC_ERROR_INIT_PARAM;
-
-  jstring js_hiveSQL = jenv_->NewStringUTF(hiveSQL);
-  if (js_hiveSQL == NULL) 
-  {
-    GetCliGlobals()->setJniErrorStr(getErrorText(HVC_ERROR_GET_ALLTBL_PARAM));
-    jenv_->PopLocalFrame(NULL);
-    return HVC_ERROR_EXECUTE_HIVE_SQL_PARAM;
-  }
-  
-  tsRecentJMFromJNI = JavaMethods_[JM_EXEC_HIVE_SQL].jm_full_name;
-  jenv_->CallVoidMethod(javaObj_, JavaMethods_[JM_EXEC_HIVE_SQL].methodID, js_hiveSQL);
-
-  if (jenv_->ExceptionCheck())
-  {
-    getExceptionDetails(__FILE__, __LINE__, "HiveClient_JNI::executeHiveSQL()");
-    jenv_->PopLocalFrame(NULL);
-    return HVC_ERROR_EXECUTE_HIVE_SQL_EXCEPTION;
-  }
-
-  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, 
-       "Exit HiveClient_JNI::executeHiveSQL(%s) called.", hiveSQL);
-  jenv_->PopLocalFrame(NULL);
-  return HVC_OK;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// 
-//////////////////////////////////////////////////////////////////////////////
-HVC_RetCode HiveClient_JNI::getAllTables(const char* schName, 
-                                         LIST(Text *)& tblNames)
-{
-  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "Enter HiveClient_JNI::getAllTables(%s, %p) called.", schName, (void *) &tblNames);
-  if (initJNIEnv() != JOI_OK)
-     return HVC_ERROR_INIT_PARAM;
-
-  jstring js_schName = jenv_->NewStringUTF(schName);
-  if (js_schName == NULL) 
-  {
-    GetCliGlobals()->setJniErrorStr(getErrorText(HVC_ERROR_GET_ALLTBL_PARAM));
-    jenv_->PopLocalFrame(NULL);
-    return HVC_ERROR_GET_ALLTBL_PARAM;
-  }
-
-  tsRecentJMFromJNI = JavaMethods_[JM_GET_ATL].jm_full_name;
-  jarray j_tblNames = 
-    (jarray)jenv_->CallObjectMethod(javaObj_, JavaMethods_[JM_GET_ATL].methodID, 
-                            js_schName);
-
-  if (jenv_->ExceptionCheck())
-  {
-    getExceptionDetails(__FILE__, __LINE__, "HiveClient_JNI::getAllTables()");
-    jenv_->PopLocalFrame(NULL);
-    return HVC_ERROR_GET_ALLTBL_EXCEPTION;
-  }
-
-  if (j_tblNames == NULL) 	
-  {	
-     GetCliGlobals()->setJniErrorStr(getErrorText(HVC_ERROR_EXISTS_EXCEPTION));
-     jenv_->PopLocalFrame(NULL);	
-     return HVC_ERROR_EXISTS_EXCEPTION;	
-  }
-
-  int numTables = convertStringObjectArrayToList(heap_, j_tblNames,
-                   tblNames);           
-  if (numTables == 0) {
-     jenv_->PopLocalFrame(NULL);
-     return HVC_DONE;
-  }
-  jenv_->PopLocalFrame(NULL);
-  return HVC_OK;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// 
-//////////////////////////////////////////////////////////////////////////////  
-void HiveClient_JNI::logIt(const char* str)
-{
-  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, str);
-}
-
 #ifdef __cplusplus
 extern "C" {
 #endif

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/HBaseClient_JNI.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/HBaseClient_JNI.h b/core/sql/executor/HBaseClient_JNI.h
index 01b0edc..4b869c6 100644
--- a/core/sql/executor/HBaseClient_JNI.h
+++ b/core/sql/executor/HBaseClient_JNI.h
@@ -605,102 +605,13 @@ private:
 };
 
 // ===========================================================================
-// ===== The HiveClient_JNI class implements access to the Java 
-// ===== HiveClient class.
-// ===========================================================================
-
-typedef enum {
-  HVC_OK     = JOI_OK
- ,HVC_FIRST  = HBC_LAST
- ,HVC_DONE   = HVC_FIRST
- ,HVC_ERROR_INIT_PARAM
- ,HVC_ERROR_INIT_EXCEPTION
- ,HVC_ERROR_CLOSE_EXCEPTION
- ,HVC_ERROR_EXISTS_PARAM
- ,HVC_ERROR_EXISTS_EXCEPTION
- ,HVC_ERROR_GET_HVT_PARAM
- ,HVC_ERROR_GET_HVT_EXCEPTION
- ,HVC_ERROR_GET_REDEFTIME_PARAM
- ,HVC_ERROR_GET_REDEFTIME_EXCEPTION
- ,HVC_ERROR_GET_ALLSCH_EXCEPTION
- ,HVC_ERROR_GET_ALLTBL_PARAM
- ,HVC_ERROR_GET_ALLTBL_EXCEPTION
- ,HVC_ERROR_EXECUTE_HIVE_SQL_PARAM
- ,HVC_ERROR_EXECUTE_HIVE_SQL_EXCEPTION
- ,HVC_LAST
-} HVC_RetCode;
-
-class HiveClient_JNI : public JavaObjectInterface
-{
-public:
-  
-  static HiveClient_JNI* getInstance();
-  static void deleteInstance();
-
-  // Destructor
-  virtual ~HiveClient_JNI();
-  
-  // Initialize JVM and all the JNI configuration.
-  // Must be called.
-  HVC_RetCode init();
-  
-  HVC_RetCode initConnection(const char* metastoreURI); 
-  bool isConnected() 
-  {
-    return isConnected_;
-  }
-
-  HVC_RetCode close();
-  HVC_RetCode exists(const char* schName, const char* tabName);
-  HVC_RetCode getHiveTableStr(const char* schName, const char* tabName, 
-                              Text& hiveTblStr);
-  HVC_RetCode getRedefTime(const char* schName, const char* tabName, 
-                           Int64& redefTime);
-  HVC_RetCode getAllSchemas(LIST(Text *)& schNames);
-  HVC_RetCode getAllTables(const char* schName, LIST(Text *)& tblNames);
-
-  HVC_RetCode executeHiveSQL(const char* hiveSQL);
-  // Get the error description.
-  static char* getErrorText(HVC_RetCode errEnum);
-  
-  static void logIt(const char* str);
-
-private:   
-  // Private Default constructor		
-  HiveClient_JNI(NAHeap *heap)
-  :  JavaObjectInterface(heap)
-  , isConnected_(FALSE)
-  {}
-
-private:  
-  enum JAVA_METHODS {
-    JM_CTOR = 0
-   ,JM_INIT
-   ,JM_CLOSE
-   ,JM_EXISTS     
-   ,JM_GET_HVT
-   ,JM_GET_RDT
-   ,JM_GET_ASH
-   ,JM_GET_ATL
-   ,JM_EXEC_HIVE_SQL
-   ,JM_LAST
-  };
-  static jclass          javaClass_; 
-  static JavaMethodInit* JavaMethods_;
-  static bool javaMethodsInitialized_;
-  // this mutex protects both JaveMethods_ and javaClass_ initialization
-  static pthread_mutex_t javaMethodsInitMutex_;
-  bool isConnected_;
-};
-
-// ===========================================================================
 // ===== The HBulkLoadClient_JNI class implements access to the Java
 // ===== HBulkLoadClient class.
 // ===========================================================================
 
 typedef enum {
   HBLC_OK     = JOI_OK
- ,HBLC_FIRST  = HVC_LAST
+ ,HBLC_FIRST  = HTC_LAST
  ,HBLC_DONE   = HBLC_FIRST
  ,HBLC_ERROR_INIT_PARAM
  ,HBLC_ERROR_INIT_EXCEPTION

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/HdfsClient_JNI.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/HdfsClient_JNI.cpp b/core/sql/executor/HdfsClient_JNI.cpp
index eed9e7d..72a898b 100644
--- a/core/sql/executor/HdfsClient_JNI.cpp
+++ b/core/sql/executor/HdfsClient_JNI.cpp
@@ -363,7 +363,7 @@ HdfsClient *HdfsClient::newInstance(NAHeap *heap, ExHdfsScanStats *hdfsStats, HD
 {
    QRLogger::log(CAT_SQL_HDFS, LL_DEBUG, "HdfsClient::newInstance() called.");
 
-      if (initJNIEnv() != JOI_OK)
+   if (initJNIEnv() != JOI_OK)
      return NULL;
    retCode = HDFS_CLIENT_OK;
    HdfsClient *hdfsClient = new (heap) HdfsClient(heap);

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/HiveClient_JNI.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/HiveClient_JNI.cpp b/core/sql/executor/HiveClient_JNI.cpp
new file mode 100644
index 0000000..3db5ce8
--- /dev/null
+++ b/core/sql/executor/HiveClient_JNI.cpp
@@ -0,0 +1,473 @@
+// **********************************************************************
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+// **********************************************************************
+
+#include "QRLogger.h"
+#include "Globals.h"
+#include "Context.h"
+#include "jni.h"
+#include "HiveClient_JNI.h"
+
+// ===========================================================================
+// ===== Class HiveClient_JNI
+// ===========================================================================
+
+JavaMethodInit* HiveClient_JNI::JavaMethods_ = NULL;
+jclass HiveClient_JNI::javaClass_ = 0;
+bool HiveClient_JNI::javaMethodsInitialized_ = false;
+pthread_mutex_t HiveClient_JNI::javaMethodsInitMutex_ = PTHREAD_MUTEX_INITIALIZER;
+
+static const char* const hvcErrorEnumStr[] = 
+{
+  "Java exception while initializing HiveClient"
+ ,"Java exception in close()."
+ ,"Preparing parameters for exists()."
+ ,"Java exception in exists()."
+ ,"Preparing parameters for getHiveTableStr()."
+ ,"Java exception in getHiveTableStr()."
+ ,"Preparing parameters for getRedefTime()."
+ ,"Java exception in getRedefTime()."
+ ,"Java exception in getAllSchemas()."
+ ,"Preparing parameters for getAllTables()."
+ ,"Java exception in getAllTables()."
+ ,"Preparing parameters for executeHiveSQL()."
+ ,"Java exception in executeHiveSQL()."
+};
+
+
+
+//////////////////////////////////////////////////////////////////////////////
+// 
+//////////////////////////////////////////////////////////////////////////////
+char* HiveClient_JNI::getErrorText(HVC_RetCode errEnum)
+{
+  if (errEnum < (HVC_RetCode)JOI_LAST)
+    return JavaObjectInterface::getErrorText((JOI_RetCode)errEnum);
+  else    
+    return (char*)hvcErrorEnumStr[errEnum-HVC_FIRST-1];
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// 
+//////////////////////////////////////////////////////////////////////////////
+HiveClient_JNI* HiveClient_JNI::getInstance()
+{
+   HVC_RetCode hvcRetcode = HVC_OK;
+
+   ContextCli *currContext = GetCliGlobals()->currContext();
+   HiveClient_JNI *hiveClient_JNI = currContext->getHiveClient();
+   if (hiveClient_JNI == NULL)
+   { 
+       NAHeap *heap = currContext->exHeap();
+       hiveClient_JNI = new (heap) HiveClient_JNI(heap);
+       if ((hvcRetcode = hiveClient_JNI->init()) == HVC_OK)
+          currContext->setHiveClient(hiveClient_JNI);
+       else {
+          NADELETE(hiveClient_JNI, HiveClient_JNI, heap);
+          hiveClient_JNI = NULL;
+       }
+   }
+   return hiveClient_JNI;
+}
+
+void HiveClient_JNI::deleteInstance()
+{
+  ContextCli *currContext = GetCliGlobals()->currContext();
+  HiveClient_JNI *hiveClient_JNI = currContext->getHiveClient();
+  if (hiveClient_JNI != NULL)
+  {
+     NAHeap *heap = currContext->exHeap();
+     NADELETE(hiveClient_JNI, HiveClient_JNI, heap);
+     currContext->setHiveClient(NULL);
+  }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// 
+//////////////////////////////////////////////////////////////////////////////
+HiveClient_JNI::~HiveClient_JNI()
+{
+   if (isInitialized())
+      close(); // error handling?
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// 
+//////////////////////////////////////////////////////////////////////////////
+HVC_RetCode HiveClient_JNI::init()
+{
+  static char className[]="org/trafodion/sql/HiveClient";
+  HVC_RetCode rc;
+
+  if (isInitialized())
+    return HVC_OK;
+  
+  if (javaMethodsInitialized_)
+    return (HVC_RetCode)JavaObjectInterface::init(className, javaClass_, JavaMethods_, (Int32)JM_LAST, javaMethodsInitialized_);
+  else
+  {
+    pthread_mutex_lock(&javaMethodsInitMutex_);
+    if (javaMethodsInitialized_)
+    {
+      pthread_mutex_unlock(&javaMethodsInitMutex_);
+      return (HVC_RetCode)JavaObjectInterface::init(className, javaClass_, JavaMethods_, (Int32)JM_LAST, javaMethodsInitialized_);
+    }
+    JavaMethods_ = new JavaMethodInit[JM_LAST];
+    
+    JavaMethods_[JM_CTOR       ].jm_name      = "<init>";
+    JavaMethods_[JM_CTOR       ].jm_signature = "()V";
+    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_RDT    ].jm_name      = "getRedefTime";
+    JavaMethods_[JM_GET_RDT    ].jm_signature = "(Ljava/lang/String;Ljava/lang/String;)J";
+    JavaMethods_[JM_GET_ASH     ].jm_name      = "getAllSchemas";
+    JavaMethods_[JM_GET_ASH     ].jm_signature = "()[Ljava/lang/Object;";
+    JavaMethods_[JM_GET_ATL    ].jm_name      = "getAllTables";
+    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;
+    pthread_mutex_unlock(&javaMethodsInitMutex_);
+  }
+  return rc;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// 
+//////////////////////////////////////////////////////////////////////////////
+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);
+  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_EXISTS_PARAM));
+    jenv_->PopLocalFrame(NULL);
+    return HVC_ERROR_EXISTS_PARAM;
+  }
+  jstring js_tabName = jenv_->NewStringUTF(tabName);
+  if (js_tabName == NULL) 
+  {
+    GetCliGlobals()->setJniErrorStr(getErrorText(HVC_ERROR_EXISTS_PARAM));
+    jenv_->PopLocalFrame(NULL);
+    return HVC_ERROR_EXISTS_PARAM;
+  }
+
+  // boolean exists(java.lang.String, java.lang.String);
+  tsRecentJMFromJNI = JavaMethods_[JM_EXISTS].jm_full_name;
+  jboolean jresult = jenv_->CallStaticBooleanMethod(javaClass_, JavaMethods_[JM_EXISTS].methodID, js_schName, js_tabName);
+
+  if (jenv_->ExceptionCheck())
+  {
+    getExceptionDetails(__FILE__, __LINE__, "HiveClient_JNI::exists()");
+    jenv_->PopLocalFrame(NULL);
+    return HVC_ERROR_EXISTS_EXCEPTION;
+  }
+
+  if (jresult == false) {
+     jenv_->PopLocalFrame(NULL);
+     return HVC_DONE;  // Table does not exist
+  }
+
+  jenv_->PopLocalFrame(NULL);
+  return HVC_OK;  // Table exists.
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// 
+//////////////////////////////////////////////////////////////////////////////
+HVC_RetCode HiveClient_JNI::getHiveTableStr(const char* schName, 
+                                            const char* tabName, 
+                                            Text& hiveTblStr)
+{
+  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "Enter HiveClient_JNI::getHiveTableStr(%s, %s, %s).", schName, tabName, hiveTblStr.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_HVT_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_HVT_PARAM;
+  }
+
+  // java.lang.String getHiveTableString(java.lang.String, java.lang.String);
+  tsRecentJMFromJNI = JavaMethods_[JM_GET_HVT].jm_full_name;
+  jstring jresult = (jstring)jenv_->CallStaticObjectMethod(javaClass_, 
+                                            JavaMethods_[JM_GET_HVT].methodID, 
+                                            js_schName, js_tabName);
+  if (jenv_->ExceptionCheck())
+  {
+    getExceptionDetails(__FILE__, __LINE__, "HiveClient_JNI::getHiveTableStr()");
+    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);
+  hiveTblStr += char_result ; // deep copy. hiveTblStr is assumed to be empty.
+  jenv_->ReleaseStringUTFChars(jresult, char_result);
+
+  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "Exit HiveClient_JNI::getHiveTableStr(%s, %s, %s).", schName, tabName, hiveTblStr.data());
+  jenv_->PopLocalFrame(NULL);
+  return HVC_OK;  // Table exists.
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// 
+//////////////////////////////////////////////////////////////////////////////  
+HVC_RetCode HiveClient_JNI::getRedefTime(const char* schName, 
+                                         const char* tabName, 
+                                         Int64& redefTime)
+{
+  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "Enter HiveClient_JNI::getRedefTime(%s, %s, %lld).", schName, tabName, redefTime);
+  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_REDEFTIME_PARAM));
+    jenv_->PopLocalFrame(NULL);
+    return HVC_ERROR_GET_REDEFTIME_PARAM;
+  }
+  jstring js_tabName = jenv_->NewStringUTF(tabName);
+  if (js_tabName == NULL) 
+  {
+    GetCliGlobals()->setJniErrorStr(getErrorText(HVC_ERROR_GET_REDEFTIME_PARAM));
+    jenv_->PopLocalFrame(NULL);
+    return HVC_ERROR_GET_REDEFTIME_PARAM;
+  }
+
+  //  jlong getRedefTime(java.lang.String, java.lang.String);
+  tsRecentJMFromJNI = JavaMethods_[JM_GET_RDT].jm_full_name;
+  jlong jresult = jenv_->CallStaticLongMethod(javaClass_, 
+                                        JavaMethods_[JM_GET_RDT].methodID, 
+                                        js_schName, js_tabName);
+
+  if (jenv_->ExceptionCheck())
+  {
+    getExceptionDetails(__FILE__, __LINE__, "HiveClient_JNI::getRedefTime()");
+    jenv_->PopLocalFrame(NULL);
+    return HVC_ERROR_GET_REDEFTIME_EXCEPTION;
+  }
+
+  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "Exit HiveClient_JNI::getRedefTime(%s, %s, %lld).", schName, tabName, redefTime);
+
+  if (jresult < 0) {
+    jenv_->PopLocalFrame(NULL);
+    return HVC_DONE; // Table does not exist
+  }
+
+  redefTime = jresult ;
+  jenv_->PopLocalFrame(NULL);
+  return HVC_OK;  // Table exists.
+  
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// 
+////////////////////////////////////////////////////////////////////////////// 
+HVC_RetCode HiveClient_JNI::getAllSchemas(NAHeap *heap, LIST(Text *)& schNames)
+{
+  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "Enter HiveClient_JNI::getAllSchemas(%p) called.", (void *) &schNames);
+  if (initJNIEnv() != JOI_OK)
+     return HVC_ERROR_INIT_PARAM;
+  if (getInstance() == NULL)
+     return HVC_ERROR_INIT_PARAM;
+
+  tsRecentJMFromJNI = JavaMethods_[JM_GET_ASH].jm_full_name;
+  jarray j_schNames= 
+     (jarray)jenv_->CallStaticObjectMethod(javaClass_, JavaMethods_[JM_GET_ASH].methodID);
+
+  if (jenv_->ExceptionCheck())
+  {
+    getExceptionDetails(__FILE__, __LINE__, "HiveClient_JNI::getAllSchemas()");
+    jenv_->PopLocalFrame(NULL);
+    return HVC_ERROR_GET_ALLSCH_EXCEPTION;
+  }
+
+  int numSchemas = convertStringObjectArrayToList(heap, j_schNames,
+                   schNames);           
+  if (numSchemas == 0) {
+     jenv_->PopLocalFrame(NULL);
+     return HVC_DONE;
+  }
+  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, 
+       "Exit HiveClient_JNI::getAllSchemas(%p) called.", (void *) &schNames);
+  jenv_->PopLocalFrame(NULL);
+  return HVC_OK;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// 
+////////////////////////////////////////////////////////////////////////////// 
+HVC_RetCode HiveClient_JNI::executeHiveSQL(const char* hiveSQL)
+{
+  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "Enter HiveClient_JNI::executeHiveSQL(%s) called.", hiveSQL);
+  if (initJNIEnv() != JOI_OK)
+     return HVC_ERROR_INIT_PARAM;
+  if (getInstance() == NULL)
+     return HVC_ERROR_INIT_PARAM;
+
+  jstring js_hiveSQL = jenv_->NewStringUTF(hiveSQL);
+  if (js_hiveSQL == NULL) 
+  {
+    GetCliGlobals()->setJniErrorStr(getErrorText(HVC_ERROR_GET_ALLTBL_PARAM));
+    jenv_->PopLocalFrame(NULL);
+    return HVC_ERROR_EXECUTE_HIVE_SQL_PARAM;
+  }
+  
+  tsRecentJMFromJNI = JavaMethods_[JM_EXEC_HIVE_SQL].jm_full_name;
+  jenv_->CallStaticVoidMethod(javaClass_, JavaMethods_[JM_EXEC_HIVE_SQL].methodID, js_hiveSQL);
+
+  if (jenv_->ExceptionCheck())
+  {
+    getExceptionDetails(__FILE__, __LINE__, "HiveClient_JNI::executeHiveSQL()");
+    jenv_->PopLocalFrame(NULL);
+    return HVC_ERROR_EXECUTE_HIVE_SQL_EXCEPTION;
+  }
+
+  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, 
+       "Exit HiveClient_JNI::executeHiveSQL(%s) called.", hiveSQL);
+  jenv_->PopLocalFrame(NULL);
+  return HVC_OK;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// 
+//////////////////////////////////////////////////////////////////////////////
+HVC_RetCode HiveClient_JNI::getAllTables(NAHeap *heap, const char* schName, 
+                                         LIST(Text *)& tblNames)
+{
+  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, "Enter HiveClient_JNI::getAllTables(%s, %p) called.", schName, (void *) &tblNames);
+  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_ALLTBL_PARAM));
+    jenv_->PopLocalFrame(NULL);
+    return HVC_ERROR_GET_ALLTBL_PARAM;
+  }
+
+  tsRecentJMFromJNI = JavaMethods_[JM_GET_ATL].jm_full_name;
+  jarray j_tblNames = 
+    (jarray)jenv_->CallStaticObjectMethod(javaClass_, JavaMethods_[JM_GET_ATL].methodID, 
+                            js_schName);
+
+  if (jenv_->ExceptionCheck())
+  {
+    getExceptionDetails(__FILE__, __LINE__, "HiveClient_JNI::getAllTables()");
+    jenv_->PopLocalFrame(NULL);
+    return HVC_ERROR_GET_ALLTBL_EXCEPTION;
+  }
+
+  if (j_tblNames == NULL) 	
+  {	
+     GetCliGlobals()->setJniErrorStr(getErrorText(HVC_ERROR_EXISTS_EXCEPTION));
+     jenv_->PopLocalFrame(NULL);	
+     return HVC_ERROR_EXISTS_EXCEPTION;	
+  }
+
+  int numTables = convertStringObjectArrayToList(heap, j_tblNames,
+                   tblNames);           
+  if (numTables == 0) {
+     jenv_->PopLocalFrame(NULL);
+     return HVC_DONE;
+  }
+  jenv_->PopLocalFrame(NULL);
+  return HVC_OK;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// 
+//////////////////////////////////////////////////////////////////////////////  
+void HiveClient_JNI::logIt(const char* str)
+{
+  QRLogger::log(CAT_SQL_HBASE, LL_DEBUG, str);
+}

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/HiveClient_JNI.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/HiveClient_JNI.h b/core/sql/executor/HiveClient_JNI.h
new file mode 100644
index 0000000..32c8c33
--- /dev/null
+++ b/core/sql/executor/HiveClient_JNI.h
@@ -0,0 +1,106 @@
+// **********************************************************************
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+// **********************************************************************
+
+// ===========================================================================
+// ===== The HiveClient_JNI class implements access to the Java 
+// ===== HiveClient class.
+// ===========================================================================
+#ifndef HIVE_CLIENT_H
+#define HIVE_CLIENT_H
+
+#include "JavaObjectInterface.h"
+
+typedef enum {
+  HVC_OK     = JOI_OK
+ ,HVC_FIRST  = JOI_LAST
+ ,HVC_DONE   = HVC_FIRST
+ ,HVC_ERROR_INIT_PARAM
+ ,HVC_ERROR_CLOSE_EXCEPTION
+ ,HVC_ERROR_EXISTS_PARAM
+ ,HVC_ERROR_EXISTS_EXCEPTION
+ ,HVC_ERROR_GET_HVT_PARAM
+ ,HVC_ERROR_GET_HVT_EXCEPTION
+ ,HVC_ERROR_GET_REDEFTIME_PARAM
+ ,HVC_ERROR_GET_REDEFTIME_EXCEPTION
+ ,HVC_ERROR_GET_ALLSCH_EXCEPTION
+ ,HVC_ERROR_GET_ALLTBL_PARAM
+ ,HVC_ERROR_GET_ALLTBL_EXCEPTION
+ ,HVC_ERROR_EXECUTE_HIVE_SQL_PARAM
+ ,HVC_ERROR_EXECUTE_HIVE_SQL_EXCEPTION
+ ,HVC_LAST
+} HVC_RetCode;
+
+class HiveClient_JNI : public JavaObjectInterface
+{
+public:
+  
+  static HiveClient_JNI* getInstance();
+  static void deleteInstance();
+
+  // Destructor
+  virtual ~HiveClient_JNI();
+  
+  // 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 getRedefTime(const char* schName, const char* tabName, 
+                           Int64& redefTime);
+  static HVC_RetCode getAllSchemas(NAHeap *heap, LIST(Text *)& schNames);
+  static HVC_RetCode getAllTables(NAHeap *heap, const char* schName, LIST(Text *)& tblNames);
+
+  static HVC_RetCode executeHiveSQL(const char* hiveSQL);
+  // Get the error description.
+  static char* getErrorText(HVC_RetCode errEnum);
+  
+  static void logIt(const char* str);
+
+private:   
+  // Private Default constructor		
+  HiveClient_JNI(NAHeap *heap)
+  :  JavaObjectInterface(heap)
+  {}
+
+private:  
+  enum JAVA_METHODS {
+    JM_CTOR = 0
+   ,JM_CLOSE
+   ,JM_EXISTS     
+   ,JM_GET_HVT
+   ,JM_GET_RDT
+   ,JM_GET_ASH
+   ,JM_GET_ATL
+   ,JM_EXEC_HIVE_SQL
+   ,JM_LAST
+  };
+  static jclass          javaClass_; 
+  static JavaMethodInit* JavaMethods_;
+  static bool javaMethodsInitialized_;
+  // this mutex protects both JaveMethods_ and javaClass_ initialization
+  static pthread_mutex_t javaMethodsInitMutex_;
+};
+#endif

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/JavaObjectInterface.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/JavaObjectInterface.cpp b/core/sql/executor/JavaObjectInterface.cpp
index 22b9003..282e40b 100644
--- a/core/sql/executor/JavaObjectInterface.cpp
+++ b/core/sql/executor/JavaObjectInterface.cpp
@@ -499,7 +499,7 @@ JOI_RetCode JavaObjectInterface::init(char *className,
                                                      JavaMethods[i].jm_signature);
         if (JavaMethods[i].methodID == 0 || jenv_->ExceptionCheck())
         { 
-          getExceptionDetails(__FILE__, __LINE__, "GetMethodId()");
+          jenv_->ExceptionClear();
           JavaMethods[i].methodID = jenv_->GetStaticMethodID(javaClass, 
                                                      JavaMethods[i].jm_name, 
                                                      JavaMethods[i].jm_signature);

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/ex_root.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ex_root.cpp b/core/sql/executor/ex_root.cpp
index 560b630..0fe945b 100644
--- a/core/sql/executor/ex_root.cpp
+++ b/core/sql/executor/ex_root.cpp
@@ -2265,27 +2265,7 @@ Int32 ex_root_tcb::cancel(ExExeStmtGlobals * glob, ComDiagsArea *&diagsArea,
             }
           else 
             {
-/*
-              // redrive the scheduler.
-              // Fix for CR 6701 - some ExExeUtil operators call back
-              // in to the CLI and explicitly clear the curr context
-              // diags area. It would be nice to have a more general
-              // fix, but meanwhile, we store off the curr context diags 
-              // area before calling scheduler and restore afterwards.
-              Statement *statement = 
-                glob->castToExMasterStmtGlobals()->getStatement();
-              ContextCli *context = statement->getContext();
-              ComDiagsArea *savedContextDiags = context->diags().copy();
-              context->diags().clear();
-*/
-
               schedRetcode = glob->getScheduler()->work();
-/*
-              savedContextDiags->mergeAfter(context->diags());
-              context->diags().clear();
-              context->diags().mergeAfter(*savedContextDiags);
-              savedContextDiags->decrRefCount();
-*/
             }
         }
       if (!getQueueDiags)

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/hiveHook.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/hiveHook.cpp b/core/sql/executor/hiveHook.cpp
index d734287..a01e277 100644
--- a/core/sql/executor/hiveHook.cpp
+++ b/core/sql/executor/hiveHook.cpp
@@ -32,6 +32,7 @@
 #include "str.h"
 #include "NAStringDef.h"
 #include "HBaseClient_JNI.h"
+#include "HiveClient_JNI.h"
 #include "Globals.h"
 
 struct hive_sd_desc* populateSD(HiveMetaData *md, Int32 mainSdID, 
@@ -64,25 +65,17 @@ HiveMetaData::HiveMetaData() : tbl_(NULL),
                                errCode_(0) ,
                                errDetail_(NULL),
                                errMethodName_(NULL),
-                               errCodeStr_(NULL),
-                               client_(NULL)
+                               errCodeStr_(NULL)
 {
 }
 
 HiveMetaData::~HiveMetaData()
 {
   clear();
-  disconnect();
 }
 
 NABoolean HiveMetaData::init()
 {
-  CollHeap *h = CmpCommon::contextHeap();
-
-  /* Create a connection */
-  if (!connect())
-    return FALSE; // errCode_ should be set
-
   return TRUE;
 }
 
@@ -136,38 +129,6 @@ static NABoolean splitURL(const char *url,
   return result;
 }
 
-NABoolean HiveMetaData::connect()
-{
-  if (!client_)
-    {
-      HiveClient_JNI* hiveClient = HiveClient_JNI::getInstance();
-      if (hiveClient->isInitialized() == FALSE)
-        {
-          HVC_RetCode retCode = hiveClient->init();
-          if (retCode != HVC_OK)
-            return recordError((Int32)retCode, "HiveClient_JNI::init()");
-        }
-      
-      if (hiveClient->isConnected() == FALSE)
-        {
-          Text metastoreURI("");
-          HVC_RetCode retCode = 
-            hiveClient->initConnection(metastoreURI.c_str());
-          if (retCode != HVC_OK)
-            return recordError((Int32)retCode, 
-                               "HiveClient_JNI::initConnection()");
-        }
-      client_ = hiveClient;
-    } // client_ exists
-  return TRUE;
-}
-
-NABoolean HiveMetaData::disconnect()
-{
-  client_ = NULL; // client connection is owned by CliGlobals. 
-  return TRUE;
-}
-
 void HiveMetaData::position()
 {
   currDesc_ = tbl_;
@@ -209,8 +170,7 @@ NABoolean HiveMetaData::recordError(Int32 errCode,
   if (errCode != HVC_OK)
     {
       errCode_ = errCode;
-      if (client_)
-        errCodeStr_ = client_->getErrorText((HVC_RetCode)errCode_);
+      errCodeStr_ = HiveClient_JNI::getErrorText((HVC_RetCode)errCode_);
       errMethodName_ = errMethodName;
       errDetail_ = GetCliGlobals()->getJniErrorStr();
       return FALSE;
@@ -722,19 +682,12 @@ struct hive_tbl_desc* HiveMetaData::getTableDesc(const char* schemaName,
    // table not found in cache, try to read it from metadata
    hive_tbl_desc * result = NULL;
    Int64 creationTS;
-   NABoolean needToConnect ;
-   needToConnect = (client_ == NULL);
-
-   /* Create a connection */
-   if (needToConnect)
-     if (!connect())
-       return NULL;
 
    NAText* tblStr = new (CmpCommon::statementHeap()) string();
    if (!tblStr)
      return NULL;
 
-   HVC_RetCode retCode = client_->getHiveTableStr(schemaName, 
+   HVC_RetCode retCode = HiveClient_JNI::getHiveTableStr(schemaName, 
                                                   tblName, *tblStr);
    if ((retCode != HVC_OK) && (retCode != HVC_DONE)) {
      recordError((Int32)retCode, "HiveClient_JNI::getTableStr()");
@@ -827,11 +780,8 @@ NABoolean HiveMetaData::validate(Int32 tableId, Int64 redefTS,
 
    // validate creation timestamp
 
-   if (!connect())
-     return FALSE;
-
    Int64 currentRedefTime = 0;
-   HVC_RetCode retCode = client_->getRedefTime(schName, tblName, 
+   HVC_RetCode retCode = HiveClient_JNI::getRedefTime(schName, tblName, 
                                                  currentRedefTime);
    if ((retCode != HVC_OK) && (retCode != HVC_DONE)) {
      return recordError((Int32)retCode, "HiveClient_JNI::getRedefTime()");

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/exp/ExpError.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpError.cpp b/core/sql/exp/ExpError.cpp
index b35c6ee..c6bf963 100644
--- a/core/sql/exp/ExpError.cpp
+++ b/core/sql/exp/ExpError.cpp
@@ -135,6 +135,20 @@ ComDiagsArea *ExRaiseSqlError(CollHeap* heap, ComDiagsArea** diagsArea,
 			intParam1, intParam2, intParam3, 
 			stringParam1, stringParam2, stringParam3);
 }
+ 
+ComDiagsArea *ExRaiseSqlError(CollHeap* heap, ComDiagsArea** diagsArea,
+              Lng32 err,
+              Lng32 * intParam1,
+              Lng32 * intParam2,
+              Lng32 * intParam3,
+              const char * stringParam1,
+              const char * stringParam2,
+              const char * stringParam3)
+{
+  return ExAddCondition(heap, diagsArea, err, NULL,
+             intParam1, intParam2, intParam3, 
+             stringParam1, stringParam2, stringParam3);
+}
 
 ComDiagsArea *ExRaiseSqlWarning(CollHeap* heap, ComDiagsArea** diagsArea,
                               ExeErrorCode err, ComCondition** cond,

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/exp/ExpError.h
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpError.h b/core/sql/exp/ExpError.h
index d1d047b..6b6b3a6 100644
--- a/core/sql/exp/ExpError.h
+++ b/core/sql/exp/ExpError.h
@@ -82,6 +82,15 @@ ComDiagsArea *ExRaiseSqlError(NAMemory * heap, ComDiagsArea** diagsArea,
 			      const char * stringParam2 = NULL,
 			      const char * stringParam3 = NULL);
 
+ComDiagsArea *ExRaiseSqlError(NAMemory * heap, ComDiagsArea** diagsArea,
+                              Lng32 err, 
+                              Lng32 * intParam1 = NULL,
+                              Lng32 * intParam2 = NULL,
+                              Lng32 * intParam3 = NULL,
+                              const char * stringParam1 = NULL,
+                              const char * stringParam2 = NULL,
+                              const char * stringParam3 = NULL);
+
 ComDiagsArea *ExRaiseSqlWarning(NAMemory * heap, ComDiagsArea** diagsArea,
 				ExeErrorCode err, ComCondition** cond=NULL);
 ComDiagsArea *ExRaiseSqlWarning(NAMemory * heap, ComDiagsArea** diagsArea,

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

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/nskgmake/executor/Makefile
----------------------------------------------------------------------
diff --git a/core/sql/nskgmake/executor/Makefile b/core/sql/nskgmake/executor/Makefile
index c530ab4..691c1d2 100755
--- a/core/sql/nskgmake/executor/Makefile
+++ b/core/sql/nskgmake/executor/Makefile
@@ -113,6 +113,7 @@ CPPSRC := Allocator.cpp \
         SequenceFileReader.cpp \
         OrcFileReader.cpp \
         HdfsClient_JNI.cpp \
+        HiveClient_JNI.cpp \
         HBaseClient_JNI.cpp
 CPPSRC += vers_libexecutor.cpp \
 	ssmpipc.cpp \

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/optimizer/NATable.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/NATable.cpp b/core/sql/optimizer/NATable.cpp
index ed11edb..6a959ec 100644
--- a/core/sql/optimizer/NATable.cpp
+++ b/core/sql/optimizer/NATable.cpp
@@ -8554,7 +8554,7 @@ NATable * NATableDB::get(CorrName& corrName, BindWA * bindWA,
         // check if this hive schema exists in hiveMD
         LIST(NAText*) tblNames(naTableHeap);
         HVC_RetCode rc =
-          hiveMetaDB_->getClient()->getAllTables(schemaNameInt, tblNames);
+          HiveClient_JNI::getAllTables((NAHeap *)naTableHeap, schemaNameInt, tblNames);
         if ((rc != HVC_OK) && (rc != HVC_DONE))
           {
             *CmpCommon::diags()

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/optimizer/NormRelExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/NormRelExpr.cpp b/core/sql/optimizer/NormRelExpr.cpp
index 876d4c8..f574b17 100644
--- a/core/sql/optimizer/NormRelExpr.cpp
+++ b/core/sql/optimizer/NormRelExpr.cpp
@@ -62,6 +62,8 @@
 #include "ItemOther.h"
 #include "ItemExpr.h"
 #include "QRDescGenerator.h"
+#include "HBaseClient_JNI.h"
+#include "HiveClient_JNI.h"
 
 #ifndef TRANSFORM_DEBUG_DECL		// artifact of NSK's OptAll.cpp ...
 #define TRANSFORM_DEBUG_DECL
@@ -9850,8 +9852,7 @@ NABoolean CommonSubExprRef::createTempTable(CSEInfo &info)
     if (tempTableType == CSEInfo::HIVE_TEMP_TABLE)
       {
         int m = CmpCommon::diags()->mark();
-        if (!CmpCommon::context()->execHiveSQL(tempTableDDL,
-                                               CmpCommon::diags()))
+        if (HiveClient_JNI::executeHiveSQL(tempTableDDL) != HVC_OK)
           {
             if (CmpCommon::statement()->recompiling() ||
                 CmpCommon::statement()->getNumOfCompilationRetries() > 0)

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/optimizer/OptimizerSimulator.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/OptimizerSimulator.cpp b/core/sql/optimizer/OptimizerSimulator.cpp
index 83e69e6..8441386 100644
--- a/core/sql/optimizer/OptimizerSimulator.cpp
+++ b/core/sql/optimizer/OptimizerSimulator.cpp
@@ -519,7 +519,7 @@ void OptimizerSimulator::dumpDDLs(const QualifiedName & qualifiedName)
         
     retcode = fetchAllRowsFromMetaContext(outQueue, query.data());
     if (retcode < 0 || retcode == 100/*rows not found*/) {
-           CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+           cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
            raiseOsimException("Errors Dumping Table DDL.");
     }
 
@@ -663,7 +663,7 @@ void OptimizerSimulator::dumpHistograms()
         //i.e. update stats hasn't been done for any table.
         else if(retcode < 0 && -4082 != retcode)
         {
-           CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+           cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
            raiseOsimException("Unload histogram data error: %d", retcode);
         }
         
@@ -724,7 +724,7 @@ void OptimizerSimulator::dumpHistograms()
         //i.e. update stats hasn't been done for any table.
         else if(retcode < 0 && -4082 != retcode)
         {
-           CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+           cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
            raiseOsimException("Unload histogram data error: %d", retcode);
         }
     
@@ -820,7 +820,7 @@ void OptimizerSimulator::dumpHiveHistograms()
         //i.e. update stats hasn't been done for any table.
         else if(retcode < 0 && -4082 != retcode)
         {
-           CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+           cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
            raiseOsimException("Unload histogram data error: %d", retcode);
         }
         
@@ -870,7 +870,7 @@ void OptimizerSimulator::dumpHiveHistograms()
         //i.e. update stats hasn't been done for any table.
         else if(retcode < 0 && -4082 != retcode)
         {
-           CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+           cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
            raiseOsimException("Unload histogram data error: %d", retcode);
         }
     
@@ -910,7 +910,7 @@ void OptimizerSimulator::dropObjects()
       retcode = executeFromMetaContext(query.data());
       if(retcode < 0)
       {
-          CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+          cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
           raiseOsimException("Drop Table %s error: %d", stdQualTblNm.c_str(), retcode);
       }
    }
@@ -943,7 +943,7 @@ void OptimizerSimulator::dropObjects()
           retcode = executeFromMetaContext(dropStmt.data());
           if(retcode < 0)
           {
-              CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+              cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
               raiseOsimException("drop external table: %d", retcode);
           }
           //unregister hive table
@@ -955,7 +955,7 @@ void OptimizerSimulator::dropObjects()
           {
               //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()));
+              //cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
               //raiseOsimException("unregister hive table: %d", retcode);
           }
           //drop hive table
@@ -1021,7 +1021,7 @@ void OptimizerSimulator::loadDDLs()
             retcode = executeFromMetaContext(statement.data());
             if(retcode < 0)
             {
-                CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+                cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
                 raiseOsimException("Create Table Error: %d", retcode);
             }
         }
@@ -1044,7 +1044,7 @@ void OptimizerSimulator::loadDDLs()
             retcode = executeFromMetaContext(statement.data());
             if(retcode < 0)
             {
-                CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+                cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
                 raiseOsimException("Create View Error: %d %s", retcode, statement.data());
             }
         }
@@ -1124,7 +1124,7 @@ void OptimizerSimulator::loadHiveDDLs()
          create_ext_schema += "\" AUTHORIZATION DB__ROOT";
          retcode = executeFromMetaContext(create_ext_schema);
          if(retcode < 0) {
-             CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+             cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
              raiseOsimException("create hive external schema: %d %s", retcode, statement.data());
          }
          //drop external table
@@ -1133,7 +1133,7 @@ void OptimizerSimulator::loadHiveDDLs()
          retcode = executeFromMetaContext(dropStmt.data());
          if(retcode < 0)
          {
-             CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+             cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
              raiseOsimException("drop external table: %d", retcode);
          }
 
@@ -1180,7 +1180,7 @@ void OptimizerSimulator::loadHiveDDLs()
             retcode = executeFromMetaContext(statement.data()); //create hive external table
             if(retcode < 0)
             {
-                CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+                cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
                 raiseOsimException("Create hive external table error:  %d", retcode);
             }
             debugMessage("done\n");
@@ -1541,12 +1541,7 @@ NABoolean OptimizerSimulator::massageTableUID(OsimHistogramEntry* entry, NAHashD
 
 void OptimizerSimulator::execHiveSQL(const char* hiveSQL)
 {
-  HiveClient_JNI *hiveClient = CmpCommon::context()->getHiveClient();
-
-  if (hiveClient == NULL)
-    raiseOsimException("Error initialize hive client.");
-  else
-    if (!CmpCommon::context()->execHiveSQL(hiveSQL))
+    if (HiveClient_JNI::executeHiveSQL(hiveSQL) != HVC_OK)
       raiseOsimException("Error running hive SQL.");
 }
 
@@ -1629,7 +1624,7 @@ short OptimizerSimulator::loadHistogramsTable(NAString* modifiedPath, QualifiedN
     retcode = executeFromMetaContext(cmd.data());
     if(retcode < 0)
     {
-        CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+        cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
         raiseOsimException("Load histogram data error:  %d", retcode);
     }
     
@@ -1650,7 +1645,7 @@ short OptimizerSimulator::loadHistogramsTable(NAString* modifiedPath, QualifiedN
     
     if(retcode < 0)
     {
-        CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+        cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
         raiseOsimException("Load histogram data error:  %d", retcode);
     }
     
@@ -1715,7 +1710,7 @@ short OptimizerSimulator::loadHistogramIntervalsTable(NAString* modifiedPath, Qu
     retcode = executeFromMetaContext(cmd.data());
     if(retcode < 0)
     {
-        CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+        cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
         raiseOsimException("Load histogram data error:  %d", retcode);
     }
     //from hive table to trafodion table.
@@ -1730,7 +1725,7 @@ short OptimizerSimulator::loadHistogramIntervalsTable(NAString* modifiedPath, Qu
     retcode = executeFromMetaContext(cmd.data());
     if(retcode < 0)
     {
-        CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+        cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
         raiseOsimException("Load histogram data error:  %d", retcode);
     }
     return retcode;
@@ -1786,7 +1781,7 @@ void OptimizerSimulator::loadHistograms(const char* histogramPath, NABoolean isH
        short retcode = executeFromMetaContext(create_stats_schema);
        if(retcode < 0)
        {
-            CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
+            cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
             raiseOsimException("create hive stats schema: return code %d", retcode);
        }
    }
@@ -2952,8 +2947,8 @@ void OptimizerSimulator::dumpHiveTableDDLs()
         query = "SHOWDDL " + qualifiedName->getQualifiedNameAsAnsiString();
         retcode = fetchAllRowsFromMetaContext(outQueue, query.data());
         if (retcode < 0 || retcode == 100/*rows not found*/) {
-               CmpCommon::diags()->mergeAfter(*(cliInterface_->getDiagsArea()));
-               raiseOsimException("Errors Dumping Table DDL.");
+           cliInterface_->retrieveSQLDiagnostics(CmpCommon::diags());
+           raiseOsimException("Errors Dumping Table DDL.");
         }
 
         if(outQueue)

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/optimizer/hiveHook.h
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/hiveHook.h b/core/sql/optimizer/hiveHook.h
index e8fa528..ead62c9 100644
--- a/core/sql/optimizer/hiveHook.h
+++ b/core/sql/optimizer/hiveHook.h
@@ -247,9 +247,6 @@ public:
   
   NABoolean init();
   
-  NABoolean connect();
-  NABoolean disconnect();
-  
   struct hive_tbl_desc* getTableDesc(const char* schemaName,
                                      const char* tblName);
   struct hive_tbl_desc* getFakedTableDesc(const char* tblName);
@@ -286,8 +283,6 @@ public:
   void recordParseError(Int32 errCode, const char* errCodeStr,
                         const char *errMethodName, const char* errDetail);
 
-  HiveClient_JNI* getClient() {return client_;}
-
 protected:
 
   // read metadata for one table
@@ -300,12 +295,6 @@ protected:
   const char *errCodeStr_;
   const char *errMethodName_;
   const char *errDetail_;
-  // HiveMetadata does not "own" this pointer. There is an assumption that
-  // client is not null then it points to a HiveClient object that has 
-  // been initialized and connected. The pointer is owened by CliGlobals.
-  // This class contains a pointer so that we don't have to check every time
-  // if it is initialized and connected
-  HiveClient_JNI* client_;
 };
 
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/sqlcomp/PrivMgrComponentPrivileges.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgrComponentPrivileges.cpp b/core/sql/sqlcomp/PrivMgrComponentPrivileges.cpp
index ecee04e..64e794a 100644
--- a/core/sql/sqlcomp/PrivMgrComponentPrivileges.cpp
+++ b/core/sql/sqlcomp/PrivMgrComponentPrivileges.cpp
@@ -1299,7 +1299,7 @@ int64_t rowCount = 0;
 MyTable &myTable = static_cast<MyTable &>(myTable_);
 
 // set pointer in diags area
-int32_t diagsMark = pDiags_->mark();
+int32_t diagsMark = (pDiags_ != NULL ? pDiags_->mark() : -1);
 
 PrivStatus privStatus = myTable.selectCountWhere(whereClause,rowCount);
 
@@ -1307,7 +1307,8 @@ PrivStatus privStatus = myTable.selectCountWhere(whereClause,rowCount);
         rowCount > 0)
       return true;
       
-   pDiags_->rewind(diagsMark);
+   if (diagsMark != -1)
+      pDiags_->rewind(diagsMark);
 
    return false;
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/sqlcomp/PrivMgrMDTable.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgrMDTable.cpp b/core/sql/sqlcomp/PrivMgrMDTable.cpp
index 54d492a..180af70 100644
--- a/core/sql/sqlcomp/PrivMgrMDTable.cpp
+++ b/core/sql/sqlcomp/PrivMgrMDTable.cpp
@@ -322,7 +322,7 @@ ExeCliInterface cliInterface(STMTHEAP, 0, NULL,
    queue = NULL;
    
 // set pointer in diags area
-int32_t diagsMark = pDiags_->mark();
+int32_t diagsMark = ((pDiags_ != NULL) ? pDiags_->mark() : -1);
 
 int32_t cliRC = cliInterface.fetchAllRows(queue,(char *)SQLStatement.c_str(),0,
                                           false,false,true);
@@ -333,7 +333,7 @@ int32_t cliRC = cliInterface.fetchAllRows(queue,(char *)SQLStatement.c_str(),0,
       return STATUS_ERROR;
    }
    
-   if (cliRC == 100) // did not find the row
+   if (cliRC == 100 && diagsMark != -1)// did not find the row
    {
       pDiags_->rewind(diagsMark);
       return STATUS_NOTFOUND;

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/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 6657aed..d86ce25 100644
--- a/core/sql/src/main/java/org/trafodion/sql/HiveClient.java
+++ b/core/sql/src/main/java/org/trafodion/sql/HiveClient.java
@@ -48,7 +48,6 @@ import org.apache.hadoop.hive.metastore.api.UnknownDBException;
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.FSDataOutputStream;
 
 import java.sql.SQLException;
 import java.sql.Connection;
@@ -59,60 +58,43 @@ 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;
-    String lastError;
-    HiveConf hiveConf = null;
-    HiveMetaStoreClient hmsClient  ;
-    FSDataOutputStream fsOut = null;
-
     public HiveClient() {
    
     }
 
-    public String getLastError() {
-        return lastError;
-    }
-
-    void setLastError(String err) {
-        lastError = err;
-    }
-
-    void setupLog4j() {
-    	String confFile = System.getProperty("trafodion.log4j.configFile");
-    	if (confFile == null) {
-           System.setProperty("trafodion.sql.log", System.getenv("TRAF_HOME") + "/logs/trafodion.sql.java.log");
-           confFile = System.getenv("TRAF_CONF") + "/log4j.sql.config";
-        }
-        PropertyConfigurator.configure(confFile);
-    }
-
-    public boolean init(String metastoreURI) 
-              throws MetaException {
-         setupLog4j();
-         if (logger.isDebugEnabled()) logger.debug("HiveClient.init(" + metastoreURI + " " + ") called.");
-         ddlTimeConst = getDDLTimeConstant();
-         hiveConf = new HiveConf();
-	 if (metastoreURI.length() > 0) {
-             hiveConf.set("hive.metastore.local", "false");
-             hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, metastoreURI);
-         }
-         hmsClient = new HiveMetaStoreClient(hiveConf, null);
-         return true;
+    static {
+      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");
+      }
     }
 
-    public boolean close() {
+    public static boolean close() {
         hmsClient.close();
         return true;
     }
 
-    public boolean exists(String schName, String tblName)  
+    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;
     }
 
-    public String getHiveTableString(String schName, String tblName)
+    public static String getHiveTableString(String schName, String tblName)
         throws MetaException, TException {
         Table table;
         if (logger.isDebugEnabled()) logger.debug("HiveClient.getHiveTableString(" + schName + " , " + 
@@ -128,7 +110,7 @@ public class HiveClient {
         return table.toString() ;
     }
 
-    public long getRedefTime(String schName, String tblName)
+    public static long getRedefTime(String schName, String tblName)
         throws MetaException, TException, ClassCastException, NullPointerException, NumberFormatException {
         Table table;
         if (logger.isDebugEnabled()) logger.debug("HiveClient.getRedefTime(" + schName + " , " + 
@@ -158,7 +140,7 @@ public class HiveClient {
         return redefTime ;
     }
 
-    public Object[] getAllSchemas() throws MetaException {
+    public static Object[] getAllSchemas() throws MetaException {
         List<String> schemaList = (hmsClient.getAllDatabases());
         if (schemaList != null)
            return schemaList.toArray();
@@ -166,7 +148,7 @@ public class HiveClient {
            return null; 
     }
 
-    public Object[] getAllTables(String schName) 
+    public static Object[] getAllTables(String schName) 
         throws MetaException, TException {
         try {
         Database db = hmsClient.getDatabase(schName);
@@ -236,42 +218,21 @@ public class HiveClient {
         }
 
         return fieldVal.toString();
-    }
+  }
 
-  ///////////////////   
-  boolean hdfsCreateFile(String fname) throws IOException
+  public static boolean hdfsCreateFile(String fname) throws IOException
   {
-    HiveConf  config = new HiveConf();
     if (logger.isDebugEnabled()) logger.debug("HiveClient.hdfsCreateFile() - started" );
     Path filePath = new Path(fname);
-    FileSystem fs = FileSystem.get(filePath.toUri(),config);
-    fsOut = fs.create(filePath, true);
+    FileSystem fs = FileSystem.get(filePath.toUri(),hiveConf);
+    fs.create(filePath, true);
     
     if (logger.isDebugEnabled()) logger.debug("HiveClient.hdfsCreateFile() - file created" );
 
     return true;
   }
   
-  boolean hdfsWrite(byte[] buff, long len) throws IOException
-  {
-
-    if (logger.isDebugEnabled()) logger.debug("HiveClient.hdfsWrite() - started" );
-    fsOut.write(buff);
-    fsOut.flush();
-    if (logger.isDebugEnabled()) logger.debug("HiveClient.hdfsWrite() - bytes written and flushed:" + len  );
-    
-    return true;
-  }
-  
-  boolean hdfsClose() throws IOException
-  {
-    if (logger.isDebugEnabled()) logger.debug("HiveClient.hdfsClose() - started" );
-    if (fsOut != null)
-       fsOut.close();
-    return true;
-  }
-  
-  public void executeHiveSQL(String ddl) throws ClassNotFoundException, SQLException
+  public static void executeHiveSQL(String ddl) throws ClassNotFoundException, SQLException
   {
       Class.forName("org.apache.hive.jdbc.HiveDriver");
       Connection con = DriverManager.getConnection("jdbc:hive2://", "hive", "");


[3/7] trafodion git commit: [TRAFODION-3009] Streamline error handling in Executor utility commands

Posted by se...@apache.org.
[TRAFODION-3009] Streamline error handling in Executor utility commands

Removed the need to allocate ComDiagsArea in advance for load command
by refactoring the ExeCliInterface::executeImmediate and
ExeCliInterface::executeImmediateExec methods.

Changes as per the review comments are also made in this commit


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

Branch: refs/heads/master
Commit: 37702da34e3c7f00735aaad0640d8f705caf19c8
Parents: 1f44166
Author: selvaganesang <se...@esgyn.com>
Authored: Thu Apr 5 05:43:35 2018 +0000
Committer: selvaganesang <se...@esgyn.com>
Committed: Thu Apr 5 05:43:35 2018 +0000

----------------------------------------------------------------------
 core/sql/bin/SqlciErrors.txt             |   2 +-
 core/sql/cli/Cli.cpp                     |   3 +-
 core/sql/cli/Context.cpp                 |   3 +-
 core/sql/executor/ExExeUtilCli.cpp       | 144 +++++++++++------------
 core/sql/executor/ExExeUtilCli.h         |   9 +-
 core/sql/executor/ExExeUtilCommon.cpp    |  33 +++---
 core/sql/executor/ExExeUtilExplain.cpp   |  28 ++---
 core/sql/executor/ExExeUtilGet.cpp       |  67 ++++-------
 core/sql/executor/ExExeUtilGetStats.cpp  |   6 +-
 core/sql/executor/ExExeUtilLoad.cpp      | 160 +++++++++-----------------
 core/sql/executor/ExExeUtilMisc.cpp      |  86 ++++++--------
 core/sql/executor/ExExeUtilVolTab.cpp    |   8 +-
 core/sql/executor/ExHdfsScan.cpp         |  14 ++-
 core/sql/executor/ExHdfsScan.h           |   1 +
 core/sql/sqlcomp/CmpDescribe.cpp         |   4 +-
 core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp |   3 +-
 core/sql/sqlcomp/CmpSeabaseDDLschema.cpp |  12 +-
 17 files changed, 254 insertions(+), 329 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/37702da3/core/sql/bin/SqlciErrors.txt
----------------------------------------------------------------------
diff --git a/core/sql/bin/SqlciErrors.txt b/core/sql/bin/SqlciErrors.txt
index e66e170..ceb95ea 100644
--- a/core/sql/bin/SqlciErrors.txt
+++ b/core/sql/bin/SqlciErrors.txt
@@ -2,7 +2,7 @@
 1000 42000 99999 BEGINNER INFRM LOGONLY A syntax error occurred.
 1001 ZZZZZ 99999 ADVANCED CRTCL DIALOUT An internal error occurred in module $0~String0 on line $1~Int0. Details($2~String1).
 1002 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Catalog $0~CatalogName does not exist.
-1003 ZZZZZ 99999 BEGINNER MINOR DBADMIN Schema $0~SchemaName does not exist.
+1003 ZZZZZ 99999 BEGINNER MINOR DBADMIN Schema $0~String0.$1~String1 does not exist.
 1004 ZZZZZ 99999 BEGINNER MINOR DBADMIN Object $0~TableName does not exist or object type is invalid for the current operation.
 1005 ZZZZZ 99999 BEGINNER MINOR DBADMIN Constraint $0~ConstraintName does not exist.
 1006 ZZZZZ 99999 BEGINNER MINOR DBADMIN Skipping authorization ID $0~Int0.

http://git-wip-us.apache.org/repos/asf/trafodion/blob/37702da3/core/sql/cli/Cli.cpp
----------------------------------------------------------------------
diff --git a/core/sql/cli/Cli.cpp b/core/sql/cli/Cli.cpp
index a6b5341..4a83a14 100644
--- a/core/sql/cli/Cli.cpp
+++ b/core/sql/cli/Cli.cpp
@@ -2375,9 +2375,10 @@ Lng32 SQLCLI_ProcessRetryQuery(
 				      SQLCHARSETCODE_UTF8,
 				      currContext,
 				      NULL);   
+                    ComDiagsArea *tmpDiagsArea = &diags;
 		  retcode =  cliInterface->
 		    executeImmediate( (char *) "SELECT TESTEXIT;", 
-				      NULL, NULL, TRUE, NULL, 0,&diags);
+				      NULL, NULL, TRUE, NULL, 0, &tmpDiagsArea);
 		  //ignore errors from this call.
 		  	    
 		}

http://git-wip-us.apache.org/repos/asf/trafodion/blob/37702da3/core/sql/cli/Context.cpp
----------------------------------------------------------------------
diff --git a/core/sql/cli/Context.cpp b/core/sql/cli/Context.cpp
index bfb043f..09f1783 100644
--- a/core/sql/cli/Context.cpp
+++ b/core/sql/cli/Context.cpp
@@ -1604,7 +1604,8 @@ void ContextCli::completeSetAuthID(
       ExeCliInterface *cliInterface = new (exHeap()) ExeCliInterface(exHeap(),
                                                                      SQLCHARSETCODE_UTF8
                                                                      ,this,NULL);   
-      cliInterface->executeImmediate((char *) "control query default * reset;", NULL, NULL, TRUE, NULL, 0,&diagsArea_);
+      ComDiagsArea *tmpDiagsArea = &diagsArea_;
+      cliInterface->executeImmediate((char *) "control query default * reset;", NULL, NULL, TRUE, NULL, 0, &tmpDiagsArea); 
    }
   
    if ((userID != databaseUserID_) ||

http://git-wip-us.apache.org/repos/asf/trafodion/blob/37702da3/core/sql/executor/ExExeUtilCli.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilCli.cpp b/core/sql/executor/ExExeUtilCli.cpp
index dc9c4e2..aa1553b 100644
--- a/core/sql/executor/ExExeUtilCli.cpp
+++ b/core/sql/executor/ExExeUtilCli.cpp
@@ -105,7 +105,6 @@ ExeCliInterface::ExeCliInterface(CollHeap * heap, Int32 isoMapping,
        input_desc_(NULL),
        output_desc_(NULL),
        rs_input_maxsize_desc_(NULL),
-       diagsArea_(NULL),
        outputBuf_(NULL),
        inputBuf_(NULL),
        currContext_(currContext),
@@ -993,22 +992,23 @@ Lng32 ExeCliInterface::executeImmediateExec(const char * stmtStr,
 					   Lng32 * outputBufLen,
 					   NABoolean nullTerminate,
 					   Int64 * rowsAffected,
-                                           ComDiagsArea *diagsArea)
+                                           ComDiagsArea **diagsArea)
 {
   Lng32 retcode = 0;
+  Lng32 diagsCount = 0;
 
   retcode = exec();
   if (retcode < 0)
     {
       deallocStuff(module_, stmt_, sql_src_, input_desc_, output_desc_);
-      return retcode;
+      goto ExecReturn;
     }
 
   retcode = fetch();
   if (retcode < 0)
     {
       deallocStuff(module_, stmt_, sql_src_, input_desc_, output_desc_);
-      return retcode;
+      goto ExecReturn;
     }
 
   if ((outputBuf) &&
@@ -1028,55 +1028,76 @@ Lng32 ExeCliInterface::executeImmediateExec(const char * stmtStr,
 	}
     }
 
-  Lng32 cliRetcode = -1;
+  Lng32 rc;
   if (retcode >= 0)
   {
-    cliRetcode = retcode;
     if (rowsAffected)
     {
       Int64 tmpRowsAffected = 0;
-      retcode = SQL_EXEC_GetDiagnosticsStmtInfo2(NULL, SQLDIAG_ROW_COUNT,
+      rc = SQL_EXEC_GetDiagnosticsStmtInfo2(NULL, SQLDIAG_ROW_COUNT,
         &tmpRowsAffected, NULL,
         0, NULL);
 
-      if(retcode == EXE_NUMERIC_OVERFLOW) 
+      if (rc == EXE_NUMERIC_OVERFLOW) 
       {
         GetRowsAffected(rowsAffected);
       }
       else
         *rowsAffected = tmpRowsAffected;
     }
+    rc = SQL_EXEC_GetDiagnosticsStmtInfo2(NULL, SQLDIAG_NUMBER,
+                       &diagsCount, NULL, 0, NULL);
+    // No need to passback the warnings of SQL_NO_DATA (100)
+    if (retcode == 100)
+       diagsCount--; 
   }
-  if (diagsArea != NULL) 
-     retcode = SQL_EXEC_MergeDiagnostics_Internal(*diagsArea);
-  clearGlobalDiags();
-
-  retcode = close();
-
+ExecReturn:
+  if (retcode < 0 ||  diagsCount > 0) 
+  {   
+     if (diagsArea != NULL) 
+     {
+         if (*diagsArea == NULL)
+            *diagsArea = ComDiagsArea::allocate(heap_); 
+         rc = SQL_EXEC_MergeDiagnostics_Internal(**diagsArea);
+     }
+     // if diagsArea is not passed in, retain the diagnostics info
+     // in ContextCli for it to be retrieved later 
+     // But, deallocate the statement
+     else
+     {
+        rc = close();
+        deallocStuff(module_, stmt_, sql_src_, input_desc_, output_desc_);
+        return retcode;
+     }
+  }
+  rc = close();
   deallocStuff(module_, stmt_, sql_src_, input_desc_, output_desc_);
-
   clearGlobalDiags();
-
-  return ((cliRetcode != -1) ? cliRetcode : retcode);
+  return retcode;
 }
-
-
-
+// When the globalDiags is not null, errors and warnings are
+// passed to the caller. If *globalsDiags points to NULL,
+// allocate ComDiagsArea and pass back the error or warnings
+// to the caller.
+// 
+// If *globalDiags points to ComDiagsArea already, pass back
+// the diagnostics conditions back to the caller after executing
+// the stmtStr along with new errors or warnings.
 Lng32 ExeCliInterface::executeImmediate(const char * stmtStr,
 				       char * outputBuf,
 				       Lng32 * outputBufLen,
 				       NABoolean nullTerminate,
 				       Int64 * rowsAffected,
 				       NABoolean monitorThis,
-				       ComDiagsArea *globalDiags)
+				       ComDiagsArea **globalDiags)
 {
   Lng32 retcode = 0;
 
   ComDiagsArea * tempDiags = NULL;
-  if (globalDiags)
+  if (globalDiags != NULL && *globalDiags != NULL)
   {
      tempDiags = ComDiagsArea::allocate(heap_);
-     tempDiags->mergeAfter(*globalDiags);
+     tempDiags->mergeAfter(**globalDiags);
   }
 
   clearGlobalDiags();
@@ -1094,17 +1115,22 @@ Lng32 ExeCliInterface::executeImmediate(const char * stmtStr,
 				 rowsAffected,
                                  globalDiags);
 ExecuteImmediateReturn:
-  if ((globalDiags) && (tempDiags))
+  if ((globalDiags))
     {
-      globalDiags->mergeAfter(*tempDiags);
+      // Allocate the diagnostics area if needed
+      // and populate the diagnostics conditions
+      if (*globalDiags == NULL && retcode != 0) {
+         *globalDiags = ComDiagsArea::allocate(getHeap());
+         SQL_EXEC_MergeDiagnostics_Internal(**globalDiags);
+      }
+      //  populate the diagnostics conditons passed in
+      if (tempDiags)
+         (*globalDiags)->mergeAfter(*tempDiags);
     }
 
   if (tempDiags)
-    {
-      tempDiags->clear();
       tempDiags->deAllocate();
-    }
-   return retcode;
+  return retcode;
 }
 
 short ExeCliInterface::fetchRowsPrologue(const char * sqlStrBuf, 
@@ -2085,11 +2111,6 @@ Lng32 ExeCliInterface::retrieveSQLDiagnostics(ComDiagsArea *toDiags)
 {
   Lng32 retcode;
   ex_assert(toDiags != NULL, "ComDiagsArea is null");
-  if (diagsArea_ != NULL)
-    {
-      diagsArea_->clear();
-      diagsArea_->deAllocate();
-    }
   retcode = SQL_EXEC_MergeDiagnostics_Internal(*toDiags);
   SQL_EXEC_ClearDiagnostics(NULL);
   return retcode;
@@ -2099,41 +2120,22 @@ Lng32 ExeCliInterface::retrieveSQLDiagnostics(ComDiagsArea *toDiags)
 ComDiagsArea *ExeCliInterface::allocAndRetrieveSQLDiagnostics(ComDiagsArea *&toDiags)
 {
   Lng32 retcode;
-
-  if (diagsArea_ != NULL)
-    {
-      diagsArea_->clear();
-      diagsArea_->deAllocate();
-    }
-  if (toDiags == NULL)
+  NABoolean daAllocated = FALSE; 
+  if (toDiags == NULL) { 
       toDiags = ComDiagsArea::allocate(heap_);
+      daAllocated = TRUE;
+  }
 
   retcode = SQL_EXEC_MergeDiagnostics_Internal(*toDiags);
   SQL_EXEC_ClearDiagnostics(NULL);
  
   if (retcode == 0)
      return toDiags;
-  else
+  else {
+     if (daAllocated)
+        toDiags->decrRefCount();
      return NULL;
-}
-
-void ExeCliInterface::retrieveOrSaveSQLDiagnostics(Lng32 cliRetcode, ComDiagsArea *diagsArea)
-{
-    Int32 rc;
-    Int32 diagsCondCount = 0;
-    rc = SQL_EXEC_GetDiagnosticsStmtInfo2(stmt_,
-                           SQLDIAG_NUMBER, &diagsCondCount,
-                           NULL, 0, NULL);
-    if (cliRetcode == 100)   
-       diagsCondCount--;
-    if (diagsCondCount > 0) { 
-       if (diagsArea == NULL) {
-          if (diagsArea_ == NULL) 
-             diagsArea_ = ComDiagsArea::allocate(heap_);
-          diagsArea = diagsArea_;
-       } 
-       SQL_EXEC_MergeDiagnostics_Internal(*diagsArea);
-    }
+  }
 }
 
 Lng32 ExeCliInterface::GetRowsAffected(Int64 *rowsAffected)
@@ -2177,7 +2179,7 @@ Lng32 ExeCliInterface::GetRowsAffected(Int64 *rowsAffected)
 
 } // GetRowsAffected()
 
-Lng32 ExeCliInterface::holdAndSetCQD(const char * defaultName, const char * defaultValue, ComDiagsArea * globalDiags)
+Lng32 ExeCliInterface::holdAndSetCQD(const char * defaultName, const char * defaultValue, ComDiagsArea *globalDiags)
 {
   Lng32 cliRC;
   
@@ -2188,7 +2190,7 @@ Lng32 ExeCliInterface::holdAndSetCQD(const char * defaultName, const char * defa
   strcat(buf, " hold;");
 
   // hold the current value for defaultName
-  cliRC = executeImmediate(buf, NULL, NULL, TRUE, NULL, 0,globalDiags);
+  cliRC = executeImmediate(buf, NULL, NULL, TRUE, NULL, 0,&globalDiags);
   if (cliRC < 0)
     {
       return cliRC;
@@ -2200,7 +2202,7 @@ Lng32 ExeCliInterface::holdAndSetCQD(const char * defaultName, const char * defa
   strcat(buf, " '");
   strcat(buf, defaultValue);
   strcat(buf, "';");
-  cliRC = executeImmediate(buf, NULL, NULL, TRUE, NULL, 0,globalDiags);
+  cliRC = executeImmediate(buf, NULL, NULL, TRUE, NULL, 0,&globalDiags);
   if (cliRC < 0)
     {
       return cliRC;
@@ -2209,7 +2211,7 @@ Lng32 ExeCliInterface::holdAndSetCQD(const char * defaultName, const char * defa
   return 0;
 }
 
-Lng32 ExeCliInterface::restoreCQD(const char * defaultName, ComDiagsArea * globalDiags)
+Lng32 ExeCliInterface::restoreCQD(const char * defaultName, ComDiagsArea *globalDiags)
 {
   Lng32 cliRC;
 
@@ -2219,7 +2221,7 @@ Lng32 ExeCliInterface::restoreCQD(const char * defaultName, ComDiagsArea * globa
   strcpy(buf, "control query default ");
   strcat(buf, defaultName);
   strcat(buf, " reset;");
-  cliRC = executeImmediate(buf, NULL, NULL, TRUE, NULL, 0,globalDiags);
+  cliRC = executeImmediate(buf, NULL, NULL, TRUE, NULL, 0,&globalDiags);
   if (cliRC < 0)
     {
       return cliRC;
@@ -2229,7 +2231,7 @@ Lng32 ExeCliInterface::restoreCQD(const char * defaultName, ComDiagsArea * globa
   strcpy(buf, "control query default ");
   strcat(buf, defaultName);
   strcat(buf, " restore;");
-  cliRC = executeImmediate(buf, NULL, NULL, TRUE, NULL, 0,globalDiags);
+  cliRC = executeImmediate(buf, NULL, NULL, TRUE, NULL, 0,&globalDiags);
   if (cliRC < 0)
     {
       return cliRC;
@@ -2240,7 +2242,7 @@ Lng32 ExeCliInterface::restoreCQD(const char * defaultName, ComDiagsArea * globa
 
 Lng32 ExeCliInterface::getCQDval(const char * defaultName, 
 				 char * val,
-				 ComDiagsArea * globalDiags)
+				 ComDiagsArea *globalDiags)
 {
   Lng32 cliRC;
 
@@ -2276,11 +2278,11 @@ Lng32 ExeCliInterface::getCQDval(const char * defaultName,
   return 0;
 }
 
-Lng32 ExeCliInterface::setCQS(const char * shape, ComDiagsArea * globalDiags)
+Lng32 ExeCliInterface::setCQS(const char * shape, ComDiagsArea *globalDiags)
 {
   Lng32 cliRC;
 
-  cliRC = executeImmediate(shape, NULL, NULL, TRUE, NULL, 0,globalDiags);
+  cliRC = executeImmediate(shape, NULL, NULL, TRUE, NULL, 0,&globalDiags);
   if (cliRC < 0)
     {
       return cliRC;
@@ -2297,7 +2299,7 @@ Lng32 ExeCliInterface::resetCQS(ComDiagsArea * globalDiags)
   char buf[400];
   
   strcpy(buf, "control query shape cut ");
-  cliRC = executeImmediate(buf, NULL, NULL, TRUE, NULL, 0,globalDiags);
+  cliRC = executeImmediate(buf, NULL, NULL, TRUE, NULL, 0,&globalDiags);
   if (cliRC < 0)
     {
       return cliRC;

http://git-wip-us.apache.org/repos/asf/trafodion/blob/37702da3/core/sql/executor/ExExeUtilCli.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilCli.h b/core/sql/executor/ExExeUtilCli.h
index ce33de4..963b567 100644
--- a/core/sql/executor/ExExeUtilCli.h
+++ b/core/sql/executor/ExExeUtilCli.h
@@ -76,7 +76,7 @@ private:
 			 NABoolean nullTerminate = TRUE,
 			 Int64 * rowsAffected = NULL,
 			 NABoolean monitorThis = FALSE,
-			 ComDiagsArea *globalDiags = NULL);
+			 ComDiagsArea **globalDiags = NULL);
 
   Lng32 executeImmediatePrepare(const char * stmt,
 				char * outputBuf = NULL,
@@ -100,7 +100,7 @@ private:
                             Lng32 * outputBufLen = NULL,
                             NABoolean nullTerminate = TRUE,
                             Int64 * rowsAffected = NULL,
-                            ComDiagsArea *diagsArea = NULL);
+                            ComDiagsArea **diagsArea = NULL);
  
   Lng32 prepare(const char * stmtStr,
 		SQLMODULE_ID * module,
@@ -247,12 +247,9 @@ private:
 
   Lng32 retrieveSQLDiagnostics(ComDiagsArea *toDiags);
   ComDiagsArea *allocAndRetrieveSQLDiagnostics(ComDiagsArea *&toDiags);
-  void retrieveOrSaveSQLDiagnostics(Lng32 cliRetCode, ComDiagsArea *toDiags);
 
   CollHeap * getHeap() { return heap_; }
 
-  ComDiagsArea * getDiagsArea() { return diagsArea_; }
-
   char * outputBuf() { return outputBuf_; };
   Int32  outputDatalen() { return outputDatalen_; };
 
@@ -374,8 +371,6 @@ private:
   Int32 numQuadFields_;
   struct SQLCLI_QUAD_FIELDS * quadFields_;
 
-  ComDiagsArea * diagsArea_;
-
   CollHeap * heap_;
 
   ContextCli * currContext_;

http://git-wip-us.apache.org/repos/asf/trafodion/blob/37702da3/core/sql/executor/ExExeUtilCommon.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilCommon.cpp b/core/sql/executor/ExExeUtilCommon.cpp
index 09f7126..450dd74 100644
--- a/core/sql/executor/ExExeUtilCommon.cpp
+++ b/core/sql/executor/ExExeUtilCommon.cpp
@@ -204,7 +204,6 @@ ExExeUtilTcb::ExExeUtilTcb(const ComTdbExeUtil & exe_util_tdb,
 					     parentQid);
 
   diagsArea_ = NULL;
-  //setDiagsArea(ComDiagsArea::allocate(getHeap()));
   
   pqStep_ = PROLOGUE_;
 
@@ -441,11 +440,10 @@ Lng32 ExExeUtilTcb::changeAuditAttribute(char * tableName,
     strcat(stmt, " no label update");
 
   strcat(stmt, ";");
-
+  ComDiagsArea *diagsArea = getDiagsArea();
   retcode = cliInterface()->executeImmediate
-    (stmt, NULL, NULL, TRUE, NULL, 0,
-     &(masterGlob->getStatement()->getContext()->diags()));
-
+    (stmt, NULL, NULL, TRUE, NULL, 0, &diagsArea); 
+  setDiagsArea(diagsArea);
   masterGlob->getStatement()->getContext()->resetSqlParserFlags(0x400); // ALLOW_AUDIT_CHANGE
   
   if (retcode < 0)
@@ -463,7 +461,7 @@ Lng32 ExExeUtilTcb::changeAuditAttribute(char * tableName,
 
 void ExExeUtilTcb::handleErrors(Lng32 rc)
 { 
-  setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+  cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 }
 
 short ExExeUtilTcb::initializeInfoList(Queue* &infoList)
@@ -669,7 +667,7 @@ short ExExeUtilTcb::executeQuery(char * task,
 	    char * stringParam1 = NULL;
 	    Lng32   intParam1 = ComDiags_UnInitialized_Int;
 
-            setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+            cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
             if (getDiagsArea() != NULL)
 	        retcode = 0;
 	    if (moveErrorRow)
@@ -858,7 +856,7 @@ Lng32 ExExeUtilTcb::setCS(const char * csName, char * csValue,
 
   cliRC = 
     cliInterface->executeImmediate(buf, NULL, NULL, TRUE, NULL,FALSE,
-				   globalDiags);
+				   &globalDiags);
   if (cliRC < 0)
     {
       return cliRC;
@@ -879,7 +877,7 @@ Lng32 ExExeUtilTcb::resetCS(const char * csName,
   strcat(buf, csName);
   strcat(buf, "' reset;");
   cliRC = cliInterface->executeImmediate(buf, NULL, NULL, TRUE, NULL,FALSE,
-					 globalDiags);
+					 &globalDiags);
   if (cliRC < 0)
     {
       return cliRC;
@@ -1052,7 +1050,7 @@ short ExExeUtilTcb::setSystemVersion()
 					 sysVersionStr_, &sysVersionStrLen_);
       if (cliRC < 0)
 	{
-          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+          cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 	  return -1;
 	}
       
@@ -1121,7 +1119,7 @@ short ExExeUtilTcb::getObjectUid(char * catName, char * schName,
 				     uid, &uidLen);
   if (cliRC < 0)
     {
-      setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+      cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
       return -1;
     }
   uid[uidLen] = 0;
@@ -1459,12 +1457,21 @@ short ExExeUtilTcb::alterAuditFlag(NABoolean audited, char * tableName,
 
 short ExExeUtilTcb::handleError()
 {
-  return ex_tcb::handleError(&qparent_, getDiagsArea());
+  short rc = ex_tcb::handleError(&qparent_, getDiagsArea());
+  diagsArea_->deAllocate();
+  diagsArea_ = NULL;
+  return rc;
 }
 
 short ExExeUtilTcb::handleDone()
 {
-  return ex_tcb::handleDone(&qparent_, getDiagsArea());
+  short rc = ex_tcb::handleDone(&qparent_, getDiagsArea());
+  if (diagsArea_ != NULL)
+  { 
+     diagsArea_->deAllocate();
+     diagsArea_ = NULL;
+  }
+  return rc;
 }
     
 short ExExeUtilTcb::createServer(char *serverName,

http://git-wip-us.apache.org/repos/asf/trafodion/blob/37702da3/core/sql/executor/ExExeUtilExplain.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilExplain.cpp b/core/sql/executor/ExExeUtilExplain.cpp
index 7d9f99c..7e12a27 100644
--- a/core/sql/executor/ExExeUtilExplain.cpp
+++ b/core/sql/executor/ExExeUtilExplain.cpp
@@ -237,7 +237,7 @@ short ExExeUtilDisplayExplainTcb::work()
 	      executeImmediate("control session 'EXPLAIN' 'ON';");
 	    if (retcode < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		pstate.step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -249,7 +249,7 @@ short ExExeUtilDisplayExplainTcb::work()
 					 "__EXPL_STMT_NAME__");
 	    if (retcode < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		pstate.step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -272,7 +272,7 @@ short ExExeUtilDisplayExplainTcb::work()
 	    
 	    if (retcode < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		pstate.step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -362,7 +362,7 @@ short ExExeUtilDisplayExplainTcb::work()
 	    retcode = cliInterface()->fetchRowsPrologue(explainQuery_);
 	    if (retcode < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		pstate.step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -389,7 +389,7 @@ short ExExeUtilDisplayExplainTcb::work()
 	    retcode = cliInterface()->fetch();
 	    if (retcode < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		pstate.step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -452,7 +452,7 @@ short ExExeUtilDisplayExplainTcb::work()
 	    retcode = cliInterface()->fetch();
 	    if (retcode < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		pstate.step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -567,7 +567,7 @@ short ExExeUtilDisplayExplainTcb::work()
 	    retcode = cliInterface()->fetchRowsEpilogue(explainQuery_);
 	    if (retcode < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 	      }
 	    
 	    retcode = 
@@ -575,7 +575,7 @@ short ExExeUtilDisplayExplainTcb::work()
 					   input_desc_, output_desc_);
 	    if (retcode < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 	      }
 
 	    if (exeUtilTdb().getStmtName() == NULL)
@@ -593,7 +593,7 @@ short ExExeUtilDisplayExplainTcb::work()
 	      executeImmediate("control session reset 'EXPLAIN';");
 	    if (retcode < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 	      }
 	    
 	    if (pstate.step_ == FETCH_EPILOGUE_AND_RETURN_ERROR_)
@@ -3916,7 +3916,7 @@ short ExExeUtilDisplayExplainComplexTcb::work()
 		// Explain will return 'info not available' in its
 		// description field.
 		// All other errors are reported.
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		if (exeUtilTdb().loadIfExists() &&
 		     getDiagsArea()->contains(-1055))
 		  {
@@ -3986,7 +3986,7 @@ short ExExeUtilDisplayExplainComplexTcb::work()
 					 FALSE, exeUtilTdb().isVolatile());
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = DROP_AND_ERROR_;
 		break;
 	      }
@@ -4210,7 +4210,7 @@ short ExExeUtilDisplayExplainShowddlTcb::work()
 
 		if (cliRC < 0)
 		  {
-                    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                    cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		    step_ = ERROR_;
 		    break;
 		  }
@@ -4226,7 +4226,7 @@ short ExExeUtilDisplayExplainShowddlTcb::work()
 
 		if (cliRC < 0)
 		  {
-                    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                    cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		    step_ = ERROR_;
 		    break;
 		  }
@@ -4251,7 +4251,7 @@ short ExExeUtilDisplayExplainShowddlTcb::work()
 
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = ERROR_;
 		break;
 	      }

http://git-wip-us.apache.org/repos/asf/trafodion/blob/37702da3/core/sql/executor/ExExeUtilGet.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilGet.cpp b/core/sql/executor/ExExeUtilGet.cpp
index 2ce8607..c77260e 100644
--- a/core/sql/executor/ExExeUtilGet.cpp
+++ b/core/sql/executor/ExExeUtilGet.cpp
@@ -689,7 +689,7 @@ Lng32 ExExeUtilGetMetadataInfoTcb::getUsingView(Queue * infoList,
 	    cliRC = cliInterface()->fetchRowsPrologue(query);
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		vStep_ = VIEWS_ERROR_;
 		break;
 	      }
@@ -703,7 +703,7 @@ Lng32 ExExeUtilGetMetadataInfoTcb::getUsingView(Queue * infoList,
 	    cliRC = cliInterface()->fetch();
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		vStep_ = VIEWS_ERROR_;
 		break;
 	      }
@@ -731,7 +731,7 @@ Lng32 ExExeUtilGetMetadataInfoTcb::getUsingView(Queue * infoList,
 	    cliRC = cliInterface()->fetchRowsEpilogue(0);
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		vStep_ = VIEWS_ERROR_;
 		break;
 	      }
@@ -845,7 +845,7 @@ Lng32 ExExeUtilGetMetadataInfoTcb::getUsedObjects(Queue * infoList,
 	    cliRC = cliInterface()->fetchRowsPrologue(query);
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		vStep_ = VIEWS_ERROR_;
 		break;
 	      }
@@ -859,7 +859,7 @@ Lng32 ExExeUtilGetMetadataInfoTcb::getUsedObjects(Queue * infoList,
 	    cliRC = cliInterface()->fetch();
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		vStep_ = VIEWS_ERROR_;
 		break;
 	      }
@@ -887,7 +887,7 @@ Lng32 ExExeUtilGetMetadataInfoTcb::getUsedObjects(Queue * infoList,
 	    cliRC = cliInterface()->fetchRowsEpilogue(0);
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		vStep_ = VIEWS_ERROR_;
 		break;
 	      }
@@ -1419,7 +1419,7 @@ Int32 ExExeUtilGetMetadataInfoTcb::getAuthID(
   cliRC = fetchAllRows(infoList_, queryBuf_, numOutputEntries_, FALSE, rc);
   if (cliRC < 0) 
   {
-    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+    cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
     return NA_UserIdDefault;
   }
 
@@ -1493,7 +1493,7 @@ char * ExExeUtilGetMetadataInfoTcb::getRoleList(
   cliRC = fetchAllRows(infoList_, queryBuf_, numOutputEntries_, FALSE, rc);
   if (cliRC < 0)
   {
-    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+    cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
     return NULL;
   }
 
@@ -1813,9 +1813,7 @@ short ExExeUtilGetMetadataInfoTcb::work()
 	    {
                if (!CmpCommon::context()->isAuthorizationEnabled())
                {
-                  ComDiagsArea * diagsArea = getDiagsArea();
-                  ExRaiseSqlError(getHeap(), &diagsArea, -CAT_AUTHORIZATION_NOT_ENABLED);
-                  setDiagsArea(diagsArea);
+                  ExRaiseSqlError(getHeap(), &diagsArea_, -CAT_AUTHORIZATION_NOT_ENABLED);
                   step_ = HANDLE_ERROR_;
                   break;
                }
@@ -2273,11 +2271,9 @@ short ExExeUtilGetMetadataInfoTcb::work()
                   // easier to just return with an error.
                   if (authID == 0)
                     { 
-                      ComDiagsArea * diagsArea = getDiagsArea();
-                      ExRaiseSqlError(getHeap(), &diagsArea, -8732,
+                      ExRaiseSqlError(getHeap(), &diagsArea_, -8732,
                           NULL, NULL, NULL,
                           getMItdb().getParam1());
-                      setDiagsArea(diagsArea);
                       step_ = HANDLE_ERROR_;
                       break;
                     }
@@ -2288,11 +2284,9 @@ short ExExeUtilGetMetadataInfoTcb::work()
                        // error if authID is not a role
                        if (!CmpSeabaseDDLauth::isRoleID(authID) && authID != PUBLIC_USER)
                         {
-                          ComDiagsArea * diagsArea = getDiagsArea();
-                          ExRaiseSqlError(getHeap(), &diagsArea, -CAT_IS_NOT_A_ROLE, 
+                          ExRaiseSqlError(getHeap(), &diagsArea_, -CAT_IS_NOT_A_ROLE, 
                               NULL, NULL, NULL,
                               getMItdb().getParam1());
-                          setDiagsArea(diagsArea);
                           step_ = HANDLE_ERROR_;
                           break;
                         }
@@ -2303,11 +2297,9 @@ short ExExeUtilGetMetadataInfoTcb::work()
                       // Return an error if authID is not a user
                       if (!CmpSeabaseDDLauth::isUserID(authID))
                         {
-                          ComDiagsArea * diagsArea = getDiagsArea();
-                          ExRaiseSqlError(getHeap(), &diagsArea, -CAT_IS_NOT_A_USER, 
+                          ExRaiseSqlError(getHeap(), &diagsArea_, -CAT_IS_NOT_A_USER, 
                               NULL, NULL, NULL,
                               getMItdb().getParam1());
-                          setDiagsArea(diagsArea);
                           step_ = HANDLE_ERROR_;
                           break;
                         }
@@ -2636,7 +2628,7 @@ short ExExeUtilGetMetadataInfoTcb::work()
 	    if (fetchAllRows(infoList_, queryBuf_, numOutputEntries_,
 			     FALSE, retcode) < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -4239,7 +4231,7 @@ short ExExeUtilGetHiveMetadataInfoTcb::work()
 	    retcode = fetchAllHiveRows(infoList_, 1, rc);
 	    if (retcode < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -5069,10 +5061,8 @@ short ExExeUtilLobShowddlTcb::fetchRows(char * query, short &rc)
     fetchAllRows(infoList_, query, 1, FALSE, rc);
   if (cliRC < 0) 
     {
-      setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
-
+      cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
       step_ = HANDLE_ERROR_;
-
       return -1;
     }
   
@@ -5523,13 +5513,11 @@ short ExExeUtilHiveMDaccessTcb::work()
             if (!retStatus)
               {
                 Lng32 intParam1 =  hiveMD_->getErrCode();
-                ComDiagsArea *diagsArea =  getDiagsArea();
-                ExRaiseSqlError(getHeap(), &diagsArea, -1190, 
+                ExRaiseSqlError(getHeap(), &diagsArea_, -1190, 
                        &intParam1, NULL, NULL,
                        hiveMD_->getErrMethodName(),
                        hiveMD_->getErrCodeStr(),
                        hiveMD_->getErrDetail());
-                setDiagsArea(diagsArea);
                 step_ = HANDLE_ERROR_;
                 break;
               }
@@ -5546,13 +5534,11 @@ short ExExeUtilHiveMDaccessTcb::work()
                 HVC_RetCode retCode = HiveClient_JNI::getAllSchemas((NAHeap *)getHeap(), schNames_);
                 if ((retCode != HVC_OK) && (retCode != HVC_DONE)) 
                   {
-		    ComDiagsArea * diagsArea = getDiagsArea();
-		    ExRaiseSqlError(getHeap(), &diagsArea, -1190, 
+		    ExRaiseSqlError(getHeap(), &diagsArea_, -1190, 
                            (Lng32 *)&retCode, NULL, NULL, 
                            (char*)"HiveClient_JNI::getAllSchemas()",
                            HiveClient_JNI::getErrorText(retCode),
                            GetCliGlobals()->getJniErrorStr());
-                    setDiagsArea(diagsArea);
                     step_ = HANDLE_ERROR_;
                     break;
                   }
@@ -5607,23 +5593,20 @@ short ExExeUtilHiveMDaccessTcb::work()
                 HVC_RetCode retCode = HiveClient_JNI::getAllTables((NAHeap *)getHeap(), currSch, tblNames_);
                 if (retCode == HVC_ERROR_EXISTS_EXCEPTION)
                   {
-		    ComDiagsArea * diagsArea = getDiagsArea();
-		    ExRaiseSqlError(getHeap(), &diagsArea, -1003, 
+		    ExRaiseSqlError(getHeap(), &diagsArea_, -1003, 
                            NULL, NULL, NULL, 
-                           (NAString("hive") + "." + currSch).data());
-                    setDiagsArea(diagsArea);
+                           hiveCat_,
+                           hiveSch_);
                     step_ = HANDLE_ERROR_;
                     break;
                   }
                 else if ((retCode != HVC_OK) && (retCode != HVC_DONE)) 
                   {
-		    ComDiagsArea * diagsArea = getDiagsArea();
-		    ExRaiseSqlError(getHeap(), &diagsArea, -1190, 
+		    ExRaiseSqlError(getHeap(), &diagsArea_, -1190, 
                            (Lng32 *)&retCode, NULL, NULL, 
                            (char*)"HiveClient_JNI::getAllTables()",
                            HiveClient_JNI::getErrorText(retCode),
                            GetCliGlobals()->getJniErrorStr());
-                    setDiagsArea(diagsArea);
                     step_ = HANDLE_ERROR_;
                     break;
                   }
@@ -5807,11 +5790,9 @@ short ExExeUtilHiveMDaccessTcb::work()
 		char strP[300];
 		sprintf(strP, "Datatype %s is not supported.", 
                         (hcd ? hcd->type_ : hpd->type_));
-                ComDiagsArea *diagsArea = getDiagsArea();
-                ExRaiseSqlError(getHeap(), &diagsArea, -CLI_GET_METADATA_INFO_ERROR,
+                ExRaiseSqlError(getHeap(), &diagsArea_, -CLI_GET_METADATA_INFO_ERROR,
                       NULL, NULL, NULL,
                       strP);
-                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -7065,9 +7046,7 @@ short ExExeUtilClusterStatsTcb::work()
               }
             else if (retcode < 0)
               {
-                ComDiagsArea *diagsArea = getDiagsArea();
-                ExRaiseSqlError(getHeap(), &diagsArea, -8451);
-                setDiagsArea(diagsArea);
+                ExRaiseSqlError(getHeap(), &diagsArea_, -8451);
                 step_ = HANDLE_ERROR_;
                 break;
               }

http://git-wip-us.apache.org/repos/asf/trafodion/blob/37702da3/core/sql/executor/ExExeUtilGetStats.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilGetStats.cpp b/core/sql/executor/ExExeUtilGetStats.cpp
index bfd9db2..1f32971 100644
--- a/core/sql/executor/ExExeUtilGetStats.cpp
+++ b/core/sql/executor/ExExeUtilGetStats.cpp
@@ -979,7 +979,7 @@ short ExExeUtilGetStatisticsTcb::work()
 	    cliRC = cliInterface()->fetchRowsPrologue(statsQuery_);
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -994,7 +994,7 @@ short ExExeUtilGetStatisticsTcb::work()
 	    cliRC = cliInterface()->fetch();
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -1130,7 +1130,7 @@ short ExExeUtilGetStatisticsTcb::work()
 	    cliRC = cliInterface()->fetch();
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }

http://git-wip-us.apache.org/repos/asf/trafodion/blob/37702da3/core/sql/executor/ExExeUtilLoad.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilLoad.cpp b/core/sql/executor/ExExeUtilLoad.cpp
index 33a93f8..d3c5c8d 100644
--- a/core/sql/executor/ExExeUtilLoad.cpp
+++ b/core/sql/executor/ExExeUtilLoad.cpp
@@ -139,10 +139,8 @@ short ExExeUtilCreateTableAsTcb::work()
 	    // allow a user transaction if NO LOAD was specified
 	    if (xnAlreadyStarted && !ctaTdb().noLoad())
               {
-                ComDiagsArea *diagsArea = getDiagsArea();
-                ExRaiseSqlError(getHeap(), &diagsArea, -20123, NULL, NULL, NULL,
+                ExRaiseSqlError(getHeap(), &diagsArea_, -20123, NULL, NULL, NULL,
                                 "This DDL operation");
-                setDiagsArea(diagsArea);
                 step_ = ERROR_;
                 break;
               }
@@ -185,8 +183,7 @@ short ExExeUtilCreateTableAsTcb::work()
 		  }
 		else
 		  {
-		    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
-		    
+		    cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		    step_ = ERROR_;
 		    break;
 		  }
@@ -342,7 +339,7 @@ short ExExeUtilCreateTableAsTcb::work()
 		 &rowsAffected);
 	    if (cliRC < 0)
             {
-              setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+              cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
               step_ = HANDLE_ERROR_;
             }
             else
@@ -428,7 +425,7 @@ short ExExeUtilCreateTableAsTcb::work()
               cliInterface()->setIsoMapping(savedIsoMapping);
 	      if (cliRC < 0)
               {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
                 step_ = HANDLE_ERROR_;
               }
               else
@@ -447,7 +444,7 @@ short ExExeUtilCreateTableAsTcb::work()
 		 &rowsAffected);
 	    if (cliRC < 0)
 	    {
-              setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+              cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
               step_ = HANDLE_ERROR_;
             }
             else
@@ -481,7 +478,7 @@ short ExExeUtilCreateTableAsTcb::work()
 	    NADELETEBASIC(usQuery, getHeap());
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -796,7 +793,7 @@ ExWorkProcRetcode ExExeUtilAqrWnrInsertTcb::work()
 
         if (cliRC < 0)
         {
-          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+          cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
           SETSTEP(ERROR_);
         }
         else
@@ -821,7 +818,7 @@ ExWorkProcRetcode ExExeUtilAqrWnrInsertTcb::work()
         NADELETEBASIC(query_, getMyHeap());
         if (cliRC < 0)
         {
-          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+          cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
           SETSTEP(ERROR_);
         }
         else
@@ -960,7 +957,7 @@ ExWorkProcRetcode ExExeUtilAqrWnrInsertTcb::work()
         {
         // mjh - tbd - warning or EMS message to give context to error on
         // delete after error on the insert?
-          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+          cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
         }
         else
           masterGlob->setAqrWnrInsertCleanedup();
@@ -1114,7 +1111,6 @@ short ExExeUtilHBaseBulkLoadTcb::work()
   short rc;
   Lng32 errorRowCount = 0;
   int len;
-  ComDiagsArea *diagsArea = NULL;
 
   // if no parent request, return
   if (qparent_.down->isEmpty())
@@ -1148,9 +1144,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
           !hblTdb().getIndexTableOnly())
       {
         //8111 - Transactions are not allowed with Bulk load.
-        ComDiagsArea * diagsArea = getDiagsArea();
-        ExRaiseSqlError(getHeap(), &diagsArea, -8111);
-        setDiagsArea(diagsArea);
+        ExRaiseSqlError(getHeap(), &diagsArea_, -8111);
         step_ = LOAD_ERROR_;
           break;
       }
@@ -1222,7 +1216,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
 
       if (cliRC < 0)
       {
-        setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+        cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
         step_ = LOAD_ERROR_;
         break;
       }
@@ -1251,14 +1245,12 @@ short ExExeUtilHBaseBulkLoadTcb::work()
       {
          Lng32 cliError = 0;
         Lng32 intParam1 = -retcode;
-        diagsArea = NULL;
-        ExRaiseSqlError(getHeap(), &diagsArea,
+        ExRaiseSqlError(getHeap(), &diagsArea_,
                           (ExeErrorCode)(8448), NULL, &intParam1,
                           &cliError, NULL,
                           " ",
                           getHbaseErrStr(retcode),
                           (char *)GetCliGlobals()->getJniErrorStr());
-        setDiagsArea(diagsArea);
         step_ = LOAD_END_ERROR_;
         break;
       }
@@ -1298,7 +1290,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
       clnpQuery = NULL;
       if (cliRC < 0)
       {
-        setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+        cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
         step_ = LOAD_END_ERROR_;
         break;
       }
@@ -1337,7 +1329,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
       diQuery = NULL;
       if (cliRC < 0)
       {
-        setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+        cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
         step_ = LOAD_END_ERROR_;
         break;
       }
@@ -1414,24 +1406,20 @@ short ExExeUtilHBaseBulkLoadTcb::work()
               masterGlob->getStatement()->getContext()->setSqlParserFlags(0x20000);
             }
           }
-        diagsArea = getDiagsArea();
-        if (diagsArea == NULL) {
-           diagsArea = ComDiagsArea::allocate(getHeap());
-           setDiagsArea(diagsArea);
-        }
+        ComDiagsArea *diagsArea = getDiagsArea();
         cliRC = cliInterface()->executeImmediate(loadQuery,
             NULL,
             NULL,
             TRUE,
             &rowsAffected_,
             FALSE,
-            diagsArea);
+            &diagsArea);
         if (parserFlagSet)
             masterGlob->getStatement()->getContext()->resetSqlParserFlags(0x20000);
+        setDiagsArea(diagsArea);
         if (cliRC < 0)
         {
           rowsAffected_ = 0;
-          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
           step_ = LOAD_END_ERROR_;
           break;
         }
@@ -1469,7 +1457,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
         upsQuery = NULL;
         if (cliRC < 0)
         {
-          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+          cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
           step_ = LOAD_ERROR_;
           break;
         }
@@ -1539,7 +1527,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
       if (cliRC < 0)
       {
         rowsAffected_ = 0;
-        setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+        cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
         setEndStatusMsg(" COMPLETION", len, TRUE);
         step_ = LOAD_END_ERROR_;
         break;
@@ -1586,7 +1574,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
 
       if (cliRC < 0)
       {
-        setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+        cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
         step_ = LOAD_END_ERROR_;
         break;
       }
@@ -1646,7 +1634,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
 
         if (cliRC < 0)
         {
-          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+          cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
           step_ = LOAD_END_ERROR_;
         }
         else
@@ -1702,7 +1690,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
       up_entry->upState.setMatchNo(0);
       up_entry->upState.status = ex_queue::Q_NO_DATA;
 
-      diagsArea = up_entry->getDiagsArea();
+      ComDiagsArea *diagsArea = up_entry->getDiagsArea();
 
       if (diagsArea == NULL)
         diagsArea = ComDiagsArea::allocate(getMyHeap());
@@ -2017,12 +2005,12 @@ short ExExeUtilHBaseBulkUnLoadTcb::resetExplainSettings()
 {
   if (cliInterface()->executeImmediate("control session reset 'EXPLAIN';") < 0)
   {
-    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+    cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
     return -1;
   }
   if (restoreCQD("generate_explain") < 0)
   {
-    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+    cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
     return -1;
   }
   return 0;
@@ -2043,7 +2031,7 @@ short ExExeUtilHBaseBulkUnLoadTcb::getTrafodionScanTables()
 
   if (holdAndSetCQD("generate_explain", "ON") < 0)
   {
-    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+    cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
     resetExplainSettings();
     return -1;
   }
@@ -2051,7 +2039,7 @@ short ExExeUtilHBaseBulkUnLoadTcb::getTrafodionScanTables()
   cliRC = cliInterface()->executeImmediate("control session 'EXPLAIN' 'ON';");
   if (cliRC < 0)
   {
-    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+    cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
     resetExplainSettings();
     return cliRC;
   }
@@ -2059,7 +2047,7 @@ short ExExeUtilHBaseBulkUnLoadTcb::getTrafodionScanTables()
   cliRC = cliInterface()->allocStuff(module, stmt, sql_src, input_desc, output_desc, "__EXPL_STMT_NAME__");
   if (cliRC < 0)
   {
-    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+    cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
     resetExplainSettings();
     return cliRC;
   }
@@ -2068,7 +2056,7 @@ short ExExeUtilHBaseBulkUnLoadTcb::getTrafodionScanTables()
   cliRC = cliInterface()->prepare(stmtStr, module, stmt, sql_src, input_desc, output_desc, NULL);
   if (cliRC < 0)
   {
-    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+    cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
     cliInterface()->deallocStuff(module, stmt, sql_src, input_desc, output_desc);
     resetExplainSettings();
     return cliRC;
@@ -2100,7 +2088,7 @@ short ExExeUtilHBaseBulkUnLoadTcb::getTrafodionScanTables()
   cliRC = cliInterface()->fetchAllRows(tbls, (char*)qry_str.data(), 0, FALSE, FALSE, TRUE);
   if (cliRC < 0)
   {
-    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+    cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
     cliInterface()->deallocStuff(module, stmt, sql_src, input_desc, output_desc);
     return cliRC;
   }
@@ -2113,7 +2101,7 @@ short ExExeUtilHBaseBulkUnLoadTcb::getTrafodionScanTables()
       cliRC = cliInterface()->deallocStuff(module, stmt, sql_src, input_desc, output_desc);
       if (cliRC < 0)
       {
-        setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+        cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
         return cliRC;
       }
     }
@@ -2139,7 +2127,7 @@ short ExExeUtilHBaseBulkUnLoadTcb::getTrafodionScanTables()
   cliRC = cliInterface()->deallocStuff(module, stmt, sql_src, input_desc, output_desc);
   if (cliRC < 0)
   {
-    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+    cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
     return cliRC;
   }
   return snapshotsList_->entries();
@@ -2179,9 +2167,7 @@ short ExExeUtilHBaseBulkUnLoadTcb::work()
       if (xnAlreadyStarted  )
       {
         //8111 - Transactions are not allowed with Bulk unload.
-        ComDiagsArea * diagsArea = getDiagsArea();
-        ExRaiseSqlError(getHeap(), &diagsArea, -8111);
-        setDiagsArea(diagsArea);
+        ExRaiseSqlError(getHeap(), &diagsArea_, -8111);
         step_ = UNLOAD_ERROR_;
         break;
       }
@@ -2208,11 +2194,9 @@ short ExExeUtilHBaseBulkUnLoadTcb::work()
         if (exists)
         {
           //EXE_UNLOAD_FILE_EXISTS
-          ComDiagsArea * diagsArea = getDiagsArea();
-          ExRaiseSqlError(getHeap(), &diagsArea, -EXE_UNLOAD_FILE_EXISTS,
+          ExRaiseSqlError(getHeap(), &diagsArea_, -EXE_UNLOAD_FILE_EXISTS,
                   NULL, NULL, NULL,
                   hblTdb().getMergePath());
-          setDiagsArea(diagsArea);
           step_ = UNLOAD_END_ERROR_;
           break;
         }
@@ -2330,12 +2314,10 @@ short ExExeUtilHBaseBulkUnLoadTcb::work()
           hbcRetCode = ehi_->verifySnapshot(*snapshotsList_->at(i)->fullTableName, *snapshotsList_->at(i)->snapshotName, exist);
           if ( hbcRetCode == HBC_OK && !exist)
           {
-            ComDiagsArea * diagsArea = getDiagsArea();
-            ExRaiseSqlError(getHeap(), &diagsArea, -8112,
+            ExRaiseSqlError(getHeap(), &diagsArea_, -8112,
                   NULL, NULL, NULL,
                   snapshotsList_->at(i)->snapshotName->data(),
                   snapshotsList_->at(i)->fullTableName->data());
-            setDiagsArea(diagsArea);
             step_ = UNLOAD_END_ERROR_;
             break;
           }
@@ -2374,7 +2356,7 @@ short ExExeUtilHBaseBulkUnLoadTcb::work()
       if (cliRC < 0)
       {
         rowsAffected_ = 0;
-        setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+        cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
         step_ = UNLOAD_END_ERROR_;
         break;
       }
@@ -2881,11 +2863,9 @@ short ExExeUtilLobExtractTcb::work()
 		      Lng32 cliError = 0;
 		      
 		      Lng32 intParam1 = 0;
-		      ComDiagsArea * diagsArea = getDiagsArea();
-		      ExRaiseSqlError(getHeap(), &diagsArea, 
+		      ExRaiseSqlError(getHeap(), &diagsArea_, 
 				      (ExeErrorCode)(8444), NULL, &intParam1, 
 				      &cliError, NULL, NULL);
-
 		      step_ = HANDLE_ERROR_;
 		    }
 		}
@@ -3000,11 +2980,9 @@ short ExExeUtilLobExtractTcb::work()
 		     lobHandle_,
 		     lobHandleLen_))
 		  {
-		    ComDiagsArea * diagsArea = getDiagsArea();
 		    ExRaiseSqlError(getMyHeap(),
-				    &diagsArea,
+				    &diagsArea_,
 				    (ExeErrorCode)(EXE_INVALID_LOB_HANDLE));
-                    setDiagsArea(diagsArea);
 		    step_ = HANDLE_ERROR_;
 		    break;
 		  }
@@ -3264,12 +3242,10 @@ short ExExeUtilLobExtractTcb::work()
 		  {
 		    Lng32 intParam1 = -retcode;
 		    Lng32 cliError;
-		    ComDiagsArea * diagsArea = getDiagsArea();
-		    ExRaiseSqlError(getHeap(), &diagsArea, 
+		    ExRaiseSqlError(getHeap(), &diagsArea_, 
 				    (ExeErrorCode)(8442), NULL, &intParam1, 
 				    &cliError, NULL, (char*)"ExpLOBInterfaceSelect",
 				    getLobErrStr(intParam1));
-                    setDiagsArea(diagsArea);
 		    step_ = HANDLE_ERROR_;
 		    break;
 		  }
@@ -3312,12 +3288,10 @@ short ExExeUtilLobExtractTcb::work()
 		Lng32 cliError = 0;
 
 		Lng32 intParam1 = -retcode;
-		ComDiagsArea * diagsArea = getDiagsArea();
-		ExRaiseSqlError(getHeap(), &diagsArea, 
+		ExRaiseSqlError(getHeap(), &diagsArea_, 
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceSelectCursor",
 				getLobErrStr(intParam1));
-                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -3367,12 +3341,10 @@ short ExExeUtilLobExtractTcb::work()
 		Lng32 cliError = 0;
 
 		Lng32 intParam1 = -retcode;
-		ComDiagsArea * diagsArea = getDiagsArea();
-		ExRaiseSqlError(getHeap(), &diagsArea, 
+		ExRaiseSqlError(getHeap(), &diagsArea_, 
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceSelectCursor",
 				getLobErrStr(intParam1));
-                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -3440,12 +3412,10 @@ short ExExeUtilLobExtractTcb::work()
 		Lng32 cliError = 0;
 
 		Lng32 intParam1 = -retcode;
-		ComDiagsArea * diagsArea = getDiagsArea();
-		ExRaiseSqlError(getHeap(), &diagsArea, 
+		ExRaiseSqlError(getHeap(), &diagsArea_, 
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceSelectCursor",
 				getLobErrStr(intParam1));
-                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      } 
@@ -3634,11 +3604,9 @@ short ExExeUtilLobUpdateTcb::work()
 		     lobHandle_,
 		     lobHandleLen_))
 		  {
-		    ComDiagsArea *diagsArea = getDiagsArea();
 		    ExRaiseSqlError(getMyHeap(),
-				    &diagsArea,
+				    &diagsArea_,
 				    (ExeErrorCode)(EXE_INVALID_LOB_HANDLE));
-                    setDiagsArea(diagsArea);
 		    step_ = HANDLE_ERROR_;
 		    break;
 		  }
@@ -3747,12 +3715,10 @@ short ExExeUtilLobUpdateTcb::work()
 		Lng32 cliError = 0;
 
 		Lng32 intParam1 = -retcode;
-		ComDiagsArea * diagsArea = getDiagsArea();
-		ExRaiseSqlError(getHeap(), &diagsArea, 
+		ExRaiseSqlError(getHeap(), &diagsArea_, 
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceUpdate",
 				getLobErrStr(intParam1));
-                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }  
@@ -3844,12 +3810,10 @@ short ExExeUtilLobUpdateTcb::work()
 		Lng32 cliError = 0;
 
 		Lng32 intParam1 = -retcode;
-		ComDiagsArea * diagsArea = getDiagsArea();
-		ExRaiseSqlError(getHeap(), &diagsArea, 
+		ExRaiseSqlError(getHeap(), &diagsArea_, 
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceUpdate",
 			 	getLobErrStr(intParam1));
-                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }  
@@ -3943,12 +3907,10 @@ short ExExeUtilLobUpdateTcb::work()
 		Lng32 cliError = 0;
 
 		Lng32 intParam1 = -retcode;
-		ComDiagsArea * diagsArea = getDiagsArea();
-		ExRaiseSqlError(getHeap(), &diagsArea, 
+		ExRaiseSqlError(getHeap(), &diagsArea_, 
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceUpdate",
 				getLobErrStr(intParam1));
-                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }  
@@ -4111,12 +4073,10 @@ short ExExeUtilFileExtractTcb::work()
 		Lng32 cliError = 0;
 
 		Lng32 intParam1 = -retcode;
-		ComDiagsArea * diagsArea = getDiagsArea();
-		ExRaiseSqlError(getHeap(), &diagsArea, 
+		ExRaiseSqlError(getHeap(), &diagsArea_, 
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceSelectCursor/open",
 				getLobErrStr(intParam1));
-                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -4159,12 +4119,10 @@ short ExExeUtilFileExtractTcb::work()
 		Lng32 cliError = 0;
 
 		Lng32 intParam1 = -retcode;
-		ComDiagsArea * diagsArea = getDiagsArea();
-		ExRaiseSqlError(getHeap(), &diagsArea, 
+		ExRaiseSqlError(getHeap(), &diagsArea_, 
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceSelectCursor/read",
 				getLobErrStr(intParam1));
-                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -4216,12 +4174,10 @@ short ExExeUtilFileExtractTcb::work()
 		Lng32 cliError = 0;
 
 		Lng32 intParam1 = -retcode;
-		ComDiagsArea * diagsArea = getDiagsArea();
-		ExRaiseSqlError(getHeap(), &diagsArea, 
+		ExRaiseSqlError(getHeap(), &diagsArea_, 
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceSelectCursor/close",
 				getLobErrStr(intParam1));
-                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -4353,12 +4309,10 @@ short ExExeUtilFileLoadTcb::work()
 		    Lng32 cliError = 0;
 		    
 		    Lng32 intParam1 = -retcode;
-		    ComDiagsArea * diagsArea = getDiagsArea();
-		    ExRaiseSqlError(getHeap(), &diagsArea, 
+		    ExRaiseSqlError(getHeap(), &diagsArea_, 
 				    (ExeErrorCode)(8442), NULL, &intParam1, 
 				    &cliError, NULL, (char*)"ExpLOBInterfaceCreate",
 				    getLobErrStr(intParam1));
-                    setDiagsArea(diagsArea);
 		    step_ = HANDLE_ERROR_;
 		    break;
 		  }
@@ -4385,11 +4339,9 @@ short ExExeUtilFileLoadTcb::work()
 		Lng32 cliError = 0;
 
 		Lng32 intParam1 = -1;
-		ComDiagsArea * diagsArea = getDiagsArea();
-		ExRaiseSqlError(getHeap(), &diagsArea, 
+		ExRaiseSqlError(getHeap(), &diagsArea_, 
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"SourceFile open");
-                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -4429,11 +4381,9 @@ short ExExeUtilFileLoadTcb::work()
 		Lng32 cliError = 0;
 
 		Lng32 intParam1 = -1;
-		ComDiagsArea * diagsArea = getDiagsArea();
-		ExRaiseSqlError(getHeap(), &diagsArea, 
+		ExRaiseSqlError(getHeap(), &diagsArea_, 
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"SourceFile read");
-                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -4474,12 +4424,10 @@ short ExExeUtilFileLoadTcb::work()
 		Lng32 cliError = 0;
 
 		Lng32 intParam1 = -retcode;
-		ComDiagsArea * diagsArea = getDiagsArea();
-		ExRaiseSqlError(getHeap(), &diagsArea, 
+		ExRaiseSqlError(getHeap(), &diagsArea_, 
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceInsert",
 				getLobErrStr(intParam1));
-                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -4506,12 +4454,10 @@ short ExExeUtilFileLoadTcb::work()
 		Lng32 cliError = 0;
 		
 		Lng32 intParam1 = -retcode;
-		ComDiagsArea * diagsArea = getDiagsArea();
-		ExRaiseSqlError(getHeap(), &diagsArea, 
+		ExRaiseSqlError(getHeap(), &diagsArea_, 
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceCloseFile",
 				getLobErrStr(intParam1));
-                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }

http://git-wip-us.apache.org/repos/asf/trafodion/blob/37702da3/core/sql/executor/ExExeUtilMisc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilMisc.cpp b/core/sql/executor/ExExeUtilMisc.cpp
index 277d5e1..8ae7124 100644
--- a/core/sql/executor/ExExeUtilMisc.cpp
+++ b/core/sql/executor/ExExeUtilMisc.cpp
@@ -102,7 +102,7 @@ short ExExeUtilFastDeleteTcb::doPurgedataCat(char * stmt)
   cliRC = holdAndSetCQD("EXE_PARALLEL_PURGEDATA", "OFF");
   if (cliRC < 0)
     {
-      setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+      cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
       return -1;
     }
 
@@ -111,7 +111,7 @@ short ExExeUtilFastDeleteTcb::doPurgedataCat(char * stmt)
 
   if (cliRC < 0)
     {
-      setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+      cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
       restoreCQD("EXE_PARALLEL_PURGEDATA");
       return -1;
     }
@@ -156,7 +156,7 @@ short ExExeUtilFastDeleteTcb::doLabelPurgedata(char * objectName,
 
   if (cliRC < 0)
     {
-      setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+      cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
       retcode = -1;
       goto cleanUpAndReturn;
     }
@@ -214,7 +214,7 @@ short ExExeUtilFastDeleteTcb::doFastDelete(char * objectName,
     executeImmediate("control query shape hold;");
   if (cliRC < 0)
     {
-      setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+      cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
       retcode = -1;
       goto cleanUpAndReturn;
     }
@@ -223,7 +223,7 @@ short ExExeUtilFastDeleteTcb::doFastDelete(char * objectName,
     cliInterface()->executeImmediate("control query shape esp_exchange(cut);");
   if (cliRC < 0)
     {
-      setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+      cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
       retcode = -1;
       goto cleanUpAndReturn;
     }
@@ -235,7 +235,7 @@ short ExExeUtilFastDeleteTcb::doFastDelete(char * objectName,
 	executeImmediate("control query default mv_internal_ignore_uninitialized 'ON';");
       if (cliRC < 0)
 	{
-          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+          cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 	  retcode = -1;
 	  goto cleanUpAndReturn;
 	}
@@ -275,7 +275,7 @@ short ExExeUtilFastDeleteTcb::doFastDelete(char * objectName,
 
   if (cliRC < 0)
     {
-      setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+      cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
       retcode = -1;
       goto cleanUpAndReturn;
     }
@@ -333,11 +333,9 @@ short ExExeUtilFastDeleteTcb::injectError(const char * val)
       ((e2) && (strcmp(e2, val) == 0)))
     {
       Lng32 errNumParam = ((Lng32)str_atoi(val, strlen(val)));
-      ComDiagsArea * diagsArea = getDiagsArea();
-      ExRaiseSqlError(getHeap(), &diagsArea, -EXE_ERROR_INJECTED,
+      ExRaiseSqlError(getHeap(), &diagsArea_, -EXE_ERROR_INJECTED,
           &errNumParam, NULL, NULL,   
 	  (e1 ? "SQLMX_TEST_POINT" : "SQLMX_PPD_ERR_TEST_POINT"));
-      setDiagsArea(diagsArea);
       return -EXE_ERROR_INJECTED;
     }
   return 0;
@@ -408,7 +406,7 @@ short ExExeUtilFastDeleteTcb::work()
 		    cliRC = cliInterface()->beginWork();
 		    if (cliRC < 0)
 		      {
-                        setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                        cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 			step_ = ERROR_;
 			break;
 		      }
@@ -443,7 +441,7 @@ short ExExeUtilFastDeleteTcb::work()
 	      {
 		if (cliRC < 0)
 		  {
-                    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                    cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		    step_ = ERROR_;
 		    break;
 		  }
@@ -456,7 +454,7 @@ short ExExeUtilFastDeleteTcb::work()
 	    cliRC = cliInterface()->beginWork();
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = ERROR_;
 		break;
 	      }
@@ -506,7 +504,7 @@ short ExExeUtilFastDeleteTcb::work()
 	      rc = injectError("10");
 	    if (rc < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		// could not acquire a ddl lock.
 		// try to purgedata using catman sequential purgedata.
 
@@ -549,7 +547,7 @@ short ExExeUtilFastDeleteTcb::work()
 	      }
 	    if (rc < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		// security validation failed
 		if ((getDiagsArea()->contains(-1017)) ||
 		    (rollbackNoPDErr))
@@ -572,7 +570,7 @@ short ExExeUtilFastDeleteTcb::work()
 	      rc = injectError("12");
 	    if (rc < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = ROLLBACK_WORK_AND_ERROR_;
 		break;
 	      }
@@ -588,7 +586,7 @@ short ExExeUtilFastDeleteTcb::work()
 		  {
 		    strcpy(failReason_, "Error during commit work.");
 
-                    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                    cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		    step_ = ROLLBACK_WORK_AND_ERROR_;
 		    break;
 		  }
@@ -603,7 +601,7 @@ short ExExeUtilFastDeleteTcb::work()
 		strcpy(buf, "SELECT TESTEXIT;");
 		cliRC = cliInterface()->executeImmediate(buf);
 		if (cliRC < 0)
-                  setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                  cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		  
 		strcpy(failReason_, " ");
 
@@ -621,7 +619,7 @@ short ExExeUtilFastDeleteTcb::work()
 	    cliRC = cliInterface()->beginWork();
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = ERROR_;
 		break;
 	      }
@@ -732,10 +730,9 @@ short ExExeUtilFastDeleteTcb::work()
 		ComDiagsArea * diagsArea = getDiagsArea();
 		// convert all errors into warnings
 		NegateAllErrors(diagsArea);
-                ExRaiseSqlError(getHeap(), &diagsArea, -EXE_PARALLEL_PURGEDATA_FAILED,
+                ExRaiseSqlError(getHeap(), &diagsArea_, -EXE_PARALLEL_PURGEDATA_FAILED,
                     NULL, NULL, NULL,
 		    failReason_);
-                setDiagsArea(diagsArea);
 	      }
 
 	    step_ = ERROR_;
@@ -758,7 +755,7 @@ short ExExeUtilFastDeleteTcb::work()
 		strcpy(buf, "SELECT TESTEXIT;");
 		cliInterface()->executeImmediate(buf);
 		if (cliRC < 0)
-                  setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                  cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		
 		step_ = ERROR_;
 		break;
@@ -769,11 +766,9 @@ short ExExeUtilFastDeleteTcb::work()
 		// raise a warning that parallel purgedata was performed.
 		if (fdTdb().returnPurgedataWarn())
 		  {
-		    ComDiagsArea * diagsArea = getDiagsArea();
-                    ExRaiseSqlError(getHeap(), &diagsArea, EXE_PURGEDATA_CAT,
+                    ExRaiseSqlError(getHeap(), &diagsArea_, EXE_PURGEDATA_CAT,
                         NULL, NULL, NULL,
 			"Parallel", "");
-                    setDiagsArea(diagsArea);
 		  }
 		step_ = DONE_;
 	      }
@@ -787,7 +782,7 @@ short ExExeUtilFastDeleteTcb::work()
 	    cliRC = cliInterface()->beginWork();
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = ERROR_;
 		break;
 	      }
@@ -802,7 +797,7 @@ short ExExeUtilFastDeleteTcb::work()
 
 	    if (rc < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = KILL_MXCMP_AND_ERROR_;
 		break;
 	      }
@@ -819,7 +814,7 @@ short ExExeUtilFastDeleteTcb::work()
 	      rc = injectError("16");
 	    if (rc < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = KILL_MXCMP_AND_ERROR_;
 		break;
 	      }
@@ -838,7 +833,7 @@ short ExExeUtilFastDeleteTcb::work()
 		  rc = injectError("17");
 		if (rc < 0)
 		  {
-                    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                    cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		    step_ = KILL_MXCMP_AND_ERROR_;
 		    break;
 		  }
@@ -847,7 +842,7 @@ short ExExeUtilFastDeleteTcb::work()
 	    cliRC = cliInterface()->commitWork();
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = ERROR_;
 		break;
 	      }
@@ -857,11 +852,9 @@ short ExExeUtilFastDeleteTcb::work()
 	    // raise a warning that parallel purgedata was performed.
 	    if (fdTdb().returnPurgedataWarn())
 	      {
-		ComDiagsArea * diagsArea = getDiagsArea();
-                ExRaiseSqlError(getHeap(), &diagsArea, EXE_PURGEDATA_CAT,
+                ExRaiseSqlError(getHeap(), &diagsArea_, EXE_PURGEDATA_CAT,
                     NULL, NULL, NULL,
 		    "Parallel", "");
-                setDiagsArea(diagsArea);
 	      }
 	  }
 	break;
@@ -880,16 +873,14 @@ short ExExeUtilFastDeleteTcb::work()
 	    // for parallel purgedata, or because parallel purgedata failed.
 	    if (fdTdb().returnPurgedataWarn())
 	      {
-		ComDiagsArea * diagsArea = getDiagsArea();
 		if (fdTdb().doPurgedataCat())
-                  ExRaiseSqlError(getHeap(), &diagsArea, EXE_PURGEDATA_CAT,
+                  ExRaiseSqlError(getHeap(), &diagsArea_, EXE_PURGEDATA_CAT,
                      NULL, NULL, NULL,
                      "Regular", "Reason: Query or the object did not meet the criteria for parallel purgedata.");
 		else
-                  ExRaiseSqlError(getHeap(), &diagsArea, EXE_PURGEDATA_CAT,
+                  ExRaiseSqlError(getHeap(), &diagsArea_, EXE_PURGEDATA_CAT,
                      NULL, NULL, NULL,
                      "Regular", "Reason: Parallel purgedata failed.");
-                setDiagsArea(diagsArea);
 	      }
 
 	    rc = doPurgedataCat(fdTdb().purgedataStmt());
@@ -1363,7 +1354,7 @@ short ExExeUtilLongRunningTcb::executeLongRunningQuery()
         "control query default HIST_ON_DEMAND_STATS_SIZE '0'");
       if (cliRC < 0) 
         {
-          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+          cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 	  return cliRC;
         }
       
@@ -1372,7 +1363,7 @@ short ExExeUtilLongRunningTcb::executeLongRunningQuery()
       short rtc = processInitial(rc);
       if ((rc != 0) && (rc != 100))
         {
-          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+          cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
         }
 
       cliRC = 
@@ -1380,7 +1371,7 @@ short ExExeUtilLongRunningTcb::executeLongRunningQuery()
             "control query default HIST_ON_DEMAND_STATS_SIZE 'RESET'");
       if (cliRC < 0) 
         {
-          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+          cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 	  return cliRC;
         }
       
@@ -1416,7 +1407,7 @@ short ExExeUtilLongRunningTcb::executeLongRunningQuery()
       short rtc = processContinuing(rc);
       if ((rc != 0) && (rc != 100))
         {
-          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+          cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
         }
 
 #ifdef _DEBUG
@@ -1978,7 +1969,7 @@ short ExExeUtilPopulateInMemStatsTcb::work()
 	    
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = ERROR_;
 	      }
 	    else
@@ -2034,7 +2025,7 @@ short ExExeUtilPopulateInMemStatsTcb::work()
 	    
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = ERROR_;
 	      }
 	    else
@@ -2090,7 +2081,7 @@ short ExExeUtilPopulateInMemStatsTcb::work()
 	    
 	    if (cliRC < 0)
 	      {
-                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+                cliInterface()->allocAndRetrieveSQLDiagnostics(diagsArea_);
 		step_ = ERROR_;
 	      }
 	    else
@@ -2563,11 +2554,9 @@ short ExExeUtilHiveQueryTcb::work()
           {
             if (HiveClient_JNI::executeHiveSQL(htTdb().getHiveQuery()) != HVC_OK)
             {
-                ComDiagsArea * diagsArea = NULL;
-                ExRaiseSqlError(getHeap(), &diagsArea, -1214,
+                ExRaiseSqlError(getHeap(), &diagsArea_, -1214,
                         NULL, NULL, NULL,
                         getSqlJniErrorStr(), htTdb().getHiveQuery()); 
-                setDiagsArea(diagsArea);
                 step_ = ERROR_;
                 break;
             }
@@ -2579,9 +2568,6 @@ short ExExeUtilHiveQueryTcb::work()
           {
             if (handleError())
               return WORK_OK;
-            if (getDiagsArea() != NULL)
-	       getDiagsArea()->clear();
-            
             step_ = DONE_;
           }
           break;

http://git-wip-us.apache.org/repos/asf/trafodion/blob/37702da3/core/sql/executor/ExExeUtilVolTab.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilVolTab.cpp b/core/sql/executor/ExExeUtilVolTab.cpp
index 365b9cd..f3db9d3 100644
--- a/core/sql/executor/ExExeUtilVolTab.cpp
+++ b/core/sql/executor/ExExeUtilVolTab.cpp
@@ -517,9 +517,7 @@ short ExExeUtilCleanupVolatileTablesTcb::work()
 	      {
 		// cannot have a transaction running.
 		// Return error.
-                ComDiagsArea * diagsArea = getDiagsArea();
-                ExRaiseSqlError(getHeap(), &diagsArea, -EXE_BEGIN_TRANSACTION_ERROR);
-                setDiagsArea(diagsArea);
+                ExRaiseSqlError(getHeap(), &diagsArea_, -EXE_BEGIN_TRANSACTION_ERROR);
 		step_ = ERROR_;
 		break;
 	      }
@@ -592,11 +590,9 @@ short ExExeUtilCleanupVolatileTablesTcb::work()
 	      {
 		// add a warning to indicate that some schemas were not
 		// dropped.
-                ComDiagsArea * diagsArea = getDiagsArea();
-                ExRaiseSqlError(getHeap(), &diagsArea, 1069,
+                ExRaiseSqlError(getHeap(), &diagsArea_, 1069,
                        NULL, NULL, NULL,
                        errorSchemas_);
-                setDiagsArea(diagsArea);
 	      }
 	    step_ = CLEANUP_HIVE_TABLES_;
 	  }

http://git-wip-us.apache.org/repos/asf/trafodion/blob/37702da3/core/sql/executor/ExHdfsScan.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExHdfsScan.cpp b/core/sql/executor/ExHdfsScan.cpp
index 91bdc62..f77d714 100644
--- a/core/sql/executor/ExHdfsScan.cpp
+++ b/core/sql/executor/ExHdfsScan.cpp
@@ -124,6 +124,7 @@ ExHdfsScanTcb::ExHdfsScanTcb(
   , hdfsScan_(NULL)
   , hdfsStats_(NULL)
   , hdfsFileInfoListAsArray_(glob->getDefaultHeap(), hdfsScanTdb.getHdfsFileInfoList()->numEntries())
+  , errBuf_(NULL)
   
 {
   Space * space = (glob ? glob->getSpace() : 0);
@@ -317,7 +318,10 @@ void ExHdfsScanTcb::freeResources()
      NADELETE(logFileHdfsClient_, HdfsClient, getHeap());
   if (hdfsScan_ != NULL) 
      NADELETE(hdfsScan_, HdfsScan, getHeap());
+  if (errBuf_ != NULL)
+     NADELETEBASIC(errBuf_, getHeap());
 }
+
 NABoolean ExHdfsScanTcb::needStatsEntry()
 {
   // stats are collected for ALL and OPERATOR options.
@@ -778,14 +782,16 @@ ExWorkProcRetcode ExHdfsScanTcb::work()
                     ComDiagsArea * diagsArea = NULL;
                     if (hdfsErrorDetail == ENOENT)
                       {
-                        char errBuf[strlen(hdfsScanTdb().tableName()) + 
-                                    strlen(hdfsFileName_) + 100];
-                        snprintf(errBuf, sizeof(errBuf),"%s (fileLoc: %s)",
+                        if (errBuf_ != NULL)
+                           NADELETEBASIC(errBuf_, getHeap());
+                        Lng32 len = strlen(hdfsScanTdb().tableName()) + strlen(hdfsFileName_) + 100;
+                           errBuf_ = new (getHeap()) char[len];
+                        snprintf(errBuf_, len, "%s (fileLoc: %s)",
                                  hdfsScanTdb().tableName(), hdfsFileName_);
                         ExRaiseSqlError(getHeap(), &diagsArea, 
                                       (ExeErrorCode)(EXE_TABLE_NOT_FOUND), NULL,
                                       NULL, NULL, NULL,
-                                      errBuf);
+                                      errBuf_);
                       }
                     else
                       ExRaiseSqlError(getHeap(), &diagsArea, 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/37702da3/core/sql/executor/ExHdfsScan.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExHdfsScan.h b/core/sql/executor/ExHdfsScan.h
index aa01b6e..c11329f 100644
--- a/core/sql/executor/ExHdfsScan.h
+++ b/core/sql/executor/ExHdfsScan.h
@@ -376,6 +376,7 @@ protected:
   int prevRangeNum_;
   int extraBytesRead_;
   NABoolean recordSkip_;
+  char *errBuf_;
 };
 
 class ExOrcScanTcb  : public ExHdfsScanTcb

http://git-wip-us.apache.org/repos/asf/trafodion/blob/37702da3/core/sql/sqlcomp/CmpDescribe.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpDescribe.cpp b/core/sql/sqlcomp/CmpDescribe.cpp
index 1aef61a..1cd7aff 100644
--- a/core/sql/sqlcomp/CmpDescribe.cpp
+++ b/core/sql/sqlcomp/CmpDescribe.cpp
@@ -633,8 +633,8 @@ short CmpDescribe(const char *query, const RelExpr *queryExpr,
               CmpCommon::diags()->clear();
 
               *CmpCommon::diags() << DgSqlCode(-CAT_SCHEMA_DOES_NOT_EXIST_ERROR)
-                                  << DgSchemaName(objQualName.getCatalogName() +
-                                                  "." +  objQualName.getSchemaName());
+                                  << DgString0(objQualName.getCatalogName())
+                                  << DgString1(objQualName.getSchemaName());
 
               rc = -1;
               goto finally;

http://git-wip-us.apache.org/repos/asf/trafodion/blob/37702da3/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
index 6fc1863..b5db51b 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
@@ -4505,7 +4505,8 @@ void CmpSeabaseDDL::handleDDLCreateAuthorizationError(
       case CAT_SCHEMA_DOES_NOT_EXIST_ERROR:
       {
          *CmpCommon::diags() << DgSqlCode(-CAT_SCHEMA_DOES_NOT_EXIST_ERROR)
-                             << DgSchemaName(catalogName + "." + schemaName);
+                                  << DgString0(catalogName)
+                                  << DgString1(schemaName);
          break;
       }
       case CAT_NOT_AUTHORIZED:

http://git-wip-us.apache.org/repos/asf/trafodion/blob/37702da3/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp b/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
index dcc7971..1bfe3cd 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
@@ -410,7 +410,8 @@ Int64 schemaUID = getObjectTypeandOwner(&cliInterface,
  if (schemaUID < 0)
    {
       *CmpCommon::diags() << DgSqlCode(-CAT_SCHEMA_DOES_NOT_EXIST_ERROR)
-                          << DgSchemaName(catalogName + "." + schemaName);
+                                  << DgString0(catalogName)
+                                  << DgString1(schemaName);
       cmpSBD.switchBackCompiler();
       return false;
    }
@@ -547,7 +548,8 @@ void CmpSeabaseDDL::dropSeabaseSchema(StmtDDLDropSchema * dropSchemaNode)
       // A Trafodion schema does not exist if the schema object row is not
       // present: CATALOG-NAME.SCHEMA-NAME.__SCHEMA__.
       *CmpCommon::diags() << DgSqlCode(-CAT_SCHEMA_DOES_NOT_EXIST_ERROR)
-                          << DgSchemaName(schemaName.getExternalName().data());
+                                  << DgString0(catName.data())
+                                  << DgString1(schName.data());
       goto label_error;
    }
 
@@ -1107,7 +1109,8 @@ void CmpSeabaseDDL::alterSeabaseSchema(StmtDDLAlterSchema * alterSchemaNode)
       // A Trafodion schema does not exist if the schema object row is not
       // present: CATALOG-NAME.SCHEMA-NAME.__SCHEMA__.
       *CmpCommon::diags() << DgSqlCode(-CAT_SCHEMA_DOES_NOT_EXIST_ERROR)
-                          << DgSchemaName(schemaName.getExternalName().data());
+                                  << DgString0(catName.data())
+                                  << DgString1(schName.data());
       goto label_error;
    }
 
@@ -1337,7 +1340,8 @@ Int64 schemaUID = getObjectTypeandOwner(&cliInterface,catalogName.data(),
       // A Trafodion schema does not exist if the schema object row is not
       // present: CATALOG-NAME.SCHEMA-NAME.__SCHEMA__.
       *CmpCommon::diags() << DgSqlCode(-CAT_SCHEMA_DOES_NOT_EXIST_ERROR)
-                          << DgSchemaName(schemaName.data());
+                                  << DgString0(catalogName.data())
+                                  << DgString1(schemaName.data());
       return;
    }
    


[2/7] trafodion git commit: [TRAFODION-3009] Streamline error handling in Executor utility commands

Posted by se...@apache.org.
[TRAFODION-3009] Streamline error handling in Executor utility commands

ComDiagsArea is now allocated only when there are warnings or error in
all the utility commands except load. In case of load, the ComDiagsArea
is allocated in advance to report error rows count.

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

[TRAFODION-3017] Simplify the hive client access in Trafodion

Hive Client functions are now moved to a new file HiveClient_JNI.h and
HiveClient_JNI.cpp. Most of the HiveClient functions are static functions
allowing to use HiveClient in Trafodion with ease.


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

Branch: refs/heads/master
Commit: 1f44166c843fd1a6e8b325a2fcbe0cf8158e099b
Parents: 659e8ec
Author: selvaganesang <se...@esgyn.com>
Authored: Thu Mar 29 00:13:15 2018 +0000
Committer: selvaganesang <se...@esgyn.com>
Committed: Tue Apr 3 01:16:37 2018 +0000

----------------------------------------------------------------------
 core/sql/arkcmp/CmpContext.cpp                  |  52 --
 core/sql/arkcmp/CmpContext.h                    |   3 -
 core/sql/cli/Context.cpp                        |   8 +-
 core/sql/cli/Globals.cpp                        |   2 +-
 core/sql/executor/ExExeUtil.h                   |   8 +-
 core/sql/executor/ExExeUtilCli.cpp              |  81 ++--
 core/sql/executor/ExExeUtilCli.h                |  14 +-
 core/sql/executor/ExExeUtilCommon.cpp           |  24 +-
 core/sql/executor/ExExeUtilExplain.cpp          |  38 +-
 core/sql/executor/ExExeUtilGet.cpp              | 171 +++----
 core/sql/executor/ExExeUtilGetStats.cpp         |   9 +-
 core/sql/executor/ExExeUtilLoad.cpp             | 157 +++---
 core/sql/executor/ExExeUtilMisc.cpp             | 156 +++---
 core/sql/executor/ExExeUtilVolTab.cpp           |  33 +-
 core/sql/executor/ExHdfsScan.cpp                |   3 +-
 core/sql/executor/HBaseClient_JNI.cpp           | 472 ------------------
 core/sql/executor/HBaseClient_JNI.h             |  91 +---
 core/sql/executor/HdfsClient_JNI.cpp            |   2 +-
 core/sql/executor/HiveClient_JNI.cpp            | 473 +++++++++++++++++++
 core/sql/executor/HiveClient_JNI.h              | 106 +++++
 core/sql/executor/JavaObjectInterface.cpp       |   2 +-
 core/sql/executor/ex_root.cpp                   |  20 -
 core/sql/executor/hiveHook.cpp                  |  60 +--
 core/sql/exp/ExpError.cpp                       |  14 +
 core/sql/exp/ExpError.h                         |   9 +
 core/sql/exp/ExpHbaseInterface.h                |   1 +
 core/sql/nskgmake/executor/Makefile             |   1 +
 core/sql/optimizer/NATable.cpp                  |   2 +-
 core/sql/optimizer/NormRelExpr.cpp              |   5 +-
 core/sql/optimizer/OptimizerSimulator.cpp       |  47 +-
 core/sql/optimizer/hiveHook.h                   |  11 -
 core/sql/sqlcomp/PrivMgrComponentPrivileges.cpp |   5 +-
 core/sql/sqlcomp/PrivMgrMDTable.cpp             |   4 +-
 .../main/java/org/trafodion/sql/HiveClient.java |  95 ++--
 34 files changed, 1040 insertions(+), 1139 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/arkcmp/CmpContext.cpp
----------------------------------------------------------------------
diff --git a/core/sql/arkcmp/CmpContext.cpp b/core/sql/arkcmp/CmpContext.cpp
index 4599508..78c3c63 100644
--- a/core/sql/arkcmp/CmpContext.cpp
+++ b/core/sql/arkcmp/CmpContext.cpp
@@ -524,58 +524,6 @@ NABoolean CmpContext::isAuthorizationEnabled( NABoolean errIfNotReady)
   return FALSE;
 }
 
-HiveClient_JNI * CmpContext::getHiveClient(ComDiagsArea *diags)
-{
-  if(NULL == hiveClient_)
-    {
-        hiveClient_ = HiveClient_JNI::getInstance();
-        if ( hiveClient_->isInitialized() == FALSE ||
-             hiveClient_->isConnected() == FALSE)
-        {
-            HVC_RetCode retCode = hiveClient_->init();
-            if (retCode != HVC_OK)
-            {
-              hiveClient_ = NULL;
-            }
-        }  
-    }
-
-  if (hiveClient_ == NULL && diags)
-    *diags << DgSqlCode(-1213);
-
-  return hiveClient_;
-}
-
-NABoolean CmpContext::execHiveSQL(const char* hiveSQL, ComDiagsArea *diags)
-{
-  NABoolean result = FALSE;
-
-  if (!hiveClient_)
-    getHiveClient(diags);
-
-  if (hiveClient_)
-    {
-      HVC_RetCode retcode = hiveClient_->executeHiveSQL(hiveSQL);
-
-      switch (retcode)
-        {
-        case HVC_OK:
-          result = TRUE;
-          break;
-
-        default:
-          result = FALSE;
-        }
-
-      if (!result && diags)
-        *diags << DgSqlCode(-1214)
-               << DgString0(GetCliGlobals()->getJniErrorStr())
-               << DgString1(hiveSQL);
-    }
-
-  return result;
-}
-
 // -----------------------------------------------------------------------
 // The CmpStatement related methods
 // -----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/arkcmp/CmpContext.h
----------------------------------------------------------------------
diff --git a/core/sql/arkcmp/CmpContext.h b/core/sql/arkcmp/CmpContext.h
index eceb9c1..135cb7e 100644
--- a/core/sql/arkcmp/CmpContext.h
+++ b/core/sql/arkcmp/CmpContext.h
@@ -283,9 +283,6 @@ public :
   
   UInt32 getStatementNum() const { return statementNum_; }
 
-  HiveClient_JNI *getHiveClient(ComDiagsArea *diags = NULL);
-  NABoolean execHiveSQL(const char* hiveSQL, ComDiagsArea *diags = NULL);
-
   // access the NAHeap* for context
   NAHeap* statementHeap();
   NAHeap* heap() { return heap_; }

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/cli/Context.cpp
----------------------------------------------------------------------
diff --git a/core/sql/cli/Context.cpp b/core/sql/cli/Context.cpp
index ab84711..bfb043f 100644
--- a/core/sql/cli/Context.cpp
+++ b/core/sql/cli/Context.cpp
@@ -96,6 +96,7 @@
 #include "HBaseClient_JNI.h"
 #include "ComDistribution.h"
 #include "LmRoutine.h"
+#include "HiveClient_JNI.h"
 
 // Printf-style tracing macros for the debug build. The macros are
 // no-ops in the release build.
@@ -294,14 +295,14 @@ ContextCli::~ContextCli()
 
 void ContextCli::deleteMe()
 {
-  ComDiagsArea & diags = cliGlobals_->currContext()->diags();
+  ComDiagsArea *diags = NULL;
 
   if (volatileSchemaCreated())
     {
       // drop volatile schema, if one exists
       short rc =
         ExExeUtilCleanupVolatileTablesTcb::dropVolatileSchema
-        (this, NULL, exCollHeap());
+        (this, NULL, exCollHeap(), diags);
       SQL_EXEC_ClearDiagnostics(NULL);
       
       rc =
@@ -2902,10 +2903,11 @@ void ContextCli::endSession(NABoolean cleanupEsps,
 void ContextCli::dropSession(NABoolean clearCmpCache)
 {
   short rc = 0;
+  ComDiagsArea *diags = NULL;
   if (volatileSchemaCreated_)
     {
       rc = ExExeUtilCleanupVolatileTablesTcb::dropVolatileSchema
-        (this, NULL, exHeap());
+        (this, NULL, exHeap(), diags);
       SQL_EXEC_ClearDiagnostics(NULL);
     }
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/cli/Globals.cpp
----------------------------------------------------------------------
diff --git a/core/sql/cli/Globals.cpp b/core/sql/cli/Globals.cpp
index 3eb4502..f716345 100644
--- a/core/sql/cli/Globals.cpp
+++ b/core/sql/cli/Globals.cpp
@@ -61,11 +61,11 @@
 #include <pthread.h>
 #include "HBaseClient_JNI.h"
 #include "HdfsClient_JNI.h"
+#include "HiveClient_JNI.h"
 #include "LmLangManagerC.h"
 #include "LmLangManagerJava.h"
 #include "CliSemaphore.h"
 
-
 #include "ExCextdecs.h"
 CliGlobals * cli_globals = NULL;
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/ExExeUtil.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtil.h b/core/sql/executor/ExExeUtil.h
index 85173c8..46349d9 100644
--- a/core/sql/executor/ExExeUtil.h
+++ b/core/sql/executor/ExExeUtil.h
@@ -270,7 +270,7 @@ class ExExeUtilTcb : public ex_tcb
   ExeCliInterface * cliInterface() { return cliInterface_; };
   ExeCliInterface * cliInterface2() { return cliInterface2_; };
 
-  ComDiagsArea * getDiagsArea() { return diagsArea_; }
+  ComDiagsArea *&getDiagsArea() { return diagsArea_; }
 
   void setDiagsArea(ComDiagsArea * d) { diagsArea_ = d; }
 
@@ -1020,10 +1020,10 @@ class ExExeUtilCleanupVolatileTablesTcb : public ExExeUtilVolatileTablesTcb
   static short dropVolatileSchema(ContextCli * currContext,
                                   char * schemaName,
                                   CollHeap * heap,
-                                  ex_globals *globals = NULL,
-                                  ComDiagsArea * diagsArea = NULL);
+                                  ComDiagsArea *&diagsArea,
+                                  ex_globals *globals = NULL);
   static short dropVolatileTables(ContextCli * currContext, CollHeap * heap);
-  short dropHiveTempTablesForCSEs(ComDiagsArea * diagsArea = NULL);
+  short dropHiveTempTablesForCSEs();
 
  private:
   enum Step

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/ExExeUtilCli.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilCli.cpp b/core/sql/executor/ExExeUtilCli.cpp
index be80cf7..dc9c4e2 100644
--- a/core/sql/executor/ExExeUtilCli.cpp
+++ b/core/sql/executor/ExExeUtilCli.cpp
@@ -219,7 +219,6 @@ Lng32 ExeCliInterface::allocStuff(SQLMODULE_ID * &module,
   )
 {
   Lng32 retcode = 0;
-
   deallocStuff(module, stmt, sql_src, input_desc, output_desc);
 
   clearGlobalDiags();
@@ -926,6 +925,8 @@ Lng32 ExeCliInterface::close()
   return retcode;
 }
 
+
+
 Lng32 ExeCliInterface::executeImmediatePrepare(const char * stmtStr,
 					       char * outputBuf,
 					       Lng32 * outputBufLen,
@@ -935,7 +936,6 @@ Lng32 ExeCliInterface::executeImmediatePrepare(const char * stmtStr,
 					      )
 {
   Lng32 retcode = 0;
-
   if (outputBufLen)
     *outputBufLen = 0;
 
@@ -993,8 +993,7 @@ Lng32 ExeCliInterface::executeImmediateExec(const char * stmtStr,
 					   Lng32 * outputBufLen,
 					   NABoolean nullTerminate,
 					   Int64 * rowsAffected,
-                                           ComDiagsArea *diagsArea
-					   )
+                                           ComDiagsArea *diagsArea)
 {
   Lng32 retcode = 0;
 
@@ -1050,7 +1049,6 @@ Lng32 ExeCliInterface::executeImmediateExec(const char * stmtStr,
   }
   if (diagsArea != NULL) 
      retcode = SQL_EXEC_MergeDiagnostics_Internal(*diagsArea);
-
   clearGlobalDiags();
 
   retcode = close();
@@ -1070,35 +1068,31 @@ Lng32 ExeCliInterface::executeImmediate(const char * stmtStr,
 				       NABoolean nullTerminate,
 				       Int64 * rowsAffected,
 				       NABoolean monitorThis,
-				       ComDiagsArea * globalDiags
-				       )
+				       ComDiagsArea *globalDiags)
 {
   Lng32 retcode = 0;
 
   ComDiagsArea * tempDiags = NULL;
   if (globalDiags)
-    {
-      tempDiags = ComDiagsArea::allocate(heap_);
-      tempDiags->mergeAfter(*globalDiags);
-    }
+  {
+     tempDiags = ComDiagsArea::allocate(heap_);
+     tempDiags->mergeAfter(*globalDiags);
+  }
 
   clearGlobalDiags();
-
   outputBuf_ = NULL;
   inputBuf_ = NULL;
   retcode = executeImmediatePrepare(stmtStr, 
 				    (nullTerminate ? outputBuf_ : outputBuf),
 				    outputBufLen,
 				    rowsAffected,monitorThis);
-  if (retcode < 0)
-    goto ExecuteImmediateReturn;
-
+  if (retcode < 0) 
+     goto ExecuteImmediateReturn;
   retcode = executeImmediateExec(stmtStr, 
 				 outputBuf, outputBufLen,
 				 nullTerminate,
 				 rowsAffected,
                                  globalDiags);
-
 ExecuteImmediateReturn:
   if ((globalDiags) && (tempDiags))
     {
@@ -1110,8 +1104,7 @@ ExecuteImmediateReturn:
       tempDiags->clear();
       tempDiags->deAllocate();
     }
-
-  return retcode;
+   return retcode;
 }
 
 short ExeCliInterface::fetchRowsPrologue(const char * sqlStrBuf, 
@@ -1439,6 +1432,7 @@ Lng32 ExeCliInterface::executeImmediateCEFC(const char * stmtStr,
 {
   Lng32 retcode = 0;
 
+
   clearGlobalDiags();
 
   outputBuf_ = NULL;
@@ -1821,7 +1815,6 @@ short ExeCliInterface::prepareAndExecRowsPrologue(const char * sqlInitialStrBuf,
   Lng32 retcode = 0;
   
   SQL_EXEC_ClearDiagnostics(NULL);
-
   retcode = allocStuff(module_, stmt_, sql_src_, input_desc_, output_desc_);
   if (retcode < 0)
     return (short)retcode;
@@ -2091,27 +2084,57 @@ Lng32 ExeCliInterface::deleteContext(char* contextHandle) // in buf contains con
 Lng32 ExeCliInterface::retrieveSQLDiagnostics(ComDiagsArea *toDiags)
 {
   Lng32 retcode;
-
+  ex_assert(toDiags != NULL, "ComDiagsArea is null");
   if (diagsArea_ != NULL)
     {
       diagsArea_->clear();
       diagsArea_->deAllocate();
     }
+  retcode = SQL_EXEC_MergeDiagnostics_Internal(*toDiags);
+  SQL_EXEC_ClearDiagnostics(NULL);
+  return retcode;
+}
 
-  if (toDiags != NULL)
-    {
-      retcode = SQL_EXEC_MergeDiagnostics_Internal(*toDiags);
-      SQL_EXEC_ClearDiagnostics(NULL);
-    }
-  else
+
+ComDiagsArea *ExeCliInterface::allocAndRetrieveSQLDiagnostics(ComDiagsArea *&toDiags)
+{
+  Lng32 retcode;
+
+  if (diagsArea_ != NULL)
     {
-      diagsArea_ = ComDiagsArea::allocate(heap_);
-      retcode = SQL_EXEC_MergeDiagnostics_Internal(*diagsArea_);
+      diagsArea_->clear();
+      diagsArea_->deAllocate();
     }
+  if (toDiags == NULL)
+      toDiags = ComDiagsArea::allocate(heap_);
 
-  return retcode;
+  retcode = SQL_EXEC_MergeDiagnostics_Internal(*toDiags);
+  SQL_EXEC_ClearDiagnostics(NULL);
+ 
+  if (retcode == 0)
+     return toDiags;
+  else
+     return NULL;
 }
 
+void ExeCliInterface::retrieveOrSaveSQLDiagnostics(Lng32 cliRetcode, ComDiagsArea *diagsArea)
+{
+    Int32 rc;
+    Int32 diagsCondCount = 0;
+    rc = SQL_EXEC_GetDiagnosticsStmtInfo2(stmt_,
+                           SQLDIAG_NUMBER, &diagsCondCount,
+                           NULL, 0, NULL);
+    if (cliRetcode == 100)   
+       diagsCondCount--;
+    if (diagsCondCount > 0) { 
+       if (diagsArea == NULL) {
+          if (diagsArea_ == NULL) 
+             diagsArea_ = ComDiagsArea::allocate(heap_);
+          diagsArea = diagsArea_;
+       } 
+       SQL_EXEC_MergeDiagnostics_Internal(*diagsArea);
+    }
+}
 
 Lng32 ExeCliInterface::GetRowsAffected(Int64 *rowsAffected)
 {

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/ExExeUtilCli.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilCli.h b/core/sql/executor/ExExeUtilCli.h
index 8c1aa9b..ce33de4 100644
--- a/core/sql/executor/ExExeUtilCli.h
+++ b/core/sql/executor/ExExeUtilCli.h
@@ -76,7 +76,7 @@ private:
 			 NABoolean nullTerminate = TRUE,
 			 Int64 * rowsAffected = NULL,
 			 NABoolean monitorThis = FALSE,
-			 ComDiagsArea * globalDiags = NULL);
+			 ComDiagsArea *globalDiags = NULL);
 
   Lng32 executeImmediatePrepare(const char * stmt,
 				char * outputBuf = NULL,
@@ -246,6 +246,8 @@ private:
   Lng32 deleteContext(char* contextHandle); // in buf contains context handle
 
   Lng32 retrieveSQLDiagnostics(ComDiagsArea *toDiags);
+  ComDiagsArea *allocAndRetrieveSQLDiagnostics(ComDiagsArea *&toDiags);
+  void retrieveOrSaveSQLDiagnostics(Lng32 cliRetCode, ComDiagsArea *toDiags);
 
   CollHeap * getHeap() { return heap_; }
 
@@ -264,19 +266,19 @@ 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 holdAndSetCQD(const char * defaultName, const char * defaultValue, ComDiagsArea *globalDiags = NULL);
+  Lng32 restoreCQD(const char * defaultName, ComDiagsArea *globalDiags = NULL);
 
   Lng32 getCQDval(const char * defaultName,
 		  char * val,
-		  ComDiagsArea * globalDiags = NULL);
+		  ComDiagsArea *globalDiags = NULL);
 
   void setNotExeUtilInternalQuery(NABoolean v)
     {(v ? flags_ |= NOT_EXEUTIL_INTERNAL_QUERY : flags_ &= ~NOT_EXEUTIL_INTERNAL_QUERY); };
   NABoolean notExeUtilInternalQuery() { return (flags_ & NOT_EXEUTIL_INTERNAL_QUERY) != 0; };
 
-  Lng32 setCQS(const char * shape, ComDiagsArea * globalDiags = NULL);
-  Lng32 resetCQS(ComDiagsArea * globalDiags = NULL);
+  Lng32 setCQS(const char * shape, ComDiagsArea *globalDiags = NULL);
+  Lng32 resetCQS(ComDiagsArea *globalDiags = NULL);
 
   // methods for routine invocation
   Lng32 getRoutine(

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/ExExeUtilCommon.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilCommon.cpp b/core/sql/executor/ExExeUtilCommon.cpp
index 6f3cb26..09f7126 100644
--- a/core/sql/executor/ExExeUtilCommon.cpp
+++ b/core/sql/executor/ExExeUtilCommon.cpp
@@ -202,10 +202,10 @@ ExExeUtilTcb::ExExeUtilTcb(const ComTdbExeUtil & exe_util_tdb,
 					     SQLCHARSETCODE_ISO88591,  // ISO_MAPPING=ISO88591
 					     currContext,
 					     parentQid);
-  
-  //diagsArea_ = NULL;
-  setDiagsArea(ComDiagsArea::allocate(getHeap()));
 
+  diagsArea_ = NULL;
+  //setDiagsArea(ComDiagsArea::allocate(getHeap()));
+  
   pqStep_ = PROLOGUE_;
 
   VersionToString(COM_VERS_MXV, versionStr_);
@@ -462,8 +462,8 @@ Lng32 ExExeUtilTcb::changeAuditAttribute(char * tableName,
 }
 
 void ExExeUtilTcb::handleErrors(Lng32 rc)
-{
-  cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+{ 
+  setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 }
 
 short ExExeUtilTcb::initializeInfoList(Queue* &infoList)
@@ -669,7 +669,9 @@ short ExExeUtilTcb::executeQuery(char * task,
 	    char * stringParam1 = NULL;
 	    Lng32   intParam1 = ComDiags_UnInitialized_Int;
 
-	    retcode = (short)cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+            setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
+            if (getDiagsArea() != NULL)
+	        retcode = 0;
 	    if (moveErrorRow)
 	      {
 		if (retcode == 0)
@@ -770,7 +772,6 @@ short ExExeUtilTcb::holdAndSetCQD(const char * defaultName, const char * default
   if (cliRC < 0)
     {
       handleErrors(cliRC);
-
       return -1;
     }
 
@@ -785,7 +786,6 @@ short ExExeUtilTcb::restoreCQD(const char * defaultName, ComDiagsArea * globalDi
   if (cliRC < 0)
     {
       handleErrors(cliRC);
-
       return -1;
     }
 
@@ -822,7 +822,6 @@ short ExExeUtilTcb::setCS(const char * csName, char * csValue,
   if (cliRC < 0)
     {
       handleErrors(cliRC);
-
       return -1;
     }
 
@@ -837,7 +836,6 @@ short ExExeUtilTcb::resetCS(const char * csName, ComDiagsArea * globalDiags)
   if (cliRC < 0)
     {
       handleErrors(cliRC);
-
       return -1;
     }
 
@@ -898,7 +896,6 @@ short ExExeUtilTcb::disableCQS()
   if (rc < 0)
     {
       handleErrors(rc);
-
       return -1;
     }
 
@@ -912,7 +909,6 @@ short ExExeUtilTcb::restoreCQS()
   if (rc < 0)
     {
       handleErrors(rc);
-
       return -1;
     }
 
@@ -1056,7 +1052,7 @@ short ExExeUtilTcb::setSystemVersion()
 					 sysVersionStr_, &sysVersionStrLen_);
       if (cliRC < 0)
 	{
-	  cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 	  return -1;
 	}
       
@@ -1125,7 +1121,7 @@ short ExExeUtilTcb::getObjectUid(char * catName, char * schName,
 				     uid, &uidLen);
   if (cliRC < 0)
     {
-      cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+      setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
       return -1;
     }
   uid[uidLen] = 0;

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/ExExeUtilExplain.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilExplain.cpp b/core/sql/executor/ExExeUtilExplain.cpp
index cb7241f..7d9f99c 100644
--- a/core/sql/executor/ExExeUtilExplain.cpp
+++ b/core/sql/executor/ExExeUtilExplain.cpp
@@ -237,8 +237,7 @@ short ExExeUtilDisplayExplainTcb::work()
 	      executeImmediate("control session 'EXPLAIN' 'ON';");
 	    if (retcode < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		pstate.step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -250,8 +249,7 @@ short ExExeUtilDisplayExplainTcb::work()
 					 "__EXPL_STMT_NAME__");
 	    if (retcode < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		pstate.step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -274,8 +272,7 @@ short ExExeUtilDisplayExplainTcb::work()
 	    
 	    if (retcode < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		pstate.step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -365,8 +362,7 @@ short ExExeUtilDisplayExplainTcb::work()
 	    retcode = cliInterface()->fetchRowsPrologue(explainQuery_);
 	    if (retcode < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		pstate.step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -393,8 +389,7 @@ short ExExeUtilDisplayExplainTcb::work()
 	    retcode = cliInterface()->fetch();
 	    if (retcode < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		pstate.step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -457,8 +452,7 @@ short ExExeUtilDisplayExplainTcb::work()
 	    retcode = cliInterface()->fetch();
 	    if (retcode < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		pstate.step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -573,7 +567,7 @@ short ExExeUtilDisplayExplainTcb::work()
 	    retcode = cliInterface()->fetchRowsEpilogue(explainQuery_);
 	    if (retcode < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 	      }
 	    
 	    retcode = 
@@ -581,7 +575,7 @@ short ExExeUtilDisplayExplainTcb::work()
 					   input_desc_, output_desc_);
 	    if (retcode < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 	      }
 
 	    if (exeUtilTdb().getStmtName() == NULL)
@@ -599,7 +593,7 @@ short ExExeUtilDisplayExplainTcb::work()
 	      executeImmediate("control session reset 'EXPLAIN';");
 	    if (retcode < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 	      }
 	    
 	    if (pstate.step_ == FETCH_EPILOGUE_AND_RETURN_ERROR_)
@@ -3922,7 +3916,7 @@ short ExExeUtilDisplayExplainComplexTcb::work()
 		// Explain will return 'info not available' in its
 		// description field.
 		// All other errors are reported.
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		if (exeUtilTdb().loadIfExists() &&
 		     getDiagsArea()->contains(-1055))
 		  {
@@ -3992,8 +3986,7 @@ short ExExeUtilDisplayExplainComplexTcb::work()
 					 FALSE, exeUtilTdb().isVolatile());
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-		
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = DROP_AND_ERROR_;
 		break;
 	      }
@@ -4217,8 +4210,7 @@ short ExExeUtilDisplayExplainShowddlTcb::work()
 
 		if (cliRC < 0)
 		  {
-		    cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-		    
+                    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		    step_ = ERROR_;
 		    break;
 		  }
@@ -4234,8 +4226,7 @@ short ExExeUtilDisplayExplainShowddlTcb::work()
 
 		if (cliRC < 0)
 		  {
-		    cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-		    
+                    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		    step_ = ERROR_;
 		    break;
 		  }
@@ -4260,8 +4251,7 @@ short ExExeUtilDisplayExplainShowddlTcb::work()
 
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = ERROR_;
 		break;
 	      }

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/ExExeUtilGet.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilGet.cpp b/core/sql/executor/ExExeUtilGet.cpp
index ff40c40..2ce8607 100644
--- a/core/sql/executor/ExExeUtilGet.cpp
+++ b/core/sql/executor/ExExeUtilGet.cpp
@@ -71,6 +71,7 @@
 #include "sql_buffer_size.h"
 
 #include "NAType.h"
+#include "HiveClient_JNI.h"
 
 //******************************************************************************
 //                                                                             *
@@ -688,8 +689,7 @@ Lng32 ExExeUtilGetMetadataInfoTcb::getUsingView(Queue * infoList,
 	    cliRC = cliInterface()->fetchRowsPrologue(query);
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		vStep_ = VIEWS_ERROR_;
 		break;
 	      }
@@ -703,8 +703,7 @@ Lng32 ExExeUtilGetMetadataInfoTcb::getUsingView(Queue * infoList,
 	    cliRC = cliInterface()->fetch();
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		vStep_ = VIEWS_ERROR_;
 		break;
 	      }
@@ -732,8 +731,7 @@ Lng32 ExExeUtilGetMetadataInfoTcb::getUsingView(Queue * infoList,
 	    cliRC = cliInterface()->fetchRowsEpilogue(0);
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		vStep_ = VIEWS_ERROR_;
 		break;
 	      }
@@ -847,8 +845,7 @@ Lng32 ExExeUtilGetMetadataInfoTcb::getUsedObjects(Queue * infoList,
 	    cliRC = cliInterface()->fetchRowsPrologue(query);
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		vStep_ = VIEWS_ERROR_;
 		break;
 	      }
@@ -862,8 +859,7 @@ Lng32 ExExeUtilGetMetadataInfoTcb::getUsedObjects(Queue * infoList,
 	    cliRC = cliInterface()->fetch();
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		vStep_ = VIEWS_ERROR_;
 		break;
 	      }
@@ -891,8 +887,7 @@ Lng32 ExExeUtilGetMetadataInfoTcb::getUsedObjects(Queue * infoList,
 	    cliRC = cliInterface()->fetchRowsEpilogue(0);
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		vStep_ = VIEWS_ERROR_;
 		break;
 	      }
@@ -1424,7 +1419,7 @@ Int32 ExExeUtilGetMetadataInfoTcb::getAuthID(
   cliRC = fetchAllRows(infoList_, queryBuf_, numOutputEntries_, FALSE, rc);
   if (cliRC < 0) 
   {
-    cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
     return NA_UserIdDefault;
   }
 
@@ -1498,7 +1493,7 @@ char * ExExeUtilGetMetadataInfoTcb::getRoleList(
   cliRC = fetchAllRows(infoList_, queryBuf_, numOutputEntries_, FALSE, rc);
   if (cliRC < 0)
   {
-    cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
     return NULL;
   }
 
@@ -1818,8 +1813,9 @@ short ExExeUtilGetMetadataInfoTcb::work()
 	    {
                if (!CmpCommon::context()->isAuthorizationEnabled())
                {
-                  ComDiagsArea * diags = getDiagsArea();
-                  *diags << DgSqlCode(-CAT_AUTHORIZATION_NOT_ENABLED);
+                  ComDiagsArea * diagsArea = getDiagsArea();
+                  ExRaiseSqlError(getHeap(), &diagsArea, -CAT_AUTHORIZATION_NOT_ENABLED);
+                  setDiagsArea(diagsArea);
                   step_ = HANDLE_ERROR_;
                   break;
                }
@@ -2277,9 +2273,11 @@ short ExExeUtilGetMetadataInfoTcb::work()
                   // easier to just return with an error.
                   if (authID == 0)
                     { 
-                      ComDiagsArea * diags = getDiagsArea();
-                      *diags << DgSqlCode(-8732)
-                             << DgString0(getMItdb().getParam1());
+                      ComDiagsArea * diagsArea = getDiagsArea();
+                      ExRaiseSqlError(getHeap(), &diagsArea, -8732,
+                          NULL, NULL, NULL,
+                          getMItdb().getParam1());
+                      setDiagsArea(diagsArea);
                       step_ = HANDLE_ERROR_;
                       break;
                     }
@@ -2290,9 +2288,11 @@ short ExExeUtilGetMetadataInfoTcb::work()
                        // error if authID is not a role
                        if (!CmpSeabaseDDLauth::isRoleID(authID) && authID != PUBLIC_USER)
                         {
-                          ComDiagsArea * diags = getDiagsArea();
-                          *diags << DgSqlCode(-CAT_IS_NOT_A_ROLE)
-                                 << DgString0(getMItdb().getParam1());
+                          ComDiagsArea * diagsArea = getDiagsArea();
+                          ExRaiseSqlError(getHeap(), &diagsArea, -CAT_IS_NOT_A_ROLE, 
+                              NULL, NULL, NULL,
+                              getMItdb().getParam1());
+                          setDiagsArea(diagsArea);
                           step_ = HANDLE_ERROR_;
                           break;
                         }
@@ -2303,9 +2303,11 @@ short ExExeUtilGetMetadataInfoTcb::work()
                       // Return an error if authID is not a user
                       if (!CmpSeabaseDDLauth::isUserID(authID))
                         {
-                          ComDiagsArea * diags = getDiagsArea();
-                          *diags << DgSqlCode(-CAT_IS_NOT_A_USER)
-                                 << DgString0(getMItdb().getParam1());
+                          ComDiagsArea * diagsArea = getDiagsArea();
+                          ExRaiseSqlError(getHeap(), &diagsArea, -CAT_IS_NOT_A_USER, 
+                              NULL, NULL, NULL,
+                              getMItdb().getParam1());
+                          setDiagsArea(diagsArea);
                           step_ = HANDLE_ERROR_;
                           break;
                         }
@@ -2634,10 +2636,8 @@ short ExExeUtilGetMetadataInfoTcb::work()
 	    if (fetchAllRows(infoList_, queryBuf_, numOutputEntries_,
 			     FALSE, retcode) < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = HANDLE_ERROR_;
-
 		break;
 	      }
 
@@ -3227,14 +3227,14 @@ short ExExeUtilGetMetadataInfoComplexTcb::work()
 	    if (fetchAllRows(infoList_, queryBuf_, 1, FALSE, retcode) < 0)
 	      {
                 // if error is 4222 (command not supported), ignore it.
-                if (getDiagsArea()->mainSQLCODE() != -4222)
-                  {
+                if (getDiagsArea() != NULL) {
+                   if (getDiagsArea()->mainSQLCODE() != -4222)
+                   {
                     step_ = HANDLE_ERROR_;
-                    
                     break;
                   }
-
-                getDiagsArea()->clear();
+                  getDiagsArea()->clear();
+                }
 	      }
 
 	    // insert a NULL entry, this will cause a blank row to be returned
@@ -3252,14 +3252,15 @@ short ExExeUtilGetMetadataInfoComplexTcb::work()
 	    if (fetchAllRows(infoList_, queryBuf_, 1, FALSE, retcode) < 0)
 	      {
                 // if error is 4222 (command not supported), ignore it.
-                if (getDiagsArea()->mainSQLCODE() != -4222)
+                if (getDiagsArea() != NULL) {
+                  if (getDiagsArea()->mainSQLCODE() != -4222)
                   {
                     step_ = HANDLE_ERROR_;
                     
                     break;
                   }
-
-                getDiagsArea()->clear();
+                  getDiagsArea()->clear();
+                }
 	      }
 
 	    // insert a NULL entry, this will cause a blank row to be returned
@@ -3380,14 +3381,15 @@ short ExExeUtilGetMetadataInfoComplexTcb::work()
                     if (fetchAllRows(infoList_, queryBuf_, 1, FALSE, retcode) < 0)
                       {
                         // if error is 4222 (command not supported), ignore it.
-                        if (getDiagsArea()->mainSQLCODE() != -4222)
+                        if (getDiagsArea() != NULL) {
+                          if (getDiagsArea()->mainSQLCODE() != -4222)
                           {
                             step_ = HANDLE_ERROR_;
                             
                             break;
                           }
-                        
-                        getDiagsArea()->clear();
+                          getDiagsArea()->clear();
+                        }
                       }
                   }
                 
@@ -3409,14 +3411,14 @@ short ExExeUtilGetMetadataInfoComplexTcb::work()
                     if (fetchAllRows(infoList_, queryBuf_, 1, FALSE, retcode) < 0)
                       {
                         // if error is 4222 (command not supported), ignore it.
-                        if (getDiagsArea()->mainSQLCODE() != -4222)
-                          {
-                            step_ = HANDLE_ERROR_;
-                            
-                            break;
-                          }
-                        
-                        getDiagsArea()->clear();
+                        if (getDiagsArea() != NULL) {
+                           if (getDiagsArea()->mainSQLCODE() != -4222)
+                           {
+                             step_ = HANDLE_ERROR_;
+                             break;
+                           }
+                           getDiagsArea()->clear();
+                        }
                       }
                   }
                 
@@ -4237,7 +4239,7 @@ short ExExeUtilGetHiveMetadataInfoTcb::work()
 	    retcode = fetchAllHiveRows(infoList_, 1, rc);
 	    if (retcode < 0)
 	      {
-                cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -5067,7 +5069,7 @@ short ExExeUtilLobShowddlTcb::fetchRows(char * query, short &rc)
     fetchAllRows(infoList_, query, 1, FALSE, rc);
   if (cliRC < 0) 
     {
-      cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+      setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 
       step_ = HANDLE_ERROR_;
 
@@ -5503,8 +5505,6 @@ short ExExeUtilHiveMDaccessTcb::work()
   ExMasterStmtGlobals *masterGlob = exeGlob->castToExMasterStmtGlobals();
   ContextCli * currContext = masterGlob->getStatement()->getContext();
   
-  ComDiagsArea * diags = getDiagsArea();
-
   while (1)
     {
       switch (step_)
@@ -5522,11 +5522,14 @@ short ExExeUtilHiveMDaccessTcb::work()
             retStatus = hiveMD_->init();
             if (!retStatus)
               {
-                *diags << DgSqlCode(-1190)
-                       << DgString0(hiveMD_->getErrMethodName())
-                       << DgString1(hiveMD_->getErrCodeStr())
-                       << DgString2(hiveMD_->getErrDetail())
-                       << DgInt0(hiveMD_->getErrCode());
+                Lng32 intParam1 =  hiveMD_->getErrCode();
+                ComDiagsArea *diagsArea =  getDiagsArea();
+                ExRaiseSqlError(getHeap(), &diagsArea, -1190, 
+                       &intParam1, NULL, NULL,
+                       hiveMD_->getErrMethodName(),
+                       hiveMD_->getErrCodeStr(),
+                       hiveMD_->getErrDetail());
+                setDiagsArea(diagsArea);
                 step_ = HANDLE_ERROR_;
                 break;
               }
@@ -5540,17 +5543,16 @@ short ExExeUtilHiveMDaccessTcb::work()
 	    if ((hiveMDtdb().mdType_ == ComTdbExeUtilHiveMDaccess::SCHEMAS_) ||
                 (! hiveMDtdb().getSchema()))
               {
-                HVC_RetCode retCode = hiveMD_->getClient()->
-                  getAllSchemas(schNames_);
+                HVC_RetCode retCode = HiveClient_JNI::getAllSchemas((NAHeap *)getHeap(), schNames_);
                 if ((retCode != HVC_OK) && (retCode != HVC_DONE)) 
                   {
-                    *diags << DgSqlCode(-1190)
-                           << DgString0((char*)
-                                        "HiveClient_JNI::getAllSchemas()")
-                           << DgString1(hiveMD_->getClient()->
-                                        getErrorText(retCode))
-                           << DgInt0(retCode)
-                           << DgString2(GetCliGlobals()->getJniErrorStr());
+		    ComDiagsArea * diagsArea = getDiagsArea();
+		    ExRaiseSqlError(getHeap(), &diagsArea, -1190, 
+                           (Lng32 *)&retCode, NULL, NULL, 
+                           (char*)"HiveClient_JNI::getAllSchemas()",
+                           HiveClient_JNI::getErrorText(retCode),
+                           GetCliGlobals()->getJniErrorStr());
+                    setDiagsArea(diagsArea);
                     step_ = HANDLE_ERROR_;
                     break;
                   }
@@ -5602,24 +5604,26 @@ short ExExeUtilHiveMDaccessTcb::work()
 
             if (! currObj)
               {
-                HVC_RetCode retCode = hiveMD_->getClient()->
-                  getAllTables(currSch, tblNames_);
+                HVC_RetCode retCode = HiveClient_JNI::getAllTables((NAHeap *)getHeap(), currSch, tblNames_);
                 if (retCode == HVC_ERROR_EXISTS_EXCEPTION)
                   {
-                    *diags << DgSqlCode(-1003)
-                           << DgSchemaName(NAString("hive") + "." + currSch);
+		    ComDiagsArea * diagsArea = getDiagsArea();
+		    ExRaiseSqlError(getHeap(), &diagsArea, -1003, 
+                           NULL, NULL, NULL, 
+                           (NAString("hive") + "." + currSch).data());
+                    setDiagsArea(diagsArea);
                     step_ = HANDLE_ERROR_;
                     break;
                   }
                 else if ((retCode != HVC_OK) && (retCode != HVC_DONE)) 
                   {
-                    *diags << DgSqlCode(-1190)
-                           << DgString0((char*)
-                                        "HiveClient_JNI::getAllTables()")
-                           << DgString1(hiveMD_->getClient()->
-                                        getErrorText(retCode))
-                           << DgInt0(retCode)
-                           << DgString2(GetCliGlobals()->getJniErrorStr());
+		    ComDiagsArea * diagsArea = getDiagsArea();
+		    ExRaiseSqlError(getHeap(), &diagsArea, -1190, 
+                           (Lng32 *)&retCode, NULL, NULL, 
+                           (char*)"HiveClient_JNI::getAllTables()",
+                           HiveClient_JNI::getErrorText(retCode),
+                           GetCliGlobals()->getJniErrorStr());
+                    setDiagsArea(diagsArea);
                     step_ = HANDLE_ERROR_;
                     break;
                   }
@@ -5803,9 +5807,11 @@ short ExExeUtilHiveMDaccessTcb::work()
 		char strP[300];
 		sprintf(strP, "Datatype %s is not supported.", 
                         (hcd ? hcd->type_ : hpd->type_));
-		*diags << DgSqlCode(-CLI_GET_METADATA_INFO_ERROR)
-		       << DgString0(strP);
-		
+                ComDiagsArea *diagsArea = getDiagsArea();
+                ExRaiseSqlError(getHeap(), &diagsArea, -CLI_GET_METADATA_INFO_ERROR,
+                      NULL, NULL, NULL,
+                      strP);
+                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -7033,8 +7039,6 @@ short ExExeUtilClusterStatsTcb::work()
   ExMasterStmtGlobals *masterGlob = exeGlob->castToExMasterStmtGlobals();
   ContextCli * currContext = masterGlob->getCliGlobals()->currContext();
 
-  ComDiagsArea * diags = getDiagsArea();
-
   while (1)
     {
       switch (step_)
@@ -7061,8 +7065,9 @@ short ExExeUtilClusterStatsTcb::work()
               }
             else if (retcode < 0)
               {
-		*diags << DgSqlCode(-8451);
-
+                ComDiagsArea *diagsArea = getDiagsArea();
+                ExRaiseSqlError(getHeap(), &diagsArea, -8451);
+                setDiagsArea(diagsArea);
                 step_ = HANDLE_ERROR_;
                 break;
               }

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/ExExeUtilGetStats.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilGetStats.cpp b/core/sql/executor/ExExeUtilGetStats.cpp
index 087820a..bfd9db2 100644
--- a/core/sql/executor/ExExeUtilGetStats.cpp
+++ b/core/sql/executor/ExExeUtilGetStats.cpp
@@ -979,8 +979,7 @@ short ExExeUtilGetStatisticsTcb::work()
 	    cliRC = cliInterface()->fetchRowsPrologue(statsQuery_);
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -995,8 +994,7 @@ short ExExeUtilGetStatisticsTcb::work()
 	    cliRC = cliInterface()->fetch();
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -1132,8 +1130,7 @@ short ExExeUtilGetStatisticsTcb::work()
 	    cliRC = cliInterface()->fetch();
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = HANDLE_ERROR_;
 		break;
 	      }

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/ExExeUtilLoad.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilLoad.cpp b/core/sql/executor/ExExeUtilLoad.cpp
index fca307c..33a93f8 100644
--- a/core/sql/executor/ExExeUtilLoad.cpp
+++ b/core/sql/executor/ExExeUtilLoad.cpp
@@ -139,9 +139,10 @@ short ExExeUtilCreateTableAsTcb::work()
 	    // allow a user transaction if NO LOAD was specified
 	    if (xnAlreadyStarted && !ctaTdb().noLoad())
               {
-                *getDiagsArea() << DgSqlCode(-20123)
-                                << DgString0("This DDL operation");
-                
+                ComDiagsArea *diagsArea = getDiagsArea();
+                ExRaiseSqlError(getHeap(), &diagsArea, -20123, NULL, NULL, NULL,
+                                "This DDL operation");
+                setDiagsArea(diagsArea);
                 step_ = ERROR_;
                 break;
               }
@@ -184,7 +185,7 @@ short ExExeUtilCreateTableAsTcb::work()
 		  }
 		else
 		  {
-		    cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+		    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		    
 		    step_ = ERROR_;
 		    break;
@@ -341,7 +342,7 @@ short ExExeUtilCreateTableAsTcb::work()
 		 &rowsAffected);
 	    if (cliRC < 0)
             {
-              cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+              setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
               step_ = HANDLE_ERROR_;
             }
             else
@@ -427,7 +428,7 @@ short ExExeUtilCreateTableAsTcb::work()
               cliInterface()->setIsoMapping(savedIsoMapping);
 	      if (cliRC < 0)
               {
-                cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
                 step_ = HANDLE_ERROR_;
               }
               else
@@ -446,7 +447,7 @@ short ExExeUtilCreateTableAsTcb::work()
 		 &rowsAffected);
 	    if (cliRC < 0)
 	    {
-              cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+              setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
               step_ = HANDLE_ERROR_;
             }
             else
@@ -480,8 +481,7 @@ short ExExeUtilCreateTableAsTcb::work()
 	    NADELETEBASIC(usQuery, getHeap());
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -796,7 +796,7 @@ ExWorkProcRetcode ExExeUtilAqrWnrInsertTcb::work()
 
         if (cliRC < 0)
         {
-          cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
           SETSTEP(ERROR_);
         }
         else
@@ -821,7 +821,7 @@ ExWorkProcRetcode ExExeUtilAqrWnrInsertTcb::work()
         NADELETEBASIC(query_, getMyHeap());
         if (cliRC < 0)
         {
-          cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
           SETSTEP(ERROR_);
         }
         else
@@ -960,7 +960,7 @@ ExWorkProcRetcode ExExeUtilAqrWnrInsertTcb::work()
         {
         // mjh - tbd - warning or EMS message to give context to error on
         // delete after error on the insert?
-          cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
         }
         else
           masterGlob->setAqrWnrInsertCleanedup();
@@ -1114,7 +1114,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
   short rc;
   Lng32 errorRowCount = 0;
   int len;
-  ComDiagsArea *diagsArea;
+  ComDiagsArea *diagsArea = NULL;
 
   // if no parent request, return
   if (qparent_.down->isEmpty())
@@ -1148,8 +1148,9 @@ short ExExeUtilHBaseBulkLoadTcb::work()
           !hblTdb().getIndexTableOnly())
       {
         //8111 - Transactions are not allowed with Bulk load.
-        ComDiagsArea * da = getDiagsArea();
-        *da << DgSqlCode(-8111);
+        ComDiagsArea * diagsArea = getDiagsArea();
+        ExRaiseSqlError(getHeap(), &diagsArea, -8111);
+        setDiagsArea(diagsArea);
         step_ = LOAD_ERROR_;
           break;
       }
@@ -1221,7 +1222,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
 
       if (cliRC < 0)
       {
-        cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+        setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
         step_ = LOAD_ERROR_;
         break;
       }
@@ -1257,6 +1258,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
                           " ",
                           getHbaseErrStr(retcode),
                           (char *)GetCliGlobals()->getJniErrorStr());
+        setDiagsArea(diagsArea);
         step_ = LOAD_END_ERROR_;
         break;
       }
@@ -1296,7 +1298,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
       clnpQuery = NULL;
       if (cliRC < 0)
       {
-        cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+        setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
         step_ = LOAD_END_ERROR_;
         break;
       }
@@ -1335,7 +1337,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
       diQuery = NULL;
       if (cliRC < 0)
       {
-        cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+        setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
         step_ = LOAD_END_ERROR_;
         break;
       }
@@ -1413,7 +1415,10 @@ short ExExeUtilHBaseBulkLoadTcb::work()
             }
           }
         diagsArea = getDiagsArea();
-
+        if (diagsArea == NULL) {
+           diagsArea = ComDiagsArea::allocate(getHeap());
+           setDiagsArea(diagsArea);
+        }
         cliRC = cliInterface()->executeImmediate(loadQuery,
             NULL,
             NULL,
@@ -1421,26 +1426,27 @@ short ExExeUtilHBaseBulkLoadTcb::work()
             &rowsAffected_,
             FALSE,
             diagsArea);
-
         if (parserFlagSet)
             masterGlob->getStatement()->getContext()->resetSqlParserFlags(0x20000);
         if (cliRC < 0)
         {
           rowsAffected_ = 0;
-          cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
           step_ = LOAD_END_ERROR_;
           break;
         }
         else {
            step_ = COMPLETE_BULK_LOAD_;
-           ComCondition *cond;
-           Lng32 entryNumber;
-           while ((cond = diagsArea->findCondition(EXE_ERROR_ROWS_FOUND, &entryNumber)) != NULL) {
-              if (errorRowCount < cond->getOptionalInteger(0))
-                 errorRowCount = cond->getOptionalInteger(0);
-              diagsArea->deleteWarning(entryNumber);
+           if (diagsArea != NULL) {
+              ComCondition *cond;
+              Lng32 entryNumber;
+              while ((cond = diagsArea->findCondition(EXE_ERROR_ROWS_FOUND, &entryNumber)) != NULL) {
+                 if (errorRowCount < cond->getOptionalInteger(0))
+                    errorRowCount = cond->getOptionalInteger(0);
+                 diagsArea->deleteWarning(entryNumber);
+              }
+              diagsArea->setRowCount(0);
            }
-           diagsArea->setRowCount(0);
         }
         if (rowsAffected_ == 0)
           step_ = LOAD_END_;
@@ -1463,7 +1469,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
         upsQuery = NULL;
         if (cliRC < 0)
         {
-          cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
           step_ = LOAD_ERROR_;
           break;
         }
@@ -1522,7 +1528,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
           strcat(clQuery, ")");
         strcat(clQuery, ";");
 
-      cliRC = cliInterface()->executeImmediate(clQuery, NULL,NULL,TRUE,NULL,TRUE, getDiagsArea());
+      cliRC = cliInterface()->executeImmediate(clQuery, NULL,NULL,TRUE,NULL,TRUE);
 
       NADELETEBASIC(clQuery, getMyHeap());
       clQuery = NULL;
@@ -1533,7 +1539,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
       if (cliRC < 0)
       {
         rowsAffected_ = 0;
-        cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+        setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
         setEndStatusMsg(" COMPLETION", len, TRUE);
         step_ = LOAD_END_ERROR_;
         break;
@@ -1580,7 +1586,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
 
       if (cliRC < 0)
       {
-        cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+        setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
         step_ = LOAD_END_ERROR_;
         break;
       }
@@ -1640,7 +1646,7 @@ short ExExeUtilHBaseBulkLoadTcb::work()
 
         if (cliRC < 0)
         {
-          cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
           step_ = LOAD_END_ERROR_;
         }
         else
@@ -2011,12 +2017,12 @@ short ExExeUtilHBaseBulkUnLoadTcb::resetExplainSettings()
 {
   if (cliInterface()->executeImmediate("control session reset 'EXPLAIN';") < 0)
   {
-    cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
     return -1;
   }
   if (restoreCQD("generate_explain") < 0)
   {
-    cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
     return -1;
   }
   return 0;
@@ -2037,7 +2043,7 @@ short ExExeUtilHBaseBulkUnLoadTcb::getTrafodionScanTables()
 
   if (holdAndSetCQD("generate_explain", "ON") < 0)
   {
-    cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
     resetExplainSettings();
     return -1;
   }
@@ -2045,7 +2051,7 @@ short ExExeUtilHBaseBulkUnLoadTcb::getTrafodionScanTables()
   cliRC = cliInterface()->executeImmediate("control session 'EXPLAIN' 'ON';");
   if (cliRC < 0)
   {
-    cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
     resetExplainSettings();
     return cliRC;
   }
@@ -2053,7 +2059,7 @@ short ExExeUtilHBaseBulkUnLoadTcb::getTrafodionScanTables()
   cliRC = cliInterface()->allocStuff(module, stmt, sql_src, input_desc, output_desc, "__EXPL_STMT_NAME__");
   if (cliRC < 0)
   {
-    cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
     resetExplainSettings();
     return cliRC;
   }
@@ -2062,7 +2068,7 @@ short ExExeUtilHBaseBulkUnLoadTcb::getTrafodionScanTables()
   cliRC = cliInterface()->prepare(stmtStr, module, stmt, sql_src, input_desc, output_desc, NULL);
   if (cliRC < 0)
   {
-    cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
     cliInterface()->deallocStuff(module, stmt, sql_src, input_desc, output_desc);
     resetExplainSettings();
     return cliRC;
@@ -2094,7 +2100,7 @@ short ExExeUtilHBaseBulkUnLoadTcb::getTrafodionScanTables()
   cliRC = cliInterface()->fetchAllRows(tbls, (char*)qry_str.data(), 0, FALSE, FALSE, TRUE);
   if (cliRC < 0)
   {
-    cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
     cliInterface()->deallocStuff(module, stmt, sql_src, input_desc, output_desc);
     return cliRC;
   }
@@ -2107,7 +2113,7 @@ short ExExeUtilHBaseBulkUnLoadTcb::getTrafodionScanTables()
       cliRC = cliInterface()->deallocStuff(module, stmt, sql_src, input_desc, output_desc);
       if (cliRC < 0)
       {
-        cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+        setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
         return cliRC;
       }
     }
@@ -2133,7 +2139,7 @@ short ExExeUtilHBaseBulkUnLoadTcb::getTrafodionScanTables()
   cliRC = cliInterface()->deallocStuff(module, stmt, sql_src, input_desc, output_desc);
   if (cliRC < 0)
   {
-    cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
     return cliRC;
   }
   return snapshotsList_->entries();
@@ -2173,8 +2179,9 @@ short ExExeUtilHBaseBulkUnLoadTcb::work()
       if (xnAlreadyStarted  )
       {
         //8111 - Transactions are not allowed with Bulk unload.
-        ComDiagsArea * da = getDiagsArea();
-        *da << DgSqlCode(-8111);
+        ComDiagsArea * diagsArea = getDiagsArea();
+        ExRaiseSqlError(getHeap(), &diagsArea, -8111);
+        setDiagsArea(diagsArea);
         step_ = UNLOAD_ERROR_;
         break;
       }
@@ -2201,9 +2208,11 @@ short ExExeUtilHBaseBulkUnLoadTcb::work()
         if (exists)
         {
           //EXE_UNLOAD_FILE_EXISTS
-          ComDiagsArea * da = getDiagsArea();
-          *da << DgSqlCode(- EXE_UNLOAD_FILE_EXISTS)
-                      << DgString0(hblTdb().getMergePath());
+          ComDiagsArea * diagsArea = getDiagsArea();
+          ExRaiseSqlError(getHeap(), &diagsArea, -EXE_UNLOAD_FILE_EXISTS,
+                  NULL, NULL, NULL,
+                  hblTdb().getMergePath());
+          setDiagsArea(diagsArea);
           step_ = UNLOAD_END_ERROR_;
           break;
         }
@@ -2321,10 +2330,12 @@ short ExExeUtilHBaseBulkUnLoadTcb::work()
           hbcRetCode = ehi_->verifySnapshot(*snapshotsList_->at(i)->fullTableName, *snapshotsList_->at(i)->snapshotName, exist);
           if ( hbcRetCode == HBC_OK && !exist)
           {
-            ComDiagsArea * da = getDiagsArea();
-            *da << DgSqlCode(-8112)
-                << DgString0(snapshotsList_->at(i)->snapshotName->data())
-                << DgString1(snapshotsList_->at(i)->fullTableName->data());
+            ComDiagsArea * diagsArea = getDiagsArea();
+            ExRaiseSqlError(getHeap(), &diagsArea, -8112,
+                  NULL, NULL, NULL,
+                  snapshotsList_->at(i)->snapshotName->data(),
+                  snapshotsList_->at(i)->fullTableName->data());
+            setDiagsArea(diagsArea);
             step_ = UNLOAD_END_ERROR_;
             break;
           }
@@ -2363,7 +2374,7 @@ short ExExeUtilHBaseBulkUnLoadTcb::work()
       if (cliRC < 0)
       {
         rowsAffected_ = 0;
-        cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+        setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
         step_ = UNLOAD_END_ERROR_;
         break;
       }
@@ -2906,10 +2917,11 @@ short ExExeUtilLobExtractTcb::work()
 		  ex_queue_entry * up_entry = qparent_.up->getTailEntry();
 
 		  // invalid state, should not be reached.
-		  ComDiagsArea * da = up_entry->getDiagsArea();
+		  ComDiagsArea *diagsArea = up_entry->getDiagsArea();
 		  ExRaiseSqlError(getMyHeap(),
-				  &da,
+				  &diagsArea,
 				  (ExeErrorCode)(EXE_INTERNAL_ERROR));
+                  setDiagsArea(diagsArea);
 		  step_ = CANCEL_;
 		}
 		break;
@@ -2988,10 +3000,11 @@ short ExExeUtilLobExtractTcb::work()
 		     lobHandle_,
 		     lobHandleLen_))
 		  {
-		    ComDiagsArea * da = getDiagsArea();
+		    ComDiagsArea * diagsArea = getDiagsArea();
 		    ExRaiseSqlError(getMyHeap(),
-				    &da,
+				    &diagsArea,
 				    (ExeErrorCode)(EXE_INVALID_LOB_HANDLE));
+                    setDiagsArea(diagsArea);
 		    step_ = HANDLE_ERROR_;
 		    break;
 		  }
@@ -3064,10 +3077,11 @@ short ExExeUtilLobExtractTcb::work()
 		{
 		  // invalid "toType"
 		  ex_queue_entry * up_entry = qparent_.up->getTailEntry();
-		  ComDiagsArea * da = up_entry->getDiagsArea();
+		  ComDiagsArea *diagsArea = up_entry->getDiagsArea();
 		  ExRaiseSqlError(getMyHeap(),
-				  &da,
+				  &diagsArea,
 				  (ExeErrorCode)(EXE_INTERNAL_ERROR));
+                  setDiagsArea(diagsArea);
 		  step_ = CANCEL_;
 		
 		break;
@@ -3255,6 +3269,7 @@ short ExExeUtilLobExtractTcb::work()
 				    (ExeErrorCode)(8442), NULL, &intParam1, 
 				    &cliError, NULL, (char*)"ExpLOBInterfaceSelect",
 				    getLobErrStr(intParam1));
+                    setDiagsArea(diagsArea);
 		    step_ = HANDLE_ERROR_;
 		    break;
 		  }
@@ -3302,6 +3317,7 @@ short ExExeUtilLobExtractTcb::work()
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceSelectCursor",
 				getLobErrStr(intParam1));
+                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -3356,6 +3372,7 @@ short ExExeUtilLobExtractTcb::work()
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceSelectCursor",
 				getLobErrStr(intParam1));
+                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -3382,10 +3399,11 @@ short ExExeUtilLobExtractTcb::work()
 	      {
 		// No other "toType" shoudl reach here - i.e TO_FILE_ or TO_STRING
 		ex_queue_entry * up_entry = qparent_.up->getTailEntry();
-		ComDiagsArea * da = up_entry->getDiagsArea();
+		ComDiagsArea *diagsArea = up_entry->getDiagsArea();
 		ExRaiseSqlError(getMyHeap(),
-				&da,
+				&diagsArea,
 				(ExeErrorCode)(EXE_INTERNAL_ERROR));
+                setDiagsArea(diagsArea);
 		step_ = CANCEL_;
 		
 		break;
@@ -3427,6 +3445,7 @@ short ExExeUtilLobExtractTcb::work()
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceSelectCursor",
 				getLobErrStr(intParam1));
+                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      } 
@@ -3615,10 +3634,11 @@ short ExExeUtilLobUpdateTcb::work()
 		     lobHandle_,
 		     lobHandleLen_))
 		  {
-		    ComDiagsArea * da = getDiagsArea();
+		    ComDiagsArea *diagsArea = getDiagsArea();
 		    ExRaiseSqlError(getMyHeap(),
-				    &da,
+				    &diagsArea,
 				    (ExeErrorCode)(EXE_INVALID_LOB_HANDLE));
+                    setDiagsArea(diagsArea);
 		    step_ = HANDLE_ERROR_;
 		    break;
 		  }
@@ -3732,6 +3752,7 @@ short ExExeUtilLobUpdateTcb::work()
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceUpdate",
 				getLobErrStr(intParam1));
+                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }  
@@ -3827,7 +3848,8 @@ short ExExeUtilLobUpdateTcb::work()
 		ExRaiseSqlError(getHeap(), &diagsArea, 
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceUpdate",
-				getLobErrStr(intParam1));
+			 	getLobErrStr(intParam1));
+                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }  
@@ -3926,6 +3948,7 @@ short ExExeUtilLobUpdateTcb::work()
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceUpdate",
 				getLobErrStr(intParam1));
+                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }  
@@ -4093,6 +4116,7 @@ short ExExeUtilFileExtractTcb::work()
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceSelectCursor/open",
 				getLobErrStr(intParam1));
+                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -4140,6 +4164,7 @@ short ExExeUtilFileExtractTcb::work()
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceSelectCursor/read",
 				getLobErrStr(intParam1));
+                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -4196,6 +4221,7 @@ short ExExeUtilFileExtractTcb::work()
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceSelectCursor/close",
 				getLobErrStr(intParam1));
+                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -4332,6 +4358,7 @@ short ExExeUtilFileLoadTcb::work()
 				    (ExeErrorCode)(8442), NULL, &intParam1, 
 				    &cliError, NULL, (char*)"ExpLOBInterfaceCreate",
 				    getLobErrStr(intParam1));
+                    setDiagsArea(diagsArea);
 		    step_ = HANDLE_ERROR_;
 		    break;
 		  }
@@ -4362,6 +4389,7 @@ short ExExeUtilFileLoadTcb::work()
 		ExRaiseSqlError(getHeap(), &diagsArea, 
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"SourceFile open");
+                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -4405,6 +4433,7 @@ short ExExeUtilFileLoadTcb::work()
 		ExRaiseSqlError(getHeap(), &diagsArea, 
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"SourceFile read");
+                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -4450,6 +4479,7 @@ short ExExeUtilFileLoadTcb::work()
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceInsert",
 				getLobErrStr(intParam1));
+                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }
@@ -4481,6 +4511,7 @@ short ExExeUtilFileLoadTcb::work()
 				(ExeErrorCode)(8442), NULL, &intParam1, 
 				&cliError, NULL, (char*)"ExpLOBInterfaceCloseFile",
 				getLobErrStr(intParam1));
+                setDiagsArea(diagsArea);
 		step_ = HANDLE_ERROR_;
 		break;
 	      }

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/ExExeUtilMisc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilMisc.cpp b/core/sql/executor/ExExeUtilMisc.cpp
index 3e11f1e..277d5e1 100644
--- a/core/sql/executor/ExExeUtilMisc.cpp
+++ b/core/sql/executor/ExExeUtilMisc.cpp
@@ -102,7 +102,7 @@ short ExExeUtilFastDeleteTcb::doPurgedataCat(char * stmt)
   cliRC = holdAndSetCQD("EXE_PARALLEL_PURGEDATA", "OFF");
   if (cliRC < 0)
     {
-      cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+      setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
       return -1;
     }
 
@@ -111,8 +111,7 @@ short ExExeUtilFastDeleteTcb::doPurgedataCat(char * stmt)
 
   if (cliRC < 0)
     {
-      cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+      setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
       restoreCQD("EXE_PARALLEL_PURGEDATA");
       return -1;
     }
@@ -157,7 +156,7 @@ short ExExeUtilFastDeleteTcb::doLabelPurgedata(char * objectName,
 
   if (cliRC < 0)
     {
-      cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+      setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
       retcode = -1;
       goto cleanUpAndReturn;
     }
@@ -215,7 +214,7 @@ short ExExeUtilFastDeleteTcb::doFastDelete(char * objectName,
     executeImmediate("control query shape hold;");
   if (cliRC < 0)
     {
-      cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+      setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
       retcode = -1;
       goto cleanUpAndReturn;
     }
@@ -224,7 +223,7 @@ short ExExeUtilFastDeleteTcb::doFastDelete(char * objectName,
     cliInterface()->executeImmediate("control query shape esp_exchange(cut);");
   if (cliRC < 0)
     {
-      cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+      setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
       retcode = -1;
       goto cleanUpAndReturn;
     }
@@ -236,7 +235,7 @@ short ExExeUtilFastDeleteTcb::doFastDelete(char * objectName,
 	executeImmediate("control query default mv_internal_ignore_uninitialized 'ON';");
       if (cliRC < 0)
 	{
-	  cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 	  retcode = -1;
 	  goto cleanUpAndReturn;
 	}
@@ -276,7 +275,7 @@ short ExExeUtilFastDeleteTcb::doFastDelete(char * objectName,
 
   if (cliRC < 0)
     {
-      cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+      setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
       retcode = -1;
       goto cleanUpAndReturn;
     }
@@ -333,14 +332,14 @@ short ExExeUtilFastDeleteTcb::injectError(const char * val)
   if (((e1) && (strcmp(e1, val) == 0)) ||
       ((e2) && (strcmp(e2, val) == 0)))
     {
-      ComDiagsArea * da = getDiagsArea();
-      *da << DgSqlCode(-EXE_ERROR_INJECTED)
-	  << (e1 ? DgString0("SQLMX_TEST_POINT") : DgString0("SQLMX_PPD_ERR_TEST_POINT"))
-	  << DgInt0((Lng32)str_atoi(val, strlen(val)));
-
+      Lng32 errNumParam = ((Lng32)str_atoi(val, strlen(val)));
+      ComDiagsArea * diagsArea = getDiagsArea();
+      ExRaiseSqlError(getHeap(), &diagsArea, -EXE_ERROR_INJECTED,
+          &errNumParam, NULL, NULL,   
+	  (e1 ? "SQLMX_TEST_POINT" : "SQLMX_PPD_ERR_TEST_POINT"));
+      setDiagsArea(diagsArea);
       return -EXE_ERROR_INJECTED;
     }
-  
   return 0;
 }
 
@@ -409,7 +408,7 @@ short ExExeUtilFastDeleteTcb::work()
 		    cliRC = cliInterface()->beginWork();
 		    if (cliRC < 0)
 		      {
-			cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                        setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 			step_ = ERROR_;
 			break;
 		      }
@@ -444,8 +443,7 @@ short ExExeUtilFastDeleteTcb::work()
 	      {
 		if (cliRC < 0)
 		  {
-		    cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-		    
+                    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		    step_ = ERROR_;
 		    break;
 		  }
@@ -458,7 +456,7 @@ short ExExeUtilFastDeleteTcb::work()
 	    cliRC = cliInterface()->beginWork();
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = ERROR_;
 		break;
 	      }
@@ -508,8 +506,7 @@ short ExExeUtilFastDeleteTcb::work()
 	      rc = injectError("10");
 	    if (rc < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		// could not acquire a ddl lock.
 		// try to purgedata using catman sequential purgedata.
 
@@ -552,8 +549,7 @@ short ExExeUtilFastDeleteTcb::work()
 	      }
 	    if (rc < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		// security validation failed
 		if ((getDiagsArea()->contains(-1017)) ||
 		    (rollbackNoPDErr))
@@ -576,7 +572,7 @@ short ExExeUtilFastDeleteTcb::work()
 	      rc = injectError("12");
 	    if (rc < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = ROLLBACK_WORK_AND_ERROR_;
 		break;
 	      }
@@ -592,7 +588,7 @@ short ExExeUtilFastDeleteTcb::work()
 		  {
 		    strcpy(failReason_, "Error during commit work.");
 
-		    cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		    step_ = ROLLBACK_WORK_AND_ERROR_;
 		    break;
 		  }
@@ -607,7 +603,7 @@ short ExExeUtilFastDeleteTcb::work()
 		strcpy(buf, "SELECT TESTEXIT;");
 		cliRC = cliInterface()->executeImmediate(buf);
 		if (cliRC < 0)
-		  cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                  setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		  
 		strcpy(failReason_, " ");
 
@@ -625,7 +621,7 @@ short ExExeUtilFastDeleteTcb::work()
 	    cliRC = cliInterface()->beginWork();
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = ERROR_;
 		break;
 	      }
@@ -733,14 +729,13 @@ short ExExeUtilFastDeleteTcb::work()
 
 	    if (step_ == ROLLBACK_WORK_AND_ERROR_)
 	      {
-		ComDiagsArea * da = getDiagsArea();
-		
+		ComDiagsArea * diagsArea = getDiagsArea();
 		// convert all errors into warnings
-		NegateAllErrors(da);
-		
-		// add a new error to indicate that parallel purgedata failed.
-		*da << DgSqlCode(-EXE_PARALLEL_PURGEDATA_FAILED)
-		    << DgString0(failReason_);
+		NegateAllErrors(diagsArea);
+                ExRaiseSqlError(getHeap(), &diagsArea, -EXE_PARALLEL_PURGEDATA_FAILED,
+                    NULL, NULL, NULL,
+		    failReason_);
+                setDiagsArea(diagsArea);
 	      }
 
 	    step_ = ERROR_;
@@ -763,7 +758,7 @@ short ExExeUtilFastDeleteTcb::work()
 		strcpy(buf, "SELECT TESTEXIT;");
 		cliInterface()->executeImmediate(buf);
 		if (cliRC < 0)
-		  cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                  setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		
 		step_ = ERROR_;
 		break;
@@ -774,10 +769,11 @@ short ExExeUtilFastDeleteTcb::work()
 		// raise a warning that parallel purgedata was performed.
 		if (fdTdb().returnPurgedataWarn())
 		  {
-		    ComDiagsArea * da = getDiagsArea();
-		    *da << DgSqlCode(EXE_PURGEDATA_CAT)
-			<< DgString0("Parallel")
-			<< DgString1("");
+		    ComDiagsArea * diagsArea = getDiagsArea();
+                    ExRaiseSqlError(getHeap(), &diagsArea, EXE_PURGEDATA_CAT,
+                        NULL, NULL, NULL,
+			"Parallel", "");
+                    setDiagsArea(diagsArea);
 		  }
 		step_ = DONE_;
 	      }
@@ -791,7 +787,7 @@ short ExExeUtilFastDeleteTcb::work()
 	    cliRC = cliInterface()->beginWork();
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = ERROR_;
 		break;
 	      }
@@ -806,7 +802,7 @@ short ExExeUtilFastDeleteTcb::work()
 
 	    if (rc < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = KILL_MXCMP_AND_ERROR_;
 		break;
 	      }
@@ -823,7 +819,7 @@ short ExExeUtilFastDeleteTcb::work()
 	      rc = injectError("16");
 	    if (rc < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = KILL_MXCMP_AND_ERROR_;
 		break;
 	      }
@@ -842,7 +838,7 @@ short ExExeUtilFastDeleteTcb::work()
 		  rc = injectError("17");
 		if (rc < 0)
 		  {
-		    cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                    setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		    step_ = KILL_MXCMP_AND_ERROR_;
 		    break;
 		  }
@@ -851,7 +847,7 @@ short ExExeUtilFastDeleteTcb::work()
 	    cliRC = cliInterface()->commitWork();
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = ERROR_;
 		break;
 	      }
@@ -861,10 +857,11 @@ short ExExeUtilFastDeleteTcb::work()
 	    // raise a warning that parallel purgedata was performed.
 	    if (fdTdb().returnPurgedataWarn())
 	      {
-		ComDiagsArea * da = getDiagsArea();
-		*da << DgSqlCode(EXE_PURGEDATA_CAT)
-		    << DgString0("Parallel")
-		    << DgString1("");
+		ComDiagsArea * diagsArea = getDiagsArea();
+                ExRaiseSqlError(getHeap(), &diagsArea, EXE_PURGEDATA_CAT,
+                    NULL, NULL, NULL,
+		    "Parallel", "");
+                setDiagsArea(diagsArea);
 	      }
 	  }
 	break;
@@ -883,15 +880,16 @@ short ExExeUtilFastDeleteTcb::work()
 	    // for parallel purgedata, or because parallel purgedata failed.
 	    if (fdTdb().returnPurgedataWarn())
 	      {
-		ComDiagsArea * da = getDiagsArea();
+		ComDiagsArea * diagsArea = getDiagsArea();
 		if (fdTdb().doPurgedataCat())
-		  *da << DgSqlCode(EXE_PURGEDATA_CAT)
-		      << DgString0("Regular")
-		      << DgString1("Reason: Query or the object did not meet the criteria for parallel purgedata.");
+                  ExRaiseSqlError(getHeap(), &diagsArea, EXE_PURGEDATA_CAT,
+                     NULL, NULL, NULL,
+                     "Regular", "Reason: Query or the object did not meet the criteria for parallel purgedata.");
 		else
-		  *da << DgSqlCode(EXE_PURGEDATA_CAT)
-		      << DgString0("Regular")
-		      << DgString1("Reason: Parallel purgedata failed.");
+                  ExRaiseSqlError(getHeap(), &diagsArea, EXE_PURGEDATA_CAT,
+                     NULL, NULL, NULL,
+                     "Regular", "Reason: Parallel purgedata failed.");
+                setDiagsArea(diagsArea);
 	      }
 
 	    rc = doPurgedataCat(fdTdb().purgedataStmt());
@@ -1365,7 +1363,7 @@ short ExExeUtilLongRunningTcb::executeLongRunningQuery()
         "control query default HIST_ON_DEMAND_STATS_SIZE '0'");
       if (cliRC < 0) 
         {
-          cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 	  return cliRC;
         }
       
@@ -1374,7 +1372,7 @@ short ExExeUtilLongRunningTcb::executeLongRunningQuery()
       short rtc = processInitial(rc);
       if ((rc != 0) && (rc != 100))
         {
-          cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
         }
 
       cliRC = 
@@ -1382,7 +1380,7 @@ short ExExeUtilLongRunningTcb::executeLongRunningQuery()
             "control query default HIST_ON_DEMAND_STATS_SIZE 'RESET'");
       if (cliRC < 0) 
         {
-          cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 	  return cliRC;
         }
       
@@ -1418,7 +1416,7 @@ short ExExeUtilLongRunningTcb::executeLongRunningQuery()
       short rtc = processContinuing(rc);
       if ((rc != 0) && (rc != 100))
         {
-          cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
+          setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
         }
 
 #ifdef _DEBUG
@@ -1980,8 +1978,7 @@ short ExExeUtilPopulateInMemStatsTcb::work()
 	    
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = ERROR_;
 	      }
 	    else
@@ -2037,8 +2034,7 @@ short ExExeUtilPopulateInMemStatsTcb::work()
 	    
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = ERROR_;
 	      }
 	    else
@@ -2094,8 +2090,7 @@ short ExExeUtilPopulateInMemStatsTcb::work()
 	    
 	    if (cliRC < 0)
 	      {
-		cliInterface()->retrieveSQLDiagnostics(getDiagsArea());
-
+                setDiagsArea(cliInterface()->allocAndRetrieveSQLDiagnostics(getDiagsArea()));
 		step_ = ERROR_;
 	      }
 	    else
@@ -2256,18 +2251,13 @@ ExExeUtilHiveTruncateTcb::~ExExeUtilHiveTruncateTcb()
 void ExExeUtilHiveTruncateTcb::freeResources()
 {
   if (htTdb().getDropOnDealloc())
-    {
+  {
       NAString hiveDropDDL("drop table ");
-      HiveClient_JNI *hiveClient = HiveClient_JNI::getInstance();
-
       hiveDropDDL += htTdb().getHiveTableName();
 
-      // ignore errors on drop
-      if (!hiveClient->isInitialized() ||
-          !hiveClient->isConnected())
-        hiveClient->init();
-      hiveClient->executeHiveSQL(hiveDropDDL);
-    }
+      // TODO: is it ok to ignore the error 
+      HiveClient_JNI::executeHiveSQL(hiveDropDDL);
+  }
   if (lobGlob_) {
     ExpLOBinterfaceCleanup(lobGlob_);
     lobGlob_ = NULL;
@@ -2426,7 +2416,6 @@ short ExExeUtilHiveTruncateTcb::work()
                           NULL, NULL, NULL,
                           reason,
                           NULL, NULL);
-          
           pentry_down->setDiagsArea(diagsArea);
           step_ = ERROR_;
         }
@@ -2572,15 +2561,16 @@ short ExExeUtilHiveQueryTcb::work()
           
         case PROCESS_QUERY_:
           {
-            ComDiagsArea * diags = getDiagsArea();
-
-            if (!CmpCommon::context()->execHiveSQL(htTdb().getHiveQuery(),
-                                                   diags))
-              {
+            if (HiveClient_JNI::executeHiveSQL(htTdb().getHiveQuery()) != HVC_OK)
+            {
+                ComDiagsArea * diagsArea = NULL;
+                ExRaiseSqlError(getHeap(), &diagsArea, -1214,
+                        NULL, NULL, NULL,
+                        getSqlJniErrorStr(), htTdb().getHiveQuery()); 
+                setDiagsArea(diagsArea);
                 step_ = ERROR_;
                 break;
-              }
-
+            }
             step_ = DONE_;
           }
           break;
@@ -2589,8 +2579,8 @@ short ExExeUtilHiveQueryTcb::work()
           {
             if (handleError())
               return WORK_OK;
-
-	    getDiagsArea()->clear();
+            if (getDiagsArea() != NULL)
+	       getDiagsArea()->clear();
             
             step_ = DONE_;
           }

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/ExExeUtilVolTab.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilVolTab.cpp b/core/sql/executor/ExExeUtilVolTab.cpp
index 9201374..365b9cd 100644
--- a/core/sql/executor/ExExeUtilVolTab.cpp
+++ b/core/sql/executor/ExExeUtilVolTab.cpp
@@ -517,9 +517,9 @@ short ExExeUtilCleanupVolatileTablesTcb::work()
 	      {
 		// cannot have a transaction running.
 		// Return error.
-                ComDiagsArea * diags = getDiagsArea();
-                *diags << DgSqlCode(-EXE_BEGIN_TRANSACTION_ERROR);
-
+                ComDiagsArea * diagsArea = getDiagsArea();
+                ExRaiseSqlError(getHeap(), &diagsArea, -EXE_BEGIN_TRANSACTION_ERROR);
+                setDiagsArea(diagsArea);
 		step_ = ERROR_;
 		break;
 	      }
@@ -558,13 +558,11 @@ short ExExeUtilCleanupVolatileTablesTcb::work()
 	    char * schemaName = vi->get(0);
 	    retcode =
 	      dropVolatileSchema(masterGlob->getStatement()->getContext(),
-				 schemaName, getHeap(), getGlobals(),
-                                 getDiagsArea());
+				 schemaName, getHeap(), getDiagsArea(), getGlobals());
 	    if (retcode < 0)
 	      {
                 // changes errors to warnings and move on to next schema.
-                if (getDiagsArea())
-                  getDiagsArea()->negateAllErrors();
+                getDiagsArea()->negateAllErrors();
 
 		// clear diags and move on to next schema.
 		// Remember that an error was returned, we will
@@ -594,9 +592,11 @@ short ExExeUtilCleanupVolatileTablesTcb::work()
 	      {
 		// add a warning to indicate that some schemas were not
 		// dropped.
-                ComDiagsArea * diags = getDiagsArea();
-                *diags << DgSqlCode(1069)
-                       << DgSchemaName(errorSchemas_);
+                ComDiagsArea * diagsArea = getDiagsArea();
+                ExRaiseSqlError(getHeap(), &diagsArea, 1069,
+                       NULL, NULL, NULL,
+                       errorSchemas_);
+                setDiagsArea(diagsArea);
 	      }
 	    step_ = CLEANUP_HIVE_TABLES_;
 	  }
@@ -605,7 +605,7 @@ short ExExeUtilCleanupVolatileTablesTcb::work()
 	case CLEANUP_HIVE_TABLES_:
 	  {
             if (cvtTdb().cleanupHiveCSETables())
-              dropHiveTempTablesForCSEs(getDiagsArea());
+              dropHiveTempTablesForCSEs();
 
 	    step_ = DONE_;
 	  }
@@ -644,8 +644,8 @@ short ExExeUtilCleanupVolatileTablesTcb::dropVolatileSchema
 (ContextCli * currContext,
  char * schemaName,
  CollHeap * heap,
- ex_globals *glob,
- ComDiagsArea *diagsArea)
+ ComDiagsArea *&diagsArea,
+ ex_globals *glob)
 {
   const char *parentQid = NULL;
   if (glob)
@@ -688,7 +688,7 @@ short ExExeUtilCleanupVolatileTablesTcb::dropVolatileSchema
 
   // issue the drop schema command 
   Lng32 cliRC = cliInterface.executeImmediate(dropSchema);
-  cliInterface.retrieveSQLDiagnostics(diagsArea);
+  cliInterface.allocAndRetrieveSQLDiagnostics(diagsArea);
                 
   // reset volatile schema bit
   //  currContext->resetSqlParserFlags(0x8000); // ALLOW_VOLATILE_SCHEMA_CREATION
@@ -736,8 +736,7 @@ short ExExeUtilCleanupVolatileTablesTcb::dropVolatileTables
   return cliRC;
 }
 
-short ExExeUtilCleanupVolatileTablesTcb::dropHiveTempTablesForCSEs(
-     ComDiagsArea * diagsArea)
+short ExExeUtilCleanupVolatileTablesTcb::dropHiveTempTablesForCSEs()
 {
   Queue * hiveTableNames = NULL;
   // Todo: CSE: support schemas other than default for temp tables
@@ -774,7 +773,7 @@ short ExExeUtilCleanupVolatileTablesTcb::dropHiveTempTablesForCSEs(
           NAString dropHiveTable("drop table ");
 
           dropHiveTable += origTableName;
-          if (!CmpCommon::context()->execHiveSQL(dropHiveTable.data()))
+          if (HiveClient_JNI::executeHiveSQL(dropHiveTable.data()) != HVC_OK)
             ; // ignore errors for now
         }
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1f44166c/core/sql/executor/ExHdfsScan.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExHdfsScan.cpp b/core/sql/executor/ExHdfsScan.cpp
index a9ab2d2..91bdc62 100644
--- a/core/sql/executor/ExHdfsScan.cpp
+++ b/core/sql/executor/ExHdfsScan.cpp
@@ -1552,7 +1552,8 @@ ExWorkProcRetcode ExHdfsScanTcb::work()
 	        da = ComDiagsArea::allocate(getHeap());
 	        workAtp_->setDiagsArea(da);
 	      }
-	      *da << DgSqlCode(-EXE_MAX_ERROR_ROWS_EXCEEDED);
+              ExRaiseSqlError(getHeap(), &da,
+                (ExeErrorCode)(EXE_MAX_ERROR_ROWS_EXCEEDED));
 	      step_ = HANDLE_ERROR_WITH_CLOSE;
 	      break;
 	    }


[5/7] trafodion git commit: Fix for seabase/TEST002 failure with commit 5623b7df82adc37e15d8cfe25c39eb33f506b333

Posted by se...@apache.org.
Fix for seabase/TEST002 failure with commit 5623b7df82adc37e15d8cfe25c39eb33f506b333


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

Branch: refs/heads/master
Commit: 3b54b364ff2f01956f9110fade27ee6765b3e050
Parents: 5623b7d
Author: selvaganesang <se...@esgyn.com>
Authored: Fri Apr 6 06:24:09 2018 +0000
Committer: selvaganesang <se...@esgyn.com>
Committed: Fri Apr 6 06:24:09 2018 +0000

----------------------------------------------------------------------
 core/sql/executor/ExExeUtilGet.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/3b54b364/core/sql/executor/ExExeUtilGet.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilGet.cpp b/core/sql/executor/ExExeUtilGet.cpp
index 3493024..97815ef 100644
--- a/core/sql/executor/ExExeUtilGet.cpp
+++ b/core/sql/executor/ExExeUtilGet.cpp
@@ -5841,7 +5841,7 @@ 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_;


[7/7] trafodion git commit: Merge PR 1504 [TRAFODION-3009] Streamline error handling in Executor utility commands

Posted by se...@apache.org.
Merge PR 1504 [TRAFODION-3009] Streamline error handling in Executor utility commands 


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

Branch: refs/heads/master
Commit: ee2cff9737cf50dabe00fba30250be7a20d96ea2
Parents: 052f7fa c9b09aa
Author: selvaganesang <se...@apache.org>
Authored: Fri Apr 6 16:05:53 2018 +0000
Committer: selvaganesang <se...@apache.org>
Committed: Fri Apr 6 16:05:53 2018 +0000

----------------------------------------------------------------------
 core/sql/arkcmp/CmpContext.cpp                  |  52 --
 core/sql/arkcmp/CmpContext.h                    |   3 -
 core/sql/bin/SqlciErrors.txt                    |   2 +-
 core/sql/cli/Cli.cpp                            |   3 +-
 core/sql/cli/Context.cpp                        |  11 +-
 core/sql/cli/Globals.cpp                        |   2 +-
 core/sql/executor/ExExeUtil.h                   |   8 +-
 core/sql/executor/ExExeUtilCli.cpp              | 165 ++++---
 core/sql/executor/ExExeUtilCli.h                |  19 +-
 core/sql/executor/ExExeUtilCommon.cpp           |  47 +-
 core/sql/executor/ExExeUtilExplain.cpp          |  38 +-
 core/sql/executor/ExExeUtilGet.cpp              | 154 +++---
 core/sql/executor/ExExeUtilGetStats.cpp         |   9 +-
 core/sql/executor/ExExeUtilLoad.cpp             | 181 ++++---
 core/sql/executor/ExExeUtilMisc.cpp             | 144 +++---
 core/sql/executor/ExExeUtilVolTab.cpp           |  29 +-
 core/sql/executor/ExHdfsScan.cpp                |  17 +-
 core/sql/executor/ExHdfsScan.h                  |   1 +
 core/sql/executor/HBaseClient_JNI.cpp           | 472 ------------------
 core/sql/executor/HBaseClient_JNI.h             |  91 +---
 core/sql/executor/HdfsClient_JNI.cpp            |   2 +-
 core/sql/executor/HiveClient_JNI.cpp            | 473 +++++++++++++++++++
 core/sql/executor/HiveClient_JNI.h              | 106 +++++
 core/sql/executor/JavaObjectInterface.cpp       |   2 +-
 core/sql/executor/ex_root.cpp                   |  20 -
 core/sql/executor/hiveHook.cpp                  |  60 +--
 core/sql/exp/ExpError.cpp                       |  14 +
 core/sql/exp/ExpError.h                         |   9 +
 core/sql/exp/ExpHbaseInterface.h                |   1 +
 core/sql/exp/ExpLOBinterface.cpp                |   5 +-
 core/sql/exp/exp_function.cpp                   |   8 +-
 core/sql/nskgmake/executor/Makefile             |   1 +
 core/sql/optimizer/NATable.cpp                  |   2 +-
 core/sql/optimizer/NormRelExpr.cpp              |   5 +-
 core/sql/optimizer/OptimizerSimulator.cpp       |  47 +-
 core/sql/optimizer/hiveHook.h                   |  11 -
 core/sql/sqlcomp/CmpDescribe.cpp                |   4 +-
 core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp        |   3 +-
 core/sql/sqlcomp/CmpSeabaseDDLschema.cpp        |  12 +-
 core/sql/sqlcomp/PrivMgrComponentPrivileges.cpp |   5 +-
 core/sql/sqlcomp/PrivMgrMDTable.cpp             |   4 +-
 .../main/java/org/trafodion/sql/HiveClient.java |  95 ++--
 42 files changed, 1083 insertions(+), 1254 deletions(-)
----------------------------------------------------------------------



[4/7] trafodion git commit: [TRAFODION-3009] Streamline error handling in Executor utility commands

Posted by se...@apache.org.
[TRAFODION-3009] Streamline error handling in Executor utility commands

Fix for hive/TEST007 failure

Merge branch 'master' of github.com:apache/trafodion into trafodion-3009_1

Conflicts:
	core/sql/executor/ExExeUtilGet.cpp


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

Branch: refs/heads/master
Commit: 5623b7df82adc37e15d8cfe25c39eb33f506b333
Parents: 37702da 052f7fa
Author: selvaganesang <se...@esgyn.com>
Authored: Fri Apr 6 01:53:27 2018 +0000
Committer: selvaganesang <se...@esgyn.com>
Committed: Fri Apr 6 01:53:27 2018 +0000

----------------------------------------------------------------------
 core/sql/bin/SqlciErrors.txt                |   2 +-
 core/sql/comexe/ComTdbExeUtil.h             |  32 +-
 core/sql/common/BaseTypes.cpp               |   3 +-
 core/sql/common/CharType.cpp                |   2 +-
 core/sql/common/CharType.h                  |  27 +-
 core/sql/common/ComResWords.cpp             |   2 -
 core/sql/common/NAType.cpp                  |  12 +-
 core/sql/common/NAType.h                    |   3 +-
 core/sql/common/OperTypeEnum.h              |   1 +
 core/sql/executor/ExExeUtil.h               |  12 +-
 core/sql/executor/ExExeUtilGet.cpp          | 119 +++--
 core/sql/executor/sql_buffer.cpp            |   3 +-
 core/sql/exp/ExpLOBaccess.cpp               |  27 +-
 core/sql/exp/ExpLOBinterface.cpp            |   5 +-
 core/sql/exp/ExpPCodeClauseGen.cpp          |   4 +
 core/sql/exp/exp_attrs.cpp                  |  12 +-
 core/sql/exp/exp_attrs.h                    |   6 +-
 core/sql/exp/exp_function.cpp               | 249 +++++++---
 core/sql/exp/exp_function.h                 |  30 +-
 core/sql/generator/GenExpGenerator.cpp      |   7 +-
 core/sql/generator/GenItemFunc.cpp          |   6 +-
 core/sql/generator/GenRelExeUtil.cpp        |   5 +-
 core/sql/generator/GenRelJoin.cpp           |   8 +-
 core/sql/generator/GenRelPackedRows.cpp     |   7 +-
 core/sql/generator/Generator.h              |   1 +
 core/sql/optimizer/BindItemExpr.cpp         | 312 +++++++++---
 core/sql/optimizer/ItemCache.cpp            |   8 +
 core/sql/optimizer/ItemExpr.cpp             |   7 +-
 core/sql/optimizer/ItemFunc.h               |  46 +-
 core/sql/optimizer/ObjectNames.cpp          |   2 +-
 core/sql/optimizer/SynthType.cpp            |  49 +-
 core/sql/optimizer/ValueDesc.cpp            |  57 ++-
 core/sql/parser/sqlparser.y                 |  45 +-
 core/sql/qmscommon/QRLogger.cpp             |   2 +-
 core/sql/regress/compGeneral/EXPECTED006.SB |  10 +-
 core/sql/regress/compGeneral/EXPECTED042    | 139 +++---
 core/sql/regress/core/EXPECTED038.LINUX     |  26 +-
 core/sql/regress/executor/EXPECTED012       | 598 ++++++++++++++++++++++-
 core/sql/regress/executor/TEST012           | 103 +++-
 core/sql/regress/hive/EXPECTED005           | 112 ++---
 core/sql/regress/seabase/EXPECTED002        | 288 ++++++-----
 core/sql/regress/seabase/EXPECTED030        |  14 +
 core/sql/regress/seabase/EXPECTED031        |  44 +-
 core/sql/regress/seabase/TEST002            |  41 +-
 core/sql/regress/seabase/TEST030            |   4 +
 core/sql/regress/seabase/TEST031            |  10 +
 core/sql/sqlcomp/CmpMain.cpp                |   8 +-
 core/sql/sqlcomp/nadefaults.cpp             |  68 +--
 48 files changed, 1901 insertions(+), 677 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/5623b7df/core/sql/bin/SqlciErrors.txt
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafodion/blob/5623b7df/core/sql/executor/ExExeUtil.h
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafodion/blob/5623b7df/core/sql/executor/ExExeUtilGet.cpp
----------------------------------------------------------------------
diff --cc core/sql/executor/ExExeUtilGet.cpp
index c77260e,4428998..3493024
--- a/core/sql/executor/ExExeUtilGet.cpp
+++ b/core/sql/executor/ExExeUtilGet.cpp
@@@ -5782,24 -5833,39 +5820,39 @@@ short ExExeUtilHiveMDaccessTcb::work(
              str_cpy(infoCol->colName, 
                      (hcd ? hcd->name_ : hpd->name_), 256, ' ');
  
-             infoCol->fsDatatype = 
-               getFSTypeFromHiveColType(hcd ? hcd->type_ : hpd->type_);
- 
- 	    if (infoCol->fsDatatype < 0)
+             Lng32 fstype = -1;
+             Lng32 length = -1;
+             Lng32 precision = -1;
+             Lng32 scale = -1;
+             char sqlType[50];
+             char displayType[100];
+             char charset[50];
+             retcode = 
+               getTypeAttrsFromHiveColType(hcd ? hcd->type_ : hpd->type_,
+                                           htd->getSDs()->isOrcFile(),
+                                           fstype, length, precision, scale,
+                                           sqlType, displayType, charset);
+                  
+ 	    if (retcode < 0)
  	      {
+                 // add a warning and continue.
  		char strP[300];
- 		sprintf(strP, "Datatype %s is not supported.", 
-                         (hcd ? hcd->type_ : hpd->type_));
-                 ExRaiseSqlError(getHeap(), &diagsArea_, -CLI_GET_METADATA_INFO_ERROR,
+ 		sprintf(strP, "Datatype %s for column '%s' in table %s.%s.%s is not supported. This table will be ignored.", 
+                         (hcd ? hcd->type_ : hpd->type_),
+                         (hcd ? hcd->name_ : hpd->name_),
+                         hiveCat_, hiveSch_, htd->tblName_);
 -		*diags << DgSqlCode(CLI_GET_METADATA_INFO_ERROR)
 -		       << DgString0(strP);
 -
++		ExRaiseSqlError(getHeap(), &diagsArea_, -CLI_GET_METADATA_INFO_ERROR,
 +                      NULL, NULL, NULL,
 +                      strP);
- 		step_ = HANDLE_ERROR_;
- 		break;
+                 step_ = ADVANCE_ROW_;
+                 break;
  	      }
  	    
- 	    const char * sdtStr = 
-               Descriptor::ansiTypeStrFromFSType(infoCol->fsDatatype);
- 	    str_cpy(infoCol->sqlDatatype, sdtStr, 32, ' ');
+             infoCol->fsDatatype = fstype;
+ 
+ 	    str_cpy(infoCol->sqlDatatype, sqlType, 32, ' ');
+ 
+ 	    str_cpy(infoCol->displayDatatype, displayType, 96, ' ');
  
              str_cpy(infoCol->hiveDatatype, (hcd ? hcd->type_ : hpd->type_), 
                      32, ' ');

http://git-wip-us.apache.org/repos/asf/trafodion/blob/5623b7df/core/sql/exp/ExpLOBinterface.cpp
----------------------------------------------------------------------
diff --cc core/sql/exp/ExpLOBinterface.cpp
index 8e73864,8e73864..730d4b7
--- a/core/sql/exp/ExpLOBinterface.cpp
+++ b/core/sql/exp/ExpLOBinterface.cpp
@@@ -310,8 -310,8 +310,11 @@@ Lng32 ExpLOBinterfaceDataModCheck(ExLob
  
        return 1;
      }
--  else if (err != LOB_OPER_OK)
++  else if (err != LOB_OPER_OK) {
++    failedLocBuf[0] = '\0';
++    failedLocBufLen = 0;
      return -err;
++  }
    else
      return 0;
  }


[6/7] trafodion git commit: Changes to report the error -1571 and -1572 correctly.

Posted by se...@apache.org.
Changes to report the error -1571 and -1572 correctly.


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

Branch: refs/heads/master
Commit: c9b09aab38970fd4875ac940ec6624f74ebe9d37
Parents: 3b54b36
Author: selvaganesang <se...@esgyn.com>
Authored: Fri Apr 6 06:32:30 2018 +0000
Committer: selvaganesang <se...@esgyn.com>
Committed: Fri Apr 6 06:32:30 2018 +0000

----------------------------------------------------------------------
 core/sql/exp/exp_function.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/c9b09aab/core/sql/exp/exp_function.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_function.cpp b/core/sql/exp/exp_function.cpp
index 75ffcf9..9a1e332 100644
--- a/core/sql/exp/exp_function.cpp
+++ b/core/sql/exp/exp_function.cpp
@@ -2238,21 +2238,21 @@ Lng32 ex_function_position::errorChecks(Lng32 startPos, Lng32 occurrence,
   // startPos is 1 based. Cannot be <= 0
   if (startPos < 0)
     {
-      ExRaiseSqlError(heap, diagsArea, (ExeErrorCode)1572);
+      ExRaiseSqlError(heap, diagsArea, -1572);
       *(*diagsArea) << DgString0("START POSITION") << DgString1("INSTR function"); 
       return -1;
     }
   
   if (startPos == 0)
     {
-      ExRaiseSqlError(heap, diagsArea, (ExeErrorCode)1571);
+      ExRaiseSqlError(heap, diagsArea, -1571);
       *(*diagsArea) << DgString0("START POSITION") << DgString1("INSTR function"); 
       return -1;
     }
   
   if (occurrence < 0)
     {
-      ExRaiseSqlError(heap, diagsArea, (ExeErrorCode)1572);
+      ExRaiseSqlError(heap, diagsArea, -1572);
       *(*diagsArea) << DgString0("OCCURRENCE") << DgString1("INSTR function"); 
 
       return -1;
@@ -2260,7 +2260,7 @@ Lng32 ex_function_position::errorChecks(Lng32 startPos, Lng32 occurrence,
   
   if (occurrence == 0)
     {
-      ExRaiseSqlError(heap, diagsArea, (ExeErrorCode)1571);
+      ExRaiseSqlError(heap, diagsArea, -1571);
       *(*diagsArea) << DgString0("OCCURRENCE") << DgString1("INSTR function"); 
 
       return -1;