@@ -609,8 +609,8 @@ public ArrayValue readArray(ClickHouseColumn column) throws IOException {
609609 ArrayValue array ;
610610 ClickHouseColumn itemTypeColumn = column .getNestedColumns ().get (0 );
611611 if (len == 0 ) {
612- Class <?> itemClass = itemTypeColumn . getDataType (). getPrimitiveClass ( );
613- array = new ArrayValue (itemClass == null ? Object . class : itemClass , 0 );
612+ Class <?> itemClass = resolveArrayItemClass ( itemTypeColumn );
613+ array = new ArrayValue (itemClass , 0 );
614614 } else if (column .getArrayNestedLevel () == 1 ) {
615615 array = readArrayItem (itemTypeColumn , len );
616616 } else {
@@ -626,7 +626,7 @@ public ArrayValue readArray(ClickHouseColumn column) throws IOException {
626626 public ArrayValue readArrayItem (ClickHouseColumn itemTypeColumn , int len ) throws IOException {
627627 ArrayValue array ;
628628 if (itemTypeColumn .isNullable ()) {
629- Class <?> itemClass = resolveNullableArrayItemClass (itemTypeColumn . getDataType () );
629+ Class <?> itemClass = resolveArrayItemClass (itemTypeColumn );
630630 array = new ArrayValue (itemClass , len );
631631 for (int i = 0 ; i < len ; i ++) {
632632 array .set (i , readValue (itemTypeColumn ));
@@ -673,30 +673,60 @@ public ArrayValue readArrayItem(ClickHouseColumn itemTypeColumn, int len) throws
673673 }
674674
675675 /**
676- * Resolves the Java class that {@link #readValue} actually returns for a given data type
677- * so that it can be used as the component type of a nullable array.
676+ * Resolves the Java class that {@link #readValue} actually returns for a given column
677+ * so that it can be used as the component type of an array.
678678 *
679679 * <p>For unsigned integer types, {@code readValue} widens the value (e.g. UInt8 → Short,
680- * UInt32 → Long), so we use {@link ClickHouseDataType#getWiderObjectClass()} which mirrors
681- * that widening. For Enum types, {@code readValue} returns {@link EnumValue} rather than the
682- * declared {@code String.class}. All other types use {@link ClickHouseDataType#getObjectClass()}.
680+ * UInt32 → Long), so we use {@link ClickHouseDataType#getWiderObjectClass()} or
681+ * {@link ClickHouseDataType#getWiderPrimitiveClass()} which mirrors that widening.
682+ * For Enum types, {@code readValue} returns {@link EnumValue} rather than the
683+ * declared {@code String.class}. All other types use {@link ClickHouseDataType#getObjectClass()}
684+ * or {@link ClickHouseDataType#getPrimitiveClass()}.
683685 *
684- * @param dataType the element data type of the array
686+ * @param itemTypeColumn the element column of the array
685687 * @return the Java class to use as the array component type; never {@code null}
686688 */
687- private static Class <?> resolveNullableArrayItemClass (ClickHouseDataType dataType ) {
688- switch (dataType ) {
689- case UInt8 :
690- case UInt16 :
691- case UInt32 :
692- case UInt64 :
693- return dataType .getWiderObjectClass ();
694- case Enum8 :
695- case Enum16 :
696- return EnumValue .class ;
697- default :
698- Class <?> cls = dataType .getObjectClass ();
699- return cls == null ? Object .class : cls ;
689+ private static Class <?> resolveArrayItemClass (ClickHouseColumn itemTypeColumn ) {
690+ ClickHouseDataType dataType = itemTypeColumn .getDataType ();
691+ if (itemTypeColumn .isNullable ()) {
692+ switch (dataType ) {
693+ case UInt8 :
694+ case UInt16 :
695+ case UInt32 :
696+ case UInt64 :
697+ return dataType .getWiderObjectClass ();
698+ case Enum8 :
699+ case Enum16 :
700+ return EnumValue .class ;
701+ default :
702+ Class <?> cls = dataType .getObjectClass ();
703+ return cls == null ? Object .class : cls ;
704+ }
705+ } else {
706+ switch (dataType ) {
707+ case UInt8 :
708+ case UInt16 :
709+ case UInt32 :
710+ case UInt64 :
711+ return dataType .getWiderPrimitiveClass ();
712+ case Enum8 :
713+ case Enum16 :
714+ return EnumValue .class ;
715+ case Variant :
716+ case Dynamic :
717+ case Geometry :
718+ return Object .class ;
719+ case Array :
720+ return ArrayValue .class ;
721+ case Tuple :
722+ case Nested :
723+ return Object [].class ;
724+ case Map :
725+ return Map .class ;
726+ default :
727+ Class <?> cls = dataType .getPrimitiveClass ();
728+ return cls == null ? Object .class : cls ;
729+ }
700730 }
701731 }
702732
0 commit comments