Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILO-HE committed Feb 16, 2024
1 parent 9838c7e commit f6c6fda
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
13 changes: 13 additions & 0 deletions velox/exec/tests/utils/QueryAssertions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ variant variantAt<TypeKind::TIMESTAMP>(
dataChunk->GetValue(column, row).GetValue<::duckdb::timestamp_t>()));
}

template <>
variant variantAt<TypeKind::UNKNOWN>(
::duckdb::DataChunk* dataChunk,
int32_t row,
int32_t column) {
return variant::null(TypeKind::UNKNOWN);
}

template <TypeKind kind>
variant variantAt(const ::duckdb::Value& value) {
if (value.type() == ::duckdb::LogicalType::INTERVAL) {
Expand All @@ -288,6 +296,11 @@ variant variantAt(const ::duckdb::Value& value) {
}
}

template <>
variant variantAt<TypeKind::UNKNOWN>(const ::duckdb::Value& value) {
return variant::null(TypeKind::UNKNOWN);
}

template <>
velox::variant variantAt<TypeKind::HUGEINT>(const ::duckdb::Value& value) {
auto hugeInt = ::duckdb::HugeIntValue::Get(value);
Expand Down
7 changes: 7 additions & 0 deletions velox/functions/prestosql/aggregates/PrestoHasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ FOLLY_ALWAYS_INLINE void PrestoHasher::hash(
hashIntegral<T>(*vector_.get(), rows, hashes);
}

template <>
FOLLY_ALWAYS_INLINE void PrestoHasher::hash<TypeKind::UNKNOWN>(
const SelectivityVector& rows,
BufferPtr& hashes) {
applyHashFunction(rows, *vector_.get(), hashes, [&](auto row) { return 0; });
}

template <>
FOLLY_ALWAYS_INLINE void PrestoHasher::hash<TypeKind::BOOLEAN>(
const SelectivityVector& rows,
Expand Down
9 changes: 8 additions & 1 deletion velox/functions/prestosql/types/JsonType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,14 +586,21 @@ simdjson::error_code appendMapKey(
const std::string_view& value,
exec::GenericWriter& writer) {
using T = typename TypeTraits<kind>::NativeType;
if constexpr (std::is_same_v<T, void>) {
if constexpr (std::is_same_v<T, void> || std::is_same_v<T, UnknownValue>) {
return simdjson::INCORRECT_TYPE;
} else {
SIMDJSON_ASSIGN_OR_RAISE(writer.castTo<T>(), fromString<T>(value));
return simdjson::SUCCESS;
}
}

template <>
simdjson::error_code appendMapKey<TypeKind::UNKNOWN>(
const std::string_view& value,
exec::GenericWriter& writer) {
VELOX_NYI("UNKNOWN type is not supported!");
}

template <>
simdjson::error_code appendMapKey<TypeKind::VARCHAR>(
const std::string_view& value,
Expand Down
29 changes: 27 additions & 2 deletions velox/type/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ struct UnknownValue {
bool operator>=(const UnknownValue& /* b */) const {
return true;
}

operator std::string() const {
return "NULL";
}
};

template <typename T>
Expand Down Expand Up @@ -1420,6 +1424,10 @@ std::shared_ptr<const OpaqueType> OPAQUE() {
return TEMPLATE_FUNC<::facebook::velox::TypeKind::TIMESTAMP>( \
__VA_ARGS__); \
} \
case ::facebook::velox::TypeKind::UNKNOWN: { \
return TEMPLATE_FUNC<::facebook::velox::TypeKind::UNKNOWN>( \
__VA_ARGS__); \
} \
default: \
VELOX_FAIL( \
"not a scalar type! kind: {}", mapTypeKindToName(typeKind)); \
Expand Down Expand Up @@ -1552,8 +1560,15 @@ std::shared_ptr<const OpaqueType> OPAQUE() {
} \
}()

#define VELOX_DYNAMIC_TYPE_DISPATCH(TEMPLATE_FUNC, typeKind, ...) \
VELOX_DYNAMIC_TYPE_DISPATCH_IMPL(TEMPLATE_FUNC, , typeKind, __VA_ARGS__)
#define VELOX_DYNAMIC_TYPE_DISPATCH(TEMPLATE_FUNC, typeKind, ...) \
[&]() { \
if ((typeKind) == ::facebook::velox::TypeKind::UNKNOWN) { \
return TEMPLATE_FUNC<::facebook::velox::TypeKind::UNKNOWN>(__VA_ARGS__); \
} else { \
return VELOX_DYNAMIC_TYPE_DISPATCH_IMPL( \
TEMPLATE_FUNC, , typeKind, __VA_ARGS__); \
} \
}()

#define VELOX_DYNAMIC_TYPE_DISPATCH_ALL(TEMPLATE_FUNC, typeKind, ...) \
[&]() { \
Expand Down Expand Up @@ -2390,6 +2405,16 @@ struct IsRowType<Row<Ts...>> {

} // namespace facebook::velox

namespace std {
template <>
struct hash<::facebook::velox::UnknownValue> {
size_t operator()(const ::facebook::velox::UnknownValue& /* value */) const {
return 0;
}
};

} // namespace std

namespace folly {
template <>
struct hasher<::facebook::velox::UnknownValue> {
Expand Down

0 comments on commit f6c6fda

Please sign in to comment.