in csrc/velox/column.h [121:183]
static velox::TypeKind promote(
velox::TypeKind a,
velox::TypeKind b,
PromoteStrategy promoteStrategy) {
constexpr auto b1 = velox::TypeKind::BOOLEAN;
constexpr auto i1 = velox::TypeKind::TINYINT;
constexpr auto i2 = velox::TypeKind::SMALLINT;
constexpr auto i4 = velox::TypeKind::INTEGER;
constexpr auto i8 = velox::TypeKind::BIGINT;
constexpr auto f4 = velox::TypeKind::REAL;
constexpr auto f8 = velox::TypeKind::DOUBLE;
constexpr auto num_numeric_types =
static_cast<int>(velox::TypeKind::DOUBLE) + 1;
VELOX_CHECK(
static_cast<int>(a) < num_numeric_types &&
static_cast<int>(b) < num_numeric_types);
if (a == b) {
return a;
}
switch (promoteStrategy) {
case PromoteStrategy::ColumnColumn: {
// Sliced from
// https://github.com/pytorch/pytorch/blob/1c502d1f8ec861c31a08d580ae7b73b7fbebebed/c10/core/ScalarType.h#L402-L421
static constexpr velox::TypeKind
promoteTypesLookup[num_numeric_types][num_numeric_types] = {
/* b1 i1 i2 i4 i8 f4 f8*/
/* b1 */ {b1, i1, i2, i4, i8, f4, f8},
/* i1 */ {i1, i1, i2, i4, i8, f4, f8},
/* i2 */ {i2, i2, i2, i4, i8, f4, f8},
/* i4 */ {i4, i4, i4, i4, i8, f4, f8},
/* i8 */ {i8, i8, i8, i8, i8, f4, f8},
/* f4 */ {f4, f4, f4, f4, f4, f4, f8},
/* f8 */ {f8, f8, f8, f8, f8, f8, f8},
};
return promoteTypesLookup[static_cast<int>(a)][static_cast<int>(b)];
} break;
case PromoteStrategy::ColumnScalar: {
// TODO: Decide on how we want to handle column-scalar type promotion.
// Current strategy is to always respect the type of the column for
// int-int cases.
static constexpr velox::TypeKind
promoteTypesLookup[num_numeric_types][num_numeric_types] = {
/* b1 i1 i2 i4 i8 f4 f8*/
/* b1 */ {b1, b1, b1, b1, b1, f4, f8},
/* i1 */ {i1, i1, i1, i1, i1, f4, f8},
/* i2 */ {i2, i2, i2, i2, i2, f4, f8},
/* i4 */ {i4, i4, i4, i4, i4, f4, f8},
/* i8 */ {i8, i8, i8, i8, i8, f4, f8},
/* f4 */ {f4, f4, f4, f4, f4, f4, f8},
/* f8 */ {f8, f8, f8, f8, f8, f8, f8},
};
return promoteTypesLookup[static_cast<int>(a)][static_cast<int>(b)];
} break;
default: {
throw std::logic_error(
"Unsupported promote: " +
std::to_string(static_cast<int64_t>(promoteStrategy)));
} break;
}
}