You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@carbondata.apache.org by qi...@apache.org on 2018/11/02 07:25:40 UTC

carbondata git commit: [CARBONDATA-3063] Support set and get carbon property in C++ SDK

Repository: carbondata
Updated Branches:
  refs/heads/master 6e58418eb -> f51f5cde1


[CARBONDATA-3063] Support set and get carbon property in C++ SDK

when user write CarbonData or read CarbonData in C++ SDK, user maybe need to change or add carbon property to avoid some problem. such as OOM.
So we support set and get carbon property in C++ SDK

This closes #2884


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

Branch: refs/heads/master
Commit: f51f5cde15b9e68abebf4440fa7fcad03b991973
Parents: 6e58418
Author: xubo245 <xu...@huawei.com>
Authored: Wed Oct 31 14:41:21 2018 +0800
Committer: QiangCai <qi...@qq.com>
Committed: Fri Nov 2 15:23:40 2018 +0800

----------------------------------------------------------------------
 .../carbondata/core/util/CarbonProperties.java  | 12 ++-
 store/CSDK/CMakeLists.txt                       |  4 +-
 store/CSDK/src/CarbonProperties.cpp             | 97 ++++++++++++++++++++
 store/CSDK/src/CarbonProperties.h               | 71 ++++++++++++++
 store/CSDK/src/CarbonRow.h                      |  1 -
 store/CSDK/test/main.cpp                        | 16 +++-
 6 files changed, 192 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/carbondata/blob/f51f5cde/core/src/main/java/org/apache/carbondata/core/util/CarbonProperties.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/carbondata/core/util/CarbonProperties.java b/core/src/main/java/org/apache/carbondata/core/util/CarbonProperties.java
index 7ec22be..d117b4d 100644
--- a/core/src/main/java/org/apache/carbondata/core/util/CarbonProperties.java
+++ b/core/src/main/java/org/apache/carbondata/core/util/CarbonProperties.java
@@ -755,7 +755,7 @@ public final class CarbonProperties {
   /**
    * This method will be used to get the properties value
    *
-   * @param key
+   * @param key property key
    * @return properties value
    */
   public String getProperty(String key) {
@@ -789,9 +789,10 @@ public final class CarbonProperties {
 
   /**
    * This method will be used to get the properties value if property is not
-   * present then it will return tghe default value
+   * present then it will return the default value
    *
-   * @param key
+   * @param key property key
+   * @param defaultValue properties default value
    * @return properties value
    */
   public String getProperty(String key, String defaultValue) {
@@ -805,8 +806,9 @@ public final class CarbonProperties {
   /**
    * This method will be used to add a new property
    *
-   * @param key
-   * @return properties value
+   * @param key property key
+   * @param value properties value
+   * @return CarbonProperties object
    */
   public CarbonProperties addProperty(String key, String value) {
     carbonProperties.setProperty(key, value);

http://git-wip-us.apache.org/repos/asf/carbondata/blob/f51f5cde/store/CSDK/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/store/CSDK/CMakeLists.txt b/store/CSDK/CMakeLists.txt
index 4da47cf..2d31c75 100644
--- a/store/CSDK/CMakeLists.txt
+++ b/store/CSDK/CMakeLists.txt
@@ -8,7 +8,9 @@ find_package(JNI REQUIRED)
 include_directories(${JNI_INCLUDE_DIRS})
 
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
-set(SOURCE_FILES src/CarbonReader.cpp src/CarbonReader.h test/main.cpp src/CarbonRow.h src/CarbonRow.cpp src/CarbonWriter.h  src/CarbonWriter.cpp src/CarbonSchemaReader.h src/CarbonSchemaReader.cpp src/Schema.h src/Schema.cpp)
+set(SOURCE_FILES src/CarbonReader.cpp src/CarbonReader.h test/main.cpp src/CarbonRow.h
+        src/CarbonRow.cpp src/CarbonWriter.h  src/CarbonWriter.cpp src/CarbonSchemaReader.h
+        src/CarbonSchemaReader.cpp src/Schema.h src/Schema.cpp src/CarbonProperties.cpp src/CarbonProperties.h)
 
 add_executable(CJDK ${SOURCE_FILES})
 get_filename_component(JAVA_JVM_LIBRARY_DIR ${JAVA_JVM_LIBRARY} DIRECTORY)

http://git-wip-us.apache.org/repos/asf/carbondata/blob/f51f5cde/store/CSDK/src/CarbonProperties.cpp
----------------------------------------------------------------------
diff --git a/store/CSDK/src/CarbonProperties.cpp b/store/CSDK/src/CarbonProperties.cpp
new file mode 100644
index 0000000..a24f969
--- /dev/null
+++ b/store/CSDK/src/CarbonProperties.cpp
@@ -0,0 +1,97 @@
+/*
+ * 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.
+ */
+
+#include <stdexcept>
+#include "CarbonProperties.h"
+
+CarbonProperties::CarbonProperties(JNIEnv *env) {
+    if (env == NULL) {
+        throw std::runtime_error("JNIEnv parameter can't be NULL.");
+    }
+    this->jniEnv = env;
+    this->carbonPropertiesClass = jniEnv->FindClass("org/apache/carbondata/core/util/CarbonProperties");
+    if (carbonPropertiesClass == NULL) {
+        throw std::runtime_error("Can't find the class in java: org/apache/carbondata/core/util/CarbonProperties");
+    }
+    jmethodID id = jniEnv->GetStaticMethodID(carbonPropertiesClass, "getInstance",
+        "()Lorg/apache/carbondata/core/util/CarbonProperties;");
+    if (id == NULL) {
+        throw std::runtime_error("Can't find the method in java: getInstance");
+    }
+    this->carbonPropertiesObject = jniEnv->CallStaticObjectMethod(carbonPropertiesClass, id);
+}
+
+
+jobject CarbonProperties::addProperty(char *key, char *value) {
+    if (key == NULL) {
+        throw std::runtime_error("key parameter can't be NULL.");
+    }
+    if (value == NULL) {
+        throw std::runtime_error("value parameter can't be NULL.");
+    }
+    jmethodID id = jniEnv->GetMethodID(carbonPropertiesClass, "addProperty",
+        "(Ljava/lang/String;Ljava/lang/String;)Lorg/apache/carbondata/core/util/CarbonProperties;");
+    if (id == NULL) {
+        throw std::runtime_error("Can't find the method in java: addProperty");
+    }
+    jvalue args[2];
+    args[0].l = jniEnv->NewStringUTF(key);;
+    args[1].l = jniEnv->NewStringUTF(value);;
+    this->carbonPropertiesObject = jniEnv->CallObjectMethodA(carbonPropertiesObject, id, args);
+    return carbonPropertiesObject;
+}
+
+char *CarbonProperties::getProperty(char *key) {
+    if (key == NULL) {
+        throw std::runtime_error("key parameter can't be NULL.");
+    }
+    jmethodID id = jniEnv->GetMethodID(carbonPropertiesClass, "getProperty",
+        "(Ljava/lang/String;)Ljava/lang/String;");
+    if (id == NULL) {
+        throw std::runtime_error("Can't find the method in java: getProperty");
+    }
+    jvalue args[1];
+    args[0].l = jniEnv->NewStringUTF(key);
+    jobject value = jniEnv->CallObjectMethodA(carbonPropertiesObject, id, args);
+    if (value == NULL) {
+        return NULL;
+    }
+    char *str = (char *) jniEnv->GetStringUTFChars((jstring) value, JNI_FALSE);
+    jniEnv->DeleteLocalRef(value);
+    return str;
+}
+
+char *CarbonProperties::getProperty(char *key, char *defaultValue) {
+    if (key == NULL) {
+        throw std::runtime_error("key parameter can't be NULL.");
+    }
+    if (defaultValue == NULL) {
+        throw std::runtime_error("defaultValue parameter can't be NULL.");
+    }
+    jmethodID id = jniEnv->GetMethodID(carbonPropertiesClass, "getProperty",
+        "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");
+    if (id == NULL) {
+        throw std::runtime_error("Can't find the method in java: getProperty");
+    }
+    jvalue args[2];
+    args[0].l = jniEnv->NewStringUTF(key);
+    args[1].l = jniEnv->NewStringUTF(defaultValue);
+    jobject value = jniEnv->CallObjectMethodA(carbonPropertiesObject, id, args);
+    char *str = (char *) jniEnv->GetStringUTFChars((jstring) value, JNI_FALSE);
+    jniEnv->DeleteLocalRef(value);
+    return str;
+}

http://git-wip-us.apache.org/repos/asf/carbondata/blob/f51f5cde/store/CSDK/src/CarbonProperties.h
----------------------------------------------------------------------
diff --git a/store/CSDK/src/CarbonProperties.h b/store/CSDK/src/CarbonProperties.h
new file mode 100644
index 0000000..a5d391b
--- /dev/null
+++ b/store/CSDK/src/CarbonProperties.h
@@ -0,0 +1,71 @@
+#include <jni.h>
+
+/*
+ * 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.
+ */
+
+class CarbonProperties {
+private:
+    /**
+     * carbonProperties Class
+     */
+    jclass carbonPropertiesClass;
+
+    /**
+     * carbonProperties Object
+     */
+    jobject carbonPropertiesObject;
+public:
+    /**
+     * jni env
+     */
+    JNIEnv *jniEnv;
+
+    /**
+     * Constructor of CarbonProperties
+     *
+     * @param env JNI env
+     */
+    CarbonProperties(JNIEnv *env);
+
+    /**
+     * This method will be used to add a new property
+     * 
+     * @param key property key
+     * @param value property value
+     * @return CarbonProperties object
+     */
+    jobject addProperty(char *key, char *value);
+
+    /**
+     * This method will be used to get the properties value
+     *
+     * @param key  property key
+     * @return  property value
+     */
+    char *getProperty(char *key);
+
+    /**
+     * This method will be used to get the properties value
+     * if property is not present then it will return the default value
+     *
+     * @param key  property key
+     * @param defaultValue  property default Value
+     * @return
+     */
+    char *getProperty(char *key, char *defaultValue);
+
+};

http://git-wip-us.apache.org/repos/asf/carbondata/blob/f51f5cde/store/CSDK/src/CarbonRow.h
----------------------------------------------------------------------
diff --git a/store/CSDK/src/CarbonRow.h b/store/CSDK/src/CarbonRow.h
index 007f8a9..2395fa6 100644
--- a/store/CSDK/src/CarbonRow.h
+++ b/store/CSDK/src/CarbonRow.h
@@ -58,7 +58,6 @@ public:
      * Constructor and express the carbon row result
      *
      * @param env JNI env
-     * @param jo carbon Row object
      */
     CarbonRow(JNIEnv *env);
 

http://git-wip-us.apache.org/repos/asf/carbondata/blob/f51f5cde/store/CSDK/test/main.cpp
----------------------------------------------------------------------
diff --git a/store/CSDK/test/main.cpp b/store/CSDK/test/main.cpp
index 876e2e1..a3ee97c 100644
--- a/store/CSDK/test/main.cpp
+++ b/store/CSDK/test/main.cpp
@@ -26,6 +26,7 @@
 #include "../src/CarbonWriter.h"
 #include "../src/CarbonSchemaReader.h"
 #include "../src/Schema.h"
+#include "../src/CarbonProperties.h"
 
 using namespace std;
 
@@ -274,6 +275,16 @@ bool tryCatchException(JNIEnv *env) {
     printf("\nfinished handle exception\n");
 }
 
+void testCarbonProperties(JNIEnv *env) {
+    printf("%s", "test Carbon Properties:");
+    CarbonProperties carbonProperties(env);
+    char *key = "carbon.unsafe.working.memory.in.mb";
+    printf("%s\t", carbonProperties.getProperty(key));
+    printf("%s\t", carbonProperties.getProperty(key, "512"));
+    carbonProperties.addProperty(key, "1024");
+    printf("%s\t", carbonProperties.getProperty(key));
+}
+
 /**
  * test write data to local disk
  *
@@ -452,11 +463,12 @@ int main(int argc, char *argv[]) {
         tryCatchException(env);
         char *indexFilePath = argv[1];
         char *dataFilePath = argv[2];
-        readSchemaInIndexFile(env, indexFilePath);
-        readSchemaInDataFile(env, dataFilePath);
+        testCarbonProperties(env);
         readFromLocalWithoutProjection(env);
         testWriteData(env, "./data", 1, argv);
         readFromLocal(env);
+        readSchemaInIndexFile(env, indexFilePath);
+        readSchemaInDataFile(env, dataFilePath);
     }
     (jvm)->DestroyJavaVM();