Skip to content

Conversation

@pramodsatya
Copy link
Collaborator

@pramodsatya pramodsatya commented Oct 17, 2025

No description provided.

@netlify
Copy link

netlify bot commented Oct 17, 2025

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit a017702
🔍 Latest deploy log https://app.netlify.com/projects/meta-velox/deploys/68f9288d55b0780008eab98d

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 17, 2025
value_{std::move(value)} {}
value_{std::move(value)} {
VELOX_CHECK_EQ(
value_.kind(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is not sufficient for complex types. Use isTypeCompatible instead. Please, add tests to ensure that ConstantTypedExpr(ARRAY(VARCHAR()), variant::array({1,2,3}) fails.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mbasmanova, updated to use isTypeCompatible. Could you PTAL?

// Constant expr created using variant
auto nullVariantToExpr =
std::make_shared<core::ConstantTypedExpr>(VARCHAR(), Variant{});
auto nullVariantToExpr = std::make_shared<core::ConstantTypedExpr>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is incorrect. Once you use isTypeCompatible it won't be needed.

Copy link
Collaborator Author

@pramodsatya pramodsatya Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variant{} is initialized with TypeKind::INVALID here, so the null variant needs to be initialized with matching type, otherwise the test fails with below error using isTypeCompatible:

C++ exception with description "Exception: VeloxRuntimeError
Error Source: RUNTIME
Error Code: INVALID_STATE
Reason: Expression type does not match variant type
Retriable: False
Expression: value_.isTypeCompatible(ITypedExpr::type())
Function: ConstantTypedExpr

Is this fine?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pramodsatya I see. This is interesting. We may need to look into the use of TypeKind::INVALID. It feels like this shouldn't exist in the first place. Especially since I assume Variant::isNull() returns true for Variant{}. Perhaps, we need another fix to replace TypeKind::INVALID with TypeKind::UNKNOWN in Variant{} constructor or just handle INVALID the same way as UNKNOWN everywhere else. Would you create an issue about this? The change in this PR is fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mbasmanova, I agree the use of TypeKind::INVALID seems incorrect here and changing to TypeKind::UNKNOWN would be better: pramodsatya@b760e87. Should I open an issue for further discussion or shall I open a PR with this commit?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pramodsatya Please, open a PR. Thanks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mbasmanova, opened #15250, please take a look when you get a chance

value_{std::move(value)} {
VELOX_CHECK(
value_.isTypeCompatible(ITypedExpr::type()),
"Expression type does not match variant type");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's include both types in the error message to help troubleshooting?


TEST_F(ConstantTypedExprTest, variantTypeCheck) {
VELOX_ASSERT_THROW(
std::make_shared<core::ConstantTypedExpr>(INTEGER(), "abc"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's introduce a helper lambda and a constant for error message to reduce copy-paste.

VELOX_ASSERT_THROW(makeConstant(INTEGER(), "abc"), ...), kTypeMismatch);

std::make_shared<core::ConstantTypedExpr>(INTEGER(), "abc"),
"Expression type does not match variant type");
VELOX_ASSERT_THROW(
std::make_shared<core::ConstantTypedExpr>(INTEGER(), variant(123LL)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add tests that use null variants.


TEST_F(ConstantTypedExprTest, variantTypeCheck) {
auto testVariantExpr =
[&](Variant value, const TypePtr type, const TypePtr expectedType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass arguments by const &

"Expression type {} does not match variant type {}",
type->toString(),
expectedType->toString()));
if (type->isPrimitiveType()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you add an else branch to verify that createVariantExpr succeeds?

@mbasmanova mbasmanova changed the title fix: Ensure ConstantTypedExpr and variant types are equivalent fix: Ensure ConstantTypedExpr and variant types are compatible Oct 22, 2025
Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@mbasmanova mbasmanova added the ready-to-merge PR that have been reviewed and are ready for merging. PRs with this tag notify the Velox Meta oncall label Oct 22, 2025
@meta-codesync
Copy link

meta-codesync bot commented Oct 22, 2025

@mbasmanova has imported this pull request. If you are a Meta employee, you can view this in D85276445.

@meta-codesync meta-codesync bot closed this in cf403b8 Oct 23, 2025
@meta-codesync
Copy link

meta-codesync bot commented Oct 23, 2025

@mbasmanova merged this pull request in cf403b8.

mhaseeb123 pushed a commit to mhaseeb123/velox that referenced this pull request Oct 27, 2025
…ookincubator#15217)

Summary: Pull Request resolved: facebookincubator#15217

Reviewed By: peterenescu

Differential Revision: D85276445

Pulled By: mbasmanova

fbshipit-source-id: ddf6a5f25541343d479bf0c00e6d48f3de79da0b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged ready-to-merge PR that have been reviewed and are ready for merging. PRs with this tag notify the Velox Meta oncall

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants