Skip to content
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

[GLUTEN-8742][VL] Improve the cast validation logic on native side #8743

Merged
merged 5 commits into from
Mar 5, 2025

Conversation

ArnavBalyan
Copy link
Contributor

@ArnavBalyan ArnavBalyan commented Feb 16, 2025

What changes were proposed in this pull request?

  • Currently the cast validation is unreadable and hard to maintain due to various addition/removals over time.
  • Refactor the validator to make cast validations consolidated and maintainable for new cast supports.

How was this patch tested?

  • Existing UTs

@github-actions github-actions bot added the VELOX label Feb 16, 2025
Copy link

#8742

@PHILO-HE PHILO-HE self-requested a review February 17, 2025 01:57
@ArnavBalyan ArnavBalyan force-pushed the arnavb/refactor-castvalidation branch from c924206 to 5c5b95e Compare February 17, 2025 14:35
@ArnavBalyan
Copy link
Contributor Author

cc @PHILO-HE could you please review UTs are now green thanks

Copy link
Contributor

@PHILO-HE PHILO-HE left a comment

Choose a reason for hiding this comment

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

@ArnavBalyan, thank you for your work! Some comments.

@@ -259,6 +259,57 @@ bool SubstraitToVeloxPlanValidator::validateLiteral(
return true;
}

bool SubstraitToVeloxPlanValidator::isDeniedCast(
Copy link
Contributor

@PHILO-HE PHILO-HE Feb 19, 2025

Choose a reason for hiding this comment

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

Preferred function name: isSupportedCast. Then return false for unsupported case.


if (toType->isIntervalYearMonth()) {
LOG_VALIDATION_MSG("Casting to " + toType->toString() + " is not supported.");
if (SubstraitToVeloxPlanValidator::isDeniedCast(fromKind, toKind, input->type(), toType)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

return isSuppportedCast(xxx);

Copy link
Contributor

Choose a reason for hiding this comment

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

Since we can easily get fromKind & toKind from the other arguments (see below), can we remove them from the argument list?

auto fromKind = input->type()->kind();
auto toKind = toType->kind();

@ArnavBalyan ArnavBalyan force-pushed the arnavb/refactor-castvalidation branch 2 times, most recently from c5e6cad to 29d503d Compare February 21, 2025 09:07
@github-actions github-actions bot added the BUILD label Feb 21, 2025
@ArnavBalyan ArnavBalyan force-pushed the arnavb/refactor-castvalidation branch from 29d503d to bc5def9 Compare February 21, 2025 09:10
@github-actions github-actions bot removed the BUILD label Feb 21, 2025
Copy link
Contributor

@PHILO-HE PHILO-HE left a comment

Choose a reason for hiding this comment

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

@ArnavBalyan, please fix code format violation, as reported by CI.

auto fromKind = input->type()->kind();
auto toKind = toType->kind();

if (SubstraitToVeloxPlanValidator::isAllowedCast(input->type(), toType)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove SubstraitToVeloxPlanValidator::, as it is not necessary.

For simplicity:
return isAllowedCast();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done formatting, isAllowedCast is using LOG_VALIDATION_MSG, etc which are scoped to SubstraitToVeloxPlanValidator, let me know if there is an alternate way thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

@ArnavBalyan, I tried with return isAllowedCast(input->type(), toType), it works. Could you change this code and let's see CI feedback?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@ArnavBalyan, I guess different GCC version has different requirement. I tested with lower GCC version. Sorry for this. Please add the namespace to make it available in this scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries at all thanks for the review, updated it

@ArnavBalyan
Copy link
Contributor Author

cc @PHILO-HE could you please take a look thanks!

core::TypedExprPtr input = exprConverter_->toVeloxExpr(castExpr.input(), inputType);

auto fromKind = input->type()->kind();
auto toKind = toType->kind();
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove these two useless lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@PHILO-HE
Copy link
Contributor

PHILO-HE commented Mar 4, 2025

cc @PHILO-HE could you please take a look thanks!

@ArnavBalyan, basically looks good! Just two trivial comments. Please also rebase the code. Thank you!

const auto& toType = SubstraitParser::parseType(castExpr.type());
core::TypedExprPtr input = exprConverter_->toVeloxExpr(castExpr.input(), inputType);
// Limited support for DATE to X.
if (fromType->isDate() && toKind != TypeKind::TIMESTAMP && toKind != TypeKind::VARCHAR) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Maybe we can refactor it into a coding style similar to Velox, which would make the code more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes agreed, currently we don't have as many cast conditions, I am adding some more casts, I'll explore this once the new casts are added

@ArnavBalyan ArnavBalyan force-pushed the arnavb/refactor-castvalidation branch 2 times, most recently from 96715f0 to 9edb0d8 Compare March 4, 2025 10:13
@ArnavBalyan ArnavBalyan force-pushed the arnavb/refactor-castvalidation branch from 9edb0d8 to e0c1519 Compare March 4, 2025 12:40
Copy link
Contributor

@PHILO-HE PHILO-HE left a comment

Choose a reason for hiding this comment

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

Thanks!

@PHILO-HE PHILO-HE changed the title [GLUTEN-8742][VL] Improve the castValidations in Velox to Substrait [GLUTEN-8742][VL] Improve the cast validation logic on native side Mar 5, 2025
@PHILO-HE PHILO-HE merged commit 67c1667 into apache:main Mar 5, 2025
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants