final public Schema ImportSchema() throws ParseException { String importFile; jj_consume_token(SCHEMA); importFile = JsonString(); jj_consume_token(SEMICOLON); try { Parser parser = new Schema.Parser(); parser.addTypes(names); // inherit names InputStream stream = findFile(importFile).openStream(); try { Schema value = parser.parse(stream); names = parser.getTypes(); // update names {if (true) return value;} } finally { stream.close(); } } catch (IOException e) { {if (true) throw error("Error importing "+importFile+": "+e, token);} } throw new Error("Missing return statement in function"); }
/** * Parses the given string CTL schema along with its dependencies as an * {@link org.apache.avro.Schema Avro schema}. * * @param avroSchema A string CTL schema to parse * @return A parsed CTL schema as an Avro schema * @throws Exception - if the given CTL schema is invalid and thus cannot be parsed. */ public static Schema parseStringCtlSchema(String avroSchema) throws Exception { Schema.Parser parser = new Schema.Parser(); ObjectMapper mapper = new ObjectMapper(); JsonNode node = mapper.readTree(avroSchema); JsonNode dependenciesNode = node.get(DEPENDENCIES); if (dependenciesNode != null && dependenciesNode.isArray()) { Map<String, Schema> types = new HashMap<>(); for (int i = 0; i < dependenciesNode.size(); i++) { JsonNode dependencyNode = dependenciesNode.get(i); Fqn fqn = new Fqn(dependencyNode.get(FQN).asText()); Schema fakeSchema = SchemaBuilder .record(fqn.getName()).namespace(fqn.getNamespace()) .fields() .endRecord(); types.put(fqn.getFqnString(), fakeSchema); } parser.addTypes(types); } return parser.parse(avroSchema); }
private String getResultantSchema(String schemaText, Map<String, SchemaParsingState> schemaParsingStates) throws InvalidSchemaException, SchemaNotFoundException { Map<String, Schema> complexTypes = traverseIncludedSchemaTypes(schemaText, schemaParsingStates); Schema.Parser parser = new Schema.Parser(); parser.addTypes(complexTypes); Schema schema = parser.parse(schemaText); Set<String> visitingTypes = new HashSet<>(); Schema updatedSchema = handleUnionFieldsWithNull(schema, visitingTypes); return (schema == updatedSchema && complexTypes.isEmpty()) ? schemaText : updatedSchema.toString(); }
try { Schema.Parser parser = new Schema.Parser(); parser.addTypes(parserTypes); parser.setValidateDefaults(isValidateDefaults());
private String getResultantSchema(String schemaText, Map<String, SchemaParsingState> schemaParsingStates) throws InvalidSchemaException, SchemaNotFoundException { Map<String, Schema> complexTypes = traverseIncludedSchemaTypes(schemaText, schemaParsingStates); Schema.Parser parser = new Schema.Parser(); parser.addTypes(complexTypes); Schema schema = parser.parse(schemaText); Set<String> visitingTypes = new HashSet<>(); Schema updatedSchema = handleUnionFieldsWithNull(schema, visitingTypes); return (schema == updatedSchema && complexTypes.isEmpty()) ? schemaText : updatedSchema.toString(); }