15 package com.cloudera.impala.analysis;
17 import java.util.EnumSet;
28 import com.cloudera.impala.thrift.THdfsFileFormat;
29 import com.google.common.base.Preconditions;
38 EnumSet.of(THdfsFileFormat.PARQUET, THdfsFileFormat.TEXT);
44 Preconditions.checkNotNull(queryStmt);
45 Preconditions.checkNotNull(createStmt);
46 this.createStmt_ = createStmt;
48 null, null, queryStmt, null);
59 super.analyze(analyzer);
67 analyzer.getQueryCtx(), analyzer.getAuthzConfig());
68 QueryStmt tmpQueryStmt = insertStmt_.getQueryStmt().clone();
71 tmpAnalyzer.setUseHiveColLabels(
true);
72 tmpQueryStmt.analyze(tmpAnalyzer);
73 if (analyzer.containsSubquery()) {
76 StmtRewriter.rewriteQueryStatement(tmpQueryStmt, tmpAnalyzer);
78 insertStmt_.setQueryStmt(tmpQueryStmt.clone());
81 tmpQueryStmt = insertStmt_.getQueryStmt().clone();
82 tmpAnalyzer =
new Analyzer(dummyRootAnalyzer);
83 tmpAnalyzer.setUseHiveColLabels(
true);
84 tmpQueryStmt.analyze(tmpAnalyzer);
88 analyzer.getMissingTbls().addAll(dummyRootAnalyzer.getMissingTbls());
92 int colCnt = tmpQueryStmt.getColLabels().size();
93 for (
int i = 0; i < colCnt; ++i) {
95 tmpQueryStmt.getColLabels().get(i), null, null);
96 colDef.setType(tmpQueryStmt.getBaseTblResultExprs().
get(i).getType());
97 createStmt_.getColumnDefs().add(colDef);
99 createStmt_.analyze(analyzer);
103 "does not support (%s) file format. Supported formats are: (%s)",
105 "PARQUET, TEXTFILE"));
121 org.apache.hadoop.hive.metastore.api.Table msTbl =
122 CatalogOpExecutor.createMetaStoreTable(createStmt_.toThrift());
128 msTbl.getSd().setLocation(analyzer.getCatalog().getTablePath(msTbl).toString());
134 createStmt_.setLocation(
new HdfsUri(msTbl.getSd().getLocation()));
143 Table table = Table.fromMetastoreTable(TableId.createInvalidId(), db, msTbl);
144 Preconditions.checkState(table != null && table instanceof
HdfsTable);
147 hdfsTable.load(hdfsTable, client.getHiveClient(), msTbl);
148 insertStmt_.setTargetTable(table);
151 }
catch (Exception e) {
158 insertStmt_.analyze(analyzer);
void analyze(Analyzer analyzer)
final CreateTableStmt createStmt_
THdfsFileFormat getFileFormat()
static final EnumSet< THdfsFileFormat > SUPPORTED_INSERT_FORMATS
final InsertStmt insertStmt_
static final String DB_DOES_NOT_EXIST_ERROR_MSG
InsertStmt getInsertStmt()
CreateTableStmt getCreateStmt()
CreateTableAsSelectStmt(CreateTableStmt createStmt, QueryStmt queryStmt)