Package org.apache.avro

Examples of org.apache.avro.Schema$LockableArrayList


    ArrayList<ColumnInfo> columns = new ArrayList<ColumnInfo>();
    columns.add(intColumn);
    // columns.add(stringColumn);

    File file = new File("data.avro");
    Schema schema = getSchema(columns);
    DatumWriter<GenericRecord> writer = new GenericDatumWriter<GenericRecord>(
        schema);
    DataFileWriter<GenericRecord> dataFileWriter = new DataFileWriter<GenericRecord>(
        writer);
    dataFileWriter.create(schema, file);
View Full Code Here


    for (ColumnInfo column : columnInfo) {

      Schema.Field columnField = getColumnField(column);
      fields.add(columnField);
    }
    Schema recordSchema = Schema.createRecord("hihoValue", null, null,
        false);
    recordSchema.setFields(fields);
    return recordSchema;
  }
View Full Code Here

    recordSchema.setFields(fields);
    return recordSchema;
  }

  public static Schema.Field getColumnField(ColumnInfo column) {
    Schema fieldSchema = getSchema(column.getType());
    Schema.Field field = new Schema.Field(column.getName(), fieldSchema,
        null, null);
    return field;
  }
View Full Code Here

      break;
    default:
      returnType = null;
      break;
    }
    Schema returnSchema = Schema.create(returnType);
    return returnSchema;
  }
View Full Code Here

    }
    dataFileWriter.appendEncoded(ByteBuffer.wrap(event.getBody()));
  }

  private void initialize(Event event) throws IOException {
    Schema schema = null;
    String schemaUrl = event.getHeaders().get(AVRO_SCHEMA_URL_HEADER);
    if (schemaUrl != null) {
      schema = schemaCache.get(schemaUrl);
      if (schema == null) {
        schema = loadFromUrl(schemaUrl);
View Full Code Here

            try {
                if(keyFormat.equals("readable")) {
                    Object keyObject;
                    String keySerializerName = keySerializerDef.getName();
                    if(isAvroSchema(keySerializerName)) {
                        Schema keySchema = Schema.parse(keySerializerDef.getCurrentSchemaInfo());
                        JsonDecoder decoder = new JsonDecoder(keySchema, keyString);
                        GenericDatumReader<Object> datumReader = new GenericDatumReader<Object>(keySchema);
                        keyObject = datumReader.read(null, decoder);
                    } else if(keySerializerName.equals(DefaultSerializerFactory.JSON_SERIALIZER_TYPE_NAME)) {
                        JsonReader jsonReader = new JsonReader(new StringReader(keyString));
View Full Code Here

                // TODO Need to check all the avro siblings work
                // For avro, we hack and extract avro key/value as a string,
                // before we do the actual parsing with the schema
                String avroString = (String) obj;
                // From here on, this is just normal avro parsing.
                Schema latestSchema = Schema.parse(serializerDef.getCurrentSchemaInfo());
                try {
                    JsonDecoder decoder = new JsonDecoder(latestSchema, avroString);
                    GenericDatumReader<Object> datumReader = new GenericDatumReader<Object>(latestSchema);
                    obj = datumReader.read(null, decoder);
                } catch(IOException io) {
View Full Code Here


        // creating initial k-v pair
        System.out.println("Creating initial Key and Value");
        String keySchemaJson = "{ \"name\": \"key\", \"type\": \"record\", \"fields\": [{ \"name\": \"user_id\", \"type\": \"int\" }] }";
        Schema keySchema = Schema.parse(keySchemaJson);
        GenericRecord key = new GenericData.Record(keySchema);
        key.put("user_id", 123);

        String valueSchemaJson = "{\n" +
                "      \"name\": \"value\",\n" +
                "      \"type\": \"record\",\n" +
                "      \"fields\": [{ \n" +
                "        \"name\": \"user_id\",\n" +
                "        \"type\": \"int\"\n" +
                "      }, {\n" +
                "        \"name\": \"gender\",\n" +
                "        \"type\": \"string\"\n" +
                "      }, {\n" +
                "        \"name\": \"age\",\n" +
                "        \"type\": \"int\",\n" +
                "        \"optional\": true\n" +
                "      }]\n" +
                "    }";
        Schema valueSchema = Schema.parse(valueSchemaJson);
        GenericRecord value = new GenericData.Record(valueSchema);

        value.put("user_id", 123);
        value.put("gender", "male");
        value.put("age", 23);
View Full Code Here

        String versionZero = "{\"type\": \"record\", \"name\": \"myrec\",\"fields\": [{ \"name\": \"original\", \"type\": \"string\" }]}";

        String versionOne = "{\"type\": \"record\", \"name\": \"myrec\",\"fields\": [{ \"name\": \"original\", \"type\": \"string\" } ,"
                            + "{ \"name\": \"new-field\", \"type\": \"string\", \"default\":\"\" }]}";

        Schema s0 = Schema.parse(versionZero);
        Schema s1 = Schema.parse(versionOne);

        Map<Integer, String> versions = new HashMap<Integer, String>();

        versions.put(0, versionZero);
        versions.put(1, versionOne);
View Full Code Here

        String versionZero = "{\"type\": \"record\", \"name\": \"myrec\",\"fields\": [{ \"name\": \"original\", \"type\": \"string\" }]}";

        String versionOne = "{\"type\": \"record\", \"name\": \"myrec\",\"fields\": [{ \"name\": \"original\", \"type\": \"string\" } ,"
                            + "{ \"name\": \"new-field\", \"type\": \"string\", \"default\":\"\" }]}";

        Schema s0 = Schema.parse(versionZero);
        Schema s1 = Schema.parse(versionOne);

        Map<Integer, String> versions = new HashMap<Integer, String>();

        versions.put(0, versionZero);
        versions.put(1, versionOne);
View Full Code Here

TOP

Related Classes of org.apache.avro.Schema$LockableArrayList

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.