SchemaFactory { static StructTypeInfo newStructTypeInfo(Fields fields) { List<String> names = new ArrayList<>(); List<TypeInfo> typeInfos = new ArrayList<>(); for (int i = 0; i < fields.size(); i++) { String name = fields.get(i).toString(); if (ROW_ID_NAME.equals(name)) { if (!fields.getTypeClass(i).equals(RecordIdentifier.class)) { throw new IllegalArgumentException(ROW_ID_NAME + " column is not of type " + RecordIdentifier.class.getSimpleName() + ". Found type: " + fields.getTypeClass(i)); } continue; } names.add(name.toLowerCase()); Class<?> type = fields.getTypeClass(i); if (type == null) { throw new IllegalArgumentException("Missing type information for field: " + name); } TypeInfo typeInfo = getTypeInfoFromClass(type); typeInfos.add(typeInfo); } return (StructTypeInfo) TypeInfoFactory.getStructTypeInfo(names, typeInfos); } private  SchemaFactory();   }
@Test public void createStructTypeInfo() { String[] names = new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k" }; Class<?>[] types = new Class<?>[] { String.class, Boolean.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, Timestamp.class, Date.class, byte[].class }; Fields fields = new Fields(names, types); StructTypeInfo typeInfo = SchemaFactory.newStructTypeInfo(fields); assertThat(typeInfo.getStructFieldTypeInfo("a"), is((TypeInfo) TypeInfoFactory.stringTypeInfo)); assertThat(typeInfo.getStructFieldTypeInfo("b"), is((TypeInfo) TypeInfoFactory.booleanTypeInfo)); assertThat(typeInfo.getStructFieldTypeInfo("c"), is((TypeInfo) TypeInfoFactory.byteTypeInfo)); assertThat(typeInfo.getStructFieldTypeInfo("d"), is((TypeInfo) TypeInfoFactory.shortTypeInfo)); assertThat(typeInfo.getStructFieldTypeInfo("e"), is((TypeInfo) TypeInfoFactory.intTypeInfo)); assertThat(typeInfo.getStructFieldTypeInfo("f"), is((TypeInfo) TypeInfoFactory.longTypeInfo)); assertThat(typeInfo.getStructFieldTypeInfo("g"), is((TypeInfo) TypeInfoFactory.floatTypeInfo)); assertThat(typeInfo.getStructFieldTypeInfo("h"), is((TypeInfo) TypeInfoFactory.doubleTypeInfo)); assertThat(typeInfo.getStructFieldTypeInfo("i"), is((TypeInfo) TypeInfoFactory.timestampTypeInfo)); assertThat(typeInfo.getStructFieldTypeInfo("j"), is((TypeInfo) TypeInfoFactory.dateTypeInfo)); assertThat(typeInfo.getStructFieldTypeInfo("k"), is((TypeInfo) TypeInfoFactory.binaryTypeInfo)); }
@Test(expected = NullPointerException.class) public void createStructTypeInfoComplex() { String[] names = new String[] { "a" }; Class<?>[] types = new Class<?>[] { List.class }; Fields fields = new Fields(names, types); SchemaFactory.newStructTypeInfo(fields); }
@Test public void bigDecimalField() throws Exception { Fields bigDecimalField = new Fields("bigD", BigDecimal.class); StructTypeInfo typeInfo = SchemaFactory.newStructTypeInfo(bigDecimalField); assertThat(typeInfo.getStructFieldTypeInfo("bigD"), is((TypeInfo) TypeInfoFactory.decimalTypeInfo)); }