diff --git a/omnioperator/omniop-native-reader/cpp/src/jni/OrcColumnarBatchJniReader.cpp b/omnioperator/omniop-native-reader/cpp/src/jni/OrcColumnarBatchJniReader.cpp index 1dd18929b5cc94c99a15ba5b7ded8e7a007c0f2d..6c221f844f2408195c1c585925cba4b66453dc1b 100644 --- a/omnioperator/omniop-native-reader/cpp/src/jni/OrcColumnarBatchJniReader.cpp +++ b/omnioperator/omniop-native-reader/cpp/src/jni/OrcColumnarBatchJniReader.cpp @@ -22,6 +22,7 @@ #include #include "jni_common.h" #include "common/UriInfo.h" +#include "type/decimal_operations.h" using namespace omniruntime::vec; using namespace omniruntime::type; @@ -356,6 +357,68 @@ std::unique_ptr CopyFixedWidth(orc::ColumnVectorBatch *field) return newVector; } + +template +std::unique_ptr CopyVarForOmniDouble(orc::ColumnVectorBatch *field) +{ + using T = typename NativeType::type; + ORC_TYPE *lvb = dynamic_cast(field); + auto numElements = lvb->numElements; + auto values = lvb->data.data(); + auto notNulls = lvb->notNull.data(); + auto newVector = std::make_unique>(numElements); + auto newVectorPtr = newVector.get(); + // Check ColumnVectorBatch has null or not firstly + if (lvb->hasNulls) { + for (uint i = 0; i < numElements; i++) { + if (!notNulls[i]) { + newVectorPtr->SetNull(i); + } else { + auto data = std::strtod(values[i], NULL); + newVectorPtr->SetValue(i, data); + } + } + } else { + for (uint i = 0; i < numElements; i++) { + auto data = std::strtod(values[i], NULL); + newVectorPtr->SetValue(i, data); + } + } + return newVector; +} + + +template +std::unique_ptr CopyLongForOmniVar(orc::ColumnVectorBatch *field) +{ + ORC_TYPE *lvb = dynamic_cast(field); + auto numElements = lvb->numElements; + auto values = lvb->data.data(); + auto notNulls = lvb->notNull.data(); + auto newVector = std::make_unique>>(numElements); + auto newVectorPtr = newVector.get(); + // Check ColumnVectorBatch has null or not firstly + if (lvb->hasNulls) { + for (uint i = 0; i < numElements; i++) { + if (!notNulls[i]) { + newVectorPtr->SetNull(i); + } else { + auto str = std::to_string(values[i]); + auto data = std::string_view(str); + newVectorPtr->SetValue(i, data); + } + } + } else { + for (uint i = 0; i < numElements; i++) { + auto str = std::to_string(values[i]); + auto data = std::string_view(str); + newVectorPtr->SetValue(i, data); + } + } + newVectorPtr->SetValues(0, values, numElements); + return newVector; +} + template std::unique_ptr CopyOptimizedForInt64(orc::ColumnVectorBatch *field) { @@ -445,6 +508,32 @@ std::unique_ptr CopyCharType(orc::ColumnVectorBatch *field) return newVector; } +std::unique_ptr CopyDoubleToOmniDecimal64Vec(orc::ColumnVectorBatch *field) +{ + orc::DoubleVectorBatch *lvb = dynamic_cast(field); + auto numElements = lvb->numElements; + auto values = lvb->data.data(); + auto notNulls = lvb->notNull.data(); + auto newVector = std::make_unique>(numElements); + auto newVectorPtr = newVector.get(); + if (lvb->hasNulls) { + for (uint i = 0; i < numElements; i++) { + if (notNulls[i]) { + omniruntime::type::Decimal64 d(values[i]); + newVectorPtr->SetValue(i, d.GetValue()); + } else { + newVectorPtr->SetNull(i); + } + } + } else { + for (uint i = 0; i < numElements; i++) { + omniruntime::type::Decimal64 d(values[i]); + newVectorPtr->SetValue(i, d.GetValue()); + } + } + return newVector; +} + std::unique_ptr CopyToOmniDecimal128Vec(orc::ColumnVectorBatch *field) { orc::Decimal128VectorBatch *lvb = dynamic_cast(field); @@ -532,6 +621,8 @@ std::unique_ptr DealLongVectorBatch(DataTypeId id, orc::ColumnVector return CopyFixedWidth(field); case omniruntime::type::OMNI_DATE64: return CopyOptimizedForInt64(field); + case omniruntime::type::OMNI_VARCHAR: + return CopyLongForOmniVar(field); default: { throw std::runtime_error("DealLongVectorBatch not support for type: " + id); } @@ -542,6 +633,8 @@ std::unique_ptr DealDoubleVectorBatch(DataTypeId id, orc::ColumnVect switch (id) { case omniruntime::type::OMNI_DOUBLE: return CopyOptimizedForInt64(field); + case omniruntime::type::OMNI_DECIMAL64: + return CopyDoubleToOmniDecimal64Vec(field); default: { throw std::runtime_error("DealDoubleVectorBatch not support for type: " + id); } @@ -592,6 +685,9 @@ std::unique_ptr CopyToOmniVec(const orc::Type *type, int omniTypeId, return CopyCharType(field); case orc::TypeKind::STRING: case orc::TypeKind::VARCHAR: + if (dataTypeId == OMNI_DOUBLE) { + return CopyVarForOmniDouble(field); + } if (dataTypeId != OMNI_VARCHAR) { throw std::runtime_error("Cannot transfer to other OMNI_TYPE but VARCHAR for orc string/varchar"); }