Skip to content

[CALCITE-3424] AssertionError thrown for user-defined table function with array argument#1519

Closed
ihuzenko wants to merge 1 commit intoapache:masterfrom
ihuzenko:CALCITE-3424
Closed

[CALCITE-3424] AssertionError thrown for user-defined table function with array argument#1519
ihuzenko wants to merge 1 commit intoapache:masterfrom
ihuzenko:CALCITE-3424

Conversation

@ihuzenko
Copy link
Member

No description provided.

}

public static QueryableTable generateStrings2(final List<Integer> list) {
return generateStrings(list.size());
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we give it a more meaning name ? not XXX2 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch, done.

nonNullType = typeFactory.createArrayType(typeFactory.createSqlType(SqlTypeName.ANY), -1);
} else {
nonNullType = typeFactory.createSqlType(type.getSqlTypeName());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you reference JavaToSqlTypeConversionRules for the type mapping ?

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

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()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what about map type?

Copy link
Member Author

@ihuzenko ihuzenko Oct 18, 2019

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

@yanlin-Lynn yanlin-Lynn Oct 18, 2019

Choose a reason for hiding this comment

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

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 {
Copy link
Contributor

@yanlin-Lynn yanlin-Lynn Oct 18, 2019

Choose a reason for hiding this comment

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

maybe add a case for map type parameter?

Copy link
Contributor

Choose a reason for hiding this comment

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

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();
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it need special consideration when it's a nested array, i.e. the element type of array is also of array

Copy link
Member Author

Choose a reason for hiding this comment

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

Could you please give an example of table function for which it's necessary to accept nested array as argument ?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can use SqlTypeUtil#isArray to decide if a type is ARRAY type.

}
}

@Test public void testTableFunctionWithArrayParameter() throws SQLException {
Copy link
Contributor

Choose a reason for hiding this comment

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

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();
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use SqlTypeUtil#isArray to decide if a type is ARRAY type.

@ihuzenko
Copy link
Member Author

Hi @danny0405 , I've updated JavaTypeFactoryImpl according to your suggestion, rebased on latest master and squashed commits. Please take a look again.

@danny0405 danny0405 added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label Oct 22, 2019
@danny0405 danny0405 closed this in 8ba2d85 Oct 23, 2019
XuQianJin-Stars pushed a commit to XuQianJin-Stars/calcite that referenced this pull request Nov 17, 2019
XuQianJin-Stars pushed a commit to XuQianJin-Stars/calcite that referenced this pull request Nov 20, 2019
XuQianJin-Stars pushed a commit to XuQianJin-Stars/calcite that referenced this pull request Nov 20, 2019
wangxlong pushed a commit to wangxlong/calcite that referenced this pull request Feb 13, 2020
jamesstarr pushed a commit to jamesstarr/calcite that referenced this pull request Aug 28, 2025
…with array argument (Igor Guzenko)

close apache#1519

Change-Id: I1e974383412a2731ab601d98b6f633bb92e859df
jamesstarr pushed a commit to jamesstarr/calcite that referenced this pull request Mar 16, 2026
…with array argument (Igor Guzenko)

close apache#1519

Change-Id: I1e974383412a2731ab601d98b6f633bb92e859df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LGTM-will-merge-soon Overall PR looks OK. Only minor things left.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants