org.apache.hadoop.hive.ql
Class Context

java.lang.Object
  extended by org.apache.hadoop.hive.ql.Context

public class Context
extends Object

Context for Semantic Analyzers. Usage: not reusable - construct a new one for each query should call clear() at end of use to remove temporary folders


Field Summary
protected  String cmd
           
protected  boolean explain
           
protected  HiveLockManager hiveLockMgr
           
protected  List<HiveLock> hiveLocks
           
protected  int pathid
           
protected  int tryCount
           
 
Constructor Summary
Context(org.apache.hadoop.conf.Configuration conf)
           
Context(org.apache.hadoop.conf.Configuration conf, String executionId)
          Create a Context with a given executionId.
 
Method Summary
 void addCS(String path, org.apache.hadoop.fs.ContentSummary cs)
           
 void clear()
           
static String generateExecutionId()
          Generate a unique executionId.
 String getCmd()
          Find the original query command.
 org.apache.hadoop.conf.Configuration getConf()
           
 org.apache.hadoop.fs.ContentSummary getCS(String path)
           
 boolean getExplain()
          Find whether the current query is an explain query
 String getExternalTmpFileURI(URI extURI)
          Get a path to store tmp data destined for external URI.
 HiveLockManager getHiveLockMgr()
           
 List<HiveLock> getHiveLocks()
           
 String getLocalScratchDir(boolean mkdir)
          Create a local scratch directory on demand and return it.
 String getLocalTmpFileURI()
          Get a tmp path on local host to store intermediate data.
 String getMRScratchDir()
          Create a map-reduce scratch directory on demand and return it.
 String getMRTmpFileURI()
          Get a path to store map-reduce intermediate data in.
 Map<String,org.apache.hadoop.fs.ContentSummary> getPathToCS()
           
 org.apache.hadoop.fs.Path getResDir()
           
 org.apache.hadoop.fs.Path getResFile()
           
 DataInput getStream()
           
 org.antlr.runtime.TokenRewriteStream getTokenRewriteStream()
           
 int getTryCount()
           
 boolean isHDFSCleanup()
           
 boolean isLocalOnlyExecutionMode()
          Does Hive wants to run tasks entirely on the local machine (where the query is being compiled)? Today this translates into running hadoop jobs locally
 boolean isMRTmpFileURI(String uriStr)
          Check if path is for intermediate data
 boolean isNeedLockMgr()
           
 void localizeKeys(Map<String,Object> map)
          Given a mapping from paths to objects, localize any MR tmp paths
 String localizeMRTmpFileURI(String originalURI)
          Given a URI for mapreduce intermediate output, swizzle the it to point to the local file system.
 void localizePaths(List<String> paths)
          Given a list of paths, localize any MR tmp paths contained therein
 void restoreOriginalTracker()
           
 void setCmd(String cmd)
          Set the original query command.
 void setExplain(boolean value)
          Set the context on whether the current query is an explain query.
 void setHDFSCleanup(boolean isHDFSCleanup)
           
 void setHiveLockMgr(HiveLockManager hiveLockMgr)
           
 void setHiveLocks(List<HiveLock> hiveLocks)
           
 void setNeedLockMgr(boolean needLockMgr)
           
 void setOriginalTracker(String originalTracker)
           
 void setResDir(org.apache.hadoop.fs.Path resDir)
           
 void setResFile(org.apache.hadoop.fs.Path resFile)
           
 void setTokenRewriteStream(org.antlr.runtime.TokenRewriteStream tokenRewriteStream)
          Set the token rewrite stream being used to parse the current top-level SQL statement.
 void setTryCount(int tryCount)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pathid

protected int pathid

explain

protected boolean explain

cmd

protected String cmd

tryCount

protected int tryCount

hiveLocks

protected List<HiveLock> hiveLocks

hiveLockMgr

protected HiveLockManager hiveLockMgr
Constructor Detail

Context

public Context(org.apache.hadoop.conf.Configuration conf)
        throws IOException
Throws:
IOException

Context

public Context(org.apache.hadoop.conf.Configuration conf,
               String executionId)
Create a Context with a given executionId. ExecutionId, together with user name and conf, will determine the temporary directory locations.

Method Detail

setExplain

public void setExplain(boolean value)
Set the context on whether the current query is an explain query.

Parameters:
value - true if the query is an explain query, false if not

getExplain

public boolean getExplain()
Find whether the current query is an explain query

Returns:
true if the query is an explain query, false if not

setCmd

public void setCmd(String cmd)
Set the original query command.

Parameters:
cmd - the original query command string

getCmd

public String getCmd()
Find the original query command.

Returns:
the original query command string

getLocalScratchDir

public String getLocalScratchDir(boolean mkdir)
Create a local scratch directory on demand and return it.


getMRScratchDir

public String getMRScratchDir()
Create a map-reduce scratch directory on demand and return it.


isMRTmpFileURI

public boolean isMRTmpFileURI(String uriStr)
Check if path is for intermediate data

Returns:
true if a uri is a temporary uri for map-reduce intermediate data, false otherwise

getMRTmpFileURI

public String getMRTmpFileURI()
Get a path to store map-reduce intermediate data in.

Returns:
next available path for map-red intermediate data

localizeMRTmpFileURI

public String localizeMRTmpFileURI(String originalURI)
Given a URI for mapreduce intermediate output, swizzle the it to point to the local file system. This can be called in case the caller decides to run in local mode (in which case all intermediate data can be stored locally)

Parameters:
originalURI - uri to localize
Returns:
localized path for map-red intermediate data

getLocalTmpFileURI

public String getLocalTmpFileURI()
Get a tmp path on local host to store intermediate data.

Returns:
next available tmp path on local fs

getExternalTmpFileURI

public String getExternalTmpFileURI(URI extURI)
Get a path to store tmp data destined for external URI.

Parameters:
extURI - external URI to which the tmp data has to be eventually moved
Returns:
next available tmp path on the file system corresponding extURI

getResFile

public org.apache.hadoop.fs.Path getResFile()
Returns:
the resFile

setResFile

public void setResFile(org.apache.hadoop.fs.Path resFile)
Parameters:
resFile - the resFile to set

getResDir

public org.apache.hadoop.fs.Path getResDir()
Returns:
the resDir

setResDir

public void setResDir(org.apache.hadoop.fs.Path resDir)
Parameters:
resDir - the resDir to set

clear

public void clear()
           throws IOException
Throws:
IOException

getStream

public DataInput getStream()

setTokenRewriteStream

public void setTokenRewriteStream(org.antlr.runtime.TokenRewriteStream tokenRewriteStream)
Set the token rewrite stream being used to parse the current top-level SQL statement. Note that this should not be used for other parsing activities; for example, when we encounter a reference to a view, we switch to a new stream for parsing the stored view definition from the catalog, but we don't clobber the top-level stream in the context.

Parameters:
tokenRewriteStream - the stream being used

getTokenRewriteStream

public org.antlr.runtime.TokenRewriteStream getTokenRewriteStream()
Returns:
the token rewrite stream being used to parse the current top-level SQL statement, or null if it isn't available (e.g. for parser tests)

generateExecutionId

public static String generateExecutionId()
Generate a unique executionId. An executionId, together with user name and the configuration, will determine the temporary locations of all intermediate files. In the future, users can use the executionId to resume a query.


isLocalOnlyExecutionMode

public boolean isLocalOnlyExecutionMode()
Does Hive wants to run tasks entirely on the local machine (where the query is being compiled)? Today this translates into running hadoop jobs locally


getHiveLocks

public List<HiveLock> getHiveLocks()

setHiveLocks

public void setHiveLocks(List<HiveLock> hiveLocks)

getHiveLockMgr

public HiveLockManager getHiveLockMgr()

setHiveLockMgr

public void setHiveLockMgr(HiveLockManager hiveLockMgr)

setOriginalTracker

public void setOriginalTracker(String originalTracker)

restoreOriginalTracker

public void restoreOriginalTracker()

addCS

public void addCS(String path,
                  org.apache.hadoop.fs.ContentSummary cs)

getCS

public org.apache.hadoop.fs.ContentSummary getCS(String path)

getPathToCS

public Map<String,org.apache.hadoop.fs.ContentSummary> getPathToCS()

getConf

public org.apache.hadoop.conf.Configuration getConf()

localizeKeys

public void localizeKeys(Map<String,Object> map)
Given a mapping from paths to objects, localize any MR tmp paths

Parameters:
map - mapping from paths to objects

localizePaths

public void localizePaths(List<String> paths)
Given a list of paths, localize any MR tmp paths contained therein

Parameters:
paths - list of paths to be localized

isHDFSCleanup

public boolean isHDFSCleanup()
Returns:
the isHDFSCleanup

setHDFSCleanup

public void setHDFSCleanup(boolean isHDFSCleanup)
Parameters:
isHDFSCleanup - the isHDFSCleanup to set

isNeedLockMgr

public boolean isNeedLockMgr()

setNeedLockMgr

public void setNeedLockMgr(boolean needLockMgr)

getTryCount

public int getTryCount()

setTryCount

public void setTryCount(int tryCount)


Copyright © 2013 The Apache Software Foundation