26
26
import java .util .stream .Stream ;
27
27
import net .snowflake .client .core .arrow .ArrayConverter ;
28
28
import net .snowflake .client .core .arrow .ArrowVectorConverter ;
29
+ import net .snowflake .client .core .arrow .MapConverter ;
29
30
import net .snowflake .client .core .arrow .StructConverter ;
30
31
import net .snowflake .client .core .arrow .StructObjectWrapper ;
31
32
import net .snowflake .client .core .arrow .VarCharConverter ;
@@ -574,10 +575,11 @@ public Object getObjectWithoutString(int columnIndex) throws SFException {
574
575
return getObjectRepresentation (columnIndex , false );
575
576
}
576
577
577
- private Object getObjectRepresentation (int columnIndex , boolean withString ) throws SFException {
578
+ private StructObjectWrapper getObjectRepresentation (int columnIndex , boolean withString )
579
+ throws SFException {
578
580
int type = resultSetMetaData .getColumnType (columnIndex );
579
581
if (type == SnowflakeUtil .EXTRA_TYPES_VECTOR ) {
580
- return getString (columnIndex );
582
+ return new StructObjectWrapper ( getString (columnIndex ), null );
581
583
}
582
584
ArrowVectorConverter converter = currentChunkIterator .getCurrentConverter (columnIndex - 1 );
583
585
int index = currentChunkIterator .getCurrentRowInRecordBatch ();
@@ -589,15 +591,33 @@ private Object getObjectRepresentation(int columnIndex, boolean withString) thro
589
591
if (obj == null ) {
590
592
return null ;
591
593
}
592
- String jsonString = withString ? converter .toString (index ) : null ;
593
594
boolean isStructuredType = resultSetMetaData .isStructuredTypeColumn (columnIndex );
594
- if (isVarcharConvertedStruct (type , isStructuredType , converter )) {
595
- return new StructObjectWrapper (jsonString , createJsonSqlInput (columnIndex , obj ));
596
- } else if (converter instanceof StructConverter ) {
597
- return new StructObjectWrapper (
598
- jsonString , createArrowSqlInput (columnIndex , (Map <String , Object >) obj ));
595
+ if (isStructuredType ) {
596
+ if (converter instanceof VarCharConverter ) {
597
+ if (type == Types .STRUCT ) {
598
+ JsonSqlInput jsonSqlInput = createJsonSqlInput (columnIndex , obj );
599
+ return new StructObjectWrapper (jsonSqlInput .getText (), jsonSqlInput );
600
+ } else if (type == Types .ARRAY ) {
601
+ SfSqlArray sfArray = getJsonArray ((String ) obj , columnIndex );
602
+ return new StructObjectWrapper (sfArray .getText (), sfArray );
603
+ } else {
604
+ throw new SFException (queryId , ErrorCode .INVALID_STRUCT_DATA );
605
+ }
606
+ } else if (converter instanceof StructConverter ) {
607
+ String jsonString = withString ? converter .toString (index ) : null ;
608
+ return new StructObjectWrapper (
609
+ jsonString , createArrowSqlInput (columnIndex , (Map <String , Object >) obj ));
610
+ } else if (converter instanceof MapConverter ) {
611
+ String jsonString = withString ? converter .toString (index ) : null ;
612
+ return new StructObjectWrapper (jsonString , obj );
613
+ } else if (converter instanceof ArrayConverter || converter instanceof VectorTypeConverter ) {
614
+ String jsonString = converter .toString (index );
615
+ return new StructObjectWrapper (jsonString , obj );
616
+ } else {
617
+ throw new SFException (queryId , ErrorCode .INVALID_STRUCT_DATA );
618
+ }
599
619
} else {
600
- return new StructObjectWrapper (jsonString , obj );
620
+ return new StructObjectWrapper (null , obj );
601
621
}
602
622
}
603
623
@@ -610,12 +630,11 @@ private SQLInput createArrowSqlInput(int columnIndex, Map<String, Object> input)
610
630
input , session , converters , resultSetMetaData .getColumnFields (columnIndex ));
611
631
}
612
632
613
- private boolean isVarcharConvertedStruct (
614
- int type , boolean isStructuredType , ArrowVectorConverter converter ) {
615
- return type == Types .STRUCT && isStructuredType && converter instanceof VarCharConverter ;
633
+ private boolean isVarcharConvertedStruct (int type , ArrowVectorConverter converter ) {
634
+ return (type == Types .STRUCT || type == Types .ARRAY ) && converter instanceof VarCharConverter ;
616
635
}
617
636
618
- private Object createJsonSqlInput (int columnIndex , Object obj ) throws SFException {
637
+ private JsonSqlInput createJsonSqlInput (int columnIndex , Object obj ) throws SFException {
619
638
try {
620
639
if (obj == null ) {
621
640
return null ;
0 commit comments