...
- for each Hive column, the table creator must specify a corresponding entry in the comma-delimited
hbase.columns.mapping
string (so for a Hive table with n columns, the string should have n entries); whitespace should not be used in between entries since these will be interperted as part of the column name, which is almost certainly not what you want - a mapping entry must be either
:key
or of the formcolumn-family-name:[column-name][#(binary|string)
(the type specification that delimited by # was added in Hive 0.9.0, earlier versions interpreted everything as strings)- If no type specification is given the value from
hbase.table.default.storage.type
will be used - Any prefixes of the valid values are valid too (i.e.
#b
instead of#binary
) - If you specify a column as
binary
the bytes in the corresponding HBase cells are expected to be of the form that HBase'sBytes
class yields.
- If no type specification is given the value from
- there must be exactly one
:key
mapping (we don't support compound keys yetthis can be mapped either to a string or struct column–see ) - (note that before HIVE-1228 in Hive 0.6,
:key
was not supported, and the first Hive column implicitly mapped to the key; as of Hive 0.6, it is now strongly recommended that you always specify the key explictly; we will drop support for implicit key mapping in the future) - if no column-name is given, then the Hive column will map to all columns in the corresponding HBase column family, and the Hive MAP datatype must be used to allow access to these (possibly sparse) columns
- there is currently no way to access the HBase timestamp attribute, and queries always access data with the latest timestamp.
- Since HBase does not associate datatype information with columns, the serde converts everything to string representation before storing it in HBase; there is currently no way to plug in a custom serde per column
- it is not necessary to reference every HBase column family, but those that are not mapped will be inaccessible via the Hive table; it's possible to map multiple Hive tables to the same HBase table
...
No Format |
---|
CREATE TABLE hbase_table_1 (key int, value string, foobar double) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ( "hbase.columns.mapping" = ":key,cf:val#s,cf:foo", "hbase.table.default.storage.type" = "binary" ); |
Simple Composite Row Keys
Info |
---|
As of Hive 0.13.0 |
Hive can read and write delimited composite keys to HBase by mapping the HBase row key to a hive struct, and using the ROW FORMAT DELIMITED...COLLECTION ITEMS TERMINATED BY. Example:
Code Block |
---|
-- Create a table with a composite row key consisting of two string fields, delimited by '~'
CREATE EXTERNAL TABLE delimited_example(key struct<f1:string, f2:string>, value string)
ROW FORMAT DELIMITED
COLLECTION ITEMS TERMINATED BY '~'
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES (
'hbase.columns.mapping'=':key,f:c1'); |
Complex Composite Row Keys and HBaseKeyFactory
Info | ||||||
---|---|---|---|---|---|---|
As of Hive 0.14.0 (0.13.0 also supports complex composite keys, but using a different interface–see
|
For more complex use cases, hive allows users to specify an HBaseKeyFactory which defines the mapping of a key to fields in a hive struct.This can be configured using the property "hbase.composite.key.factory" in the SERDEPROPERTIES option:
Code Block |
---|
-- Parse a row key with 3 fixed width fields each of width 10
-- Example taken from: https://svn.apache.org/repos/asf/hive/trunk/hbase-handler/src/test/queries/positive/hbase_custom_key2.q
CREATE TABLE hbase_ck_4(key struct<col1:string,col2:string,col3:string>, value string)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES (
"hbase.table.name" = "hbase_custom2",
"hbase.columns.mapping" = ":key,cf:string",
"hbase.composite.key.factory"="org.apache.hadoop.hive.hbase.SampleHBaseKeyFactory2"); |
"hbase.composite.key.factory" should be the fully qualified class name of a class implementing HBaseKeyFactory. See SampleHBaseKeyFactory2 for a fixed length example in the same package. This class must be on your classpath in order for the above example to work. TODO: place these in an accessible place; they're currently only in test code.
Put Timestamps
Info | ||
---|---|---|
| ||
As of Hive 0.9.0 |
...