SchemaUtils { public static StructType appendFields(StructType from, List<StructField> fields) { StructType to = DataTypes.createStructType(from.fields()); for (StructField field : fields) { to = to.add(field); } return to; }  static StructType stringValueSchema(); static StructType binaryValueSchema(); static StructType subsetSchema(StructType schema, final List<String> fieldNames); static StructType subtractSchema(StructType schema, List<String> subtractFieldNames); static StructType appendFields(StructType from, List<StructField> fields); static Set<InstantiatedComponent> getSchemaComponents(Config config,
      boolean configure, String ...schemaConfigPaths);  }
@Test public void testAppendFields() { StructField field1 = DataTypes.createStructField("field1", DataTypes.StringType, true); StructField field2 = DataTypes.createStructField("field2", DataTypes.IntegerType, true); StructField field3 = DataTypes.createStructField("field3", DataTypes.FloatType, true); StructType schema = DataTypes.createStructType(Lists.newArrayList(field1, field2, field3)); StructField field4 = DataTypes.createStructField("field4", DataTypes.BooleanType, true); StructField field5 = DataTypes.createStructField("field5", DataTypes.StringType, true); StructType appendSchema = SchemaUtils.appendFields(schema, Lists.newArrayList(field4, field5)); assertEquals(appendSchema.length(), 5); assertEquals(appendSchema.fields()[0], field1); assertEquals(appendSchema.fields()[1], field2); assertEquals(appendSchema.fields()[2], field3); assertEquals(appendSchema.fields()[3], field4); assertEquals(appendSchema.fields()[4], field5); }