Skip to content

Commit

Permalink
Add getReal() function similar to getSigned().
Browse files Browse the repository at this point in the history
Changed getCurrValue() to getCurrIntValue().
  • Loading branch information
jackdelv committed Oct 12, 2023
1 parent a3e9506 commit d63ca53
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
53 changes: 27 additions & 26 deletions plugins/parquet/parquetembed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,21 @@ unsigned __int64 getUnsigned(std::shared_ptr<ParquetArrayVisitor> *array_visitor
}
}

double getReal(std::shared_ptr<ParquetArrayVisitor> *array_visitor, int index)
{
switch ((*array_visitor)->size)
{
case 2:
return (*array_visitor)->half_float_arr->Value(index);
case 4:
return (*array_visitor)->float_arr->Value(index);
case 8:
return (*array_visitor)->double_arr->Value(index);
default:
failx("getReal: Invalid size %i", (*array_visitor)->size);
}
}

std::string_view ParquetRowBuilder::getCurrView(const RtlFieldInfo *field)
{
serialized.clear();
Expand All @@ -885,14 +900,8 @@ std::string_view ParquetRowBuilder::getCurrView(const RtlFieldInfo *field)
return (*array_visitor)->bin_arr->GetView(currArrayIndex());
case LargeBinaryType:
return (*array_visitor)->large_bin_arr->GetView(currArrayIndex());
case DoubleType:
tokenSerializer.serialize((*array_visitor)->double_arr->Value(currArrayIndex()), serialized);
return serialized.str();
case HalfFloatType:
tokenSerializer.serialize((*array_visitor)->half_float_arr->Value(currArrayIndex()), serialized);
return serialized.str();
case FloatType:
tokenSerializer.serialize((*array_visitor)->float_arr->Value(currArrayIndex()), serialized);
case RealType:
tokenSerializer.serialize(getReal(array_visitor, currArrayIndex()), serialized);
return serialized.str();
case IntType:
tokenSerializer.serialize(getSigned(array_visitor, currArrayIndex()), serialized);
Expand Down Expand Up @@ -923,7 +932,7 @@ std::string_view ParquetRowBuilder::getCurrView(const RtlFieldInfo *field)
}
}

__int64 ParquetRowBuilder::getCurrValue(const RtlFieldInfo *field)
__int64 ParquetRowBuilder::getCurrIntValue(const RtlFieldInfo *field)
{
switch ((*array_visitor)->type)
{
Expand All @@ -933,12 +942,8 @@ __int64 ParquetRowBuilder::getCurrValue(const RtlFieldInfo *field)
return getSigned(array_visitor, currArrayIndex());
case UIntType:
return getUnsigned(array_visitor, currArrayIndex());
case DoubleType:
return (*array_visitor)->double_arr->Value(currArrayIndex());
case HalfFloatType:
return (*array_visitor)->half_float_arr->Value(currArrayIndex());
case FloatType:
return (*array_visitor)->float_arr->Value(currArrayIndex());
case RealType:
return getReal(array_visitor, currArrayIndex());
case DateType:
return (*array_visitor)->size == 32 ? (*array_visitor)->date32_arr->Value(currArrayIndex()) : (*array_visitor)->date64_arr->Value(currArrayIndex());
case TimestampType:
Expand Down Expand Up @@ -973,7 +978,7 @@ bool ParquetRowBuilder::getBooleanResult(const RtlFieldInfo *field)
return p.boolResult;
}

return getCurrValue(field);
return getCurrIntValue(field);
}

/**
Expand Down Expand Up @@ -1015,14 +1020,10 @@ double ParquetRowBuilder::getRealResult(const RtlFieldInfo *field)
return p.doubleResult;
}

switch((*array_visitor)->type)
{ case DoubleType:
return (*array_visitor)->double_arr->Value(currArrayIndex());
case FloatType:
return (*array_visitor)->float_arr->Value(currArrayIndex());
default:
return getCurrValue(field);
}
if ((*array_visitor)->type == RealType)
return getReal(array_visitor, currArrayIndex());
else
return getCurrIntValue(field);
}

/**
Expand All @@ -1041,7 +1042,7 @@ __int64 ParquetRowBuilder::getSignedResult(const RtlFieldInfo *field)
return p.intResult;
}

return getCurrValue(field);
return getCurrIntValue(field);
}

/**
Expand All @@ -1063,7 +1064,7 @@ unsigned __int64 ParquetRowBuilder::getUnsignedResult(const RtlFieldInfo *field)
if ((*array_visitor)->type == UIntType)
return getUnsigned(array_visitor, currArrayIndex());
else
return getCurrValue(field);
return getCurrIntValue(field);
}

/**
Expand Down
15 changes: 8 additions & 7 deletions plugins/parquet/parquetembed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,14 @@ enum ParquetArrayType
TimestampType,
TimeType,
DurationType,
HalfFloatType,
FloatType,
StringType,
LargeStringType,
BinaryType,
LargeBinaryType,
DecimalType,
ListType,
StructType,
DoubleType
RealType
};

class ParquetArrayVisitor : public arrow::ArrayVisitor
Expand Down Expand Up @@ -261,19 +259,22 @@ class ParquetArrayVisitor : public arrow::ArrayVisitor
arrow::Status Visit(const arrow::HalfFloatArray &array)
{
half_float_arr = &array;
type = HalfFloatType;
type = RealType;
size = 2;
return arrow::Status::OK();
}
arrow::Status Visit(const arrow::FloatArray &array)
{
float_arr = &array;
type = FloatType;
type = RealType;
size = 4;
return arrow::Status::OK();
}
arrow::Status Visit(const arrow::DoubleArray &array)
{
double_arr = &array;
type = DoubleType;
type = RealType;
size = 8;
return arrow::Status::OK();
}
arrow::Status Visit(const arrow::StringArray &array)
Expand Down Expand Up @@ -897,7 +898,7 @@ class ParquetRowBuilder : public CInterfaceOf<IFieldSource>
protected:
const std::shared_ptr<arrow::Array> &getChunk(std::shared_ptr<arrow::ChunkedArray> *column);
std::string_view getCurrView(const RtlFieldInfo *field);
__int64 getCurrValue(const RtlFieldInfo *field);
__int64 getCurrIntValue(const RtlFieldInfo *field);
void nextField(const RtlFieldInfo *field);
void nextFromStruct(const RtlFieldInfo *field);
void xpathOrName(StringBuffer &outXPath, const RtlFieldInfo *field) const;
Expand Down

0 comments on commit d63ca53

Please sign in to comment.