-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Enhancement][fe] Add ability to cast ROW and ARRAY datatype for Trino #48976
Conversation
@@ -1292,6 +1308,9 @@ private Type getGenericDataType(GenericDataType dataType) { | |||
throw new ParsingException("Unknown type: %s", typeName); | |||
} else if (typeName.equals("real")) { | |||
return ScalarType.createType(PrimitiveType.FLOAT); | |||
} else if (typeName.equals("array")) { | |||
TypeParameter typeParam = (TypeParameter) dataType.getArguments().get(0); | |||
return new ArrayType(getType(typeParam.getValue())); | |||
} else { | |||
// this contains datetime/date/numeric type | |||
return ScalarType.createType(typeName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most risky bug in this code is:
Potential ClassCastException
due to assuming that the argument for an "array" type is always of type TypeParameter
.
You can modify the code like this:
import io.trino.sql.tree.DataTypeParameter;
// ...
// Line 1292-1295
} else if (typeName.equals("array")) {
if (!(dataType.getArguments().get(0) instanceof TypeParameter)) {
throw new ParsingException("Expected a TypeParameter for array type but got: %s", dataType.getArguments().get(0).getClass().getSimpleName());
}
TypeParameter typeParam = (TypeParameter) dataType.getArguments().get(0);
return new ArrayType(getType(typeParam.getValue()));
}
Signed-off-by: 🐼 Samrose Ahmed 🐼 <[email protected]>
a004a7a
to
907430b
Compare
Quality Gate passedIssues Measures |
[FE Incremental Coverage Report]✅ pass : 13 / 13 (100.00%) file detail
|
[BE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
@Mergifyio backport branch-3.3 |
✅ Backports have been created
|
#48976) Signed-off-by: 🐼 Samrose Ahmed 🐼 <[email protected]> (cherry picked from commit 722346b)
…o (backport #48976) (#49026) Co-authored-by: Samrose <[email protected]>
StarRocks#48976) Signed-off-by: 🐼 Samrose Ahmed 🐼 <[email protected]>
Why I'm doing:
Currently cast as row and cast as array not supported for trino dialect.
What I'm doing:
Fixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: