-
Notifications
You must be signed in to change notification settings - Fork 193
Default empty array() return type to ARRAY<VARCHAR> #5421
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,17 @@ public SqlReturnTypeInference getReturnTypeInference() { | |
| RelDataType originalType = | ||
| SqlLibraryOperators.ARRAY.getReturnTypeInference().inferReturnType(sqlOperatorBinding); | ||
| RelDataType innerType = originalType.getComponentType(); | ||
| // For empty `array()` Calcite infers element type as NULL, which downstream | ||
| // serializers (notably the analytics-engine route's substrait converter) | ||
| // reject with "Unable to convert the type UNKNOWN". Default to VARCHAR — the | ||
| // result is empty either way, so the chosen scalar element type doesn't | ||
| // affect any value computation, but it gives the call a substrait-serializable | ||
| // type. Existing v2-engine tests (which feed Object lists straight through to | ||
| // ExprCollectionValue) are unaffected because the empty list contains no | ||
| // elements that need to be cast. | ||
| if (innerType == null || isUnknownLikeType(innerType.getSqlTypeName())) { | ||
| innerType = typeFactory.createSqlType(SqlTypeName.VARCHAR); | ||
| } | ||
|
Comment on lines
+54
to
+56
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is CAST(ARRAY[] to VARCHAR[])? Add an UT to cover this assumption.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refer PostgreSQL, it does not allow construct empty ARRAY[]. https://www.postgresql.org/docs/current/sql-expressions.html#SQL-SYNTAX-ARRAY-CONSTRUCTORS But in PPL, we allow create emtpy array(). So which means we implict covert to varchar[] in future, right?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes — semantically equivalent to Yes, Substrait limitation — Substrait's UT added in aa82704 —
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right — that's the trade-off. Postgres requires the explicit cast ( Long-term we could expose a PPL |
||
| return createArrayType( | ||
| typeFactory, typeFactory.createTypeWithNullability(innerType, true), true); | ||
| } catch (Exception e) { | ||
|
|
@@ -63,6 +74,17 @@ public UDFOperandMetadata getOperandMetadata() { | |
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Calcite's {@link SqlLibraryOperators#ARRAY} infers a {@code NULL}-element array for an empty | ||
| * call list and an {@code UNKNOWN}-element array when type inference can't pick one (e.g. all | ||
| * operands are typeless nulls). Either of those bubbles up to the analytics-engine route's | ||
| * substrait converter as "Unable to convert the type UNKNOWN" — substrait has no encoding for | ||
| * either marker. Treat both as needing a concrete fallback. | ||
| */ | ||
| private static boolean isUnknownLikeType(SqlTypeName sqlTypeName) { | ||
| return sqlTypeName == SqlTypeName.NULL || sqlTypeName == SqlTypeName.UNKNOWN; | ||
| } | ||
|
|
||
| public static class ArrayImplementor implements NotNullImplementor { | ||
| @Override | ||
| public Expression implement( | ||
|
|
||
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.
np: If possible, can we make the comment more concise. I think it's okay to leave most context/details in PR description.
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.
Trimmed in 22d0cce — comment now just points to the PR description.