Hi Matt, Since you end-up with SqlTypeName.OTHER I guess when you create the type you use RelDataTypeFactory#createJavaType [1]. Have you tried using RelDataTypeFactory#createStructType [2]?
There are already use-cases using combinations of arrays with structs and Avatica seems to handle them without problem so it may be worth giving it a try. Best, Stamatis [1] https://github.com/apache/calcite/blob/2088488ac8327b19512a76a122cae2961fc551c3/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactory.java#L61 [2] https://github.com/apache/calcite/blob/2088488ac8327b19512a76a122cae2961fc551c3/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactory.java#L87 On Thu, Jul 30, 2020 at 11:22 PM Matt Burgess <[email protected]> wrote: > Hi all, > > Does anyone have an example of a Calcite table with a column with > array type where the elements are "custom" Java classes (not in > JavaToSqlTypeConversionRules)? > > I'm running into an issue in Apache NiFi where we have our own type > "Record" and our table model can have a column of type Record and/or a > column of type Array[Record]. For the simple Record case, the SQL type > of Record comes back as OTHER, and since that's the only custom type > in our system, we presume that OTHER means Record and the object we're > looking at is a Record, and we proceed and things seem to work well > for that case. > > I thought the same would go for Array[Record], but if I try to SELECT > that column, I get an error: > > java.lang.IllegalStateException: Unhandled ARRAY component type: > OBJECT, id: 1111 > > Looking at the code, it appears that at some point > RelDataTypeFactoryImpl tries to get a SqlTypeName for our Record > class, and since it's not in the mapping in > JavaToSqlTypeConversionRules, it returns SqlTypeName.OTHER. That maps > to java.sql.Types.OTHER (1111), and the AbstractCursor.ArrayAccessor > doesn't like it. > > I can wrap the Record.class JavaType in a MultisetType to get things > like CARDINALITY to work, but that's a hack and I still can't SELECT > the Array[Record] column. > > Should SqlTypeName.OTHER map to JAVA_OBJECT instead? Am I approaching > this correctly? If so is there a workaround and if not, can you help > me wrap my head around this? :) For reference, [1] is the Jira case > I'm working on. > > Thank you, > Matt > > [1] https://issues.apache.org/jira/browse/NIFI-7601 >
