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

Function SmallestTypeFor

cpp/src/arrow/compute/expression.cc:386–520  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

384namespace {
385
386TypeHolder SmallestTypeFor(const arrow::Datum& value) {
387 switch (value.type()->id()) {
388 case Type::INT8:
389 return int8();
390 case Type::UINT8:
391 return uint8();
392 case Type::INT16: {
393 int16_t i16 = value.scalar_as<Int16Scalar>().value;
394 if (i16 <= std::numeric_limits<int8_t>::max() &&
395 i16 >= std::numeric_limits<int8_t>::min()) {
396 return int8();
397 }
398 return int16();
399 }
400 case Type::UINT16: {
401 uint16_t ui16 = value.scalar_as<UInt16Scalar>().value;
402 if (ui16 <= std::numeric_limits<uint8_t>::max()) {
403 return uint8();
404 }
405 return uint16();
406 }
407 case Type::INT32: {
408 int32_t i32 = value.scalar_as<Int32Scalar>().value;
409 if (i32 <= std::numeric_limits<int8_t>::max() &&
410 i32 >= std::numeric_limits<int8_t>::min()) {
411 return int8();
412 }
413 if (i32 <= std::numeric_limits<int16_t>::max() &&
414 i32 >= std::numeric_limits<int16_t>::min()) {
415 return int16();
416 }
417 return int32();
418 }
419 case Type::UINT32: {
420 uint32_t ui32 = value.scalar_as<UInt32Scalar>().value;
421 if (ui32 <= std::numeric_limits<uint8_t>::max()) {
422 return uint8();
423 }
424 if (ui32 <= std::numeric_limits<uint16_t>::max()) {
425 return uint16();
426 }
427 return uint32();
428 }
429 case Type::INT64: {
430 int64_t i64 = value.scalar_as<Int64Scalar>().value;
431 if (i64 <= std::numeric_limits<int8_t>::max() &&
432 i64 >= std::numeric_limits<int8_t>::min()) {
433 return int8();
434 }
435 if (i64 <= std::numeric_limits<int16_t>::max() &&
436 i64 >= std::numeric_limits<int16_t>::min()) {
437 return int16();
438 }
439 if (i64 <= std::numeric_limits<int32_t>::max() &&
440 i64 >= std::numeric_limits<int32_t>::min()) {
441 return int32();
442 }
443 return int64();

Calls 6

timezoneMethod · 0.80
timestampFunction · 0.50
idMethod · 0.45
typeMethod · 0.45
sizeMethod · 0.45
unitMethod · 0.45

Tested by

no test coverage detected