1616package org .eclipse .jnosql .diana .cassandra .column ;
1717
1818
19+ import com .datastax .oss .driver .api .core .CqlIdentifier ;
1920import com .datastax .oss .driver .api .core .cql .ColumnDefinition ;
2021import com .datastax .oss .driver .api .core .cql .ColumnDefinitions ;
2122import com .datastax .oss .driver .api .core .cql .Row ;
23+ import com .datastax .oss .driver .api .core .data .UdtValue ;
2224import com .datastax .oss .driver .api .core .type .DataType ;
2325import com .datastax .oss .driver .api .core .type .ListType ;
26+ import com .datastax .oss .driver .api .core .type .UserDefinedType ;
2427import com .datastax .oss .driver .api .core .type .codec .TypeCodec ;
2528import com .datastax .oss .driver .api .core .type .codec .TypeCodecs ;
29+ import com .datastax .oss .driver .api .core .type .codec .registry .CodecRegistry ;
2630import com .datastax .oss .driver .shaded .guava .common .reflect .TypeToken ;
2731import com .datastax .oss .protocol .internal .ProtocolConstants ;
2832import jakarta .nosql .Value ;
@@ -58,12 +62,13 @@ public static ColumnEntity toDocumentEntity(Row row) {
5862
5963
6064 private static Column getColumn (ColumnDefinition definition , Object result ) {
65+
66+
6167 switch (definition .getType ().getProtocolCode ()) {
6268 case ProtocolConstants .DataType .UDT :
6369 return Column .class .cast (result );
6470 case ProtocolConstants .DataType .LIST :
6571 case ProtocolConstants .DataType .SET :
66- return Column .of (definition .getName ().asInternal (), Value .of (result ));
6772 default :
6873 return Column .of (definition .getName ().asInternal (), Value .of (result ));
6974 }
@@ -73,8 +78,26 @@ static Object get(ColumnDefinition definition, Row row) {
7378
7479 String name = definition .getName ().asInternal ();
7580 final DataType type = definition .getType ();
81+ if (type instanceof UserDefinedType ) {
82+ return getUDT (name , row .getUdtValue (name ));
83+ }
7684 final TypeCodec <Object > codec = row .codecRegistry ().codecFor (type );
7785 return row .get (name , codec );
7886 }
7987
88+ private static UDT getUDT (String name , UdtValue udtValue ) {
89+ final UserDefinedType type = udtValue .getType ();
90+ List <Column > columns = new ArrayList <>();
91+ List <String > names = type .getFieldNames ().stream ().map (CqlIdentifier ::asInternal ).collect (toList ());
92+ for (CqlIdentifier fieldName : type .getFieldNames ()) {
93+ final int index = names .indexOf (fieldName .asInternal ());
94+ DataType fieldType = type .getFieldTypes ().get (index );
95+ Object elementValue = udtValue .get (fieldName , CodecRegistry .DEFAULT .codecFor (fieldType ));
96+ if (elementValue != null ) {
97+ columns .add (Column .of (fieldName .asInternal (), elementValue ));
98+ }
99+ }
100+ return UDT .builder (type .getName ().asInternal ()).withName (name ).addUDT (columns ).build ();
101+ }
102+
80103}
0 commit comments