Package com.linkedin.data.schema

Examples of com.linkedin.data.schema.SchemaParser$DefinedAndReferencedNames


      final Schema readerSchema = Schema.parse(readerSchemaText);

      GenericRecord record = genericRecordFromString(emptyRecord, emptySchema, readerSchema);
      if (debug) System.out.println(record);

      SchemaParser parser = new SchemaParser();
      parser.getValidationOptions().setAvroUnionMode(true);
      parser.parse(readerSchemaText);
      if (debug) System.out.println(parser.errorMessage());
      assertFalse(parser.hasError());

    }
  }
View Full Code Here


  @Test
  public void testClassNameDataSchemaResolver()
  {
    final ClassNameDataSchemaResolver resolver = new ClassNameDataSchemaResolver();
    final SchemaParser parser = new SchemaParser(resolver);

    final Class<? extends RecordTemplate> testClass = ClassNameFooRecord.class;
    final String nonExistSchemaName = "Non-Existing Schema";

    final DataSchema existSchema = parser.lookupName(testClass.getName());
    assertNotNull(existSchema);
    assertTrue(existSchema instanceof RecordDataSchema);
    assertEquals(((RecordDataSchema) existSchema).getFullName(), testClass.getCanonicalName());
    assertFalse(resolver.isBadLocation(new ClassNameDataSchemaLocation(testClass.getName())));

    final DataSchema nonExistSchema = parser.lookupName(nonExistSchemaName);
    assertNull(nonExistSchema);
    assertTrue(parser.errorMessage().contains(nonExistSchemaName));
    assertTrue(resolver.isBadLocation(new ClassNameDataSchemaLocation(nonExistSchemaName)));
  }
View Full Code Here

    assertTrue(resolver.isBadLocation(new ClassNameDataSchemaLocation(nonExistSchemaName)));
  }

  public void lookup(DataSchemaResolver resolver, String[][] lookups, char separator, boolean debug)
  {
    SchemaParser parser = new SchemaParser(resolver);

    for (String[] entry : lookups)
    {
      String name = entry[0];
      String expectFound = entry[1];
      String expected = entry[2];
      DataSchema schema = parser.lookupName(name);
      if (debug) { out.println("----" + name + "-----"); }
      String errorMessage = parser.errorMessage();
      if (debug && errorMessage.isEmpty() == false) { out.println(errorMessage); }
      if (expectFound == ERROR)
      {
        assertTrue(parser.hasError());
        assertTrue(expected == null || errorMessage.contains(expected));
      }
      else if (expectFound == FOUND)
      {
        assertTrue(schema != null);
        String schemaText = schema.toString();
        if (debug) { out.println(schemaText); }
        assertFalse(parser.hasError());
        assertTrue(schema instanceof NamedDataSchema);
        NamedDataSchema namedSchema = (NamedDataSchema) schema;
        assertEquals(namedSchema.getFullName(), name);
        assertTrue(schemaText.contains(expected));
        assertTrue(resolver.bindings().containsKey(name));
        assertSame(resolver.bindings().get(name), namedSchema);
        String location = entry[3];
        DataSchemaLocation namedSchemalocation = resolver.nameToDataSchemaLocations().get(name);
        String locationNorm;
        if (namedSchemalocation.toString().contains(".jar"))
        {
          locationNorm = location.replace(separator, '/');
        }
        else
        {
          locationNorm = location.replace('/', separator);
        }
        assertNotNull(namedSchemalocation);
        assertEquals(namedSchemalocation.toString().indexOf(locationNorm),
                     namedSchemalocation.toString().length() - locationNorm.length());
        assertTrue(resolver.locationResolved(namedSchemalocation));
      }
      else if (expectFound == NOT_FOUND)
      {
        assertTrue(schema == null);
        assertFalse(parser.hasError());
        assertTrue(expected == null || errorMessage.contains(expected));
        assertFalse(resolver.bindings().containsKey(name));
      }
      else
      {
View Full Code Here

    return bais;
  }

  static public SchemaParser schemaParserFromString(String s) throws UnsupportedEncodingException, IOException
  {
    SchemaParser parser = new SchemaParser();
    parser.parse(inputStreamFromString(s));
    return parser;
  }
View Full Code Here

    return parser;
  }

  static public SchemaParser schemaParserFromObjects(List<Object> objects) throws IOException
  {
    SchemaParser parser = new SchemaParser();
    parser.parse(objects);
    return parser;
  }
View Full Code Here

    return schemaParserFromObjects(objects);
  }

  static public DataSchema dataSchemaFromString(String s) throws IOException
  {
    SchemaParser parser = schemaParserFromString(s);
    if (parser.hasError())
    {
      out.println("ERROR: " + parser.errorMessage());
      return null;
    }
    return parser.topLevelDataSchemas().get(parser.topLevelDataSchemas().size() - 1);
  }
View Full Code Here

      try
      {
        final ValidationOptions val = new ValidationOptions();
        val.setAvroUnionMode(isAvroMode);

        final SchemaParser schemaParser = new SchemaParser();
        schemaParser.setValidationOptions(val);

        schemaParser.parse(new FileInputStream(sourceFile));
        if (schemaParser.hasError())
        {
          _log.error("Error parsing " + sourceFile.getPath() + ": " + schemaParser.errorMessageBuilder().toString());
          exitCode = 1;
          continue;
        }

        final DataSchema originalSchema = schemaParser.topLevelDataSchemas().get(0);
        if (!(originalSchema instanceof NamedDataSchema))
        {
          _log.error(sourceFile.getPath() + " does not contain valid NamedDataSchema");
          exitCode = 1;
          continue;
        }

        final SchemaParser filterParser = new SchemaParser();
        filterParser.setValidationOptions(val);

        final NamedDataSchema filteredSchema = Filters.removeByPredicate((NamedDataSchema) originalSchema,
                                                                         predicate, filterParser);
        if (filterParser.hasError())
        {
          _log.error("Error applying predicate: " + filterParser.errorMessageBuilder().toString());
          exitCode = 1;
          continue;
        }

        final String relativePath = sourceDirectoryURI.relativize(sourceFile.toURI()).getPath();
View Full Code Here

    return data;
  }

  public SchemaSampleDataGenerator(DataSchemaResolver resolver, DataGenerationOptions spec)
  {
    _schemaParser = new SchemaParser(resolver);
    _spec = spec;
  }
View Full Code Here

   * @throws IllegalArgumentException if the data schema in JSON format is invalid or
   *                                  there is more than one top level schema.
   */
  public static DataSchema parseSchema(String schemaText, DataSchemaResolver schemaResolver) throws IllegalArgumentException
  {
    SchemaParser parser = SchemaParserFactory.instance().create(schemaResolver);
    parser.parse(schemaText);
    if (parser.hasError())
    {
      if (debug)
      {
        out.println(parser.errorMessage());
      }
      throw new IllegalArgumentException(parser.errorMessage());
    }
    if (parser.topLevelDataSchemas().size() != 1)
    {
      throw new IllegalArgumentException("More than one top level schemas");
    }

    return parser.topLevelDataSchemas().get(0);
  }
View Full Code Here

  }

  @Test
  public void testFailCollectionFile() throws IOException
  {
    final SchemaParser sp = new SchemaParser();
    sp.parse("\"StringRef\"");

    final Collection<CompatibilityInfo> resourceTestErrors = new HashSet<CompatibilityInfo>();
    final Collection<CompatibilityInfo> modelTestErrors = new HashSet<CompatibilityInfo>();
    resourceTestErrors.add(
      new CompatibilityInfo(Arrays.<Object>asList("", "collection", "identifier", "params"),
                            CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from string to long"));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "supports"),
                                         CompatibilityInfo.Type.ARRAY_NOT_CONTAIN,
                                         new StringArray(Arrays.asList("batch_get", "create", "delete", "get"))));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "methods"),
                                         CompatibilityInfo.Type.ARRAY_MISSING_ELEMENT, "batch_get"));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "finders", "search", "metadata", "type"),
                                                 CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from array to int"));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "finders", "search", "assocKeys"),
                                                 CompatibilityInfo.Type.VALUE_NOT_EQUAL,
                                                 new StringArray(Arrays.asList("q", "s")), new StringArray(Arrays.asList("q", "changed_key"))));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "finders", "find_assocKey_downgrade", "assocKeys"),
                                                 CompatibilityInfo.Type.FINDER_ASSOCKEYS_DOWNGRADE));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "actions", "oneAction", "parameters", "bitfield", "items"),
                                                 CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from boolean to int"));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "actions", "oneAction", "parameters", "someString", "type"),
                                                 CompatibilityInfo.Type.TYPE_UNKNOWN, sp.errorMessage()));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "actions", "oneAction", "parameters", "stringMap", "type"),
                                                 CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from string to int"));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "anotherAction", "parameters"),
                                                 CompatibilityInfo.Type.ARRAY_MISSING_ELEMENT, "subMap"));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "exceptionTest", "throws"),
View Full Code Here

TOP

Related Classes of com.linkedin.data.schema.SchemaParser$DefinedAndReferencedNames

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.