Search in sources :

Example 11 with CodeLocation

use of com.linkedin.avroutil1.model.CodeLocation in project avro-util by linkedin.

the class AvscParser method parseUnionSchema.

private SchemaOrRef parseUnionSchema(JsonArrayExt arrayNode, AvscFileParseContext context, boolean topLevel) {
    CodeLocation codeLocation = locationOf(context.getUri(), arrayNode);
    List<SchemaOrRef> unionTypes = new ArrayList<>(arrayNode.size());
    for (JsonValue jsonValue : arrayNode) {
        JsonValueExt unionNode = (JsonValueExt) jsonValue;
        SchemaOrRef type = parseSchemaDeclOrRef(unionNode, context, false);
        unionTypes.add(type);
    }
    AvroUnionSchema unionSchema = new AvroUnionSchema(codeLocation);
    unionSchema.setTypes(unionTypes);
    context.defineSchema(unionSchema, topLevel);
    return new SchemaOrRef(codeLocation, unionSchema);
}
Also used : CodeLocation(com.linkedin.avroutil1.model.CodeLocation) SchemaOrRef(com.linkedin.avroutil1.model.SchemaOrRef) ArrayList(java.util.ArrayList) JsonValue(javax.json.JsonValue) AvroUnionSchema(com.linkedin.avroutil1.model.AvroUnionSchema) JsonValueExt(com.linkedin.avroutil1.parser.jsonpext.JsonValueExt)

Example 12 with CodeLocation

use of com.linkedin.avroutil1.model.CodeLocation in project avro-util by linkedin.

the class AvscParser method parseAliases.

private List<AvroName> parseAliases(JsonObjectExt objectNode, AvscFileParseContext context, AvroType avroType, AvroName name) {
    JsonArrayExt aliasesArray = getOptionalArray(objectNode, "aliases");
    if (aliasesArray == null || aliasesArray.isEmpty()) {
        return null;
    }
    List<AvroName> aliases = new ArrayList<>(aliasesArray.size());
    for (int i = 0; i < aliasesArray.size(); i++) {
        // !=null
        JsonValueExt aliasNode = (JsonValueExt) aliasesArray.get(i);
        JsonValue.ValueType fieldNodeType = aliasNode.getValueType();
        if (fieldNodeType != JsonValue.ValueType.STRING) {
            throw new AvroSyntaxException("alias " + i + " for " + name.getSimpleName() + " at " + aliasNode.getStartLocation() + " expected to be a STRING, not a " + JsonPUtil.describe(fieldNodeType) + " (" + aliasNode + ")");
        }
        String aliasStr = ((JsonStringExt) aliasNode).getString();
        AvroName alias;
        if (aliasStr.contains(".")) {
            int lastDot = aliasStr.lastIndexOf('.');
            alias = new AvroName(aliasStr.substring(lastDot + 1), aliasStr.substring(0, lastDot));
        } else {
            alias = new AvroName(aliasStr, name.getNamespace());
        }
        if (aliases.contains(alias)) {
            TextLocation fieldStartLocation = Util.convertLocation(aliasNode.getStartLocation());
            TextLocation fieldEndLocation = Util.convertLocation(aliasNode.getEndLocation());
            CodeLocation aliasCodeLocation = new CodeLocation(context.getUri(), fieldStartLocation, fieldEndLocation);
            context.addIssue(AvscIssues.duplicateAlias(alias.getFullname(), aliasCodeLocation));
        } else {
            aliases.add(alias);
        }
    }
    return aliases;
}
Also used : CodeLocation(com.linkedin.avroutil1.model.CodeLocation) AvroSyntaxException(com.linkedin.avroutil1.parser.exceptions.AvroSyntaxException) JsonStringExt(com.linkedin.avroutil1.parser.jsonpext.JsonStringExt) AvroName(com.linkedin.avroutil1.model.AvroName) ArrayList(java.util.ArrayList) JsonValue(javax.json.JsonValue) JsonArrayExt(com.linkedin.avroutil1.parser.jsonpext.JsonArrayExt) JsonValueExt(com.linkedin.avroutil1.parser.jsonpext.JsonValueExt) TextLocation(com.linkedin.avroutil1.model.TextLocation)

Aggregations

CodeLocation (com.linkedin.avroutil1.model.CodeLocation)8 SchemaOrRef (com.linkedin.avroutil1.model.SchemaOrRef)6 AvroSyntaxException (com.linkedin.avroutil1.parser.exceptions.AvroSyntaxException)5 JsonValueExt (com.linkedin.avroutil1.parser.jsonpext.JsonValueExt)5 AvroLogicalType (com.linkedin.avroutil1.model.AvroLogicalType)3 AvroName (com.linkedin.avroutil1.model.AvroName)3 AvroType (com.linkedin.avroutil1.model.AvroType)3 TextLocation (com.linkedin.avroutil1.model.TextLocation)3 ArrayList (java.util.ArrayList)3 JsonValue (javax.json.JsonValue)3 AvroJavaStringRepresentation (com.linkedin.avroutil1.model.AvroJavaStringRepresentation)2 AvroPrimitiveSchema (com.linkedin.avroutil1.model.AvroPrimitiveSchema)2 JsonPropertiesContainer (com.linkedin.avroutil1.model.JsonPropertiesContainer)2 JsonArrayExt (com.linkedin.avroutil1.parser.jsonpext.JsonArrayExt)2 AvroArraySchema (com.linkedin.avroutil1.model.AvroArraySchema)1 AvroEnumSchema (com.linkedin.avroutil1.model.AvroEnumSchema)1 AvroFixedSchema (com.linkedin.avroutil1.model.AvroFixedSchema)1 AvroLiteral (com.linkedin.avroutil1.model.AvroLiteral)1 AvroMapSchema (com.linkedin.avroutil1.model.AvroMapSchema)1 AvroNamedSchema (com.linkedin.avroutil1.model.AvroNamedSchema)1