Skip to content

Commit

Permalink
Fix decimal translation
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdelv committed Aug 22, 2024
1 parent f625a05 commit 1d76ff1
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions plugins/parquet/parquetembed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1917,23 +1917,26 @@ void ParquetRecordBinder::processDecimal(const void *value, unsigned digits, uns
rtlDataAttr decText;
val.setDecimal(digits, precision, value);
val.getStringX(bytes, decText.refstr());
// unsigned numDigits;
// val.getPrecision(numDigits, precision);
// assert(numDigits <= 64 && precision <= 32);
// int32_t decDigits = (int32_t) numDigits;
// int32_t decPrecision = (int32_t) precision;

unsigned numDigits = 0;
val.getPrecision(numDigits, precision);
assert(numDigits <= 64 && precision <= 32);
int32_t decDigits = (int32_t) numDigits;
int32_t decPrecision = (int32_t) precision;

arrow::ArrayBuilder *fieldBuilder = parquetWriter->getFieldBuilder(field);
if (fieldBuilder->type()->id() == arrow::Type::DECIMAL128)
{
arrow::Decimal128Builder *decimal128Builder = static_cast<arrow::Decimal128Builder *>(fieldBuilder);
PARQUET_ASSIGN_OR_THROW(arrow::Decimal128 decimal128, arrow::Decimal128::FromString(std::string_view(decText.getstr(), bytes)));
arrow::Decimal128 decimal128;
reportIfFailure(arrow::Decimal128::FromString(std::string_view(decText.getstr(), bytes), &decimal128, &decDigits, &decPrecision));
reportIfFailure(decimal128Builder->Append(decimal128));
}
else if (fieldBuilder->type()->id() == arrow::Type::DECIMAL256)
{
arrow::Decimal256Builder *decimal256Builder = static_cast<arrow::Decimal256Builder *>(fieldBuilder);
PARQUET_ASSIGN_OR_THROW(arrow::Decimal256 decimal256, arrow::Decimal256::FromString(std::string_view(decText.getstr(), bytes)));
arrow::Decimal256 decimal256;
reportIfFailure(arrow::Decimal256::FromString(std::string_view(decText.getstr(), bytes), &decimal256, &decDigits, &decPrecision));
reportIfFailure(decimal256Builder->Append(decimal256));
}
else
Expand Down

0 comments on commit 1d76ff1

Please sign in to comment.