org.apache.pig.impl.util
Class Utils

java.lang.Object
  extended by org.apache.pig.impl.util.Utils

public class Utils
extends Object

Class with utility static methods


Constructor Summary
Utils()
           
 
Method Summary
static FuncSpec buildSimpleFuncSpec(String className, byte... types)
           
static boolean checkNullAndClass(Object obj1, Object obj2)
          This method is a helper for classes to implement Object.equals(java.lang.Object) The method checks whether the two arguments are both null or both not null and whether they are of the same class
static boolean checkNullEquals(Object obj1, Object obj2, boolean checkEquality)
          This method is a helper for classes to implement Object.equals(java.lang.Object) checks if two objects are equals - two levels of checks are made - first if both are null or not null.
static InputStream getCompositeStream(InputStream in, Properties properties)
           
static ResourceSchema getSchema(LoadFunc wrappedLoadFunc, String location, boolean checkExistence, org.apache.hadoop.mapreduce.Job job)
           
static Schema getSchemaFromBagSchemaString(String schemaString)
          getSchemaFromBagSchemaString NOTE: use this call when you need to generate a Schema object from the representation generated by Schema#toString.
static Schema getSchemaFromString(String schemaString)
           
static ResourceSchema getSchemaWithInputSourceTag(ResourceSchema schema, String fieldName)
          This method adds FieldSchema of 'input source tag/path' as the first field.
static Schema getScriptSchema(String loadFuncSignature, org.apache.hadoop.conf.Configuration conf)
          A helper function for retrieving the script schema set by the LOLoad function.
static String getScriptSchemaKey(String loadFuncSignature)
           
static String getStackStraceStr(Throwable e)
           
static String getStringFromArray(String[] arr)
           
static String getTmpFileCompressorName(PigContext pigContext)
           
static Class<? extends FileInputLoadFunc> getTmpFileStorageClass(Properties properties)
           
static FileInputLoadFunc getTmpFileStorageObject(org.apache.hadoop.conf.Configuration conf)
           
static boolean isLocal(PigContext pigContext, org.apache.hadoop.conf.Configuration conf)
           
static
<O> Collection<O>
mergeCollection(Collection<O> a, Collection<O> b)
           
static LogicalSchema parseSchema(String schemaString)
           
static void recomputeProperties(org.apache.hadoop.mapred.JobConf jobConf, Properties properties)
          Method to apply pig properties to JobConf (replaces properties with resulting jobConf values).
static void setMapredCompressionCodecProps(org.apache.hadoop.conf.Configuration conf)
           
static void setTmpFileCompressionOnConf(PigContext pigContext, org.apache.hadoop.conf.Configuration conf)
           
static String slashisize(String str)
          Replace sequences of two slashes ("\\") with one slash ("\") (not escaping a slash in grunt is disallowed, but a double slash doesn't get converted into a regular slash, so we have to do it instead)
static String substituteVars(String expr)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utils

public Utils()
Method Detail

checkNullEquals

public static boolean checkNullEquals(Object obj1,
                                      Object obj2,
                                      boolean checkEquality)
This method is a helper for classes to implement Object.equals(java.lang.Object) checks if two objects are equals - two levels of checks are made - first if both are null or not null. If either is null, check is made whether both are null. If both are non null, equality also is checked if so indicated

Parameters:
obj1 - first object to be compared
obj2 - second object to be compared
checkEquality - flag to indicate whether object equality should be checked if obj1 and obj2 are non-null
Returns:
true if the two objects are equal false otherwise

checkNullAndClass

public static boolean checkNullAndClass(Object obj1,
                                        Object obj2)
This method is a helper for classes to implement Object.equals(java.lang.Object) The method checks whether the two arguments are both null or both not null and whether they are of the same class

Parameters:
obj1 - first object to compare
obj2 - second object to compare
Returns:
true if both objects are null or both are not null and if both are of the same class if not null false otherwise

getScriptSchema

public static Schema getScriptSchema(String loadFuncSignature,
                                     org.apache.hadoop.conf.Configuration conf)
                              throws IOException
A helper function for retrieving the script schema set by the LOLoad function.

Parameters:
loadFuncSignature -
conf -
Returns:
Schema
Throws:
IOException

getScriptSchemaKey

public static String getScriptSchemaKey(String loadFuncSignature)

getSchema

public static ResourceSchema getSchema(LoadFunc wrappedLoadFunc,
                                       String location,
                                       boolean checkExistence,
                                       org.apache.hadoop.mapreduce.Job job)
                                throws IOException
Throws:
IOException

getSchemaFromString

public static Schema getSchemaFromString(String schemaString)
                                  throws ParserException
Parameters:
schemaString - a String representation of the Schema without any enclosing curly-braces.Not for use with Schema#toString
Returns:
Schema instance
Throws:
ParserException

getSchemaFromBagSchemaString

public static Schema getSchemaFromBagSchemaString(String schemaString)
                                           throws ParserException
getSchemaFromBagSchemaString NOTE: use this call when you need to generate a Schema object from the representation generated by Schema#toString. This call strips the enclosing outer curly braces from the toString representation, which are placed there because the actual representation of the schema data is as a Bag-type relation.

Parameters:
schemaString - a String representation of the Schema to instantiate, in the form generated by Schema.toString()
Returns:
Schema instance
Throws:
ParserException

parseSchema

public static LogicalSchema parseSchema(String schemaString)
                                 throws ParserException
Throws:
ParserException

getSchemaWithInputSourceTag

public static ResourceSchema getSchemaWithInputSourceTag(ResourceSchema schema,
                                                         String fieldName)
This method adds FieldSchema of 'input source tag/path' as the first field. This will be called only when PigStorage is invoked with '-tagFile' or '-tagPath' option and the schema file is present to be loaded.

Parameters:
schema -
fieldName -
Returns:
ResourceSchema

getTmpFileCompressorName

public static String getTmpFileCompressorName(PigContext pigContext)

getTmpFileStorageObject

public static FileInputLoadFunc getTmpFileStorageObject(org.apache.hadoop.conf.Configuration conf)
                                                 throws IOException
Throws:
IOException

getTmpFileStorageClass

public static Class<? extends FileInputLoadFunc> getTmpFileStorageClass(Properties properties)

setMapredCompressionCodecProps

public static void setMapredCompressionCodecProps(org.apache.hadoop.conf.Configuration conf)

setTmpFileCompressionOnConf

public static void setTmpFileCompressionOnConf(PigContext pigContext,
                                               org.apache.hadoop.conf.Configuration conf)
                                        throws IOException
Throws:
IOException

getStringFromArray

public static String getStringFromArray(String[] arr)

buildSimpleFuncSpec

public static FuncSpec buildSimpleFuncSpec(String className,
                                           byte... types)

slashisize

public static String slashisize(String str)
Replace sequences of two slashes ("\\") with one slash ("\") (not escaping a slash in grunt is disallowed, but a double slash doesn't get converted into a regular slash, so we have to do it instead)

Parameters:
str -
Returns:
the resulting string

mergeCollection

public static <O> Collection<O> mergeCollection(Collection<O> a,
                                                Collection<O> b)

getCompositeStream

public static InputStream getCompositeStream(InputStream in,
                                             Properties properties)

recomputeProperties

public static void recomputeProperties(org.apache.hadoop.mapred.JobConf jobConf,
                                       Properties properties)
Method to apply pig properties to JobConf (replaces properties with resulting jobConf values).

Parameters:
conf - JobConf with appropriate hadoop resource files
properties - Pig properties that will override hadoop properties; properties might be modified

getStackStraceStr

public static String getStackStraceStr(Throwable e)

isLocal

public static boolean isLocal(PigContext pigContext,
                              org.apache.hadoop.conf.Configuration conf)

substituteVars

public static String substituteVars(String expr)


Copyright © 2007-2012 The Apache Software Foundation