e.printStackTrace();
}
}
// Handle different types of CREATE TABLE command
CreateTableDesc crtTblDesc = null;
switch (command_type) {
case CREATE_TABLE: // REGULAR CREATE TABLE DDL
tblProps = addDefaultProperties(tblProps);
crtTblDesc = new CreateTableDesc(tableName, isExt, cols, partCols,
bucketCols, sortCols, numBuckets, rowFormatParams.fieldDelim, rowFormatParams.fieldEscape,
rowFormatParams.collItemDelim, rowFormatParams.mapKeyDelim, rowFormatParams.lineDelim, comment,
storageFormat.inputFormat, storageFormat.outputFormat, location, shared.serde,
storageFormat.storageHandler, shared.serdeProps, tblProps, ifNotExists);
validateCreateTable(crtTblDesc);
// outputs is empty, which means this create table happens in the current
// database.
SessionState.get().setCommandType(HiveOperation.CREATETABLE);
rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(),
crtTblDesc), conf));
break;
case CTLT: // create table like <tbl_name>
CreateTableLikeDesc crtTblLikeDesc = new CreateTableLikeDesc(tableName, isExt,
storageFormat.inputFormat, storageFormat.outputFormat, location,
shared.serde, shared.serdeProps, ifNotExists, likeTableName);
SessionState.get().setCommandType(HiveOperation.CREATETABLE);
rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(),
crtTblLikeDesc), conf));
break;
case CTAS: // create table as select
// Verify that the table does not already exist
String databaseName;
try {
Table dumpTable = db.newTable(tableName);
databaseName = dumpTable.getDbName();
if (null == db.getDatabase(dumpTable.getDbName()) ) {
throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(dumpTable.getDbName()));
}
if (null != db.getTable(dumpTable.getDbName(), dumpTable.getTableName(), false)) {
throw new SemanticException(ErrorMsg.TABLE_ALREADY_EXISTS.getMsg(tableName));
}
} catch (HiveException e) {
throw new SemanticException(e);
}
tblProps = addDefaultProperties(tblProps);
crtTblDesc = new CreateTableDesc(databaseName, tableName, isExt, cols, partCols,
bucketCols, sortCols, numBuckets, rowFormatParams.fieldDelim, rowFormatParams.fieldEscape,
rowFormatParams.collItemDelim, rowFormatParams.mapKeyDelim, rowFormatParams.lineDelim, comment, storageFormat.inputFormat,
storageFormat.outputFormat, location, shared.serde, storageFormat.storageHandler, shared.serdeProps,
tblProps, ifNotExists);
qb.setTableDesc(crtTblDesc);