Example #1
0
  private void recordType(
      DataSchema schema, Map<String, NamedDataSchema> foundTypes, List<NamedDataSchema> typeOrder) {
    if (schema instanceof NamedDataSchema) {
      NamedDataSchema namedDataSchema = (NamedDataSchema) schema;

      if (!foundTypes.containsKey(namedDataSchema.getFullName())) {
        foundTypes.put(namedDataSchema.getFullName(), namedDataSchema);

        if (schema instanceof RecordDataSchema) // recurse into record, record any contained types.
        {
          RecordDataSchema recordDataSchema = (RecordDataSchema) schema;
          for (RecordDataSchema.Field field : recordDataSchema.getFields()) {
            recordType(field.getType(), foundTypes, typeOrder);
          }
        }

        typeOrder.add(namedDataSchema);
      }
    } else if (schema instanceof ArrayDataSchema) {
      ArrayDataSchema arraySchema = (ArrayDataSchema) schema;
      recordType(arraySchema.getItems(), foundTypes, typeOrder);
    } else if (schema instanceof MapDataSchema) {
      MapDataSchema mapSchema = (MapDataSchema) schema;
      recordType(mapSchema.getValues(), foundTypes, typeOrder);
    } else if (schema instanceof UnionDataSchema) {
      UnionDataSchema unionSchema = (UnionDataSchema) schema;
      for (DataSchema type : unionSchema.getTypes()) {
        recordType(type, foundTypes, typeOrder);
      }
    }
  }
Example #2
0
 private void checkName(NamedDataSchema older, NamedDataSchema newer) {
   if (_options.isCheckNames() && older.getFullName().equals(newer.getFullName()) == false) {
     appendMessage(
         CompatibilityMessage.Impact.BREAKS_NEW_AND_OLD_READERS,
         "name changed from %s to %s",
         older.getFullName(),
         newer.getFullName());
   }
 }
 @Override
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append(getClass().getSimpleName()).append("\n");
   if (_initMessages.isEmpty() == false) {
     sb.append("Initialization message:\n");
     _initMessages.appendTo(sb);
   }
   sb.append("Validators:\n");
   for (Map.Entry<Object, List<Validator>> e : _cache.entrySet()) {
     sb.append("  ");
     Object key = e.getKey();
     if (key instanceof RecordDataSchema.Field) {
       sb.append(((RecordDataSchema.Field) key).getName()).append(" (field)");
     } else if (key instanceof NamedDataSchema) {
       sb.append(((NamedDataSchema) key).getFullName()).append(" (named schema)");
     } else {
       sb.append(key.toString());
     }
     sb.append("\n");
     for (Validator v : e.getValue()) {
       sb.append("    ").append(v).append("\n");
     }
   }
   return sb.toString();
 }