Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CARBONDATA-2997] Support read schema from index file and data file i…
…n CSDK 1.support readSchemaInIndexFile 2.support readSchemaInDataFile 3.support get field name and data type name 4.suppport get array child element data type name 5.can read schema when carbonreader has set ak,sk,endpoint 6.TODO: need support read scehma from S3 in the future This closes #2807
- Loading branch information
Showing
11 changed files
with
687 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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 "CarbonSchemaReader.h" | ||
|
||
CarbonSchemaReader::CarbonSchemaReader(JNIEnv *env) { | ||
if (env == NULL) { | ||
throw std::runtime_error("JNIEnv parameter can't be NULL."); | ||
} | ||
this->carbonSchemaReaderClass = env->FindClass("org/apache/carbondata/sdk/file/CarbonSchemaReader"); | ||
if (carbonSchemaReaderClass == NULL) { | ||
throw std::runtime_error("Can't find the class in java: org/apache/carbondata/sdk/file/CarbonSchemaReader"); | ||
} | ||
this->jniEnv = env; | ||
} | ||
|
||
jobject CarbonSchemaReader::readSchemaInDataFile(char *path) { | ||
if (path == NULL) { | ||
throw std::runtime_error("path parameter can't be NULL."); | ||
} | ||
jmethodID methodID = jniEnv->GetStaticMethodID(carbonSchemaReaderClass, "readSchemaInDataFile", | ||
"(Ljava/lang/String;)Lorg/apache/carbondata/sdk/file/Schema;"); | ||
if (methodID == NULL) { | ||
throw std::runtime_error("Can't find the method in java: readSchemaInDataFile"); | ||
} | ||
jstring jPath = jniEnv->NewStringUTF(path); | ||
jvalue args[1]; | ||
args[0].l = jPath; | ||
jobject result = jniEnv->CallStaticObjectMethodA(carbonSchemaReaderClass, methodID, args); | ||
if (jniEnv->ExceptionCheck()) { | ||
throw jniEnv->ExceptionOccurred(); | ||
} | ||
return result; | ||
} | ||
|
||
jobject CarbonSchemaReader::readSchemaInIndexFile(char *path) { | ||
if (path == NULL) { | ||
throw std::runtime_error("path parameter can't be NULL."); | ||
} | ||
jmethodID methodID = jniEnv->GetStaticMethodID(carbonSchemaReaderClass, "readSchemaInIndexFile", | ||
"(Ljava/lang/String;)Lorg/apache/carbondata/sdk/file/Schema;"); | ||
if (methodID == NULL) { | ||
throw std::runtime_error("Can't find the method in java: readSchemaInDataFile"); | ||
} | ||
jstring jPath = jniEnv->NewStringUTF(path); | ||
jvalue args[1]; | ||
args[0].l = jPath; | ||
jobject result = jniEnv->CallStaticObjectMethodA(carbonSchemaReaderClass, methodID, args); | ||
if (jniEnv->ExceptionCheck()) { | ||
throw jniEnv->ExceptionOccurred(); | ||
} | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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 <jni.h> | ||
|
||
class CarbonSchemaReader { | ||
private: | ||
|
||
/** | ||
* jni env | ||
*/ | ||
JNIEnv *jniEnv; | ||
|
||
/** | ||
* carbonSchemaReader Class for get method id and call method | ||
*/ | ||
jclass carbonSchemaReaderClass; | ||
|
||
public: | ||
|
||
/** | ||
* constructor with jni env | ||
* | ||
* @param env jni env | ||
*/ | ||
CarbonSchemaReader(JNIEnv *env); | ||
|
||
/** | ||
* read Schema from Data File | ||
* | ||
* @param path Data File path | ||
* @return carbon schema object | ||
*/ | ||
jobject readSchemaInDataFile(char *path); | ||
|
||
/** | ||
* read Schema from index File | ||
* | ||
* @param path index File path | ||
* @return carbon schema object | ||
*/ | ||
jobject readSchemaInIndexFile(char *path); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* 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 <jni.h> | ||
#include <stdexcept> | ||
#include "Schema.h" | ||
|
||
Schema::Schema(JNIEnv *env, jobject schema) { | ||
if (env == NULL) { | ||
throw std::runtime_error("JNIEnv parameter can't be NULL."); | ||
} | ||
if (schema == NULL) { | ||
throw std::runtime_error("schema parameter can't be NULL."); | ||
} | ||
this->schemaClass = env->FindClass("org/apache/carbondata/sdk/file/Schema"); | ||
if (schemaClass == NULL) { | ||
throw std::runtime_error("Can't find the class in java: org/apache/carbondata/sdk/file/Schema"); | ||
} | ||
this->jniEnv = env; | ||
this->schema = schema; | ||
} | ||
|
||
int Schema::getFieldsLength() { | ||
jmethodID methodID = jniEnv->GetMethodID(schemaClass, "getFieldsLength", | ||
"()I"); | ||
if (methodID == NULL) { | ||
throw std::runtime_error("Can't find the method in java: getFieldsLength"); | ||
} | ||
return jniEnv->CallIntMethod(schema, methodID); | ||
}; | ||
|
||
void Schema::checkOrdinal(int ordinal) { | ||
if (ordinal < 0) { | ||
throw std::runtime_error("ordinal parameter can't be negative."); | ||
} | ||
} | ||
|
||
char *Schema::getFieldName(int ordinal) { | ||
checkOrdinal(ordinal); | ||
jmethodID methodID = jniEnv->GetMethodID(schemaClass, "getFieldName", | ||
"(I)Ljava/lang/String;"); | ||
if (methodID == NULL) { | ||
throw std::runtime_error("Can't find the method in java: getFieldName"); | ||
} | ||
jvalue args[1]; | ||
args[0].i = ordinal; | ||
jobject fieldName = jniEnv->CallObjectMethodA(schema, methodID, args); | ||
return (char *) jniEnv->GetStringUTFChars((jstring) fieldName, JNI_FALSE); | ||
}; | ||
|
||
char *Schema::getFieldDataTypeName(int ordinal) { | ||
checkOrdinal(ordinal); | ||
jmethodID methodID = jniEnv->GetMethodID(schemaClass, "getFieldDataTypeName", | ||
"(I)Ljava/lang/String;"); | ||
if (methodID == NULL) { | ||
throw std::runtime_error("Can't find the method in java: getFieldDataTypeName"); | ||
} | ||
jvalue args[1]; | ||
args[0].i = ordinal; | ||
jobject fieldName = jniEnv->CallObjectMethodA(schema, methodID, args); | ||
return (char *) jniEnv->GetStringUTFChars((jstring) fieldName, JNI_FALSE); | ||
}; | ||
|
||
char *Schema::getArrayElementTypeName(int ordinal) { | ||
checkOrdinal(ordinal); | ||
jmethodID methodID = jniEnv->GetMethodID(schemaClass, "getArrayElementTypeName", | ||
"(I)Ljava/lang/String;"); | ||
if (methodID == NULL) { | ||
throw std::runtime_error("Can't find the method in java: getArrayElementTypeName"); | ||
} | ||
jvalue args[1]; | ||
args[0].i = ordinal; | ||
jobject fieldName = jniEnv->CallObjectMethodA(schema, methodID, args); | ||
if (jniEnv->ExceptionCheck()) { | ||
throw jniEnv->ExceptionOccurred(); | ||
} | ||
return (char *) jniEnv->GetStringUTFChars((jstring) fieldName, JNI_FALSE); | ||
}; |
Oops, something went wrong.