CREATE MAPPING

Syntax

CREATE [TEMP] MAPPING mapping_name [FOR TABLE table_name] '(' keyDescription ',' [familyMapping [, ...]] ')'

keyDescription:
    key_name KEY [WIDTH int_expr]

familyMapping:
    family_name [INCLUDE UNMAPPED] '(' columnDescription  [, ...] ')'

column_Description:
    column_name type ['['']'] [WIDTH int_expr] [ALIAS alias_name] [DEFAULT constant_expr]

type:
      BOOLEAN   (BOOL)
    | BYTE
    | CHAR
    | SHORT
    | INTEGER (INT)
    | LONG
    | FLOAT
    | DOUBLE
    | STRING  (VARCHAR)
    | DATE    (DATETIME)
    | OBJECT  (OBJ)

Description

Defines a mapping. A mapping is required to select, insert and delete records.

  • If TEMP is omitted, then the mapping is persisted in HBase and is visible to all connections. If TEMP is included, then the mapping is specific to the connection and will go away when the connection is closed. A TEMP mapping is visible to only the connection on which it was declared.
  • If the table name clause is omitted, then the table name defaults to the mapping name.
  • Mutiple mappings can reference the same HBase table.
  • A single KEY attribute is required for a mapping.
  • [] indicates an array type.
  • A WIDTH value on a KEY column is required if a secondary index is present.
  • If a WIDTH value is specified (for KEY columns), then the corresponding range values and INSERT values are validated against the specified width value.
  • Column_definitions require a family qualified column name and a type.
  • Types can be abbreviations and synonyms are shown in () above.
  • The default value is used whenever a value is missing for that attribute in a given record. The constant_expr cannot contain any named parameters or column references.
  • The DEFAULT clause cannot be used with array values.
  • The scope of an ALIAS name is across all families in a table.
  • Each family can have an optional INCLUDE UNMAPPED clause. If the clause is present for a given family, then all query result set values for that family that are *not* described in the mapping are put in a map. The name of each unmapped value is the family qualified name, i.e., family:column, and the type of each unmapped value is byte[] (since no type information is known). If an unmapped value is returned for a family that does not have the INCLUDE UNMAPPED clause, then the value is ignored.
  • Column descriptions can have an alias name. If present, it can be used interchangeably with the fully qualified column name. Without an alias, column descriptions are referenced as "family:column".

Examples

        HConnection conn = HConnectionManager.newConnection();

        // Mapping named foo that corresponds to table foo.
        conn.execute("CREATE TEMP MAPPING foo (keyval key, family1 (val1 STRING))");
        // Mapping named mapping1 that corresponds to table foo.
        conn.execute("CREATE MAPPING mapping1 FOR TABLE foo (keyval key, family1 (val1 STRING ALIAS val2))");
        // A column with a default value.
        conn.execute("CREATE MAPPING mapping1 FOR TABLE foo "
                     + "("
                     + "keyval key, "
                     + "family1 (val1 STRING ALIAS val1 DEFAULT 'this is a default value')"
                     + ")");
        // A Mapping with a with an INCLUDE UNMAPPED clause.
        conn.execute("CREATE TEMP MAPPING mapping1 FOR TABLE foo "
                     + "("
                     + "keyval key, "
                     + "family1 INCLUDE UNMAPPED ("
                     + "  val1 STRING ALIAS val1, "
                     + "  val2 STRING ALIAS val3 "
                     + "))");