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

Function FormatStatValue

cpp/src/parquet/types.cc:189–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

187} // namespace
188
189std::string FormatStatValue(Type::type parquet_type, ::std::string_view val,
190 const std::shared_ptr<const LogicalType>& logical_type) {
191 // Statistics values come straight from the file's Thrift metadata, so their
192 // length is attacker controlled and the spec allows them to be truncated.
193 // Every fixed-width read below clamps its copy to val.size() so a too-short
194 // value cannot drive a load past the end of the buffer.
195 std::stringstream result;
196 const char* bytes = val.data();
197 switch (parquet_type) {
198 case Type::BOOLEAN: {
199 bool value{};
200 std::memcpy(&value, bytes, std::min(sizeof(bool), val.size()));
201 result << value;
202 break;
203 }
204 case Type::INT32: {
205 if (logical_type != nullptr && logical_type->is_decimal()) {
206 return FormatDecimalValue(parquet_type, val, logical_type);
207 }
208 return FormatNumericValue<int32_t>(val);
209 }
210 case Type::INT64: {
211 if (logical_type != nullptr && logical_type->is_decimal()) {
212 return FormatDecimalValue(parquet_type, val, logical_type);
213 }
214 return FormatNumericValue<int64_t>(val);
215 }
216 case Type::DOUBLE: {
217 return FormatNumericValue<double>(val);
218 }
219 case Type::FLOAT: {
220 return FormatNumericValue<float>(val);
221 }
222 case Type::INT96: {
223 std::array<int32_t, 3> values{};
224 std::memcpy(values.data(), bytes, std::min(sizeof(values), val.size()));
225 result << values[0] << " " << values[1] << " " << values[2];
226 break;
227 }
228 case Type::BYTE_ARRAY:
229 case Type::FIXED_LEN_BYTE_ARRAY: {
230 if (logical_type != nullptr) {
231 if (logical_type->is_decimal()) {
232 return FormatDecimalValue(parquet_type, val, logical_type);
233 }
234 if (logical_type->is_string()) {
235 return std::string(val);
236 }
237 if (logical_type->is_float16()) {
238 return FormatFloat16Value(val);
239 }
240 }
241 return FormatNonUTF8Value(val);
242 }
243 case Type::UNDEFINED:
244 default:
245 break;
246 }

Callers 3

TESTFunction · 0.85
DebugPrintMethod · 0.85
JSONPrintMethod · 0.85

Calls 9

FormatDecimalValueFunction · 0.85
FormatFloat16ValueFunction · 0.85
FormatNonUTF8ValueFunction · 0.85
is_decimalMethod · 0.80
is_stringMethod · 0.80
is_float16Method · 0.80
strMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45

Tested by 1

TESTFunction · 0.68