Skip to content

[CALCITE-3429] AssertionError for user-defined table function with map argument#1521

Closed
yanlin-Lynn wants to merge 1 commit intoapache:masterfrom
yanlin-Lynn:java-type
Closed

[CALCITE-3429] AssertionError for user-defined table function with map argument#1521
yanlin-Lynn wants to merge 1 commit intoapache:masterfrom
yanlin-Lynn:java-type

Conversation

@yanlin-Lynn
Copy link
Contributor

@yanlin-Lynn yanlin-Lynn commented Oct 18, 2019

Similar to #1519, using map in table function may cause exception.
Please refer to jira CALCITE-3429 for full stack trace.

To fix it, this PR make the follow changes:

  1. Add map info from Java Map class to SqlTypeName.Map
  2. SqlTypeName.Map is not a basic type, should not be used in factory method createSqlType, just like SqlTypeName.Array
  3. Add coerce rule for SqlTypeName.MAP

@yanlin-Lynn yanlin-Lynn force-pushed the java-type branch 2 times, most recently from c56ce7a to e91f07d Compare October 21, 2019 03:04
@danny0405
Copy link
Contributor

Can we avoid to use Refinement XXX for the title and commit message ? This kind of title really confused me a lot, instead, you should just specify that you did in the message, for example, for this patch, you can use "Support MAP type for JavaToSqlTypeConversionRules"

@yanlin-Lynn yanlin-Lynn force-pushed the java-type branch 2 times, most recently from 7e0e168 to 4b9707b Compare October 21, 2019 07:29
@yanlin-Lynn yanlin-Lynn changed the title [CALCITE-3429] Refinement for implementation of sql type factory [CALCITE-3429] Support MAP type for JavaToSqlTypeConversionRules Oct 21, 2019
+ "postalCode,country,phoneNumber,addressTag]\n"
+ "primaryAddress=PDX[addressLine1,addressLine2,addressLine3,city,state,postalCode,"
+ "country,phoneNumber,addressTag]\n")
.returns(new Consumer<ResultSet>() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I update this case to make it pass.
But I'm not quite familiar with the logic, hopes someone more familiar with it can review this.

@yanlin-Lynn
Copy link
Contributor Author

Can we avoid to use Refinement XXX for the title and commit message ? This kind of title really confused me a lot, instead, you should just specify that you did in the message, for example, for this patch, you can use "Support MAP type for JavaToSqlTypeConversionRules"

Sure, I'll avoid this next time.

* Using ANY type as value type.
*/
@Override public RelDataType getValueType() {
if (Map.class.isAssignableFrom(clazz)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does any code use these 2 methods ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, inSqlItemOperator.
If don't override these 2 methods, running org.apache.calcite.adapter.geode.rel.GeodeBookstoreTest will get NullPointerException

Caused by: java.lang.NullPointerException
	at org.apache.calcite.sql.fun.SqlItemOperator.getChecker(SqlItemOperator.java:103)
	at org.apache.calcite.sql.fun.SqlItemOperator.checkOperandTypes(SqlItemOperator.java:91)
	at org.apache.calcite.sql.SqlOperator.validateOperands(SqlOperator.java:432)
	at org.apache.calcite.sql.SqlOperator.deriveType(SqlOperator.java:518)
	at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5639)
	at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5626)
	at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:139)
	at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1692)
	at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1677)
	at org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem(SqlValidatorImpl.java:480)
	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelectList(SqlValidatorImpl.java:4117)
	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3396)
	at org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
	at org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:1009)
	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:969)
	at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:216)

*/
@Override public RelDataType getKeyType() {
if (Map.class.isAssignableFrom(clazz)) {
return createSqlType(SqlTypeName.ANY);
Copy link
Contributor

@jinxing64 jinxing64 Oct 27, 2019

Choose a reason for hiding this comment

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

Say the map is by Integer -> Integer
Why return SqlTypeName.ANY here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I cannot find a way to get the Integer parameter type when create type with Map class.
And use SqlTypeName.ANY can cover other types.

@yanlin-Lynn yanlin-Lynn changed the title [CALCITE-3429] Support MAP type for JavaToSqlTypeConversionRules [CALCITE-3429] AssertionError for user-defined table function with map argument Oct 29, 2019
@yanlin-Lynn yanlin-Lynn force-pushed the java-type branch 2 times, most recently from 5128659 to 5ff8d44 Compare October 29, 2019 13:45
@yanlin-Lynn
Copy link
Contributor Author

@ihuzenko Inspired by your PR (#1519), I checked using Map in table function, and throws exception too.
I refactor some part of your code, hope you can help to review when you have time.

@yanlin-Lynn
Copy link
Contributor Author

hi, @danny0405
Thanks for reviewing.
I cannot see how this PR is blocked?
Can you give more details, if it need to update this PR.

…p argument (Wang Yanlin)

1. Add map info from Java Map class to SqlTypeName.Map
2. SqlTypeName.Map is not a basic type, should not be used in factory method "createSqlType", just like SqlTypeName.Array
3. Add coerce rule for SqlTypeName.MAP
@danny0405
Copy link
Contributor

Sorry for the delay, reviewing now ~

@danny0405 danny0405 added accepted-and-would-rework-soon This patch is overall ok, but need some refactoring by the committers. and removed blocked-by-another-pr labels Dec 5, 2019
@danny0405 danny0405 closed this in ff44204 Dec 6, 2019
@yanlin-Lynn yanlin-Lynn deleted the java-type branch December 6, 2019 06:30
wangxlong pushed a commit to wangxlong/calcite that referenced this pull request Feb 13, 2020
…p argument (Wang Yanlin)

1. Add map info from Java Map class to SqlTypeName.Map
2. SqlTypeName.Map is not a basic type, should not be used in factory method "createSqlType", just like SqlTypeName.Array
3. Add coerce rule for SqlTypeName.MAP

Fix-up(by Danny):
* Fix GeodeTable#query field type inference;
* Fix GeodeUtils#convert for nested PdxInstance because in
JavaTypeFactoryExtImpl#createPdxType, the nested PdxInstance is inferred
as Map type(we can not describe nested JavaType correctly now).

close apache#1521
jamesstarr pushed a commit to jamesstarr/calcite that referenced this pull request Mar 16, 2026
…p argument (Wang Yanlin)

1. Add map info from Java Map class to SqlTypeName.Map
2. SqlTypeName.Map is not a basic type, should not be used in factory method "createSqlType", just like SqlTypeName.Array
3. Add coerce rule for SqlTypeName.MAP

Fix-up(by Danny):
* Fix GeodeTable#query field type inference;
* Fix GeodeUtils#convert for nested PdxInstance because in
JavaTypeFactoryExtImpl#createPdxType, the nested PdxInstance is inferred
as Map type(we can not describe nested JavaType correctly now).

close apache#1521

Change-Id: If1449d398b20914614dc573ee15d999b24223c3d
jamesstarr pushed a commit to jamesstarr/calcite that referenced this pull request Mar 16, 2026
apache#124)

…p argument (Wang Yanlin)

1. Add map info from Java Map class to SqlTypeName.Map
2. SqlTypeName.Map is not a basic type, should not be used in factory
method "createSqlType", just like SqlTypeName.Array
3. Add coerce rule for SqlTypeName.MAP

Fix-up(by Danny):
* Fix GeodeTable#query field type inference;
* Fix GeodeUtils#convert for nested PdxInstance because in
JavaTypeFactoryExtImpl#createPdxType, the nested PdxInstance is inferred
as Map type(we can not describe nested JavaType correctly now).

close apache#1521

Change-Id: If1449d398b20914614dc573ee15d999b24223c3d
jamesstarr pushed a commit to jamesstarr/calcite that referenced this pull request Mar 16, 2026
…p argument (Wang Yanlin)

1. Add map info from Java Map class to SqlTypeName.Map
2. SqlTypeName.Map is not a basic type, should not be used in factory method "createSqlType", just like SqlTypeName.Array
3. Add coerce rule for SqlTypeName.MAP

Fix-up(by Danny):
* Fix GeodeTable#query field type inference;
* Fix GeodeUtils#convert for nested PdxInstance because in
JavaTypeFactoryExtImpl#createPdxType, the nested PdxInstance is inferred
as Map type(we can not describe nested JavaType correctly now).

close apache#1521

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

Labels

accepted-and-would-rework-soon This patch is overall ok, but need some refactoring by the committers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants