Exemplo n.º 1
0
  /** Parse the given string, return resulting data if appropriate. */
  ParseResult internalParse(
      String s, Map<String, Integer> targetUnionDecisions, boolean mustConsumeStr) {
    boolean hasData = false;
    GenericData.Record gdr = new GenericData.Record(getAvroSchema());
    String currentStr = s;

    for (InferredType subelt : structTypes) {
      if (currentStr.length() == 0) {
        return null;
      }
      ParseResult pr = subelt.internalParse(currentStr, targetUnionDecisions, false);
      if (pr == null) {
        return null;
      }
      if (pr.hasData()) {
        hasData = true;
        gdr.put(subelt.getName(), pr.getData());
      }
      currentStr = pr.getRemainingString();
    }
    if (mustConsumeStr && currentStr.trim().length() != 0) {
      return null;
    }
    return new ParseResult(gdr, hasData, currentStr);
  }
Exemplo n.º 2
0
 Schema computeAvroSchema() {
   List<Schema.Field> fields = new ArrayList<Schema.Field>();
   for (InferredType it : structTypes) {
     Schema itS = it.getAvroSchema();
     if (itS == null) {
       continue;
     }
     fields.add(
         new Schema.Field(
             it.getName(), it.getAvroSchema(), it.getDocString(), it.getDefaultValue()));
   }
   Schema s = Schema.createRecord(name, "RECORD", "", false);
   s.setFields(fields);
   return s;
 }