RowUtils { public static Row remove(Row row, String fieldName) { List<StructField> removedFields = Lists.newArrayList(row.schema().fields()); removedFields.remove(row.fieldIndex(fieldName)); StructType removedSchema = new StructType(removedFields.toArray(new StructField[0])); List<Object> removedValues = Lists.newArrayList(RowUtils.valuesFor(row)); removedValues.remove(row.fieldIndex(fieldName)); return new RowWithSchema(removedSchema, removedValues.toArray()); }  static Object toRowValue(Object item, DataType type, Map<RowUtils.RowValueMetadata, Object> metadata); static Object toRowValue(Object item, DataType type); static Row subsetRow(Row row, StructType subsetSchema); static Row set(Row row, String fieldName, Object replacement); static Row append(Row row, Object value); static Row append(Row row, String fieldName, DataType fieldType, boolean nullable, Object value); static Row append(Row row, Row append); static Row remove(Row row, String fieldName); static Row remove(Row row, List<String> fieldNames); static Object[] valuesFor(Row row); static boolean different(Row first, Row second, List<String> valueFieldNames); static Column[] toColumnArray(List<String> columnList);  }
@Test public void testRemoveOneField() { 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 removeSchema = DataTypes.createStructType(Lists.newArrayList(field1, field2, field3)); Row remove = new RowWithSchema(removeSchema, "hello", 1, 1.0); Row removed = RowUtils.remove(remove, "field2"); Row expected = new RowWithSchema( DataTypes.createStructType(Lists.newArrayList(field1, field3)), "hello", 1.0); assertEquals(expected, removed); }
@Test public void testRemoveMultipleFields() { 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 removeSchema = DataTypes.createStructType(Lists.newArrayList(field1, field2, field3)); Row remove = new RowWithSchema(removeSchema, "hello", 1, 1.0); Row removed = RowUtils.remove(remove, Lists.newArrayList("field3", "field2")); Row expected = new RowWithSchema( DataTypes.createStructType(Lists.newArrayList(field1)), "hello"); assertEquals(expected, removed); }