Skip to content

[multistage][hotfix] fix type cast handling and value literal gen#9456

Merged
walterddr merged 3 commits intoapache:masterfrom
walterddr:pr_fix_cast_handling
Sep 26, 2022
Merged

[multistage][hotfix] fix type cast handling and value literal gen#9456
walterddr merged 3 commits intoapache:masterfrom
walterddr:pr_fix_cast_handling

Conversation

@walterddr
Copy link
Contributor

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Sep 23, 2022

Codecov Report

Merging #9456 (3c05dfc) into master (fea74a4) will increase coverage by 0.07%.
The diff coverage is 73.91%.

@@             Coverage Diff              @@
##             master    #9456      +/-   ##
============================================
+ Coverage     68.34%   68.42%   +0.07%     
+ Complexity     5106     4738     -368     
============================================
  Files          1904     1909       +5     
  Lines        101641   101760     +119     
  Branches      15431    15445      +14     
============================================
+ Hits          69471    69627     +156     
+ Misses        27241    27195      -46     
- Partials       4929     4938       +9     
Flag Coverage Δ
integration2 24.74% <47.82%> (+0.01%) ⬆️
unittests1 67.12% <69.56%> (+0.02%) ⬆️
unittests2 15.50% <4.34%> (+0.03%) ⬆️

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

Impacted Files Coverage Δ
...ery/optimizer/filter/NumericalFilterOptimizer.java 80.89% <72.72%> (-1.84%) ⬇️
...he/pinot/query/runtime/operator/OperatorUtils.java 100.00% <100.00%> (ø)
...inion/event/DefaultMinionEventObserverFactory.java 50.00% <0.00%> (-16.67%) ⬇️
...ore/query/scheduler/resources/ResourceManager.java 84.00% <0.00%> (-12.00%) ⬇️
...lter/predicate/NotInPredicateEvaluatorFactory.java 73.13% <0.00%> (-4.48%) ⬇️
...ion/function/DistinctCountAggregationFunction.java 50.22% <0.00%> (-4.04%) ⬇️
.../apache/pinot/segment/local/utils/SchemaUtils.java 94.11% <0.00%> (-3.22%) ⬇️
.../pinot/core/query/scheduler/PriorityScheduler.java 77.77% <0.00%> (-2.78%) ⬇️
...core/query/pruner/SelectionQuerySegmentPruner.java 83.52% <0.00%> (-2.36%) ⬇️
...pache/pinot/minion/event/MinionEventObservers.java 89.65% <0.00%> (-1.73%) ⬇️
... and 46 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 September 23, 2022 17:28
// Expression can not be a column name.
return false;
/** @return field data type extracted from the expression. null if we can't determine the type. */
private static @Nullable FieldSpec.DataType getDataType(Expression expression, Schema schema) {
Copy link
Contributor

Choose a reason for hiding this comment

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

(convention) Move @Nullable to a separate line

Suggested change
private static @Nullable FieldSpec.DataType getDataType(Expression expression, Schema schema) {
@Nullable
private static FieldSpec.DataType getDataType(Expression expression, Schema schema) {

Comment on lines +465 to +472
FieldSpec.DataType dataType;
if ("INTEGER".equals(targetTypeLiteral)) {
dataType = FieldSpec.DataType.INT;
} else if ("VARCHAR".equals(targetTypeLiteral)) {
dataType = FieldSpec.DataType.STRING;
} else {
dataType = FieldSpec.DataType.valueOf(targetTypeLiteral);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider making a util for this part, and make DataTypeConversionFunctions.cast() and CastTransformFunction use the util. Currently they already have different behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

they are not equivalent. conversion function operates @ScalarFunction which runs on PinotDataType (physical data type) and here it runs on FieldSpec.DataType.

* @return Canonicalize form of the input function name
*/
public static String canonicalizeFunctionName(String functionName) {
functionName = StringUtils.replace(functionName, " ", "_");
Copy link
Contributor

Choose a reason for hiding this comment

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

We should just remove the space. See TransformFunctionFactory.canonicalize() for example

// Test optimized constant literal.
new Object[]{"SELECT col1 FROM a WHERE col3 > 0 AND col3 < -5"},
new Object[]{"SELECT COALESCE(SUM(col3), 0) FROM a WHERE col1 = 'foo' AND col1 = 'bar'"},
new Object[]{"SELECT SUM(CAST(col3 AS INTEGER)) FROM a HAVING MIN(col3) BETWEEN 1 AND 0"},
Copy link
Contributor

Choose a reason for hiding this comment

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

For the query at line 307, can we add a test with CAST to LONG ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CAST TO LONG is not supported. LONG is not a SQL standard type -- it has to be CAST TO BIGINT

case GREATER_THAN:
case GREATER_THAN_OR_EQUAL:
case LESS_THAN:
case LESS_THAN_OR_EQUAL:
Copy link
Contributor

Choose a reason for hiding this comment

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

BETWEEN ?

String column = expression.getIdentifier().getName();
FieldSpec fieldSpec = schema.getFieldSpecFor(column);
if (fieldSpec != null && fieldSpec.isSingleValueField()) {
return fieldSpec.getDataType();
Copy link
Contributor

@siddharthteotia siddharthteotia Sep 26, 2022

Choose a reason for hiding this comment

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

if fieldSpec is null, then probably it implies that column / identifier does not exist in the schema and we should throw error instead of returning null ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah but it shouldn't reach here to begin with

* @return Canonicalize form of the input function name
*/
public static String canonicalizeFunctionName(String functionName) {
functionName = StringUtils.remove(functionName, " ");
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally this should not even be allowed imo. Can you give an example ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

calcite automatically converts multi-part functions like IS NOT NULL to that in SqlOp table.

@walterddr
Copy link
Contributor Author

will follow up with the comments in a separate PR especially refactoring out the CAST type conversion into a utility class.

@walterddr walterddr merged commit 6e697d8 into apache:master Sep 26, 2022
61yao pushed a commit to 61yao/pinot that referenced this pull request Oct 3, 2022
…ache#9456)

* also support implicit type casting
* also add value literal bug fix when casting
* address comments

Co-authored-by: Rong Rong <rongr@startree.ai>
@walterddr walterddr deleted the pr_fix_cast_handling 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants