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

[bugfix] fix case-when issue #9702

Merged
merged 4 commits into from Nov 5, 2022
Merged

Conversation

walterddr
Copy link
Contributor

@walterddr walterddr commented Nov 1, 2022

case when is not parsed the same in SqlNode and RelNode. this address the discrepancy in the compilation between v1 and v2.

Release Note

This change is backward incompatible with some of the CASE WHEN queries.

  • when there's only one CASE WHEN clause, nothing will break.
  • when using multiple WHEN clause
    • when non-boolean expression used in condition check, query might fail during cluster upgrade
      • e.g.CASE WHEN <non_boolean_expr> THEN ... will not work during cluster upgrade,
      • use explicit cast CASE WHEN CAST(<non_boolean_expr> AS BOOLEAN) THEN ... instead.
    • when all expressions in WHEN or THEN clause are boolean, query might fail during cluster upgrade
      • e.g. when CASE [WHEN <boolean_expr> THEN <boolean_expr>]+ ELSE <boolean_expr> END will not work during cluster upgrade.
      • no workaround for this at the moment

@codecov-commenter
Copy link

Codecov Report

Merging #9702 (414e0fc) into master (91fa86b) will increase coverage by 41.88%.
The diff coverage is 82.35%.

@@              Coverage Diff              @@
##             master    #9702       +/-   ##
=============================================
+ Coverage     28.13%   70.01%   +41.88%     
- Complexity       53     5326     +5273     
=============================================
  Files          1936     1950       +14     
  Lines        103927   104332      +405     
  Branches      15770    15806       +36     
=============================================
+ Hits          29235    73044    +43809     
+ Misses        71832    26167    -45665     
- Partials       2860     5121     +2261     
Flag Coverage Δ
integration1 25.42% <10.29%> (+0.01%) ⬆️
integration2 24.73% <8.33%> (+0.05%) ⬆️
unittests1 67.44% <82.35%> (?)
unittests2 15.69% <71.56%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ot/common/function/scalar/ComparisonFunctions.java 42.85% <ø> (+5.35%) ⬆️
.../pinot/common/function/scalar/ObjectFunctions.java 73.07% <55.55%> (+73.07%) ⬆️
...ator/transform/function/CaseTransformFunction.java 59.45% <70.00%> (+23.71%) ⬆️
...org/apache/pinot/sql/parsers/CalciteSqlParser.java 84.17% <75.00%> (+15.82%) ⬆️
...t/query/runtime/plan/ServerRequestPlanVisitor.java 78.57% <78.57%> (ø)
...va/org/apache/pinot/query/runtime/QueryRunner.java 81.55% <90.00%> (+81.55%) ⬆️
...e/pinot/query/runtime/plan/PlanRequestContext.java 92.85% <92.85%> (ø)
...ot/query/runtime/executor/WorkerQueryExecutor.java 100.00% <100.00%> (+100.00%) ⬆️
.../pinot/query/runtime/plan/PhysicalPlanVisitor.java 96.87% <100.00%> (ø)
.../runtime/plan/server/ServerPlanRequestContext.java 100.00% <100.00%> (ø)
... and 1335 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@walterddr walterddr marked this pull request as ready for review November 1, 2022 23:18
if (o != null) {
return o;
@ScalarFunction
public static Object caseWhen(boolean c1, Object o1, Object oe) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the function name case or caseWhen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

operator name is case, the relNode function name is caseWhen

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting.. But does that mean these functions won't be recognized by v1 engine because the function name is case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not really. the info passed over to the stages contains SqlOperator and function. it will use SqlOperator to lookup first before using function name. thus v1 engine will correctly composed out the transform version of the "case"; and intermediate stage will use the scalar function correctly.

for (int i = 0; i < numWhenStatements; i++) {
if (arguments.get(i * 2).getResultMetadata().getDataType() != DataType.BOOLEAN) {
hasLegacyFormat = true;
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

(MAJOR) This can break when the first loop didn't break but the second loop break because some wrong arguments already added to the list.
Also, we should check in favor of the new order. We can check if the first half of the arguments are all boolean, and if the odd index arguments are all boolean. If both are all booleans or both are not all booleans or the first half are all booleans, use the new order; use the legacy one otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it. yeah also this is not in critical path i will just make sure the check occurs afterward by looping it again

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if (all_first_half_are_expression_boolean_type && odd_half_has_non_boolean_type) then use

@Jackie-Jiang Jackie-Jiang added backward-incompat Referenced by PRs that introduce or fix backward compat issues bugfix labels Nov 2, 2022
@Jackie-Jiang
Copy link
Contributor

Please add some description in the PR to describe the backward incompatibility in certain case. Also, do not mark it as multistage

@walterddr walterddr changed the title [multistage][bugfix] fix case-when issue [bugfix] fix case-when issue Nov 2, 2022
@walterddr walterddr added the multi-stage Related to the multi-stage query engine label Nov 3, 2022
@Jackie-Jiang
Copy link
Contributor

WARNING: This PR is backward incompatible because we should not change the format sent by broker before upgrading servers. #10291 is the patch to revert back the broker format

@walterddr walterddr deleted the pr_bugfix_casewhen branch December 6, 2023 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backward-incompat Referenced by PRs that introduce or fix backward compat issues bugfix multi-stage Related to the multi-stage query engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants