@Test public void toSchemaNullable() throws Exception { StructType input = DataTypes.createStructType(Lists.newArrayList( DataTypes.createStructField("field1", DataTypes.BooleanType, false), DataTypes.createStructField("field2", DataTypes.StringType, true), DataTypes.createStructField("field3", DataTypes.DateType, false), DataTypes.createStructField("field4", DataTypes.TimestampType, false) )); Schema schema = AvroUtils.schemaFor(input); assertEquals("Invalid field count", 4, schema.getFields().size()); assertEquals("Invalid field name", "field1", schema.getFields().get(0).name()); assertEquals("Invalid field type", Schema.Type.BOOLEAN, schema.getFields().get(0).schema().getType()); assertEquals("Invalid field default", null, schema.getFields().get(0).defaultVal()); assertEquals("Invalid nullable (union) type", Schema.Type.UNION, schema.getFields().get(1).schema().getType()); assertEquals("Invalid nullable (union) type count", 2, schema.getFields().get(1).schema().getTypes().size()); assertEquals("Invalid field type", Schema.Type.STRING, schema.getFields().get(1).schema().getTypes().get(0).getType()); assertEquals("Invalid union default", null, schema.getFields().get(1).defaultVal()); }
public static Schema schemaFor(StructType structType) { return schemaFor(structType, null, null); }
AvroUtils { public static Schema schemaFor(StructType structType) { return schemaFor(structType, null, null); } }
AvroUtils { public static Schema schemaFor(StructType structType) { return schemaFor(structType, null, null); }  }
AvroUtils { public static Schema schemaFor(StructType structType) { return schemaFor(structType, null, null); }  static Schema schemaFor(StructType structType); static Schema schemaFor(StructType structType, String record, String namespace); static Schema typeFor(DataType dataType); static Schema typeFor(DataType dataType, boolean isOptional); static StructType structTypeFor(Schema schema); static DataType dataTypeFor(Schema schemaType); }
AvroUtils { public static Schema schemaFor(StructType structType) { return schemaFor(structType, null, null); }  static Schema schemaFor(StructType structType); static Schema schemaFor(StructType structType, String record, String namespace); static Schema typeFor(DataType dataType); static Schema typeFor(DataType dataType, boolean isOptional); static StructType structTypeFor(Schema schema); static DataType dataTypeFor(Schema schemaType);  }