Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ShowFilesStmt.java
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package com.cloudera.impala.analysis;
16 
17 import java.util.List;
18 
21 import com.cloudera.impala.thrift.TShowFilesParams;
22 import com.cloudera.impala.thrift.TPartitionKeyValue;
25 import com.cloudera.impala.thrift.TTableName;
26 import com.google.common.base.Preconditions;
27 import com.google.common.base.Joiner;
28 import com.google.common.collect.Lists;
29 
37 public class ShowFilesStmt extends StatementBase {
39 
40  // Show files for all the partitions if this is null.
42 
43  // Set during analysis.
44  protected Table table_;
45 
46  public ShowFilesStmt(TableName tableName, PartitionSpec partitionSpec) {
47  this.tableName_ = tableName;
48  this.partitionSpec_ = partitionSpec;
49  }
50 
51  @Override
52  public String toSql() {
53  StringBuilder strBuilder = new StringBuilder();
54  strBuilder.append("SHOW FILES IN " + tableName_.toString());
55  if (partitionSpec_ != null) strBuilder.append(" " + partitionSpec_.toSql());
56  return strBuilder.toString();
57  }
58 
59  @Override
60  public void analyze(Analyzer analyzer) throws AnalysisException {
62  tableName_ = new TableName(analyzer.getDefaultDb(), tableName_.getTbl());
63  }
64  table_ = analyzer.getTable(tableName_, Privilege.VIEW_METADATA);
65  if (!(table_ instanceof HdfsTable)) {
66  throw new AnalysisException(String.format(
67  "SHOW FILES not applicable to a non hdfs table: %s", table_.getFullName()));
68  }
69 
70  // Analyze the partition spec, if one was specified.
71  if (partitionSpec_ != null) {
72  partitionSpec_.setTableName(tableName_);
73  partitionSpec_.setPartitionShouldExist();
74  partitionSpec_.setPrivilegeRequirement(Privilege.VIEW_METADATA);
75  partitionSpec_.analyze(analyzer);
76  }
77  }
78 
79  public TShowFilesParams toThrift() {
80  TShowFilesParams params = new TShowFilesParams();
81  params.setTable_name(new TTableName(tableName_.getDb(), tableName_.getTbl()));
82  if (partitionSpec_ != null) {
83  params.setPartition_spec(partitionSpec_.toThrift());
84  }
85  return params;
86  }
87 }
ShowFilesStmt(TableName tableName, PartitionSpec partitionSpec)