public class XMLLoader extends LoadFunc
For example if the input xml (input.xml) is like this
foobar
barfoo
foo
justname
And your pig script is like this
--load the jar files
register /homes/aloks/pig/udfLib/loader.jar;
-- load the dataset using XMLLoader
-- A is the bag containing the tuple which contains one atom i.e doc see output
A = load '/user/aloks/pig/input.xml using loader.XMLLoader('property') as (doc:chararray);
--dump the result
dump A;
Then you will get the output
(
foobar
barfoo
)
(
justname
)
Where each () indicate one record
| Modifier and Type | Class and Description |
|---|---|
static class |
XMLLoader.XMLFileInputFormat |
static class |
XMLLoader.XMLFileRecordReader |
| Modifier and Type | Field and Description |
|---|---|
protected org.apache.commons.logging.Log |
mLog
logger from pig
|
String |
recordIdentifier
The record seperated.
|
| Constructor and Description |
|---|
XMLLoader() |
XMLLoader(String recordIdentifier)
Constructs a Pig loader that uses specified string as the record seperater
for example if the recordIdentifier is document.
|
| Modifier and Type | Method and Description |
|---|---|
Tuple |
createTuple(byte[] content) |
boolean |
equals(Object obj)
to check for equality
|
boolean |
equals(XMLLoader other)
to check for equality
|
org.apache.hadoop.mapreduce.InputFormat |
getInputFormat()
This will be called during planning on the front end.
|
Tuple |
getNext()
Retrieves the next tuple to be processed.
|
void |
prepareToRead(org.apache.hadoop.mapreduce.RecordReader reader,
PigSplit split)
Initializes LoadFunc for reading data.
|
void |
setLocation(String location,
org.apache.hadoop.mapreduce.Job job)
Communicate to the loader the location of the object(s) being loaded.
|
getAbsolutePath, getLoadCaster, getPathStrings, join, relativeToAbsolutePath, setUDFContextSignature, warnprotected final org.apache.commons.logging.Log mLog
public String recordIdentifier
public XMLLoader()
public XMLLoader(String recordIdentifier)
recordIdentifier - the xml tag which is used to pull recordspublic Tuple getNext() throws IOException
getNext in class LoadFuncIOExceptionpublic boolean equals(Object obj)
public boolean equals(XMLLoader other)
XMLLoader - objectpublic org.apache.hadoop.mapreduce.InputFormat getInputFormat()
throws IOException
LoadFuncgetInputFormat in class LoadFuncIOException - if there is an exception during InputFormat
constructionpublic void prepareToRead(org.apache.hadoop.mapreduce.RecordReader reader,
PigSplit split)
throws IOException
LoadFuncprepareToRead in class LoadFuncreader - RecordReader to be used by this instance of the LoadFuncsplit - The input PigSplit to processIOException - if there is an exception during initializationpublic 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.Copyright © 2007-2012 The Apache Software Foundation