Package com.linkedin.data.schema

Examples of com.linkedin.data.schema.RecordDataSchema


    ValidationOptions options = normalCoercionValidationOption();
    options.setCoercionMode(coercionMode);

    if (debug) out.println("--------------\nschemaText: " + schemaText);

    RecordDataSchema schema = (RecordDataSchema) dataSchemaFromString(schemaText);
    if (debug) out.println("schema: " + schema);
    assertTrue(schema != null);

    DataMap map = new DataMap();
    for (Object[] row : inputs)
    {
      if (debug) out.println("input: " + row[0] + " expected output: " + row[1]);
      map.put(key, row[0]);
      ValidationResult result = validate(map, schema, options);
      if (debug) out.println("result: " + result);
      assertTrue(result.isValid());
      if (result.hasFix())
      {
        DataMap fixedMap = (DataMap) result.getFixed();
        assertSame(fixedMap.getClass(), DataMap.class);
        Object fixed = fixedMap.get(key);
        assertTrue(fixed != null);
        Class<?> fixedClass = fixed.getClass();
        Class<?> goodClass = row[0].getClass();
        if (debug) out.println(goodClass + " " + fixedClass);
        switch (schema.getField(key).getType().getDereferencedType())
        {
          case BYTES:
          case FIXED:
            // String to ByteString conversion check
            assertNotSame(goodClass, fixedClass);
View Full Code Here


  {
    final boolean debug = false;

    if (debug) out.println("--------------\nschemaText: " + schemaText);

    RecordDataSchema schema = (RecordDataSchema) dataSchemaFromString(schemaText);
    if (debug) out.println("schema: " + schema);
    assertTrue(schema != null);

    DataMap map = new DataMap();
    for (Object good : goodObjects)
View Full Code Here

    else
    {
      value = result;
      status = HttpStatus.S_200_OK;
    }
    RecordDataSchema actionReturnRecordDataSchema = routingResult.getResourceMethod().getActionReturnRecordDataSchema();
    @SuppressWarnings("unchecked")
    FieldDef<Object> actionReturnFieldDef =
        (FieldDef<Object>) routingResult.getResourceMethod().getActionReturnFieldDef();
    final ActionResponse<?> actionResponse =
        new ActionResponse<Object>(value, actionReturnFieldDef, actionReturnRecordDataSchema);
View Full Code Here

  private void testDataTranslation(String schemaText, String[][] row) throws IOException
  {
    boolean debug = false;

    if (debug) out.print(schemaText);
    RecordDataSchema recordDataSchema = (RecordDataSchema) TestUtil.dataSchemaFromString(schemaText);
    Schema avroSchema = SchemaTranslator.dataToAvroSchema(recordDataSchema);

    if (debug) out.println(avroSchema);

    // translate data
View Full Code Here

  }

  @Test
  public void testKeySchema()
  {
    RecordDataSchema schema = (RecordDataSchema) DataTemplateUtil.parseSchema
        (
            "{ \"type\" : \"record\", \"name\" : \"omni\", \"fields\" : [ { \"name\" : \"int\", \"type\" : \"int\" } ] }"
        );

    TypeSpec<OmniRecord> keyType = new TypeSpec<OmniRecord>(OmniRecord.class, schema);
View Full Code Here

          }
          result = resultList;
          break;
        case RECORD:
          DataMap recordMap = (DataMap) value;
          RecordDataSchema recordDataSchema = (RecordDataSchema) dataSchema;
          DataMap resultRecordMap = new DataMap(recordDataSchema.getFields().size() * 2);
          for (RecordDataSchema.Field field : recordDataSchema.getFields())
          {
            String fieldName = field.getName();
            Object fieldValue = recordMap.get(fieldName);
            path.add(fieldName);
            Object resultFieldValue = translateField(path, fieldValue, field);
View Full Code Here

  }

  @Test(dataProvider="dataElementFactories")
  public void testDataElement(DataElementFactory factory) throws IOException
  {
    RecordDataSchema fooSchema = (RecordDataSchema) TestUtil.dataSchemaFromString(fooSchemaText);
    ArrayDataSchema arraySchema = (ArrayDataSchema) fooSchema.getField("array").getType();

    String fooText =
      "{\n" +
      "  \"int\" : 34,\n" +
      "  \"string\" : \"abc\",\n" +
      "  \"array\" : [\n" +
      "    { \"int\" : 56 },\n" +
      "    { \"string\" : \"xyz\" },\n" +
      "    { \"array\" : [\n" +
      "      { \"int\" : 78 }\n" +
      "    ] }\n" +
      "  ]\n" +
      "}\n";

    DataMap foo = TestUtil.dataMapFromString(fooText);

    DataElement root = factory.create(foo, DataElement.ROOT_NAME, fooSchema, null);
    DataElement int1 = factory.create(foo.get("int"), "int", fooSchema.getField("int").getType(), root);
    DataElement string1 = factory.create(foo.get("string"), "string", fooSchema.getField("string").getType(), root);
    DataElement array1 = factory.create(foo.get("array"), "array", fooSchema.getField("array").getType(), root);

    DataElement foo20 = factory.create(array1.getChild(0), 0, arraySchema.getItems(), array1);
    DataElement foo21 = factory.create(array1.getChild(1), 1, arraySchema.getItems(), array1);
    DataElement foo22 = factory.create(array1.getChild(2), 2, arraySchema.getItems(), array1);

    DataElement int20 = factory.create(foo20.getChild("int"), "int", fooSchema.getField("int").getType(), foo20);
    DataElement string21 = factory.create(foo21.getChild("string"), "string", fooSchema.getField("string").getType(), foo21);
    DataElement array22 = factory.create(foo22.getChild("array"), "array", fooSchema.getField("array").getType(), foo22);

    DataElement foo30 = factory.create(array22.getChild(0), 0, arraySchema.getItems(), array22);
    DataElement int30 = factory.create(foo30.getChild("int"), "int", fooSchema.getField("int").getType(), foo30);

    // test path

    Object[][] testPathInput =
      {
View Full Code Here

        .replace("##ANYRECORD_NAME", ANYRECORD_AVRO_FULL_NAME);
    String fullAvroSchemaJson = AVRO_SCHEMA_JSON_TEMPLATE.replace("##FIELDS", avroSchemaFieldsJsonAfterVariableExpansion);

    SchemaParser parser = TestUtil.schemaParserFromString(fullSchemaJson);
    assertFalse(parser.hasError(), parser.errorMessage());
    RecordDataSchema schema = (RecordDataSchema) parser.topLevelDataSchemas().get(2);

    String avroJsonOutput = SchemaTranslator.dataToAvroSchemaJson(schema);
    assertEquals(TestUtil.dataMapFromString(avroJsonOutput), TestUtil.dataMapFromString(fullAvroSchemaJson));
    Schema avroSchema = Schema.parse(avroJsonOutput);
    Schema avroSchema2 = SchemaTranslator.dataToAvroSchema(schema);
View Full Code Here

          }
          result = dataList;
          break;
        case RECORD:
          GenericRecord record = (GenericRecord) value;
          RecordDataSchema recordDataSchema = (RecordDataSchema) dereferencedDataSchema;
          dataMap = new DataMap(avroSchema.getFields().size());
          for (RecordDataSchema.Field field : recordDataSchema.getFields())
          {
            String fieldName = field.getName();
            Object fieldValue = record.get(fieldName);
            boolean isOptional = field.getOptional();
            if (isOptional && fieldValue == null)
View Full Code Here

      int i = 0;
      String schemaText = (String) row[i++];
      Predicate predicate = (Predicate) row[i++];
      String avroSchemaText = (String) row[i++];

      RecordDataSchema schema = (RecordDataSchema) TestUtil.dataSchemaFromString(schemaText);
      NamedDataSchema filteredSchema = Filters.removeByPredicate(schema, predicate, new SchemaParser());
      Schema filteredAvroSchema = SchemaTranslator.dataToAvroSchema(filteredSchema);

      Schema expectedAvroSchema = Schema.parse(avroSchemaText);
      assertEquals(filteredAvroSchema, expectedAvroSchema);
View Full Code Here

TOP

Related Classes of com.linkedin.data.schema.RecordDataSchema

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.