MCPcopy Create free account
hub / github.com/apache/arrow / FormatDecimalValue

Function FormatDecimalValue

cpp/src/parquet/types.cc:120–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120std::string FormatDecimalValue(Type::type parquet_type, ::std::string_view val,
121 const std::shared_ptr<const LogicalType>& logical_type) {
122 ARROW_DCHECK(logical_type != nullptr && logical_type->is_decimal());
123
124 const auto& decimal_type =
125 ::arrow::internal::checked_cast<const DecimalLogicalType&>(*logical_type);
126 const int32_t scale = decimal_type.scale();
127
128 std::stringstream result;
129 switch (parquet_type) {
130 case Type::INT32: {
131 int32_t int_value{};
132 std::memcpy(&int_value, val.data(), std::min(sizeof(int32_t), val.size()));
133 ::arrow::Decimal128 decimal_value(int_value);
134 result << decimal_value.ToString(scale);
135 break;
136 }
137 case Type::INT64: {
138 int64_t long_value{};
139 std::memcpy(&long_value, val.data(), std::min(sizeof(int64_t), val.size()));
140 ::arrow::Decimal128 decimal_value(long_value);
141 result << decimal_value.ToString(scale);
142 break;
143 }
144 case Type::FIXED_LEN_BYTE_ARRAY:
145 case Type::BYTE_ARRAY: {
146 auto decimal_result = ::arrow::Decimal256::FromBigEndian(
147 reinterpret_cast<const uint8_t*>(val.data()), static_cast<int32_t>(val.size()));
148 if (!decimal_result.ok()) {
149 throw ParquetException("Failed to parse decimal value: ",
150 decimal_result.status().message());
151 }
152 result << decimal_result.ValueUnsafe().ToString(scale);
153 break;
154 }
155 default:
156 throw ParquetException("Unsupported decimal type: ", TypeToString(parquet_type));
157 }
158
159 return result.str();
160}
161
162std::string FormatNonUTF8Value(::std::string_view val) {
163 if (val.empty()) {

Callers 1

FormatStatValueFunction · 0.85

Calls 12

ParquetExceptionFunction · 0.85
TypeToStringFunction · 0.85
is_decimalMethod · 0.80
ValueUnsafeMethod · 0.80
strMethod · 0.80
FromBigEndianFunction · 0.50
scaleMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
ToStringMethod · 0.45
okMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected