Skip to content

Commit

Permalink
Merge ea0a9cd into ac94dba
Browse files Browse the repository at this point in the history
  • Loading branch information
xubo245 committed Nov 1, 2018
2 parents ac94dba + ea0a9cd commit 2914916
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 9 deletions.
Expand Up @@ -755,7 +755,7 @@ public static String getStorePath() {
/**
* This method will be used to get the properties value
*
* @param key
* @param key property key
* @return properties value
*/
public String getProperty(String key) {
Expand Down Expand Up @@ -789,9 +789,10 @@ private String getSessionPropertyValue(String key) {

/**
* 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) {
Expand All @@ -805,8 +806,9 @@ public String getProperty(String key, String defaultValue) {
/**
* 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);
Expand Down
4 changes: 3 additions & 1 deletion store/CSDK/CMakeLists.txt
Expand Up @@ -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)
Expand Down
97 changes: 97 additions & 0 deletions 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;
}
71 changes: 71 additions & 0 deletions 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);

};
1 change: 0 additions & 1 deletion store/CSDK/src/CarbonRow.h
Expand Up @@ -58,7 +58,6 @@ class CarbonRow {
* Constructor and express the carbon row result
*
* @param env JNI env
* @param jo carbon Row object
*/
CarbonRow(JNIEnv *env);

Expand Down
16 changes: 14 additions & 2 deletions store/CSDK/test/main.cpp
Expand Up @@ -26,6 +26,7 @@
#include "../src/CarbonWriter.h"
#include "../src/CarbonSchemaReader.h"
#include "../src/Schema.h"
#include "../src/CarbonProperties.h"

using namespace std;

Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 2914916

Please sign in to comment.