org.springframework.data.hadoop.pig
Class PigTemplate

java.lang.Object
  extended by org.springframework.data.hadoop.pig.PigTemplate
All Implemented Interfaces:
InitializingBean, ResourceLoaderAware, PigOperations

public class PigTemplate
extends Object
implements InitializingBean, PigOperations, ResourceLoaderAware

Helper class that simplifies Pig data access code. Automatically handles the creation of a PigServer (which is non-thread-safe) and converts Pig exceptions into DataAccessExceptions.

Author:
Costin Leau

Constructor Summary
PigTemplate()
          Constructs a new PigTemplate instance.
PigTemplate(PigServerFactory pigFactory)
          Constructs a new PigTemplate instance.
 
Method Summary
 void afterPropertiesSet()
           
protected  DataAccessException convertPigAccessException(ExecException ex)
          Converts the given Pig exception to an appropriate exception from the org.springframework.dao hierarchy.
protected  DataAccessException convertPigAccessException(IOException ex)
          Converts the given Pig exception to an appropriate exception from the org.springframework.dao hierarchy.
protected  PigServer createPigServer()
           
<T> T
execute(PigCallback<T> action)
          Executes the action specified by the given callback object within an active PigServer.
 List<ExecJob> executeScript(Iterable<PigScript> scripts)
          Executes multiple scripts that result in a list of job executions.
 List<ExecJob> executeScript(PigScript script)
          Executes the given script identified by location and arguments that results in a list of job executions.
 List<ExecJob> executeScript(String script)
          Executes the given Pig Latin that results in a list of job executions.
 List<ExecJob> executeScript(String script, Map<?,?> arguments)
          Executes the given Pig Latin with arguments that results in a list of job executions.
 void setPigFactory(PigServerFactory pigServerFactory)
          Sets the PigServer factory.
 void setResourceLoader(ResourceLoader resourceLoader)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PigTemplate

public PigTemplate()
Constructs a new PigTemplate instance. Expects setPigFactory(PigServerFactory) to be called before using it.


PigTemplate

public PigTemplate(PigServerFactory pigFactory)
Constructs a new PigTemplate instance.

Parameters:
pigFactory - pig factory
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface InitializingBean

execute

public <T> T execute(PigCallback<T> action)
          throws DataAccessException
Executes the action specified by the given callback object within an active PigServer.

Specified by:
execute in interface PigOperations
Parameters:
action - callback object that specifies the Hive action
Returns:
the action result object
Throws:
DataAccessException

convertPigAccessException

protected DataAccessException convertPigAccessException(IOException ex)
Converts the given Pig exception to an appropriate exception from the org.springframework.dao hierarchy.

Parameters:
ex - Pig exception
Returns:
a corresponding DataAccessException

convertPigAccessException

protected DataAccessException convertPigAccessException(ExecException ex)
Converts the given Pig exception to an appropriate exception from the org.springframework.dao hierarchy.

Parameters:
ex - Pig exception
Returns:
a corresponding DataAccessException

executeScript

public List<ExecJob> executeScript(String script)
                            throws DataAccessException
Executes the given Pig Latin that results in a list of job executions. The script is interpreted as a URL or if that fails, as a Pig Latin statement.

Specified by:
executeScript in interface PigOperations
Parameters:
script - script URL or pig latin statement
Returns:
list of job executions
Throws:
DataAccessException

executeScript

public List<ExecJob> executeScript(String script,
                                   Map<?,?> arguments)
                            throws DataAccessException
Executes the given Pig Latin with arguments that results in a list of job executions. The script is interpreted as a URL or if that fails, as a Pig Latin statement.

Specified by:
executeScript in interface PigOperations
Parameters:
script - script URL or pig latin statement
arguments - script arguments
Returns:
list of job executions
Throws:
DataAccessException

executeScript

public List<ExecJob> executeScript(PigScript script)
                            throws DataAccessException
Executes the given script identified by location and arguments that results in a list of job executions.

Specified by:
executeScript in interface PigOperations
Parameters:
script - script location and arguments
Returns:
list of job executions
Throws:
DataAccessException

executeScript

public List<ExecJob> executeScript(Iterable<PigScript> scripts)
                            throws DataAccessException
Executes multiple scripts that result in a list of job executions.

Specified by:
executeScript in interface PigOperations
Parameters:
scripts - scripts location and arguments
Returns:
list of job executions
Throws:
DataAccessException

createPigServer

protected PigServer createPigServer()

setPigFactory

public void setPigFactory(PigServerFactory pigServerFactory)
Sets the PigServer factory.

Parameters:
pigServerFactory -

setResourceLoader

public void setResourceLoader(ResourceLoader resourceLoader)
Specified by:
setResourceLoader in interface ResourceLoaderAware