@Override
public ASTNode preAnalyze(HiveSemanticAnalyzerHookContext context,
ASTNode ast) throws SemanticException {
Hive db;
try {
db = context.getHive();
} catch (HiveException e) {
throw new SemanticException(
"Couldn't get Hive DB instance in semantic analysis phase.",
e);
}
// Analyze and create tbl properties object
int numCh = ast.getChildCount();
String inputFormat = null, outputFormat = null;
tableName = BaseSemanticAnalyzer.getUnescapedName((ASTNode) ast
.getChild(0));
boolean likeTable = false;
for (int num = 1; num < numCh; num++) {
ASTNode child = (ASTNode) ast.getChild(num);
switch (child.getToken().getType()) {
case HiveParser.TOK_QUERY: // CTAS
throw new SemanticException(
"Operation not supported. Create table as " +
"Select is not a valid operation.");
case HiveParser.TOK_TABLEBUCKETS:
break;
case HiveParser.TOK_TBLSEQUENCEFILE:
inputFormat = HCatConstants.SEQUENCEFILE_INPUT;
outputFormat = HCatConstants.SEQUENCEFILE_OUTPUT;
break;
case HiveParser.TOK_TBLTEXTFILE:
inputFormat = org.apache.hadoop.mapred.TextInputFormat.class.getName();
outputFormat = org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat.class.getName();
break;
case HiveParser.TOK_LIKETABLE:
likeTable = true;
break;
case HiveParser.TOK_IFNOTEXISTS:
try {
List<String> tables = db.getTablesByPattern(tableName);
if (tables != null && tables.size() > 0) { // table
// exists
return ast;
}
} catch (HiveException e) {