Skip to content

Commit f7c7e66

Browse files
PHILO-HEzhejiangxiaomai
authored andcommitted
Support date type in SubstraitToVeloxPlan and hash function (#96)
1 parent 0e5d6d1 commit f7c7e66

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

velox/functions/sparksql/Hash.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ void applyWithType(
6969
CASE(VARBINARY, hash.hashBytes, StringView);
7070
CASE(REAL, hash.hashFloat, float);
7171
CASE(DOUBLE, hash.hashDouble, double);
72+
CASE(DATE, hash.hashDate, int32_t);
7273
#undef CASE
7374
default:
7475
VELOX_NYI(
@@ -135,6 +136,10 @@ class Murmur3Hash final {
135136
return fmix(h1, input.size());
136137
}
137138

139+
uint32_t hashDate(Date input, uint32_t seed) {
140+
return hashInt32(input.days(), seed);
141+
}
142+
138143
private:
139144
uint32_t mixK1(uint32_t k1) {
140145
k1 *= 0xcc9e2d51;
@@ -235,6 +240,10 @@ class XxHash64 final {
235240
return fmix(hash);
236241
}
237242

243+
uint32_t hashDate(Date input, uint32_t seed) {
244+
return hashInt32(input.days(), seed);
245+
}
246+
238247
private:
239248
uint64_t fmix(uint64_t hash) {
240249
hash ^= hash >> 33;

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)