Skip to content

Conversation

@Jackie-Jiang
Copy link
Contributor

@Jackie-Jiang Jackie-Jiang commented Oct 9, 2023

Currently when literal is single quoted (e.g. 'abc', '123', '1.23'), the type is auto-derived based on the literal itself. Also, it can only derive to big-decimal, timestamp or string but not other numeric types.
In Standard SQL (we reference PostgreSQL convention as standard), single quoted literal has unknown type and the type should be resolved based on the context around the literal (read more here).

This PR:

  • Preserve the literal type, and only resolve the type when the context is clear
  • Fix the wrong behavior when quoted string is used as number (currently it will be resolved as 0)
  • Fix CASE to follow the PostgreSQL convention (read more here), and fix a bug of reading float value as double type

Incompatible

Following standard SQL, single quoted literal won't have its type auto-derived. In order to create big-decimal literal, user should use cast('12345.6789' AS DECIMAL) explicitly

@Jackie-Jiang Jackie-Jiang added enhancement incompatible Indicate PR that introduces backward incompatibility release-notes Referenced by PRs that need attention when compiling the next release notes bugfix labels Oct 9, 2023
@codecov-commenter
Copy link

codecov-commenter commented Oct 9, 2023

Codecov Report

❌ Patch coverage is 84.98024% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.24%. Comparing base (aff30d6) to head (afd4c0e).
⚠️ Report is 3068 commits behind head on master.

Files with missing lines Patch % Lines
...ator/transform/function/CaseTransformFunction.java 86.66% 8 Missing and 4 partials ⚠️
...e/pinot/common/request/context/LiteralContext.java 88.17% 8 Missing and 3 partials ⚠️
...org/apache/pinot/common/utils/http/HttpClient.java 0.00% 5 Missing ⚠️
...unction/IntegerTupleSketchAggregationFunction.java 0.00% 4 Missing ⚠️
...gregation/function/AggregationFunctionFactory.java 50.00% 0 Missing and 3 partials ⚠️
...pache/pinot/common/utils/request/RequestUtils.java 87.50% 0 Missing and 1 partial ⚠️
...ot/core/operator/filter/H3IndexFilterOperator.java 50.00% 1 Missing ⚠️
...ry/runtime/plan/server/ServerPlanRequestUtils.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #11763      +/-   ##
============================================
+ Coverage     63.08%   63.24%   +0.15%     
  Complexity     1140     1140              
============================================
  Files          2343     2343              
  Lines        126320   126335      +15     
  Branches      19423    19436      +13     
============================================
+ Hits          79694    79900     +206     
+ Misses        40953    40765     -188     
+ Partials       5673     5670       -3     
Flag Coverage Δ
integration <0.01% <0.00%> (ø)
integration1 <0.01% <0.00%> (ø)
integration2 0.00% <0.00%> (ø)
java-11 63.16% <84.98%> (+0.09%) ⬆️
java-17 63.08% <84.98%> (+0.12%) ⬆️
java-20 63.08% <84.98%> (+0.11%) ⬆️
temurin 63.24% <84.98%> (+0.15%) ⬆️
unittests 63.23% <84.98%> (+0.15%) ⬆️
unittests1 67.42% <84.98%> (+0.17%) ⬆️
unittests2 14.42% <0.00%> (+0.02%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Choose a reason for hiding this comment

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

instead of changing it we should add one more for -1 to make sure the results is actually considered as true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is for backward compatible where we used to allow 0 and 1. We never allow -1, so that shouldn't be needed. More tests are covered in LiteralContextText

Comment on lines +496 to +500
Copy link
Contributor

Choose a reason for hiding this comment

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

is this relevant?

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 directly relevant, but find this not able to return the error during debugging.

Copy link
Contributor

Choose a reason for hiding this comment

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

if (sqlNumericLiteral.isExact()) {
  if (sqlNumericLiteral.isInteger()) {
    // long/int
  } else {
    // float/double
  }
} else {
  // TODO support exact decimal
  // decimal
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is incorrect. FLOAT/DOUBLE is not exact.

Copy link
Contributor

Choose a reason for hiding this comment

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

ST_POINT is ANY on 3rd argument, should it be boolean or integer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be boolean. We allow int for backward compatibility only because this function was introduced before BOOLEAN is supported

Copy link
Contributor

Choose a reason for hiding this comment

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

i dont really think . can be added in function name percentile99.5(col) is not valid. (https://www.postgresql.org/docs/current/xfunc-sql.html)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for percentile(col, 99.5) which is allowed

Comment on lines 258 to 262
Copy link
Contributor

Choose a reason for hiding this comment

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

is this even needed? we should handle it in RequestUtils

  • AFAIK the arrFloat[rowIdx] will point to the double signature,
  • once uncomment the TODO it will use the float signature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed. We cannot directly cast float to double because that will create wrong value (e.g 0.05f -> 0.05000000074505806), then cause wrong result. Added more notes

Copy link
Contributor

@xiangfu0 xiangfu0 left a comment

Choose a reason for hiding this comment

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

Let's also put the incompatible items into PR descriptions.

testTransformFunction(transformFunction, expectedBigDecimalValues);

expression = RequestContextUtils.getExpression(
String.format("add(add(12,%s),%s,add(add(%s,%s),'12110.34556677889901122335678',%s),%s)", STRING_SV_COLUMN,
Copy link
Contributor

@xiangfu0 xiangfu0 Oct 13, 2023

Choose a reason for hiding this comment

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

Does it mean we won't auto infer big decimal/ts values and enforce the cast always?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. In standard SQL, literal cannot be auto inferred based on its value.

@elonazoulay
Copy link
Contributor

This is great, thanks so much for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix enhancement incompatible Indicate PR that introduces backward incompatibility release-notes Referenced by PRs that need attention when compiling the next release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants