You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@carbondata.apache.org by GitBox <gi...@apache.org> on 2019/01/14 03:04:46 UTC

[GitHub] xubo245 commented on a change in pull request #2991: [CARBONDATA-3043] Add build script and add test case with GoogleTest Framework for CSDK

xubo245 commented on a change in pull request #2991: [CARBONDATA-3043] Add build script and add test case with GoogleTest Framework for CSDK
URL: https://github.com/apache/carbondata/pull/2991#discussion_r247377909
 
 

 ##########
 File path: store/CSDK/test/main_ft.cpp
 ##########
 @@ -0,0 +1,1172 @@
+/*
+ * 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 <iostream>
+#include <jni.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include "../src/CarbonReader.h"
+#include "../src/CarbonRow.h"
+#include "../src/CarbonWriter.h"
+#include "../src/CarbonSchemaReader.h"
+#include "../src/Schema.h"
+#include "../src/CarbonProperties.h"
+#include "gtest/gtest.h"
+
+using namespace std;
+
+JavaVM *jvm;
+JNIEnv *env;
+int my_argc;
+char** my_argv;
+
+/**
+ * init jvm
+ *
+ * @return
+ */
+JNIEnv *initJVM() {
+    JNIEnv *env;
+    JavaVMInitArgs vm_args;
+    int parNum = 2;
+    int res;
+    JavaVMOption options[parNum];
+
+    options[0].optionString = "-Djava.class.path=../../sdk/target/carbondata-sdk.jar";
+    options[1].optionString = "-verbose:jni";                // For debug and check the jni information
+    //    options[2].optionString = "-Xmx12000m";            // change the jvm max memory size
+    //    options[3].optionString = "-Xms5000m";             // change the jvm min memory size
+    //    options[4].optionString = "-Djava.compiler=NONE";  // forbidden JIT
+    vm_args.version = JNI_VERSION_1_8;
+    vm_args.nOptions = parNum;
+    vm_args.options = options;
+    vm_args.ignoreUnrecognized = JNI_FALSE;
+
+    res = JNI_CreateJavaVM(&jvm, (void **) &env, &vm_args);
+    if (res < 0) {
+        fprintf(stderr, "\nCan't create Java VM\n");
+        exit(1);
+    }
+
+    return env;
+}
+
+
+/**
+ * convert Exception to String(Exception toString())
+ * @param jthrowable exc
+ * @return exception as String
+ */
+ char* convertExceptionToString(jthrowable exc){
+        jboolean isCopy = false;
+        jmethodID toString = env->GetMethodID(env->FindClass("java/lang/Object"), "toString", "()Ljava/lang/String;");
+        jstring s = (jstring) env->CallObjectMethod(exc, toString);
+        char *exception_string = (char *) env->GetStringUTFChars(s, JNI_FALSE);
+        return exception_string;
+
+    }
+
+/**
+ * print array result
+ *
+ * @param env JNIEnv
+ * @param arr array
+ */
+void printArray(JNIEnv *env, jobjectArray arr) {
+    if (env->ExceptionCheck()) {
+        throw env->ExceptionOccurred();
+    }
+    jsize length = env->GetArrayLength(arr);
+    int j = 0;
+    for (j = 0; j < length; j++) {
+        jobject element = env->GetObjectArrayElement(arr, j);
+        if (env->ExceptionCheck()) {
+            throw env->ExceptionOccurred();
+        }
+        char *str = (char *) env->GetStringUTFChars((jstring) element, JNI_FALSE);
+        printf("%s\t", str);
+    }
+    env->DeleteLocalRef(arr);
+}
+
+/**
+ * print boolean result
+ *
+ * @param env JNIEnv
+ * @param bool1 boolean value
+ */
+void printBoolean(jboolean bool1) {
+    if (bool1) {
+        printf("true\t");
+    } else {
+        printf("false\t");
+    }
+}
+
+/**
+ * print result of reading data
+ *
+ * @param env JNIEnv
+ * @param reader CarbonReader object
+ */
+void printResultWithException(JNIEnv *env, CarbonReader reader) {
+    CarbonRow carbonRow(env);
+    try {
+        while (reader.hasNext()) {
+            jobject row = reader.readNextRow();
+            carbonRow.setCarbonRow(row);
+            printf("%s\t", carbonRow.getString(1));
+            printf("%d\t", carbonRow.getInt(1));
+            printf("%ld\t", carbonRow.getLong(2));
+            printf("%s\t", carbonRow.getVarchar(1));
+            printArray(env, carbonRow.getArray(0));
+            printf("%d\t", carbonRow.getShort(5));
+            printf("%d\t", carbonRow.getInt(6));
+            printf("%ld\t", carbonRow.getLong(7));
+            printf("%lf\t", carbonRow.getDouble(8));
+            printBoolean(carbonRow.getBoolean(9));
+            printf("%s\t", carbonRow.getDecimal(9));
+            printf("%f\t", carbonRow.getFloat(11));
+            printf("\n");
+            env->DeleteLocalRef(row);
+        }
+        reader.close();
+        carbonRow.close();
+    } catch (jthrowable e) {
+        env->ExceptionDescribe();
+        printf("%s",convertExceptionToString(e));
+        reader.close();
+        carbonRow.close();
+        throw e;
+    }
+}
+
+/**
+ * print result of reading data
+ *
+ * @param env JNIEnv
+ * @param reader CarbonReader object
+ */
+void printResult(JNIEnv *env, CarbonReader reader) {
+    try {
+        CarbonRow carbonRow(env);
+        while (reader.hasNext()) {
+            jobject row = reader.readNextRow();
+            carbonRow.setCarbonRow(row);
+            printf("%s\t", carbonRow.getString(0));
+            printf("%d\t", carbonRow.getInt(1));
+            printf("%ld\t", carbonRow.getLong(2));
+            //printf("%s\t", carbonRow.getVarchar(3));
 
 Review comment:
   Why do you remove this?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services