Package org.apache.avro.specific

Examples of org.apache.avro.specific.SpecificDatumReader$SchemaConstructable


    if (!EventWriter.VERSION.equals(version)) {
      throw new IOException("Incompatible event log version: "+version);
    }
   
    this.schema = Schema.parse(in.readLine());
    this.reader = new SpecificDatumReader(schema);
    this.decoder = DecoderFactory.get().jsonDecoder(schema, in);
  }
View Full Code Here


   */
  @SuppressWarnings({ "rawtypes", "unchecked" })
  public static Object fromAvroJsonString(String json, Schema schema) throws IOException {
    final InputStream jsonInput = new ByteArrayInputStream(json.getBytes("UTF-8"));
    final Decoder decoder = DecoderFactory.get().jsonDecoder(schema, jsonInput);
    final SpecificDatumReader reader = new SpecificDatumReader(schema);
    return reader.read(null, decoder);
  }
View Full Code Here

    if (!EventWriter.VERSION.equals(version)) {
      throw new IOException("Incompatible event log version: "+version);
    }
   
    this.schema = Schema.parse(in.readLine());
    this.reader = new SpecificDatumReader(schema);
    this.decoder = DecoderFactory.get().jsonDecoder(schema, in);
  }
View Full Code Here

  @SuppressWarnings("rawtypes")
  private SpecificDatumReader getDatumReader(String schemaId, Schema fieldSchema) {
    SpecificDatumReader<?> reader = (SpecificDatumReader<?>) readerMap
        .get(schemaId);
    if (reader == null) {
      reader = new SpecificDatumReader(fieldSchema);// ignore dirty bits
      SpecificDatumReader localReader = null;
      if ((localReader = readerMap.putIfAbsent(schemaId, reader)) != null) {
        reader = localReader;
      }
    }
    return reader;
View Full Code Here

    Object fieldValue = null;
    switch (fieldSchema.getType()) {
    case MAP:
    case ARRAY:
    case RECORD:
      @SuppressWarnings("rawtypes")
      SpecificDatumReader reader = getDatumReader(fieldSchema.getFullName(),
          fieldSchema);
      fieldValue = IOUtils.deserialize((byte[]) solrValue, reader, fieldSchema,
          persistent.get(field.pos()));
      break;
    case ENUM:
      fieldValue = AvroUtils.getEnumValue(fieldSchema, (String) solrValue);
      break;
    case FIXED:
      throw new IOException("???");
      // break;
    case BYTES:
      fieldValue = ByteBuffer.wrap((byte[]) solrValue);
      break;
    case STRING:
      fieldValue = new Utf8(solrValue.toString());
      break;
    case UNION:
      if (fieldSchema.getTypes().size() == 2 && isNullable(fieldSchema)) {
        // schema [type0, type1]
        Type type0 = fieldSchema.getTypes().get(0).getType();
        Type type1 = fieldSchema.getTypes().get(1).getType();

        // Check if types are different and there's a "null", like
        // ["null","type"] or ["type","null"]
        if (!type0.equals(type1)) {
          if (type0.equals(Schema.Type.NULL))
            fieldSchema = fieldSchema.getTypes().get(1);
          else
            fieldSchema = fieldSchema.getTypes().get(0);
        } else {
          fieldSchema = fieldSchema.getTypes().get(0);
        }
        fieldValue = deserializeFieldValue(field, fieldSchema, solrValue,
            persistent);
      } else {
        @SuppressWarnings("rawtypes")
        SpecificDatumReader unionReader = getDatumReader(
            String.valueOf(fieldSchema.hashCode()), fieldSchema);
        fieldValue = IOUtils.deserialize((byte[]) solrValue, unionReader,
            fieldSchema, persistent.get(field.pos()));
        break;
View Full Code Here

      // (key name in map will be "UNION-type-type-...")
      String schemaId = schema.getType().equals(Schema.Type.UNION) ? String.valueOf(schema.hashCode()) : schema.getFullName();     
     
      SpecificDatumReader<?> reader = (SpecificDatumReader<?>)readerMap.get(schemaId);
      if (reader == null) {
        reader = new SpecificDatumReader(schema);// ignore dirty bits
        SpecificDatumReader localReader=null;
        if((localReader=readerMap.putIfAbsent(schemaId, reader))!=null) {
          reader = localReader;
        }
      }
     
View Full Code Here

  public static Object deserializer(Object value, Schema schema) throws IOException{
    String schemaId = schema.getFullName();     
   
    SpecificDatumReader<?> reader = (SpecificDatumReader<?>)readerMap.get(schemaId);
    if (reader == null) {
      reader = new SpecificDatumReader(schema);// ignore dirty bits
      SpecificDatumReader localReader=null;
      if((localReader=readerMap.putIfAbsent(schemaId, reader))!=null) {
        reader = localReader;
      }
    }
   
View Full Code Here

  @InterfaceAudience.Private
  @Override
  public DatumReader getReader(Class<SpecificRecord> clazz) {
    try {
      return new SpecificDatumReader(clazz.newInstance().getSchema());
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
View Full Code Here

  }
 
  public static void assertOutput(String output, Configuration conf)
      throws NumberFormatException, IOException, InterruptedException {

    DatumReader datumReader = new SpecificDatumReader(AvroTweetsJoin.getAvroOutputSchema());
    FileReader reader = DataFileReader.openReader(new File(output),datumReader);
   
    Record record=null;
    record = (Record)reader.next(record);
   
View Full Code Here

      readFiles(new GenericDatumReader<Object>());
    }

  @Test
    public void testGeneratedSpecific() throws IOException {
      readFiles(new SpecificDatumReader("org.apache.avro."));
    }
View Full Code Here

TOP

Related Classes of org.apache.avro.specific.SpecificDatumReader$SchemaConstructable

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.