15 package com.cloudera.impala.analysis;
17 import org.apache.hadoop.fs.permission.FsAction;
21 import com.cloudera.impala.thrift.TAccessEvent;
22 import com.cloudera.impala.thrift.TCatalogObjectType;
23 import com.cloudera.impala.thrift.TCreateTableLikeParams;
24 import com.cloudera.impala.thrift.THdfsFileFormat;
25 import com.cloudera.impala.thrift.TTableName;
26 import com.google.common.base.Preconditions;
58 boolean ifNotExists) {
59 Preconditions.checkNotNull(tableName);
60 Preconditions.checkNotNull(srcTableName);
61 this.tableName_ = tableName;
62 this.srcTableName_ = srcTableName;
64 this.comment_ = comment;
65 this.fileFormat_ = fileFormat;
66 this.location_ = location;
67 this.ifNotExists_ = ifNotExists;
70 public String
getTbl() {
return tableName_.getTbl(); }
71 public String
getSrcTbl() {
return srcTableName_.getTbl(); }
83 Preconditions.checkNotNull(
dbName_);
97 Preconditions.checkNotNull(
owner_);
103 StringBuilder sb =
new StringBuilder(
"CREATE ");
108 sb.append(tableName_.getTbl() +
" LIKE ");
110 sb.append(srcTableName_.getTbl());
114 return sb.toString();
118 TCreateTableLikeParams params =
new TCreateTableLikeParams();
119 params.setTable_name(
new TTableName(
getDb(),
getTbl()));
125 params.setLocation(
location_ == null ? null : location_.toString());
132 Preconditions.checkState(
tableName_ != null && !tableName_.isEmpty());
133 Preconditions.checkState(
srcTableName_ != null && !srcTableName_.isEmpty());
138 tableName_.analyze();
140 owner_ = analyzer.getUser().getName();
145 String.format(
"%s.%s", dbName_,
getTbl()));
147 analyzer.addAccessEvent(
new TAccessEvent(dbName_ +
"." +
tableName_.
getTbl(),
148 TCatalogObjectType.TABLE, Privilege.CREATE.toString()));
151 location_.analyze(analyzer,
Privilege.ALL, FsAction.READ_WRITE);
final boolean ifNotExists_
void analyze(Analyzer analyzer)
final TableName tableName_
final THdfsFileFormat fileFormat_
TCreateTableLikeParams toThrift()
CreateTableLikeStmt(TableName tableName, TableName srcTableName, boolean isExternal, String comment, THdfsFileFormat fileFormat, HdfsUri location, boolean ifNotExists)
final TableName srcTableName_
static final String TBL_ALREADY_EXISTS_ERROR_MSG
THdfsFileFormat getFileFormat()
final boolean isExternal_