Skip to content

Commit

Permalink
Allow UNKNOWN type in HivePartitionFunction (#7784)
Browse files Browse the repository at this point in the history
Summary:

This diff fixes #7487.

Reviewed By: Yuhta

Differential Revision: D51604009
  • Loading branch information
kagamiori authored and facebook-github-bot committed Dec 5, 2023
1 parent 975ca3a commit ae4ca60
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
27 changes: 26 additions & 1 deletion velox/connectors/hive/HivePartitionFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ inline uint32_t hashOne<TypeKind::TIMESTAMP>(const Timestamp& value) {
return hashTimestamp(value);
}

template <>
inline uint32_t hashOne<TypeKind::UNKNOWN>(const UnknownValue& /*value*/) {
VELOX_FAIL("Unknown values cannot be non-NULL");
}

template <TypeKind kind>
void hashPrimitive(
const DecodedVector& values,
Expand Down Expand Up @@ -245,6 +250,26 @@ void HivePartitionFunction::hashTyped<TypeKind::TIMESTAMP>(
hashPrimitive<TypeKind::TIMESTAMP>(values, rows, mix, hashes);
}

template <>
void HivePartitionFunction::hashTyped<TypeKind::UNKNOWN>(
const DecodedVector& values,
const SelectivityVector& rows,
bool mix,
std::vector<uint32_t>& hashes,
size_t /* poolIndex */) {
hashPrimitive<TypeKind::UNKNOWN>(values, rows, mix, hashes);
}

template <>
void HivePartitionFunction::hashTyped<TypeKind::OPAQUE>(
const DecodedVector& /*values*/,
const SelectivityVector& /*rows*/,
bool /*mix*/,
std::vector<uint32_t>& /*hashes*/,
size_t /* poolIndex */) {
VELOX_UNSUPPORTED("Hive partitioning function doesn't support OPAQUE type");
}

template <>
void HivePartitionFunction::hashTyped<TypeKind::ARRAY>(
const DecodedVector& values,
Expand Down Expand Up @@ -426,7 +451,7 @@ void HivePartitionFunction::hash(
// gets implemented, this function will need to change
// significantly.

VELOX_DYNAMIC_TYPE_DISPATCH(
VELOX_DYNAMIC_TYPE_DISPATCH_ALL(
hashTyped, typeKind, values, rows, mix, hashes, poolIndex);
}

Expand Down
14 changes: 14 additions & 0 deletions velox/connectors/hive/tests/HivePartitionFunctionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,3 +727,17 @@ TEST_F(HivePartitionFunctionTest, function) {
}
}
}

TEST_F(HivePartitionFunctionTest, unknown) {
auto values = makeAllNullFlatVector<UnknownValue>(4);

assertPartitions(values, 1, {0, 0, 0, 0});
assertPartitions(values, 2, {0, 0, 0, 0});
assertPartitions(values, 500, {0, 0, 0, 0});
assertPartitions(values, 997, {0, 0, 0, 0});

assertPartitionsWithConstChannel(values, 1);
assertPartitionsWithConstChannel(values, 2);
assertPartitionsWithConstChannel(values, 500);
assertPartitionsWithConstChannel(values, 997);
}

0 comments on commit ae4ca60

Please sign in to comment.