You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Valerii Florov (JIRA)" <ji...@apache.org> on 2018/07/19 16:02:00 UTC
[jira] [Commented] (CALCITE-2117) IllegalStateException when
accessing data with type MAP ARRAY
[ https://issues.apache.org/jira/browse/CALCITE-2117?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16549460#comment-16549460 ]
Valerii Florov commented on CALCITE-2117:
-----------------------------------------
Hello Janislav
This issue may be resolved at least by two ways. One of them you can see in my branch here [CALCITE-2117|https://github.com/ValeriiFlorov/calcite/commit/37fa1a884ebdb127b30caf6fd080de90a4d31552]
Just one line of code in org.apache.calcite.sql.type.SqlTypeName was changed. Tests were completed and passed.
Another way is also possible. It demands changing in calcite-avatika. Small fix in org.apache.calcite.avatica.util.AbstractCursor.ArrayAccessor#convertValue() method like this:
{code:java}
case Types.OTHER:
if (componentType.getName().endsWith("MAP")) {
return componentAccessor.getObject();
} else {
throw new IllegalStateException("Unhandled ARRAY component type: " + componentType.rep
+ ", id: " + componentType.id);
}{code}
this piece of code may be added before default: branch in the switch in this method.
Looks more messy but it works too. What way do you think is more preferable?
Best regards
Valery
> IllegalStateException when accessing data with type MAP ARRAY
> -------------------------------------------------------------
>
> Key: CALCITE-2117
> URL: https://issues.apache.org/jira/browse/CALCITE-2117
> Project: Calcite
> Issue Type: Bug
> Components: avatica
> Affects Versions: 1.14.0
> Reporter: Janislav Jankov
> Priority: Major
>
> Here is a simple test case to demonstrate the issue:
> {code}
> @Test
> public void testArrayOfMaps() throws Throwable {
> Class.forName("org.apache.calcite.jdbc.Driver");
> try (Connection connection = DriverManager.getConnection("jdbc:calcite:");
> Statement statement = connection.createStatement()) {
> String sql = "select ARRAY[1, 2], ARRAY[MAP['key', 'value']]";
> ResultSet resultSet = statement.executeQuery(sql);
> resultSet.next();
> Array a1 = resultSet.getArray(1);
> Assert.assertArrayEquals(new int[] {1, 2}, (int[]) a1.getArray());
> resultSet.getArray(2);
> }
> }
> {code}
> Accessing the second field with {{resultSet.getArray(2)}} or {{resultSet.getObject(2)}} throws the following exception:
> {code}
> java.lang.IllegalStateException: Unhandled ARRAY component type: OBJECT, id: 1111
> at org.apache.calcite.avatica.util.AbstractCursor$ArrayAccessor.convertValue(AbstractCursor.java:1336)
> at org.apache.calcite.avatica.util.AbstractCursor$ArrayAccessor.getObject(AbstractCursor.java:1289)
> at org.apache.calcite.avatica.util.AbstractCursor$ArrayAccessor.getArray(AbstractCursor.java:1342)
> at org.apache.calcite.avatica.AvaticaResultSet.getArray(AvaticaResultSet.java:731)
> {code}
> Looking at the AbstractCursor.ArrayAccessor::convertValue the Types.OTHER (which MAP resolves to) is not explicitly covered. Seems like it should be in the same bucket as STRUCT and JAVA_OBJECT
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)