2424
2525import java .math .BigDecimal ;
2626import java .util .Arrays ;
27+ import java .util .Collection ;
2728import java .util .EnumMap ;
28- import java .util .EnumSet ;
2929import java .util .HashSet ;
3030import java .util .List ;
3131import java .util .Map ;
4141final class ConverterCommons {
4242
4343 static final Map <DataTypeRoot , Set <Class <?>>> SUPPORTED_TYPES = createSupportedTypes ();
44- static final Set <DataTypeRoot > SUPPORTED_COMPLEX_TYPES =
45- EnumSet .of (DataTypeRoot .ARRAY , DataTypeRoot .MAP );
4644
4745 private static Map <DataTypeRoot , Set <Class <?>>> createSupportedTypes () {
4846 Map <DataTypeRoot , Set <Class <?>>> map = new EnumMap <>(DataTypeRoot .class );
@@ -64,8 +62,6 @@ private static Map<DataTypeRoot, Set<Class<?>>> createSupportedTypes() {
6462 map .put (
6563 DataTypeRoot .TIMESTAMP_WITH_LOCAL_TIME_ZONE ,
6664 setOf (java .time .Instant .class , java .time .OffsetDateTime .class ));
67- map .put (DataTypeRoot .ARRAY , setOf (java .util .Arrays .class ));
68- map .put (DataTypeRoot .MAP , setOf (java .util .Map .class ));
6965 return map ;
7066 }
7167
@@ -115,16 +111,36 @@ static void validateProjectionSubset(RowType projection, RowType tableSchema) {
115111 }
116112
117113 static void validateCompatibility (DataType fieldType , PojoType .Property prop ) {
118- Set < Class <?>> supported = SUPPORTED_TYPES . get ( fieldType .getTypeRoot () );
114+ DataTypeRoot typeRoot = fieldType .getTypeRoot ();
119115 Class <?> actual = prop .type ;
116+ if (typeRoot == DataTypeRoot .ARRAY ) {
117+ if (!actual .isArray () && !Collection .class .isAssignableFrom (actual )) {
118+ throw new IllegalArgumentException (
119+ String .format (
120+ "Field '%s' must be an array or Collection for ARRAY type, got %s" ,
121+ prop .name , actual .getName ()));
122+ }
123+ return ;
124+ }
125+
126+ if (typeRoot == DataTypeRoot .MAP ) {
127+ if (!Map .class .isAssignableFrom (actual )) {
128+ throw new IllegalArgumentException (
129+ String .format (
130+ "Field '%s' must be a Map for MAP type, got %s" ,
131+ prop .name , actual .getName ()));
132+ }
133+ return ;
134+ }
135+
136+ Set <Class <?>> supported = SUPPORTED_TYPES .get (fieldType .getTypeRoot ());
120137 if (supported == null ) {
121138 throw new UnsupportedOperationException (
122139 String .format (
123140 "Unsupported field type %s for field %s." ,
124141 fieldType .getTypeRoot (), prop .name ));
125142 }
126- if (!supported .contains (actual )
127- & !SUPPORTED_COMPLEX_TYPES .contains (fieldType .getTypeRoot ())) {
143+ if (!supported .contains (actual )) {
128144 throw new IllegalArgumentException (
129145 String .format (
130146 "Field '%s' in POJO has Java type %s which is incompatible with Fluss type %s. Supported Java types: %s" ,
0 commit comments