[CALCITE-3424] AssertionError thrown for user-defined table function with array argument#1519
[CALCITE-3424] AssertionError thrown for user-defined table function with array argument#1519ihuzenko wants to merge 1 commit intoapache:masterfrom
Conversation
| } | ||
|
|
||
| public static QueryableTable generateStrings2(final List<Integer> list) { | ||
| return generateStrings(list.size()); |
There was a problem hiding this comment.
Can we give it a more meaning name ? not XXX2 ?
core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java
Outdated
Show resolved
Hide resolved
| nonNullType = typeFactory.createArrayType(typeFactory.createSqlType(SqlTypeName.ANY), -1); | ||
| } else { | ||
| nonNullType = typeFactory.createSqlType(type.getSqlTypeName()); | ||
| } |
There was a problem hiding this comment.
Can you reference JavaToSqlTypeConversionRules for the type mapping ?
There was a problem hiding this comment.
There is no need to use JavaToSqlTypeConversionRules here because type contains SqlTypeName. Most probably this check just need to be rewritten to switch case based on the enum values and further java class investigation isn't necessary here. To be honest the API of typeFactory which promises to createSqlType(...) for sqlTypeName and implicitly throws assertion errors is really bad.
There was a problem hiding this comment.
I didn't mean to use JavaToSqlTypeConversionRules directly, i meant to match all the java collection classes that synced with what JavaToSqlTypeConversionRules has already matched.
| type.isNullable()); | ||
| Class javaClass = ((JavaType) type).getJavaClass(); | ||
| final RelDataType nonNullType; | ||
| if (javaClass.isArray()) { |
There was a problem hiding this comment.
Issue described in Jira ticket relates to ARRAY assertion inside SqlTypeFactoryImpl's assertBasic method:
private void assertBasic(SqlTypeName typeName) {
assert typeName != null;
assert typeName != SqlTypeName.MULTISET
: "use createMultisetType() instead";
assert typeName != SqlTypeName.ARRAY
: "use createArrayType() instead";
assert typeName != SqlTypeName.ROW
: "use createStructType() instead";
assert !SqlTypeName.INTERVAL_TYPES.contains(typeName)
: "use createSqlIntervalType() instead";
}For map type assertion isn't fired here and I think it's rare case that someone will accept map arguments (or others from the method body) into custom table function.
There was a problem hiding this comment.
I'm not sure is it a bug or is just designed like this.
For me, it's probably a bug.
I create a PR(#1521) trying to fix it.
| } | ||
| } | ||
|
|
||
| @Test public void testTableFunctionWithArrayParameter() throws SQLException { |
There was a problem hiding this comment.
maybe add a case for map type parameter?
There was a problem hiding this comment.
I think array is enough, just like what the commit describes.
| final RelDataType relDataType; | ||
| if (sqlTypeName == SqlTypeName.ARRAY) { | ||
| RelDataType elementType = type.getComponentType() == null | ||
| ? typeFactory.createSqlType(SqlTypeName.ANY) : type.getComponentType(); |
There was a problem hiding this comment.
Does it need special consideration when it's a nested array, i.e. the element type of array is also of array
There was a problem hiding this comment.
Could you please give an example of table function for which it's necessary to accept nested array as argument ?
There was a problem hiding this comment.
You can use SqlTypeUtil#isArray to decide if a type is ARRAY type.
| } | ||
| } | ||
|
|
||
| @Test public void testTableFunctionWithArrayParameter() throws SQLException { |
There was a problem hiding this comment.
I think array is enough, just like what the commit describes.
| final RelDataType relDataType; | ||
| if (sqlTypeName == SqlTypeName.ARRAY) { | ||
| RelDataType elementType = type.getComponentType() == null | ||
| ? typeFactory.createSqlType(SqlTypeName.ANY) : type.getComponentType(); |
There was a problem hiding this comment.
You can use SqlTypeUtil#isArray to decide if a type is ARRAY type.
…with array argument
cda24dc to
050c368
Compare
|
Hi @danny0405 , I've updated JavaTypeFactoryImpl according to your suggestion, rebased on latest master and squashed commits. Please take a look again. |
…with array argument (Igor Guzenko) close apache#1519
…with array argument (Igor Guzenko) close apache#1519
…with array argument (Igor Guzenko) close apache#1519
…with array argument (Igor Guzenko) close apache#1519
…with array argument (Igor Guzenko) close apache#1519 Change-Id: I1e974383412a2731ab601d98b6f633bb92e859df
…with array argument (Igor Guzenko) close apache#1519 Change-Id: I1e974383412a2731ab601d98b6f633bb92e859df
No description provided.