-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[CALCITE-3429] AssertionError for user-defined table function with map argument #1521
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 all commits
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 |
|---|---|---|
|
|
@@ -605,6 +605,32 @@ public RelDataType getComponentType() { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * For {@link JavaType} created with {@link Map} class, | ||
| * cannot get the type of key and value. | ||
| * Using ANY type as key type. | ||
| */ | ||
| @Override public RelDataType getKeyType() { | ||
| if (Map.class.isAssignableFrom(clazz)) { | ||
| return createSqlType(SqlTypeName.ANY); | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * For {@link JavaType} created with {@link Map} class, | ||
| * cannot get the type of key and value. | ||
| * Using ANY type as value type. | ||
| */ | ||
| @Override public RelDataType getValueType() { | ||
| if (Map.class.isAssignableFrom(clazz)) { | ||
|
Contributor
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. Does any code use these 2 methods ?
Contributor
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, in |
||
| return createSqlType(SqlTypeName.ANY); | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| public Charset getCharset() { | ||
| return this.charset; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,14 +22,20 @@ | |
|
|
||
| import org.apache.geode.cache.Cache; | ||
| import org.apache.geode.cache.Region; | ||
| import org.apache.geode.pdx.PdxInstance; | ||
|
|
||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.DriverManager; | ||
| import java.sql.ResultSet; | ||
| import java.sql.SQLException; | ||
| import java.util.Arrays; | ||
| import java.util.function.Consumer; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| /** | ||
| * Tests using {@code Bookshop} schema. | ||
|
|
@@ -379,10 +385,37 @@ public void testSelectWithNestedPdx2() { | |
| calciteAssert() | ||
| .query("select primaryAddress from geode.BookCustomer limit 2") | ||
| .returnsCount(2) | ||
| .returns("primaryAddress=PDX[addressLine1,addressLine2,addressLine3,city,state," | ||
| + "postalCode,country,phoneNumber,addressTag]\n" | ||
| + "primaryAddress=PDX[addressLine1,addressLine2,addressLine3,city,state,postalCode," | ||
| + "country,phoneNumber,addressTag]\n") | ||
| .returns(new Consumer<ResultSet>() { | ||
|
Contributor
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. I update this case to make it pass. |
||
| /** | ||
| * The result of {@link org.apache.geode.pdx.internal.PdxInstanceImpl} | ||
| * instance's toString method, has a prefix with random int value, | ||
| * removes the prefix before checking. The prefix may like this | ||
| * "PDX[10872742,org.apache.calcite.adapter.geode.primaryAddress]" | ||
| */ | ||
| @Override public void accept(ResultSet resultSet) { | ||
| try { | ||
| StringBuilder builder = new StringBuilder(); | ||
| final String prefix = "org.apache.calcite.adapter.geode.primaryAddress"; | ||
| while (resultSet.next()) { | ||
| PdxInstance o = (PdxInstance) resultSet.getObject(1); | ||
| int index = o.toString().indexOf(prefix); | ||
| builder.append( | ||
| o.toString().substring(index + prefix.length() + 1)); | ||
| builder.append("\n"); | ||
| } | ||
| assertThat(builder.toString(), | ||
| is("{addressLine1=123 Main St., addressLine2=java.lang.NullPointerException," | ||
| + " addressLine3=java.lang.NullPointerException, addressTag=HOME, city=Topeka," | ||
| + " country=US, phoneNumber=423-555-3322, postalCode=50505, state=KS}\n" | ||
| + "{addressLine1=123 Main St., addressLine2=java.lang.NullPointerException," | ||
| + " addressLine3=java.lang.NullPointerException, addressTag=HOME," | ||
| + " city=San Francisco, country=US," + " phoneNumber=423-555-3322," | ||
| + " postalCode=50505, state=CA}\n")); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| }) | ||
| .explainContains("PLAN=GeodeToEnumerableConverter\n" | ||
| + " GeodeProject(primaryAddress=[$3])\n" | ||
| + " GeodeSort(fetch=[2])\n" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Say the map is by
Integer -> IntegerWhy return SqlTypeName.ANY here ?
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.
Because I cannot find a way to get the
Integerparameter type when create type with Map class.And use
SqlTypeName.ANYcan cover other types.