org.apache.hadoop.hive.ql.parse
Class BaseSemanticAnalyzer

java.lang.Object
  extended by org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer
Direct Known Subclasses:
DDLSemanticAnalyzer, ExplainSemanticAnalyzer, ExportSemanticAnalyzer, FunctionSemanticAnalyzer, ImportSemanticAnalyzer, LoadSemanticAnalyzer, SemanticAnalyzer

public abstract class BaseSemanticAnalyzer
extends Object

BaseSemanticAnalyzer.


Nested Class Summary
static class BaseSemanticAnalyzer.tableSpec
          tableSpec.
 
Field Summary
protected static String COLUMNAR_SERDE
           
protected  HiveConf conf
           
protected  SessionState.LogHelper console
           
protected  Context ctx
           
protected  Hive db
           
protected  FetchTask fetchTask
           
static int HIVE_COLUMN_ORDER_ASC
           
static int HIVE_COLUMN_ORDER_DESC
           
protected  HashMap<String,String> idToTableNameMap
           
protected  HashSet<ReadEntity> inputs
          ReadEntitites that are passed to the hooks.
protected  LineageInfo linfo
          Lineage information for the query.
protected  org.apache.commons.logging.Log LOG
           
protected  HashSet<WriteEntity> outputs
          List of WriteEntities that are passed to the hooks.
protected  QueryProperties queryProperties
           
protected static String RCFILE_INPUT
           
protected static String RCFILE_OUTPUT
           
protected  List<Task<? extends Serializable>> rootTasks
           
protected static String SEQUENCEFILE_INPUT
           
protected static String SEQUENCEFILE_OUTPUT
           
protected  TableAccessInfo tableAccessInfo
           
protected static String TEXTFILE_INPUT
           
protected static String TEXTFILE_OUTPUT
           
 
Constructor Summary
BaseSemanticAnalyzer(HiveConf conf)
           
 
Method Summary
 void analyze(ASTNode ast, Context ctx)
           
protected  void analyzeDDLSkewedValues(List<List<String>> skewedValues, ASTNode child)
          Handle skewed values in DDL.
abstract  void analyzeInternal(ASTNode ast)
           
protected  List<String> analyzeSkewedTablDDLColNames(List<String> skewedColNames, ASTNode child)
          Analyze list bucket column names
protected  boolean analyzeStoredAdDirs(ASTNode child)
          process stored as directories
static String charSetString(String charSetName, String charSetString)
           
protected  HashMap<String,String> extractPartitionSpecs(org.antlr.runtime.tree.Tree partspec)
           
protected  List<String> getColumnNames(ASTNode ast)
           
protected  List<Order> getColumnNamesOrder(ASTNode ast)
           
protected  List<FieldSchema> getColumns(ASTNode ast)
           
static List<FieldSchema> getColumns(ASTNode ast, boolean lowerCase)
          Get the list of FieldSchema out of the ASTNode.
 Hive getDb()
           
 FetchTask getFetchTask()
           
 HashMap<String,String> getIdToTableNameMap()
           
 HashSet<ReadEntity> getInputs()
           
 LineageInfo getLineageInfo()
          Gets the lineage information.
 HashSet<WriteEntity> getOutputs()
           
 QueryProperties getQueryProperties()
           
 List<FieldSchema> getResultSchema()
           
 List<Task<? extends Serializable>> getRootTasks()
           
protected  List<String> getSkewedValueFromASTNode(ASTNode ast)
          Given a ASTNode, return list of values.
protected  List<String> getSkewedValuesFromASTNode(Node node)
          Retrieve skewed values from ASTNode.
 TableAccessInfo getTableAccessInfo()
          Gets the table access information.
protected static String getTypeStringFromAST(ASTNode typeNode)
           
static String getUnescapedName(ASTNode tableOrColumnNode)
          Get dequoted name from a table/column node.
static String getUnescapedName(ASTNode tableOrColumnNode, String currentDatabase)
           
static String getUnescapedUnqualifiedTableName(ASTNode node)
          Get the unqualified name from a table node.
protected  void handleGenericFileFormat(ASTNode node)
           
 void init()
           
 void initCtx(Context ctx)
           
 boolean isValidPrefixSpec(Table tTable, Map<String,String> spec)
          Checks if given specification is proper specification for prefix of partition cols, for table partitioned by ds, hr, min valid ones are (ds='2008-04-08'), (ds='2008-04-08', hr='12'), (ds='2008-04-08', hr='12', min='30') invalid one is for example (ds='2008-04-08', min='30')
static void readProps(ASTNode prop, Map<String,String> mapProp)
          Converts parsed key/value properties pairs into a map.
protected  void reset()
           
 void setFetchTask(FetchTask fetchTask)
           
 void setLineageInfo(LineageInfo linfo)
          Sets the lineage information.
 void setTableAccessInfo(TableAccessInfo tableAccessInfo)
          Sets the table access information.
static String stripQuotes(String val)
           
static String unescapeIdentifier(String val)
          Remove the encapsulating "`" pair from the identifier.
static String unescapeSQLString(String b)
           
 void validate()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

db

protected final Hive db

conf

protected final HiveConf conf

rootTasks

protected List<Task<? extends Serializable>> rootTasks

fetchTask

protected FetchTask fetchTask

LOG

protected final org.apache.commons.logging.Log LOG

console

protected final SessionState.LogHelper console

ctx

protected Context ctx

idToTableNameMap

protected HashMap<String,String> idToTableNameMap

queryProperties

protected QueryProperties queryProperties

HIVE_COLUMN_ORDER_ASC

public static int HIVE_COLUMN_ORDER_ASC

HIVE_COLUMN_ORDER_DESC

public static int HIVE_COLUMN_ORDER_DESC

inputs

protected HashSet<ReadEntity> inputs
ReadEntitites that are passed to the hooks.


outputs

protected HashSet<WriteEntity> outputs
List of WriteEntities that are passed to the hooks.


linfo

protected LineageInfo linfo
Lineage information for the query.


tableAccessInfo

protected TableAccessInfo tableAccessInfo

TEXTFILE_INPUT

protected static final String TEXTFILE_INPUT

TEXTFILE_OUTPUT

protected static final String TEXTFILE_OUTPUT

SEQUENCEFILE_INPUT

protected static final String SEQUENCEFILE_INPUT

SEQUENCEFILE_OUTPUT

protected static final String SEQUENCEFILE_OUTPUT

RCFILE_INPUT

protected static final String RCFILE_INPUT

RCFILE_OUTPUT

protected static final String RCFILE_OUTPUT

COLUMNAR_SERDE

protected static final String COLUMNAR_SERDE
Constructor Detail

BaseSemanticAnalyzer

public BaseSemanticAnalyzer(HiveConf conf)
                     throws SemanticException
Throws:
SemanticException
Method Detail

getIdToTableNameMap

public HashMap<String,String> getIdToTableNameMap()

analyzeInternal

public abstract void analyzeInternal(ASTNode ast)
                              throws SemanticException
Throws:
SemanticException

init

public void init()

initCtx

public void initCtx(Context ctx)

analyze

public void analyze(ASTNode ast,
                    Context ctx)
             throws SemanticException
Throws:
SemanticException

validate

public void validate()
              throws SemanticException
Throws:
SemanticException

getRootTasks

public List<Task<? extends Serializable>> getRootTasks()

getFetchTask

public FetchTask getFetchTask()
Returns:
the fetchTask

setFetchTask

public void setFetchTask(FetchTask fetchTask)
Parameters:
fetchTask - the fetchTask to set

reset

protected void reset()

stripQuotes

public static String stripQuotes(String val)

charSetString

public static String charSetString(String charSetName,
                                   String charSetString)
                            throws SemanticException
Throws:
SemanticException

getUnescapedName

public static String getUnescapedName(ASTNode tableOrColumnNode)
Get dequoted name from a table/column node.

Parameters:
tableOrColumnNode - the table or column node
Returns:
for table node, db.tab or tab. for column node column.

getUnescapedName

public static String getUnescapedName(ASTNode tableOrColumnNode,
                                      String currentDatabase)

getUnescapedUnqualifiedTableName

public static String getUnescapedUnqualifiedTableName(ASTNode node)
Get the unqualified name from a table node. This method works for table names qualified with their schema (e.g., "db.table") and table names without schema qualification. In both cases, it returns the table name without the schema.

Parameters:
node - the table node
Returns:
the table name without schema qualification (i.e., if name is "db.table" or "table", returns "table")

unescapeIdentifier

public static String unescapeIdentifier(String val)
Remove the encapsulating "`" pair from the identifier. We allow users to use "`" to escape identifier for table names, column names and aliases, in case that coincide with Hive language keywords.


readProps

public static void readProps(ASTNode prop,
                             Map<String,String> mapProp)
Converts parsed key/value properties pairs into a map.

Parameters:
prop - ASTNode parent of the key/value pairs
mapProp - property map which receives the mappings

unescapeSQLString

public static String unescapeSQLString(String b)

getInputs

public HashSet<ReadEntity> getInputs()

getOutputs

public HashSet<WriteEntity> getOutputs()

getResultSchema

public List<FieldSchema> getResultSchema()
Returns:
the schema for the fields which will be produced when the statement is executed, or null if not known

getColumns

protected List<FieldSchema> getColumns(ASTNode ast)
                                throws SemanticException
Throws:
SemanticException

handleGenericFileFormat

protected void handleGenericFileFormat(ASTNode node)
                                throws SemanticException
Throws:
SemanticException

getColumns

public static List<FieldSchema> getColumns(ASTNode ast,
                                           boolean lowerCase)
                                    throws SemanticException
Get the list of FieldSchema out of the ASTNode.

Throws:
SemanticException

getColumnNames

protected List<String> getColumnNames(ASTNode ast)

getColumnNamesOrder

protected List<Order> getColumnNamesOrder(ASTNode ast)

getTypeStringFromAST

protected static String getTypeStringFromAST(ASTNode typeNode)
                                      throws SemanticException
Throws:
SemanticException

getLineageInfo

public LineageInfo getLineageInfo()
Gets the lineage information.

Returns:
LineageInfo associated with the query.

setLineageInfo

public void setLineageInfo(LineageInfo linfo)
Sets the lineage information.

Parameters:
linfo - The LineageInfo structure that is set in the optimization phase.

getTableAccessInfo

public TableAccessInfo getTableAccessInfo()
Gets the table access information.

Returns:
TableAccessInfo associated with the query.

setTableAccessInfo

public void setTableAccessInfo(TableAccessInfo tableAccessInfo)
Sets the table access information.

Parameters:
taInfo - The TableAccessInfo structure that is set in the optimization phase.

extractPartitionSpecs

protected HashMap<String,String> extractPartitionSpecs(org.antlr.runtime.tree.Tree partspec)
                                                throws SemanticException
Throws:
SemanticException

isValidPrefixSpec

public final boolean isValidPrefixSpec(Table tTable,
                                       Map<String,String> spec)
                                throws HiveException
Checks if given specification is proper specification for prefix of partition cols, for table partitioned by ds, hr, min valid ones are (ds='2008-04-08'), (ds='2008-04-08', hr='12'), (ds='2008-04-08', hr='12', min='30') invalid one is for example (ds='2008-04-08', min='30')

Parameters:
spec - specification key-value map
Returns:
true if the specification is prefix; never returns false, but throws
Throws:
HiveException

getDb

public Hive getDb()

getQueryProperties

public QueryProperties getQueryProperties()

getSkewedValueFromASTNode

protected List<String> getSkewedValueFromASTNode(ASTNode ast)
Given a ASTNode, return list of values. use case: create table xyz list bucketed (col1) with skew (1,2,5) AST Node is for (1,2,5)

Parameters:
ast -
Returns:

getSkewedValuesFromASTNode

protected List<String> getSkewedValuesFromASTNode(Node node)
                                           throws SemanticException
Retrieve skewed values from ASTNode.

Parameters:
node -
Returns:
Throws:
SemanticException

analyzeSkewedTablDDLColNames

protected List<String> analyzeSkewedTablDDLColNames(List<String> skewedColNames,
                                                    ASTNode child)
                                             throws SemanticException
Analyze list bucket column names

Parameters:
skewedColNames -
child -
Returns:
Throws:
SemanticException

analyzeDDLSkewedValues

protected void analyzeDDLSkewedValues(List<List<String>> skewedValues,
                                      ASTNode child)
                               throws SemanticException
Handle skewed values in DDL. It can be used by both skewed by ... on () and set skewed location ().

Parameters:
skewedValues -
child -
Throws:
SemanticException

analyzeStoredAdDirs

protected boolean analyzeStoredAdDirs(ASTNode child)
process stored as directories

Parameters:
child -
Returns:


Copyright © 2013 The Apache Software Foundation