FieldTypeDescriptors { public static TypeDescriptor javaTypeForFieldType(FieldType fieldType) { switch (fieldType.getTypeName()) { case LOGICAL_TYPE: return javaTypeForFieldType(fieldType.getLogicalType().getBaseType()); case ARRAY: return TypeDescriptors.lists(javaTypeForFieldType(fieldType.getCollectionElementType())); case ITERABLE: return TypeDescriptors.iterables( javaTypeForFieldType(fieldType.getCollectionElementType())); case MAP: return TypeDescriptors.maps( javaTypeForFieldType(fieldType.getMapKeyType()), javaTypeForFieldType(fieldType.getMapValueType())); case ROW: return TypeDescriptors.rows(); default: return PRIMITIVE_MAPPING.get(fieldType.getTypeName()); } }  static TypeDescriptor javaTypeForFieldType(FieldType fieldType); static FieldType fieldTypeForJavaType(TypeDescriptor typeDescriptor);  }
@Test public void testPrimitiveTypeToJavaType() { assertEquals( TypeDescriptors.bytes(), FieldTypeDescriptors.javaTypeForFieldType(FieldType.BYTE)); assertEquals( TypeDescriptors.shorts(), FieldTypeDescriptors.javaTypeForFieldType(FieldType.INT16)); assertEquals( TypeDescriptors.integers(), FieldTypeDescriptors.javaTypeForFieldType(FieldType.INT32)); assertEquals( TypeDescriptors.longs(), FieldTypeDescriptors.javaTypeForFieldType(FieldType.INT64)); assertEquals( TypeDescriptors.bigdecimals(), FieldTypeDescriptors.javaTypeForFieldType(FieldType.DECIMAL)); assertEquals( TypeDescriptors.floats(), FieldTypeDescriptors.javaTypeForFieldType(FieldType.FLOAT)); assertEquals( TypeDescriptors.doubles(), FieldTypeDescriptors.javaTypeForFieldType(FieldType.DOUBLE)); assertEquals( TypeDescriptors.strings(), FieldTypeDescriptors.javaTypeForFieldType(FieldType.STRING)); assertEquals( TypeDescriptor.of(Instant.class), FieldTypeDescriptors.javaTypeForFieldType(FieldType.DATETIME)); assertEquals( TypeDescriptors.booleans(), FieldTypeDescriptors.javaTypeForFieldType(FieldType.BOOLEAN)); assertEquals( TypeDescriptor.of(byte[].class), FieldTypeDescriptors.javaTypeForFieldType(FieldType.BYTES)); }
@Test public void testRowTypeToJavaType() { assertEquals( TypeDescriptors.lists(TypeDescriptors.rows()), FieldTypeDescriptors.javaTypeForFieldType( FieldType.array(FieldType.row(Schema.builder().build())))); }
@Test public void testArrayTypeToJavaType() { assertEquals( TypeDescriptors.lists(TypeDescriptors.longs()), FieldTypeDescriptors.javaTypeForFieldType(FieldType.array(FieldType.INT64))); assertEquals( TypeDescriptors.lists(TypeDescriptors.lists(TypeDescriptors.longs())), FieldTypeDescriptors.javaTypeForFieldType( FieldType.array(FieldType.array(FieldType.INT64)))); }
@Test public void testIterableTypeToJavaType() { assertEquals( TypeDescriptors.iterables(TypeDescriptors.longs()), FieldTypeDescriptors.javaTypeForFieldType(FieldType.iterable(FieldType.INT64))); assertEquals( TypeDescriptors.iterables(TypeDescriptors.iterables(TypeDescriptors.longs())), FieldTypeDescriptors.javaTypeForFieldType( FieldType.iterable(FieldType.iterable(FieldType.INT64)))); }
@Test public void testMapTypeToJavaType() { assertEquals( TypeDescriptors.maps(TypeDescriptors.strings(), TypeDescriptors.longs()), FieldTypeDescriptors.javaTypeForFieldType( FieldType.map(FieldType.STRING, FieldType.INT64))); assertEquals( TypeDescriptors.maps( TypeDescriptors.strings(), TypeDescriptors.lists(TypeDescriptors.longs())), FieldTypeDescriptors.javaTypeForFieldType( FieldType.map(FieldType.STRING, FieldType.array(FieldType.INT64)))); }