Package org.apache.avro.generic

Examples of org.apache.avro.generic.IndexedRecord


    assertEquals(1, avroPartitioner.getPartition(avroKey, new AvroValue<Object>(), 2));
  }

  @Test
  public void testGetPartition_NegativeHashValue() {
    IndexedRecord indexedRecord = new MockIndexedRecord(-3);
    AvroKey<IndexedRecord> avroKey = new AvroKey<IndexedRecord>(indexedRecord);

    assertEquals(3, avroPartitioner.getPartition(avroKey, new AvroValue<Object>(), 5));
    assertEquals(1, avroPartitioner.getPartition(avroKey, new AvroValue<Object>(), 2));
  }
View Full Code Here


    assertEquals(1, avroPartitioner.getPartition(avroKey, new AvroValue<Object>(), 2));
  }

  @Test
  public void testGetPartition_IntegerMinValue() {
    IndexedRecord indexedRecord = new MockIndexedRecord(Integer.MIN_VALUE);
    AvroKey<IndexedRecord> avroKey = new AvroKey<IndexedRecord>(indexedRecord);

    assertEquals(0, avroPartitioner.getPartition(avroKey, new AvroValue<Object>(), Integer.MAX_VALUE));
  }
View Full Code Here

      AvroParquetReader<IndexedRecord> reader = null;
      try {
        reader = new AvroParquetReader(conf, path);
        while (true) {
          IndexedRecord datum;
          try {
            datum = reader.read();
          } catch (EOFException e) {
            return true; // be lenient
          }
View Full Code Here

      if (avroResult == AvroConversions.ERROR) {
        LOG.debug("Cannot convert record: {} to schema: {}", inputRecord, schema);
        return false;         
      }
     
      IndexedRecord avroRecord = new GenericData.Record(schema);
      avroRecord.put(field.pos(), avroResult);
      outputRecord.put(Fields.ATTACHMENT_BODY, avroRecord);
     
      // pass record to next command in chain:
      return super.doProcess(outputRecord);
    }
View Full Code Here

      // RECORD, ENUM, ARRAY, MAP, UNION, FIXED, STRING, BYTES, INT, LONG, FLOAT,
      // DOUBLE, BOOLEAN, NULL
      switch (schema.getType()) {
      case RECORD: {
        IndexedRecord avroRecord = (IndexedRecord) datum;
        for (Field field : schema.getFields()) {
          flatten(avroRecord.get(field.pos()), field.schema(), list);
        }
        break;
      }
      case ENUM: {
        GenericEnumSymbol symbol = (GenericEnumSymbol) datum;
View Full Code Here

    private void extractTree(Object datum, Schema schema, Record outputRecord, String prefix) {
      // RECORD, ENUM, ARRAY, MAP, UNION, FIXED, STRING, BYTES, INT, LONG, FLOAT,
      // DOUBLE, BOOLEAN, NULL
      switch (schema.getType()) {
      case RECORD: {
        IndexedRecord avroRecord = (IndexedRecord) datum;
        String prefix2 = prefix + "/";
        for (Field field : schema.getFields()) {
          extractTree(avroRecord.get(field.pos()), field.schema(), outputRecord, prefix2 + field.name());
        }
        break;
      }
      case ENUM: {
        GenericEnumSymbol symbol = (GenericEnumSymbol) datum;
View Full Code Here

        schema = fixedSchema;
      }
     
      Record outputRecord = inputRecord.copy();
      AbstractParser.removeAttachments(outputRecord);
      IndexedRecord avroRecord = new GenericData.Record(schema);
     
      for (Field field : schema.getFields()) {
        String morphlineFieldName = mappings.get(field.name());
        if (morphlineFieldName == null) {
          morphlineFieldName = field.name();
        }
        List list = inputRecord.get(morphlineFieldName);
       
        Object avroResult = AvroConversions.ERROR;
        if (field.schema().getType() == Schema.Type.ARRAY) {
          avroResult = AvroConversions.toAvro(list, field);
        } else if (list.size() == 0) {
          try { // this will fail if there is no default value
            avroResult = ReflectData.get().getDefaultValue(field);
          } catch (AvroRuntimeException e) {
            avroResult = AvroConversions.ERROR;
          }
        } else if (list.size() == 1) {
          avroResult = AvroConversions.toAvro(list.get(0), field);
        }
       
        if (avroResult == AvroConversions.ERROR) {
          LOG.debug("Cannot convert item: {} to schema: {}", list, schema);
          return false;         
        }
        avroRecord.put(field.pos(), avroResult);
      }

      outputRecord.put(Fields.ATTACHMENT_BODY, avroRecord);
       
      // pass record to next command in chain:
View Full Code Here

    if (field.schema().getType() == Schema.Type.MAP) {
      return new HashMap<CharSequence, Object>(
          (Map<CharSequence, Object>) fieldValue);
    } else if (field.schema().getType() == Schema.Type.RECORD) {
      Map<CharSequence, Object> keyAsColumnValues = new HashMap<CharSequence, Object>();
      IndexedRecord avroRecord = (IndexedRecord) fieldValue;
      for (Field avroRecordField : avroRecord.getSchema().getFields()) {
        keyAsColumnValues.put(avroRecordField.name(),
            avroRecord.get(avroRecordField.pos()));
      }
      return keyAsColumnValues;
    } else {
      throw new ValidationException(
          "Only MAP or RECORD type valid for keyAsColumn fields. Found "
View Full Code Here

    // DOUBLE, BOOLEAN, NULL
    switch (schema.getType()) {
      case RECORD:
        if (item instanceof Map) {
          Map<String,Object> map = (Map) item;
          IndexedRecord record = new GenericData.Record(schema);
          for (Field field : schema.getFields()) {
            Object value = map.get(field.name());
            Object result = toAvro(value, field);
            if (result == ERROR) {
              return ERROR;
            }
            record.put(field.pos(), result);
          }
          return record;
        }
        return ERROR;
      case ENUM:
View Full Code Here

    if (field.schema().getType() == Schema.Type.MAP) {
      return new HashMap<CharSequence, Object>(
          (Map<CharSequence, Object>) fieldValue);
    } else if (field.schema().getType() == Schema.Type.RECORD) {
      Map<CharSequence, Object> keyAsColumnValues = new HashMap<CharSequence, Object>();
      IndexedRecord avroRecord = (IndexedRecord) fieldValue;
      for (Field avroRecordField : avroRecord.getSchema().getFields()) {
        keyAsColumnValues.put(avroRecordField.name(),
            avroRecord.get(avroRecordField.pos()));
      }
      return keyAsColumnValues;
    } else {
      throw new SchemaValidationException(
          "Only MAP or RECORD type valid for keyAsColumn fields. Found "
View Full Code Here

TOP

Related Classes of org.apache.avro.generic.IndexedRecord

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.