public class MultiStorage extends StoreFunc
A = LOAD 'mydata' USING PigStorage() as (a, b, c);
STORE A INTO '/my/home/output' USING MultiStorage('/my/home/output','0', 'bz2', '\\t');
Parameter details:- ========== /my/home/output (Required) :
The DFS path where output directories and files will be created. 0
(Required) : Index of field whose values should be used to create
directories and files( field 'a' in this case). 'bz2' (Optional) : The
compression type. Default is 'none'. Supported types are:- 'none', 'gz' and
'bz2' '\\t' (Optional) : Output field separator.
Let 'a1', 'a2' be the unique values of field 'a'. Then output may look like
this
/my/home/output/a1/a1-0000 /my/home/output/a1/a1-0001
/my/home/output/a1/a1-0002 ... /my/home/output/a2/a2-0000
/my/home/output/a2/a2-0001 /my/home/output/a2/a2-0002
The prefix '0000*' is the task-id of the mapper/reducer task executing this
store. In case user does a GROUP BY on the field followed by MultiStorage(),
then its imperative that all tuples for a particular group will go exactly to
1 reducer. So in the above case for e.g. there will be only 1 file each under
'a1' and 'a2' directories.
If the output is compressed,then the sub directories and the output files will
be having the extension. Say for example in the above case if bz2 is used one file
will look like ;/my/home/output.bz2/a1.bz2/a1-0000.bz2Modifier and Type | Class and Description |
---|---|
static class |
MultiStorage.MultiStorageOutputFormat |
Constructor and Description |
---|
MultiStorage(String parentPathStr,
String splitFieldIndex) |
MultiStorage(String parentPathStr,
String splitFieldIndex,
String compression) |
MultiStorage(String parentPathStr,
String splitFieldIndex,
String compression,
String fieldDel)
Constructor
|
Modifier and Type | Method and Description |
---|---|
org.apache.hadoop.mapreduce.OutputFormat |
getOutputFormat()
Return the OutputFormat associated with StoreFunc.
|
void |
prepareToWrite(org.apache.hadoop.mapreduce.RecordWriter writer)
Initialize StoreFunc to write data.
|
void |
putNext(Tuple tuple)
Write a tuple to the data store.
|
void |
setStoreLocation(String location,
org.apache.hadoop.mapreduce.Job job)
Communicate to the storer the location where the data needs to be stored.
|
Boolean |
supportsParallelWriteToStoreLocation()
DAG execution engines like Tez support optimizing union by writing to
output location in parallel from tasks of different vertices.
|
checkSchema, cleanupOnFailure, cleanupOnFailureImpl, cleanupOnSuccess, relToAbsPathForStoreLocation, setStoreFuncUDFContextSignature, warn
public MultiStorage(String parentPathStr, String splitFieldIndex, String compression, String fieldDel)
parentPathStr
- Parent output dir path (this will be specified in store statement,
so MultiStorage don't use this parameter in reality. However, we don't
want to change the construct to break backward compatibility)splitFieldIndex
- key field indexcompression
- 'bz2', 'bz', 'gz' or 'none'fieldDel
- Output record field delimiter.public void putNext(Tuple tuple) throws IOException
StoreFunc
putNext
in interface StoreFuncInterface
putNext
in class StoreFunc
tuple
- the tuple to store.IOException
- if an exception occurs during the writepublic org.apache.hadoop.mapreduce.OutputFormat getOutputFormat() throws IOException
StoreFunc
getOutputFormat
in interface StoreFuncInterface
getOutputFormat
in class StoreFunc
OutputFormat
associated with StoreFuncIOException
- if an exception occurs while constructing the
OutputFormatpublic void prepareToWrite(org.apache.hadoop.mapreduce.RecordWriter writer) throws IOException
StoreFunc
prepareToWrite
in interface StoreFuncInterface
prepareToWrite
in class StoreFunc
writer
- RecordWriter to use.IOException
- if an exception occurs during initializationpublic void setStoreLocation(String location, org.apache.hadoop.mapreduce.Job job) throws IOException
StoreFunc
StoreFunc
here is the
return value of StoreFunc.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.
StoreFunc.checkSchema(ResourceSchema)
will be called before any call to
StoreFunc.setStoreLocation(String, Job)
.setStoreLocation
in interface StoreFuncInterface
setStoreLocation
in class StoreFunc
location
- Location returned by
StoreFunc.relToAbsPathForStoreLocation(String, Path)
job
- The Job
objectIOException
- if the location is not valid.public Boolean supportsParallelWriteToStoreLocation()
StoreFunc
PigConfiguration.PIG_TEZ_OPT_UNION_SUPPORTED_STOREFUNCS
and
PigConfiguration.PIG_TEZ_OPT_UNION_UNSUPPORTED_STOREFUNCS
settings to determine if the StoreFunc supports it.supportsParallelWriteToStoreLocation
in class StoreFunc
Copyright © 2007-2012 The Apache Software Foundation