Skip to content

Commit 238e35f

Browse files
authored
Support date type in SubstraitToVeloxPlan and hash function (#96)
1 parent 7a34ae7 commit 238e35f

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

velox/functions/sparksql/Hash.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ uint32_t hashDouble(double input, uint32_t seed) {
106106
input == -0. ? 0 : *reinterpret_cast<uint64_t*>(&input), seed);
107107
}
108108

109+
uint32_t hashDate(Date input, uint32_t seed) {
110+
return hashInt32(input.days(), seed);
111+
}
112+
109113
class HashFunction final : public exec::VectorFunction {
110114
bool isDefaultNullBehavior() const final {
111115
return false;
@@ -154,6 +158,7 @@ class HashFunction final : public exec::VectorFunction {
154158
CASE(VARBINARY, hashBytes, StringView);
155159
CASE(REAL, hashFloat, float);
156160
CASE(DOUBLE, hashDouble, double);
161+
CASE(DATE, hashDate, int32_t);
157162
#undef CASE
158163
default:
159164
VELOX_NYI("Unsupported type for HASH(): {}", arg->type()->toString());

velox/substrait/SubstraitToVeloxPlan.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,13 @@ void SubstraitVeloxPlanConverter::setFilterMap(
16151615
setColInfoMap<std::string>(
16161616
functionName, colIdxVal, val, reverse, colInfoMap);
16171617
break;
1618+
case TypeKind::DATE:
1619+
if (substraitLit) {
1620+
val = variant(Date(substraitLit.value().date()));
1621+
}
1622+
setColInfoMap<int>(
1623+
functionName, colIdxVal, val, reverse, colInfoMap);
1624+
break;
16181625
default:
16191626
VELOX_NYI(
16201627
"Subfield filters creation not supported for input type '{}'",
@@ -1892,6 +1899,10 @@ connector::hive::SubfieldFilters SubstraitVeloxPlanConverter::mapToFilters(
18921899
constructSubfieldFilters<TypeKind::VARCHAR, common::Filter>(
18931900
colIdx, inputNameList[colIdx], colInfoMap[colIdx], filters);
18941901
break;
1902+
case TypeKind::DATE:
1903+
constructSubfieldFilters<TypeKind::DATE, common::BigintRange>(
1904+
colIdx, inputNameList[colIdx], colInfoMap[colIdx], filters);
1905+
break;
18951906
default:
18961907
VELOX_NYI(
18971908
"Subfield filters creation not supported for input type '{}'",

velox/substrait/SubstraitToVeloxPlanValidator.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,8 @@ bool SubstraitToVeloxPlanValidator::validate(
336336
return false;
337337
}
338338

339-
// In velox, the supported hash type in projectNode is
340-
// BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, VARCHAR, VARBINARY
341-
// REAL, DOUBLE. Hash.cpp (L148 - L156)
342339
for (auto i = 0; i < types.size(); i++) {
343340
switch (types[i]->kind()) {
344-
case TypeKind::DATE:
345-
return false;
346341
case TypeKind::ARRAY:
347342
return false;
348343
default:;

velox/substrait/TypeUtils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ struct RangeTraits<TypeKind::VARCHAR> {
6060
using NativeType = std::string;
6161
};
6262

63+
template <>
64+
struct RangeTraits<TypeKind::DATE> {
65+
using RangeType = common::BigintRange;
66+
using MultiRangeType = common::BigintMultiRange;
67+
using NativeType = int32_t;
68+
};
69+
6370
#endif /* RANGETRAITS_H */
6471

6572
} // namespace facebook::velox::substrait

0 commit comments

Comments
 (0)