org.apache.pig
Class PigServer

java.lang.Object
  extended by org.apache.pig.PigServer

public class PigServer
extends Object

This class is the program's connection to Pig. Typically a program will create a PigServer instance. The programmer then registers queries using registerQuery() and retrieves results using openIterator() or store().


Nested Class Summary
static class PigServer.ExecType
          The type of query execution
 
Field Summary
 String Result
           
 
Constructor Summary
PigServer(PigContext context)
           
PigServer(PigServer.ExecType execType)
           
PigServer(PigServer.ExecType execType, Properties properties)
           
PigServer(String execTypeString)
           
 
Method Summary
 void addPathToSkip(String path)
          Add a path to be skipped while automatically shipping binaries for streaming.
 long capacity()
          Returns the unused byte capacity of an HDFS filesystem.
 void debugOff()
           
 void debugOn()
           
 boolean deleteFile(String filename)
           
 void dumpSchema(String alias)
           
 boolean existsFile(String filename)
           
 void explain(String alias, PrintStream stream)
          Provide information on how a pig query will be executed.
 long fileSize(String filename)
          Returns the length of a file in bytes which exists in the HDFS (accounts for replication).
 Map<String,LogicalPlan> getAliases()
           
 PigContext getPigContext()
           
 String[] listPaths(String dir)
           
 boolean mkdirs(String dirs)
           
 Iterator<Tuple> openIterator(String id)
          Forces execution of query (and all queries from which it reads), in order to materialize result
static PigServer.ExecType parseExecType(String str)
           
 void registerFunction(String function, String functionSpec)
          Defines an alias for the given function spec.
 void registerJar(String name)
          Registers a jar file.
 void registerQuery(String query)
          Register a query with the Pig runtime.
 void registerStreamingCommand(String commandAlias, StreamingCommand command)
          Defines an alias for the given streaming command.
 boolean renameFile(String source, String target)
           
 void setJobName(String name)
           
 void showExamples(LogicalPlan lp)
           
 void showExamples(String id)
           
 void shutdown()
           
 void store(LogicalPlan readFrom, String filename, String func)
           
 void store(String id, String filename)
          Store an alias into a file
 void store(String id, String filename, String func)
          forces execution of query (and all queries from which it reads), in order to store result in file
 long totalHadoopTimeSpent()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Result

public String Result
Constructor Detail

PigServer

public PigServer(String execTypeString)
          throws ExecException,
                 IOException
Throws:
ExecException
IOException

PigServer

public PigServer(PigServer.ExecType execType)
          throws ExecException
Throws:
ExecException

PigServer

public PigServer(PigServer.ExecType execType,
                 Properties properties)
          throws ExecException
Throws:
ExecException

PigServer

public PigServer(PigContext context)
          throws ExecException
Throws:
ExecException
Method Detail

parseExecType

public static PigServer.ExecType parseExecType(String str)
                                        throws IOException
Throws:
IOException

getPigContext

public PigContext getPigContext()

debugOn

public void debugOn()

debugOff

public void debugOff()

addPathToSkip

public void addPathToSkip(String path)
Add a path to be skipped while automatically shipping binaries for streaming.

Parameters:
path - path to be skipped

registerFunction

public void registerFunction(String function,
                             String functionSpec)
Defines an alias for the given function spec. This is useful for functions that require arguments to the constructor.

Parameters:
aliases - - the new function alias to define.
functionSpec - - the name of the function and any arguments. It should have the form: classname('arg1', 'arg2', ...)

registerStreamingCommand

public void registerStreamingCommand(String commandAlias,
                                     StreamingCommand command)
Defines an alias for the given streaming command.

Parameters:
commandAlias - - the new command alias to define
command - - streaming command to be executed

registerJar

public void registerJar(String name)
                 throws IOException
Registers a jar file. Name of the jar file can be an absolute or relative path. If multiple resources are found with the specified name, the first one is registered as returned by getSystemResources. A warning is issued to inform the user.

Parameters:
name - of the jar file to register
Throws:
IOException

registerQuery

public void registerQuery(String query)
                   throws IOException
Register a query with the Pig runtime. The query is parsed and registered, but it is not executed until it is needed.

Parameters:
query - a Pig Latin expression to be evaluated.
Throws:
IOException

dumpSchema

public void dumpSchema(String alias)
                throws IOException
Throws:
IOException

setJobName

public void setJobName(String name)

openIterator

public Iterator<Tuple> openIterator(String id)
                             throws IOException
Forces execution of query (and all queries from which it reads), in order to materialize result

Throws:
IOException

store

public void store(String id,
                  String filename)
           throws IOException
Store an alias into a file

Parameters:
id: - The alias to store
filename: - The file to which to store to
Throws:
IOException

store

public void store(String id,
                  String filename,
                  String func)
           throws IOException
forces execution of query (and all queries from which it reads), in order to store result in file

Throws:
IOException

store

public void store(LogicalPlan readFrom,
                  String filename,
                  String func)
           throws IOException
Throws:
IOException

explain

public void explain(String alias,
                    PrintStream stream)
             throws IOException
Provide information on how a pig query will be executed. For now this information is very developer focussed, and probably not very useful to the average user.

Parameters:
alias - Name of alias to explain.
stream - PrintStream to write explanation to.
Throws:
IOException - if the requested alias cannot be found.

capacity

public long capacity()
              throws IOException
Returns the unused byte capacity of an HDFS filesystem. This value does not take into account a replication factor, as that can vary from file to file. Thus if you are using this to determine if you data set will fit in the HDFS, you need to divide the result of this call by your specific replication setting.

Returns:
Throws:
IOException

fileSize

public long fileSize(String filename)
              throws IOException
Returns the length of a file in bytes which exists in the HDFS (accounts for replication).

Parameters:
filename -
Throws:
IOException

existsFile

public boolean existsFile(String filename)
                   throws IOException
Throws:
IOException

deleteFile

public boolean deleteFile(String filename)
                   throws IOException
Throws:
IOException

renameFile

public boolean renameFile(String source,
                          String target)
                   throws IOException
Throws:
IOException

mkdirs

public boolean mkdirs(String dirs)
               throws IOException
Throws:
IOException

listPaths

public String[] listPaths(String dir)
                   throws IOException
Throws:
IOException

totalHadoopTimeSpent

public long totalHadoopTimeSpent()

getAliases

public Map<String,LogicalPlan> getAliases()

shutdown

public void shutdown()

showExamples

public void showExamples(String id)
                  throws IOException
Throws:
IOException

showExamples

public void showExamples(LogicalPlan lp)
                  throws IOException
Throws:
IOException


Copyright © ${year} The Apache Software Foundation