RowUtils { public static boolean different(Row first, Row second, List<String> valueFieldNames) { for (String valueFieldName : valueFieldNames) { Object firstValue = first.get(first.fieldIndex(valueFieldName)); Object secondValue = second.get(second.fieldIndex(valueFieldName)); if (firstValue != null && secondValue != null && !firstValue.equals(secondValue)) { return true; } if ((firstValue != null && secondValue == null) || (firstValue == null && secondValue != null)) { return true; } } return false; }  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 testDifferent() { 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)); Row row1 = new RowWithSchema(schema, "hello", 1, 2.0); Row row2 = new RowWithSchema(schema, "hello", 10, -2.0); assertTrue(RowUtils.different(row1, row2, Lists.newArrayList("field1", "field2", "field3"))); assertTrue(!RowUtils.different(row1, row2, Lists.newArrayList("field1"))); }
@Test public void testDifferentForDifferentSchemas() { 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 schema1 = DataTypes.createStructType(Lists.newArrayList(field1, field2, field3)); StructType schema2 = DataTypes.createStructType(Lists.newArrayList(field3, field2, field1)); Row row1 = new RowWithSchema(schema1, "hello", 1, 2.0); Row row2 = new RowWithSchema(schema2, -2.0, 10, "hello"); assertTrue(RowUtils.different(row1, row2, Lists.newArrayList("field1", "field2", "field3"))); assertTrue(!RowUtils.different(row1, row2, Lists.newArrayList("field1"))); }