-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for casting UNKNOWN type to any other type #6996
Conversation
✅ Deploy Preview for meta-velox canceled.
|
bc36f5a
to
eaa0b75
Compare
eaa0b75
to
cddc99b
Compare
be9f06c
to
7f546f2
Compare
d35bc61
to
214198b
Compare
@mbasmanova, could you spare some time to review this patch? Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PHILO-HE Curious, what's the motivation for this PR?
@@ -274,6 +274,14 @@ variant variantAt<TypeKind::TIMESTAMP>( | |||
dataChunk->GetValue(column, row).GetValue<::duckdb::timestamp_t>())); | |||
} | |||
|
|||
template <> | |||
variant variantAt<TypeKind::UNKNOWN>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would this be called? I believe there is a check for null before this call. If that's the case, then, perhaps, a safer implementation would be to throw VELOX_UNREACHABLE.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just removed it and will cover it in another PR.
velox/expression/CastExpr.cpp
Outdated
@@ -724,6 +734,9 @@ void CastExpr::applyPeeled( | |||
fromType->asRow(), | |||
toType); | |||
break; | |||
case TypeKind::UNKNOWN: | |||
result = applyUnknown(rows, input, context, fromType, toType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just inline
result = BaseVector::createNullConstant(toType, rows.end(), context.pool());
velox/expression/CastExpr.h
Outdated
@@ -113,6 +113,13 @@ class CastExpr : public SpecialForm { | |||
const TypePtr& toType, | |||
VectorPtr& result); | |||
|
|||
VectorPtr applyUnknown( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is not using any member variables, hence, can be a free function in .cpp file. Also, the implementation is a one-liner and there is only one caller, hence, this function is not needed at all.
@@ -371,6 +371,19 @@ TEST_F(CastExprTest, basics) { | |||
{"1.888", "2.5", "3.6", "100.44", "-100.101", "1", "-2"}); | |||
} | |||
|
|||
TEST_F(CastExprTest, fromUnknownType) { | |||
testCast<UnknownValue, int>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int -> int32_t
Can we test all types?
FOLLY_ALWAYS_INLINE void PrestoHasher::hash<TypeKind::UNKNOWN>( | ||
const SelectivityVector& rows, | ||
BufferPtr& hashes) { | ||
applyHashFunction(rows, *vector_.get(), hashes, [&](auto row) { return 0; }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you add a test case for this change?
simdjson::error_code appendMapKey<TypeKind::UNKNOWN>( | ||
const std::string_view& value, | ||
exec::GenericWriter& writer) { | ||
VELOX_NYI("UNKNOWN type is not supported!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this ever be called? Isn't there a null check before this call? If so, VELOX_UNREACHABLE would be more appropriate.
velox/type/Type.h
Outdated
@@ -129,6 +129,10 @@ struct UnknownValue { | |||
bool operator>=(const UnknownValue& /* b */) const { | |||
return true; | |||
} | |||
|
|||
operator std::string() const { | |||
return "NULL"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this change for? Would it be possible to add a test?
velox/type/Type.h
Outdated
@@ -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>( \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this change? It will require a lot of updates to existing code. Would it be possible to avoid it?
ff45670
to
d4576d4
Compare
Hi @mbasmanova, thanks for your review! The motivation is we are trying to fix issues when enabling Spark NullType (UNKNOWN type of Velox). |
velox/type/Type.h
Outdated
@@ -2390,6 +2390,16 @@ struct IsRowType<Row<Ts...>> { | |||
|
|||
} // namespace facebook::velox | |||
|
|||
namespace std { | |||
template <> | |||
struct hash<::facebook::velox::UnknownValue> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hash for UNKNOWN type is required by VectorMakerStats. If lacked, compiling will fail.
See https://github.com/facebookincubator/velox/blob/main/velox/vector/tests/utils/VectorMakerStats.h#L86.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VectorMakerStats is deprecated. It would be great to not use it (and eventually delete it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just removed this and introduced some code in VectorMakerStats.h
to make the compiling pass. Maybe, better to delete deprecated code in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good % let's update documentation.
Hi @mbasmanova, I found the added tests can pass without any change for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PHILO-HE Looks good % one nit.
@@ -2,6 +2,8 @@ | |||
Conversion Functions | |||
==================== | |||
|
|||
Casting from UNKNOWN type to all other scalar types are supported, e.g., cast(NULL as int). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: "Casting.. are supported" -> "Casting... is supported"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mbasmanova, just fixed it and rebased the code. Thanks!
@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
98f569a
to
596a342
Compare
@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@mbasmanova merged this pull request in 62b8cfd. |
No description provided.