Package org.apache.avro.specific

Examples of org.apache.avro.specific.SpecificDatumReader


         
          currentArray.add(fromBytes(currentSchema, entry.getValue().get()));

          break;
        case RECORD:
          SpecificDatumReader reader = new SpecificDatumReader(field.schema());
          byte[] val = entry.getValue().get();
          // TODO reuse decoder
          BinaryDecoder decoder = DecoderFactory.defaultFactory().createBinaryDecoder(val, null);
          persistent.put(field.pos(), reader.read(null, decoder));
          break;
        default:
          persistent.put(field.pos(), fromBytes(field.schema(), entry.getValue().get()));
      }
    }
View Full Code Here


      throw new IOException("Incompatible event log version: "+version);
    }

    Schema myschema = new SpecificData(Event.class.getClassLoader()).getSchema(Event.class);
    this.schema = Schema.parse(in.readLine());
    this.reader = new SpecificDatumReader(schema, myschema);
    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

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

  @Test
    public void testGeneratedSpecific() throws IOException {
      readFiles(new SpecificDatumReader("org.apache.avro."));
    }
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

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

  @Test
    public void testGeneratedSpecific() throws IOException {
      readFiles(new SpecificDatumReader());
    }
View Full Code Here

         
          currentArray.add(fromBytes(currentSchema, entry.getValue().get()));

          break;
        case RECORD:
          SpecificDatumReader reader = new SpecificDatumReader(field.schema());
          byte[] val = entry.getValue().get();
          // TODO reuse decoder
          BinaryDecoder decoder = DecoderFactory.defaultFactory().createBinaryDecoder(val, null);
          persistent.put(field.pos(), reader.read(null, decoder));
          break;
        default:
          persistent.put(field.pos(), fromBytes(field.schema(), entry.getValue().get()));
      }
    }
View Full Code Here

    case BOOLEAN: return val[0] != 0;
    case RECORD:
      Map<String, SpecificDatumReader<?>> readerMap = readerMaps.get();
      SpecificDatumReader<?> reader = readerMap.get(schema.getFullName());
      if (reader == null) {
        reader = new SpecificDatumReader(schema);    
        readerMap.put(schema.getFullName(), reader);
      }
     
      // initialize a decoder, possibly reusing previous one
      BinaryDecoder decoderFromCache = decoders.get();
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 = new JsonDecoder(schema, in);
  }
View Full Code Here

TOP

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

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.