Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
BaseTableRef.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 
18 import com.google.common.base.Preconditions;
19 
25 public class BaseTableRef extends TableRef {
26  public BaseTableRef(TableRef tableRef, Path resolvedPath) {
27  super(tableRef);
28  resolvedPath_ = resolvedPath;
29  Preconditions.checkState(resolvedPath_.isResolved());
30  Preconditions.checkNotNull(resolvedPath_.getRootTable());
31  // Set implicit aliases if no explicit one was given.
32  if (hasExplicitAlias()) return;
33  aliases_ = new String[] {
34  getTable().getTableName().toString().toLowerCase(),
35  getTable().getName().toLowerCase() };
36  }
37 
41  private BaseTableRef(BaseTableRef other) {
42  super(other);
43  }
44 
48  @Override
49  public void analyze(Analyzer analyzer) throws AnalysisException {
50  Preconditions.checkNotNull(getPrivilegeRequirement());
51  desc_ = analyzer.registerTableRef(this);
52  isAnalyzed_ = true;
53  analyzeJoin(analyzer);
54  }
55 
56  @Override
57  protected String tableRefToSql() {
58  // Enclose the alias in quotes if Hive cannot parse it without quotes.
59  // This is needed for view compatibility between Impala and Hive.
60  String aliasSql = null;
61  String alias = getExplicitAlias();
62  if (alias != null) aliasSql = ToSqlUtils.getIdentSql(alias);
63  return getTable().getTableName().toSql() +
64  ((aliasSql != null) ? " " + aliasSql : "");
65  }
66 
67  public String debugString() { return tableRefToSql(); }
68  @Override
69  public TableRef clone() { return new BaseTableRef(this); }
70 }
BaseTableRef(TableRef tableRef, Path resolvedPath)
void analyzeJoin(Analyzer analyzer)
Definition: TableRef.java:339