pitrou commented on code in PR #14380:
URL: https://github.com/apache/arrow/pull/14380#discussion_r993215782
##########
cpp/src/arrow/json/converter_test.cc:
##########
@@ -190,9 +190,12 @@ TEST(ConverterTest, Decimal128And256) {
options.explicit_schema = schema({field("", decimal_type)});
std::string json_source = R"(
- {"" : "02.0000000000"}
- {"" : "30.0000000000"}
- )";
+ {"" : "02.0000000000"}
+ {"" : "30.0000000000"}
+ {"" : "30.01"}
+ {"" : "30.0000000000123"}
Review Comment:
For example, our CSV reader would emit an error instead of dropping some
digits like this.
##########
cpp/src/arrow/json/converter.cc:
##########
@@ -166,10 +166,19 @@ class DecimalConverter : public PrimitiveConverter {
using Builder = typename TypeTraits<T>::BuilderType;
Builder builder(out_type_, pool_);
RETURN_NOT_OK(builder.Resize(dict_array.indices()->length()));
+ const auto& decimal_type(checked_cast<const DecimalType&>(*out_type_));
+ int32_t out_scale = decimal_type.scale();
- auto visit_valid = [&builder](string_view repr) {
- ARROW_ASSIGN_OR_RAISE(value_type value,
-
TypeTraits<T>::BuilderType::ValueType::FromString(repr));
+ auto visit_valid = [&builder, out_scale](string_view repr) {
+ value_type value;
+ int32_t precision, scale;
+ RETURN_NOT_OK(TypeTraits<T>::BuilderType::ValueType::FromString(
+ repr, &value, &precision, &scale));
Review Comment:
While we are it, can we also check that `precision` does not exceed the
expected precision?
##########
cpp/src/arrow/json/converter_test.cc:
##########
@@ -190,9 +190,12 @@ TEST(ConverterTest, Decimal128And256) {
options.explicit_schema = schema({field("", decimal_type)});
std::string json_source = R"(
- {"" : "02.0000000000"}
- {"" : "30.0000000000"}
- )";
+ {"" : "02.0000000000"}
+ {"" : "30.0000000000"}
+ {"" : "30.01"}
+ {"" : "30.0000000000123"}
Review Comment:
Do we want truncation to happen silently or would we rather get an error
here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]