Repository: trafodion
Updated Branches:
refs/heads/master 052f7faa4 -> ee2cff973
Advertising
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",
"");