[multistage][hotfix] fix type cast handling and value literal gen#9456
[multistage][hotfix] fix type cast handling and value literal gen#9456walterddr merged 3 commits intoapache:masterfrom
Conversation
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
| // 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) { |
There was a problem hiding this comment.
(convention) Move @Nullable to a separate line
| private static @Nullable FieldSpec.DataType getDataType(Expression expression, Schema schema) { | |
| @Nullable | |
| private static FieldSpec.DataType getDataType(Expression expression, Schema schema) { |
| 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); | ||
| } |
There was a problem hiding this comment.
Consider making a util for this part, and make DataTypeConversionFunctions.cast() and CastTransformFunction use the util. Currently they already have different behavior.
There was a problem hiding this comment.
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, " ", "_"); |
There was a problem hiding this comment.
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"}, |
There was a problem hiding this comment.
For the query at line 307, can we add a test with CAST to LONG ?
There was a problem hiding this comment.
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: |
| String column = expression.getIdentifier().getName(); | ||
| FieldSpec fieldSpec = schema.getFieldSpecFor(column); | ||
| if (fieldSpec != null && fieldSpec.isSingleValueField()) { | ||
| return fieldSpec.getDataType(); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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, " "); |
There was a problem hiding this comment.
Ideally this should not even be allowed imo. Can you give an example ?
There was a problem hiding this comment.
calcite automatically converts multi-part functions like IS NOT NULL to that in SqlOp table.
|
will follow up with the comments in a separate PR especially refactoring out the CAST type conversion into a utility class. |
…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>
No description provided.