public class HBaseStorage extends LoadFunc implements StoreFuncInterface, LoadPushDown, OrderedLoadFunc, StoreResources, CollectableLoadFunc
Below is an example showing how to load data from HBase:
raw = LOAD 'hbase://SampleTable'
USING org.apache.pig.backend.hadoop.hbase.HBaseStorage(
'info:first_name info:last_name friends:* info:*', '-loadKey true -limit 5')
AS (id:bytearray, first_name:chararray, last_name:chararray, friends_map:map[], info_map:map[]);
This example loads data redundantly from the info column family just to
illustrate usage. Note that the row key is inserted first in the result schema.
To load only column names that start with a given prefix, specify the column
name with a trailing '*'. For example passing friends:bob_* to
the constructor in the above example would cause only columns that start with
bob_ to be loaded.
Note that when using a prefix like friends:bob_*, explicit HBase filters are set for
all columns and prefixes specified. Querying HBase with many filters can cause performance
degredation. This is typically seen when mixing one or more prefixed descriptors with a large list
of columns. In that case better perfomance will be seen by either loading the entire family via
friends:* or by specifying explicit column descriptor names.
Below is an example showing how to store data into HBase:
copy = STORE raw INTO 'hbase://SampleTableCopy'
USING org.apache.pig.backend.hadoop.hbase.HBaseStorage(
'info:first_name info:last_name friends:* info:*');
Note that STORE will expect the first value in the tuple to be the row key.
Scalars values need to map to an explicit column descriptor and maps need to
map to a column family name. In the above examples, the friends
column family data from SampleTable will be written to a
buddies column family in the SampleTableCopy table.| Modifier and Type | Class and Description |
|---|---|
class |
HBaseStorage.ColumnInfo
Class to encapsulate logic around which column names were specified in each
position of the column list.
|
LoadPushDown.OperatorSet, LoadPushDown.RequiredField, LoadPushDown.RequiredFieldList, LoadPushDown.RequiredFieldResponse| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
gt_ |
protected byte[] |
gte_ |
protected byte[] |
lt_ |
protected byte[] |
lte_ |
| Constructor and Description |
|---|
HBaseStorage(String columnList)
Constructor.
|
HBaseStorage(String columnList,
String optString)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
checkSchema(ResourceSchema s)
Set the schema for data to be stored.
|
void |
cleanupOnFailure(String location,
org.apache.hadoop.mapreduce.Job job)
This method will be called by Pig if the job which contains this store
fails.
|
void |
cleanupOnSuccess(String location,
org.apache.hadoop.mapreduce.Job job)
This method will be called by Pig if the job which contains this store
is successful, and some cleanup of intermediate resources is required.
|
org.apache.hadoop.hbase.client.Delete |
createDelete(Object key,
byte type,
long timestamp)
Public method to initialize a Delete.
|
org.apache.hadoop.hbase.client.Put |
createPut(Object key,
byte type)
Public method to initialize a Put.
|
void |
ensureAllKeyInstancesInSameSplit()
When this method is called, Pig is communicating to the Loader that it must
load data such that all instances of a key are in same split.
|
List<HBaseStorage.ColumnInfo> |
getColumnInfoList()
Returns the ColumnInfo list so external objects can inspect it.
|
List<LoadPushDown.OperatorSet> |
getFeatures()
Determine the operators that can be pushed to the loader.
|
org.apache.hadoop.mapreduce.InputFormat |
getInputFormat()
This will be called during planning on the front end.
|
LoadCaster |
getLoadCaster()
Set up the caster to use for reading values out of, and writing to, HBase.
|
Tuple |
getNext()
Retrieves the next tuple to be processed.
|
org.apache.hadoop.mapreduce.OutputFormat |
getOutputFormat()
Return the OutputFormat associated with StoreFuncInterface.
|
List<String> |
getShipFiles()
Allow a LoadFunc to specify a list of files located locally and would like to ship to backend
(through distributed cache).
|
org.apache.hadoop.io.WritableComparable<org.apache.hadoop.hbase.mapreduce.TableSplit> |
getSplitComparable(org.apache.hadoop.mapreduce.InputSplit split)
The WritableComparable object returned will be used to compare
the position of different splits in an ordered stream
|
void |
prepareToRead(org.apache.hadoop.mapreduce.RecordReader reader,
PigSplit split)
Initializes LoadFunc for reading data.
|
void |
prepareToWrite(org.apache.hadoop.mapreduce.RecordWriter writer)
Initialize StoreFuncInterface to write data.
|
LoadPushDown.RequiredFieldResponse |
pushProjection(LoadPushDown.RequiredFieldList requiredFieldList)
Indicate to the loader fields that will be needed.
|
void |
putNext(Tuple t)
Write a tuple to the data store.
|
String |
relativeToAbsolutePath(String location,
org.apache.hadoop.fs.Path curDir)
This method is called by the Pig runtime in the front end to convert the
input location to an absolute path if the location is relative.
|
String |
relToAbsPathForStoreLocation(String location,
org.apache.hadoop.fs.Path curDir)
This method is called by the Pig runtime in the front end to convert the
output location to an absolute path if the location is relative.
|
protected void |
setColumnInfoList(List<HBaseStorage.ColumnInfo> columnInfoList)
Updates the ColumnInfo List.
|
void |
setLocation(String location,
org.apache.hadoop.mapreduce.Job job)
Communicate to the loader the location of the object(s) being loaded.
|
void |
setStoreFuncUDFContextSignature(String signature)
This method will be called by Pig both in the front end and back end to
pass a unique signature to the
StoreFuncInterface which it can use to store
information in the UDFContext which it needs to store between
various method invocations in the front end and back end. |
void |
setStoreLocation(String location,
org.apache.hadoop.mapreduce.Job job)
Communicate to the storer the location where the data needs to be stored.
|
void |
setUDFContextSignature(String signature)
This method will be called by Pig both in the front end and back end to
pass a unique signature to the
LoadFunc. |
protected void |
storeProjectedFieldNames(LoadPushDown.RequiredFieldList requiredFieldList)
Stores the requiredFieldsList as a serialized object so it can be fetched on the cluster.
|
getAbsolutePath, getCacheFiles, getPathStrings, join, warnclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetCacheFilesprotected transient byte[] gt_
protected transient byte[] gte_
protected transient byte[] lt_
protected transient byte[] lte_
public HBaseStorage(String columnList) throws org.apache.commons.cli.ParseException, IOException
columnList - columnlist that is a presented string delimited by space and/or
commas. To retreive all columns in a column family Foo,
specify a column as either Foo: or Foo:*.
To fetch only columns in the CF that start with bar, specify
Foo:bar*. The resulting tuple will always be the size
of the number of tokens in columnList. Items in the
tuple will be scalar values when a full column descriptor is
specified, or a map of column descriptors to values when a column
family is specified.org.apache.commons.cli.ParseException - when unable to parse argumentsIOExceptionpublic HBaseStorage(String columnList, String optString) throws org.apache.commons.cli.ParseException, IOException
columnList - optString - Loader options. Known options:org.apache.commons.cli.ParseExceptionIOExceptionpublic List<HBaseStorage.ColumnInfo> getColumnInfoList()
protected void setColumnInfoList(List<HBaseStorage.ColumnInfo> columnInfoList)
protected void storeProjectedFieldNames(LoadPushDown.RequiredFieldList requiredFieldList) throws FrontendException
FrontendExceptionpublic Tuple getNext() throws IOException
LoadFuncgetNext in class LoadFuncIOException - if there is an exception while retrieving the next
tuplepublic org.apache.hadoop.mapreduce.InputFormat getInputFormat()
LoadFuncgetInputFormat in class LoadFuncpublic void prepareToRead(org.apache.hadoop.mapreduce.RecordReader reader,
PigSplit split)
LoadFuncprepareToRead in class LoadFuncreader - RecordReader to be used by this instance of the LoadFuncsplit - The input PigSplit to processpublic void setUDFContextSignature(String signature)
LoadFuncLoadFunc. The signature can be used
to store into the UDFContext any information which the
LoadFunc needs to store between various method invocations in the
front end and back end. A use case is to store LoadPushDown.RequiredFieldList
passed to it in LoadPushDown.pushProjection(RequiredFieldList) for
use in the back end before returning tuples in LoadFunc.getNext().
This method will be call before other methods in LoadFuncsetUDFContextSignature in class LoadFuncsignature - a unique signature to identify this LoadFuncpublic void setLocation(String location, org.apache.hadoop.mapreduce.Job job) throws IOException
LoadFuncLoadFunc.relativeToAbsolutePath(String, Path). Implementations
should use this method to communicate the location (and any other information)
to its underlying InputFormat through the Job object.
This method will be called in the frontend and backend multiple times. Implementations
should bear in mind that this method is called multiple times and should
ensure there are no inconsistent side effects due to the multiple calls.setLocation in class LoadFunclocation - Location as returned by
LoadFunc.relativeToAbsolutePath(String, Path)job - the Job object
store or retrieve earlier stored information from the UDFContextIOException - if the location is not valid.public List<String> getShipFiles()
LoadFuncFuncUtils for utility function to facilitate it
The default implementation returns null.getShipFiles in interface StoreResourcesgetShipFiles in class LoadFuncpublic String relativeToAbsolutePath(String location, org.apache.hadoop.fs.Path curDir) throws IOException
LoadFuncrelativeToAbsolutePath in class LoadFunclocation - location as provided in the "load" statement of the scriptcurDir - the current working direction based on any "cd" statements
in the script before the "load" statement. If there are no "cd" statements
in the script, this would be the home directory -
/user/
IOException - if the conversion is not possiblepublic LoadCaster getLoadCaster() throws IOException
getLoadCaster in class LoadFuncLoadCaster associated with this loader. Returning null
indicates that casts from byte array are not supported for this loader.
constructionIOException - if there is an exception during LoadCasterpublic org.apache.hadoop.mapreduce.OutputFormat getOutputFormat()
throws IOException
StoreFuncInterfacegetOutputFormat in interface StoreFuncInterfaceOutputFormat associated with StoreFuncInterfaceIOException - if an exception occurs while constructing the
OutputFormatpublic void checkSchema(ResourceSchema s) throws IOException
StoreFuncInterfacecheckSchema in interface StoreFuncInterfaces - to be checkedIOException - if this schema is not acceptable. It should include
a detailed error message indicating what is wrong with the schema.public void prepareToWrite(org.apache.hadoop.mapreduce.RecordWriter writer)
throws IOException
StoreFuncInterfaceprepareToWrite in interface StoreFuncInterfacewriter - RecordWriter to use.IOException - if an exception occurs during initializationpublic void putNext(Tuple t) throws IOException
StoreFuncInterfaceputNext in interface StoreFuncInterfacet - the tuple to store.IOException - if an exception occurs during the writepublic org.apache.hadoop.hbase.client.Delete createDelete(Object key, byte type, long timestamp) throws IOException
key - type - timestamp - IOExceptionpublic org.apache.hadoop.hbase.client.Put createPut(Object key, byte type) throws IOException
key - type - IOExceptionpublic String relToAbsPathForStoreLocation(String location, org.apache.hadoop.fs.Path curDir) throws IOException
StoreFuncInterfaceLoadFunc.getAbsolutePath(java.lang.String, org.apache.hadoop.fs.Path) provides a default
implementation for hdfs and hadoop local file system and it can be used
to implement this method.relToAbsPathForStoreLocation in interface StoreFuncInterfacelocation - location as provided in the "store" statement of the scriptcurDir - the current working direction based on any "cd" statements
in the script before the "store" statement. If there are no "cd" statements
in the script, this would be the home directory -
/user/
IOException - if the conversion is not possiblepublic void setStoreFuncUDFContextSignature(String signature)
StoreFuncInterfaceStoreFuncInterface which it can use to store
information in the UDFContext which it needs to store between
various method invocations in the front end and back end. This is necessary
because in a Pig Latin script with multiple stores, the different
instances of store functions need to be able to find their (and only their)
data in the UDFContext object.setStoreFuncUDFContextSignature in interface StoreFuncInterfacesignature - a unique signature to identify this StoreFuncInterfacepublic void setStoreLocation(String location, org.apache.hadoop.mapreduce.Job job) throws IOException
StoreFuncInterfaceStoreFuncInterface here is the
return value of StoreFuncInterface.relToAbsPathForStoreLocation(String, Path)
This method will be called in the frontend and backend multiple times. Implementations
should bear in mind that this method is called multiple times and should
ensure there are no inconsistent side effects due to the multiple calls.
StoreFuncInterface.checkSchema(ResourceSchema) will be called before any call to
StoreFuncInterface.setStoreLocation(String, Job).setStoreLocation in interface StoreFuncInterfacelocation - Location returned by
StoreFuncInterface.relToAbsPathForStoreLocation(String, Path)job - The Job objectIOException - if the location is not valid.public void cleanupOnFailure(String location, org.apache.hadoop.mapreduce.Job job) throws IOException
StoreFuncInterfacecleanupOnFailure in interface StoreFuncInterfacelocation - Location returned by
StoreFuncInterface.relToAbsPathForStoreLocation(String, Path)job - The Job object - this should be used only to obtain
cluster properties through JobContextImpl.getConfiguration() and not to set/query
any runtime job information.IOExceptionpublic void cleanupOnSuccess(String location, org.apache.hadoop.mapreduce.Job job) throws IOException
StoreFuncInterfacecleanupOnSuccess in interface StoreFuncInterfacelocation - Location returned by
StoreFuncInterface.relToAbsPathForStoreLocation(String, Path)job - The Job object - this should be used only to obtain
cluster properties through JobContextImpl.getConfiguration() and not to set/query
any runtime job information.IOExceptionpublic List<LoadPushDown.OperatorSet> getFeatures()
LoadPushDowngetFeatures in interface LoadPushDownpublic LoadPushDown.RequiredFieldResponse pushProjection(LoadPushDown.RequiredFieldList requiredFieldList) throws FrontendException
LoadPushDownpushProjection in interface LoadPushDownrequiredFieldList - RequiredFieldList indicating which columns will be needed.
This structure is read only. User cannot make change to it inside pushProjection.FrontendExceptionpublic void ensureAllKeyInstancesInSameSplit()
throws IOException
CollectableLoadFuncensureAllKeyInstancesInSameSplit in interface CollectableLoadFuncIOExceptionpublic org.apache.hadoop.io.WritableComparable<org.apache.hadoop.hbase.mapreduce.TableSplit> getSplitComparable(org.apache.hadoop.mapreduce.InputSplit split)
throws IOException
OrderedLoadFuncgetSplitComparable in interface OrderedLoadFuncsplit - An InputSplit from the InputFormat underlying this loader.IOExceptionCopyright © 2007-2012 The Apache Software Foundation