Skip to content

Commit 0842f48

Browse files
authored
Merge pull request #3099 from yashwantbezawada/fix-arrow-decimal-to-float
Fix Arrow decimal type conversion to float instead of integer
2 parents 3a3ca5e + 01d350c commit 0842f48

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

rust/perspective-python/perspective/tests/table/test_table_arrow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def test_table_arrow_loads_decimal_stream(self, util):
185185
tbl = Table(arrow_data)
186186
assert tbl.size() == 10
187187
assert tbl.schema() == {
188-
"a": "integer",
188+
"a": "float",
189189
}
190190
assert tbl.view().to_columns() == {"a": data[0]}
191191

@@ -389,7 +389,7 @@ def test_table_arrow_loads_decimal128_legacy(self, util):
389389
tbl = Table(arrow_data)
390390
assert tbl.size() == 10
391391
assert tbl.schema() == {
392-
"a": "integer",
392+
"a": "float",
393393
}
394394
assert tbl.view().to_columns() == {"a": data[0]}
395395

rust/perspective-server/cpp/perspective/src/cpp/arrow_loader.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,12 @@ convert_type(const std::string& src) {
170170
if (src == "uint64") {
171171
return DTYPE_UINT64;
172172
}
173-
if (src == "decimal" || src == "decimal128" || src == "int64") {
173+
if (src == "int64") {
174174
return DTYPE_INT64;
175175
}
176+
if (src == "decimal" || src == "decimal128") {
177+
return DTYPE_FLOAT64;
178+
}
176179
if (src == "float") {
177180
return DTYPE_FLOAT32;
178181
}
@@ -750,16 +753,13 @@ copy_array(
750753
case arrow::Decimal128Type::type_id:
751754
case arrow::DecimalType::type_id: {
752755
std::shared_ptr<arrow::Decimal128Array> scol =
753-
std::static_pointer_cast<arrow::DecimalArray>(src);
756+
std::static_pointer_cast<arrow::Decimal128Array>(src);
757+
auto decimal_type =
758+
std::static_pointer_cast<arrow::Decimal128Type>(src->type());
759+
int32_t scale = decimal_type->scale();
754760
auto* vals = (arrow::Decimal128*)scol->raw_values();
755761
for (uint32_t i = 0; i < len; ++i) {
756-
arrow::Status status =
757-
vals[i].ToInteger(dest->get_nth<int64_t>(offset + i));
758-
if (!status.ok()) {
759-
PSP_COMPLAIN_AND_ABORT(
760-
"Could not write Decimal to column: " + status.message()
761-
);
762-
};
762+
dest->set_nth<double>(offset + i, vals[i].ToDouble(scale));
763763
}
764764
} break;
765765
case arrow::BooleanType::type_id: {

0 commit comments

Comments
 (0)