org.apache.avro.hadoop.io

## Class AvroKeyValue<K,V>

- java.lang.Object
- - org.apache.avro.hadoop.io.AvroKeyValue<K,V>

- Type Parameters:
    `K` - The java type for the key.
    `V` - The java type for the value.

      public class AvroKeyValue<K,V>
      extends Object

  A helper object for working with the Avro generic records that are used to store key/value pairs in an Avro container file.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `AvroKeyValue.Iterator<K,V>` A wrapper for iterators over GenericRecords that are known to be KeyValue records.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `KEY_FIELD` The name of the generic record field containing the key.
    `static String` | `KEY_VALUE_PAIR_RECORD_NAME` The name of the key value pair generic record.
    `static String` | `KEY_VALUE_PAIR_RECORD_NAMESPACE` The namespace of the key value pair generic record.
    `static String` | `VALUE_FIELD` The name of the generic record field containing the value.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AvroKeyValue(GenericRecord keyValueRecord)` Wraps a GenericRecord that is a key value pair.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `GenericRecord` | `get()` Gets the wrapped key/value GenericRecord.
    `K` | `getKey()` Read the key.
    `static Schema` | `getSchema(Schema keySchema, Schema valueSchema)` Creates a KeyValuePair generic record schema.
    `V` | `getValue()` Read the value.
    `void` | `setKey(K key)` Sets the key.
    `void` | `setValue(V value)` Sets the value.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### KEY_VALUE_PAIR_RECORD_NAME

          public static final String KEY_VALUE_PAIR_RECORD_NAME

      The name of the key value pair generic record.
      See Also:
        Constant Field Values

    - #### KEY_VALUE_PAIR_RECORD_NAMESPACE

          public static final String KEY_VALUE_PAIR_RECORD_NAMESPACE

      The namespace of the key value pair generic record.
      See Also:
        Constant Field Values

    - #### KEY_FIELD

          public static final String KEY_FIELD

      The name of the generic record field containing the key.
      See Also:
        Constant Field Values

    - #### VALUE_FIELD

          public static final String VALUE_FIELD

      The name of the generic record field containing the value.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### AvroKeyValue

          public AvroKeyValue(GenericRecord keyValueRecord)

      Wraps a GenericRecord that is a key value pair.

  - ### Method Detail

    - #### get

          public GenericRecord get()

      Gets the wrapped key/value GenericRecord.
      Returns:
        The key/value Avro generic record.

    - #### getKey

          public K getKey()

      Read the key.
      Returns:
        The key from the key/value generic record.

    - #### getValue

          public V getValue()

      Read the value.
      Returns:
        The value from the key/value generic record.

    - #### setKey

          public void setKey(K key)

      Sets the key.
      Parameters:
        `key` - The key.

    - #### setValue

          public void setValue(V value)

      Sets the value.
      Parameters:
        `value` - The value.

    - #### getSchema

          public static Schema getSchema(Schema keySchema,
                                         Schema valueSchema)

      Creates a KeyValuePair generic record schema.
      Returns:
        A schema for a generic record with two fields: 'key' and 'value'.

Copyright © 2009–2024 The Apache Software Foundation. All rights reserved.