Search in sources :

Example 1 with FixedDataSchema

use of com.linkedin.data.schema.FixedDataSchema in project rest.li by linkedin.

the class PdlSchemaParser method parseFixed.

private FixedDataSchema parseFixed(NamedTypeDeclarationContext context, FixedDeclarationContext fixed) throws ParseException {
    Name name = toName(fixed.name);
    FixedDataSchema schema = new FixedDataSchema(name);
    bindNameToSchema(name, schema);
    schema.setSize(fixed.size, errorMessageBuilder());
    setProperties(context, schema);
    return schema;
}
Also used : FixedDataSchema(com.linkedin.data.schema.FixedDataSchema) Name(com.linkedin.data.schema.Name)

Example 2 with FixedDataSchema

use of com.linkedin.data.schema.FixedDataSchema in project rest.li by linkedin.

the class TestSchemaSampleDataGenerator method testFixedSchema.

@Test
public void testFixedSchema() {
    final FixedDataSchema schema = (FixedDataSchema) DataTemplateUtil.getSchema(FixedMD5.class);
    final ByteString value = (ByteString) SchemaSampleDataGenerator.buildData(schema, _spec);
    Assert.assertSame(value.length(), schema.getSize());
}
Also used : ByteString(com.linkedin.data.ByteString) FixedDataSchema(com.linkedin.data.schema.FixedDataSchema) FixedMD5(com.linkedin.pegasus.generator.test.FixedMD5) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 3 with FixedDataSchema

use of com.linkedin.data.schema.FixedDataSchema in project rest.li by linkedin.

the class TemplateSpecGenerator method generateNamedSchema.

private ClassTemplateSpec generateNamedSchema(NamedDataSchema schema) {
    pushCurrentLocation(_schemaResolver.nameToDataSchemaLocations().get(schema.getFullName()));
    // make sure no duplicate template spec classname which should be binding name of the schema
    final String className = schema.getBindingName();
    checkForClassNameConflict(className, schema);
    final ClassTemplateSpec templateClass;
    switch(schema.getType()) {
        case RECORD:
            templateClass = generateRecord((RecordDataSchema) schema);
            break;
        case ENUM:
            templateClass = generateEnum((EnumDataSchema) schema);
            break;
        case FIXED:
            templateClass = generateFixed((FixedDataSchema) schema);
            break;
        default:
            throw unrecognizedSchemaType(null, null, schema);
    }
    popCurrentLocation();
    return templateClass;
}
Also used : ClassTemplateSpec(com.linkedin.pegasus.generator.spec.ClassTemplateSpec) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) FixedDataSchema(com.linkedin.data.schema.FixedDataSchema)

Example 4 with FixedDataSchema

use of com.linkedin.data.schema.FixedDataSchema in project rest.li by linkedin.

the class ExampleRequestResponseGenerator method generateFieldDefValue.

private Object generateFieldDefValue(FieldDef<?> fieldDef) {
    Object value = _dataGenerator.buildData(fieldDef.getName(), fieldDef.getDataSchema());
    DataSchema dereferencedDataSchema = fieldDef.getDataSchema().getDereferencedDataSchema();
    if (!dereferencedDataSchema.isPrimitive()) {
        switch(dereferencedDataSchema.getType()) {
            case FIXED:
                value = new FixedTemplatePlaceholder(value, (FixedDataSchema) dereferencedDataSchema);
                break;
            case ENUM:
                // just use the string value already generated.  Will be coerced by DataTemplateUtil.DynamicEnumCoercer.
                break;
            case ARRAY:
                value = new ArrayTemplatePlaceholder<Object>((DataList) value, (ArrayDataSchema) dereferencedDataSchema, Object.class);
                break;
            case RECORD:
                value = new RecordTemplatePlaceholder((DataMap) value, (RecordDataSchema) dereferencedDataSchema);
                break;
            case MAP:
                value = new MapTemplatePlaceholder<Object>((DataMap) value, (MapDataSchema) dereferencedDataSchema, Object.class);
                break;
            case UNION:
                value = new UnionTemplatePlaceholder(value, (UnionDataSchema) dereferencedDataSchema);
                break;
            case TYPEREF:
                throw new IllegalStateException("TYPEREF should not be returned for a dereferenced byte. schema: " + fieldDef.getDataSchema());
            default:
                throw new IllegalStateException("Unrecognized enum value: " + dereferencedDataSchema.getType());
        }
    }
    return value;
}
Also used : MapDataSchema(com.linkedin.data.schema.MapDataSchema) DataMap(com.linkedin.data.DataMap) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) FixedDataSchema(com.linkedin.data.schema.FixedDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) MapDataSchema(com.linkedin.data.schema.MapDataSchema) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) DataList(com.linkedin.data.DataList) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) FixedDataSchema(com.linkedin.data.schema.FixedDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema)

Example 5 with FixedDataSchema

use of com.linkedin.data.schema.FixedDataSchema in project rest.li by linkedin.

the class CompatibilityChecker method check.

private void check(DataSchema older, DataSchema newer) {
    Checked toCheck = new Checked(older, newer);
    if (_checked.contains(toCheck)) {
        return;
    }
    _checked.add(toCheck);
    if (older == newer) {
        return;
    }
    int pathCount = 1;
    if (_options.getMode() == CompatibilityOptions.Mode.DATA) {
        older = older.getDereferencedDataSchema();
        while (newer.getType() == DataSchema.Type.TYPEREF) {
            TyperefDataSchema typerefDataSchema = ((TyperefDataSchema) newer);
            _path.addLast(typerefDataSchema.getFullName());
            _path.addLast(DataSchemaConstants.REF_KEY);
            pathCount++;
            newer = typerefDataSchema.getRef();
        }
    }
    if (newer.getType() == DataSchema.Type.TYPEREF) {
        _path.addLast(((TyperefDataSchema) newer).getFullName());
    } else {
        _path.addLast(newer.getUnionMemberKey());
    }
    switch(newer.getType()) {
        case TYPEREF:
            if (isSameType(older, newer))
                checkTyperef((TyperefDataSchema) older, (TyperefDataSchema) newer);
            break;
        case RECORD:
            if (isSameType(older, newer))
                checkRecord((RecordDataSchema) older, (RecordDataSchema) newer);
            break;
        case ARRAY:
            if (isSameType(older, newer))
                checkArray((ArrayDataSchema) older, (ArrayDataSchema) newer);
            break;
        case MAP:
            if (isSameType(older, newer))
                checkMap((MapDataSchema) older, (MapDataSchema) newer);
            break;
        case ENUM:
            if (isSameType(older, newer))
                checkEnum((EnumDataSchema) older, (EnumDataSchema) newer);
            break;
        case FIXED:
            if (isSameType(older, newer))
                checkFixed((FixedDataSchema) older, (FixedDataSchema) newer);
            break;
        case UNION:
            if (isSameType(older, newer))
                checkUnion((UnionDataSchema) older, (UnionDataSchema) newer);
            break;
        default:
            if (newer instanceof PrimitiveDataSchema)
                checkPrimitive(older, newer);
            else
                throw new IllegalStateException("Unknown schema type " + newer.getType() + ", checking old schema " + older + ", new schema " + newer);
            break;
    }
    for (; pathCount > 0; pathCount--) {
        _path.removeLast();
    }
    return;
}
Also used : ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) PrimitiveDataSchema(com.linkedin.data.schema.PrimitiveDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) MapDataSchema(com.linkedin.data.schema.MapDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) FixedDataSchema(com.linkedin.data.schema.FixedDataSchema)

Aggregations

FixedDataSchema (com.linkedin.data.schema.FixedDataSchema)8 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)4 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)4 ByteString (com.linkedin.data.ByteString)3 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)3 MapDataSchema (com.linkedin.data.schema.MapDataSchema)3 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)3 DataList (com.linkedin.data.DataList)2 DataMap (com.linkedin.data.DataMap)2 DataSchema (com.linkedin.data.schema.DataSchema)2 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)2 FixedTemplate (com.linkedin.data.template.FixedTemplate)2 Name (com.linkedin.data.schema.Name)1 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)1 PrimitiveDataSchema (com.linkedin.data.schema.PrimitiveDataSchema)1 ClassTemplateSpec (com.linkedin.pegasus.generator.spec.ClassTemplateSpec)1 FixedMD5 (com.linkedin.pegasus.generator.test.FixedMD5)1 TyperefTest (com.linkedin.pegasus.generator.test.TyperefTest)1 UnionTest (com.linkedin.pegasus.generator.test.UnionTest)1 Test (org.testng.annotations.Test)1