public static int compareGenericRecords()

in spanner-data-validator-java/src/main/java/com/google/migration/Helpers.java [281:308]


  public static int compareGenericRecords(GenericRecord lhs,
      GenericRecord rhs,
      boolean skipSchemaValidation) {
    Schema lhsSchema = lhs.getSchema();
    Schema rhsSchema = rhs.getSchema();

    if(!skipSchemaValidation) {
      int lhsColsCount = lhsSchema.getFields().size();
      int rhsColsCount = rhsSchema.getFields().size();

      if (lhsColsCount != rhsColsCount) {
        String errMsg = String.format("Schema cols don't match for %s and %s", lhsSchema.getName(),
            rhsSchema.getName());
        LOG.error(errMsg);
        LOG.error(String.format("LHS schema: %s, RHS schema: %s", lhsSchema, rhsSchema));
        throw new RuntimeException(errMsg);
      } // if
    } // if

    List<Schema.Field> fields = lhsSchema.getFields();
    int compareResult = -1;
    for(Schema.Field field: fields) {
      compareResult = compareGenericRecordField(field, lhs, rhs);
      if(compareResult != 0) return compareResult;
    } // for

    return compareResult;
  }