Search in sources :

Example 16 with RecordDataSchema

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

the class TestTypeRefRecordTemplate method testMapSchema.

@Test
public void testMapSchema() {
    TyperefTest record = new TyperefTest();
    RecordDataSchema recordDataSchema = record.schema();
    DoubleMap doubleMap = new DoubleMap();
    record.setDoubleRefMap(doubleMap);
    doubleMap = record.getDoubleRefMap();
    assertEquals(doubleMap.schema(), DataTemplateUtil.getSchema(DoubleMap.class));
    assertNotEquals(recordDataSchema.getField("doubleRefMap").getType(), doubleMap.schema());
    IntegerMap intMap = new IntegerMap();
    record.setIntMap(intMap);
    intMap = record.getIntMap();
    assertEquals(intMap.schema(), DataTemplateUtil.getSchema(IntegerMap.class));
    assertNotEquals(recordDataSchema.getField("intMap").getType(), intMap.schema());
    record.setIntRefMap(intMap);
    intMap = record.getIntRefMap();
    assertEquals(intMap.schema(), DataTemplateUtil.getSchema(IntegerMap.class));
    assertNotEquals(recordDataSchema.getField("intRefMap").getType(), intMap.schema());
    assertNotEquals(recordDataSchema.getField("intMap").getType(), recordDataSchema.getField("intRefMap").getType());
}
Also used : RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) Test(org.testng.annotations.Test)

Example 17 with RecordDataSchema

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

the class TestLongStringLiteral method testSchema.

@Test
public void testSchema() {
    DataSchema schema = DataTemplateUtil.getSchema(LongStringLiteral.class);
    String schemaText = schema.toString();
    assertTrue(schemaText.length() > 65536);
    RecordDataSchema recordDataSchema = (RecordDataSchema) schema;
    RecordDataSchema.Field field = recordDataSchema.getField("text");
    DataList defaultValue = (DataList) field.getDefault();
    assertEquals(defaultValue.size(), 400);
    for (Object s : defaultValue) {
        assertEquals(s, LOREM);
    }
}
Also used : RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) DataList(com.linkedin.data.DataList) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) Test(org.testng.annotations.Test)

Example 18 with RecordDataSchema

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

the class TestRecord method testRecord.

private <T extends RecordTemplate> void testRecord(Class<T> recordClass) {
    try {
        T record = recordClass.newInstance();
        RecordDataSchema schema = (RecordDataSchema) DataTemplateUtil.getSchema(recordClass);
        RecordDataSchema schema2 = record.schema();
        assertSame(schema, schema2);
    } catch (IllegalAccessException exc) {
        fail("Unexpected exception", exc);
    } catch (InstantiationException exc) {
        fail("Unexpected exception", exc);
    }
}
Also used : RecordDataSchema(com.linkedin.data.schema.RecordDataSchema)

Example 19 with RecordDataSchema

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

the class TestTypeRefRecordTemplate method testMapSchema.

@Test
public void testMapSchema() {
    TyperefTest record = new TyperefTest();
    RecordDataSchema recordDataSchema = record.schema();
    DoubleMap doubleMap = new DoubleMap();
    record.setDoubleRefMap(doubleMap);
    doubleMap = record.getDoubleRefMap();
    assertEquals(doubleMap.schema(), DataTemplateUtil.getSchema(DoubleMap.class));
    assertNotEquals(recordDataSchema.getField("doubleRefMap").getType(), doubleMap.schema());
    IntegerMap intMap = new IntegerMap();
    record.setIntMap(intMap);
    intMap = record.getIntMap();
    assertEquals(intMap.schema(), DataTemplateUtil.getSchema(IntegerMap.class));
    assertNotEquals(recordDataSchema.getField("intMap").getType(), intMap.schema());
    record.setIntRefMap(intMap);
    intMap = record.getIntRefMap();
    assertEquals(intMap.schema(), DataTemplateUtil.getSchema(IntegerMap.class));
    assertNotEquals(recordDataSchema.getField("intRefMap").getType(), intMap.schema());
    assertNotEquals(recordDataSchema.getField("intMap").getType(), recordDataSchema.getField("intRefMap").getType());
}
Also used : IntegerMap(com.linkedin.data.template.IntegerMap) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) DoubleMap(com.linkedin.data.template.DoubleMap) Test(org.testng.annotations.Test)

Example 20 with RecordDataSchema

use of com.linkedin.data.schema.RecordDataSchema 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)

Aggregations

RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)63 DataMap (com.linkedin.data.DataMap)26 DataSchema (com.linkedin.data.schema.DataSchema)25 Test (org.testng.annotations.Test)24 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)15 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)14 MapDataSchema (com.linkedin.data.schema.MapDataSchema)12 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)12 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)10 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)8 Name (com.linkedin.data.schema.Name)8 FixedDataSchema (com.linkedin.data.schema.FixedDataSchema)7 ArrayList (java.util.ArrayList)7 FieldDef (com.linkedin.data.template.FieldDef)6 Schema (org.apache.avro.Schema)6 DataList (com.linkedin.data.DataList)5 ActionResponse (com.linkedin.restli.common.ActionResponse)5 GenericRecord (org.apache.avro.generic.GenericRecord)5 SchemaParser (com.linkedin.data.schema.SchemaParser)4 TyperefTest (com.linkedin.pegasus.generator.test.TyperefTest)4