Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
IncompleteTable.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.catalog;
16 
17 import java.util.List;
18 import java.util.Set;
19 
20 import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
21 
24 import com.cloudera.impala.thrift.TCatalogObjectType;
25 import com.cloudera.impala.thrift.TErrorCode;
26 import com.cloudera.impala.thrift.TStatus;
27 import com.cloudera.impala.thrift.TTable;
28 import com.cloudera.impala.thrift.TTableDescriptor;
29 import com.google.common.base.Joiner;
30 import com.google.common.collect.Lists;
31 
37 public class IncompleteTable extends Table {
38  // The cause for the incomplete metadata. If there is no cause given (cause_ = null),
39  // then this is assumed to be an uninitialized table (table that does not have
40  // its metadata loaded).
42 
43  private IncompleteTable(TableId id, Db db, String name,
44  ImpalaException cause) {
45  super(id, null, db, name, null);
46  cause_ = cause;
47  }
48 
53  public ImpalaException getCause() { return cause_; }
54 
58  @Override
59  public boolean isLoaded() { return cause_ != null; }
60 
61  @Override
62  public TCatalogObjectType getCatalogObjectType() { return TCatalogObjectType.TABLE; }
63 
64  @Override
65  public int getNumNodes() { throw new IllegalStateException(cause_); }
66 
67  @Override
68  public TTableDescriptor toThriftDescriptor(Set<Long> referencedPartitions) {
69  throw new IllegalStateException(cause_);
70  }
71 
72  @Override
73  public void load(Table oldValue, HiveMetaStoreClient client,
74  org.apache.hadoop.hive.metastore.api.Table msTbl) throws TableLoadingException {
75  if (cause_ instanceof TableLoadingException) {
76  throw (TableLoadingException) cause_;
77  } else {
78  throw new TableLoadingException("Table metadata incomplete: ", cause_);
79  }
80  }
81 
82  @Override
83  public TTable toThrift() {
84  TTable table = new TTable(db_.getName(), name_);
85  table.setId(id_.asInt());
86  if (cause_ != null) {
87  table.setLoad_status(new TStatus(TErrorCode.INTERNAL_ERROR,
88  Lists.newArrayList(JniUtil.throwableToString(cause_),
89  JniUtil.throwableToStackTrace(cause_))));
90  }
91  return table;
92  }
93 
94  @Override
95  protected void loadFromThrift(TTable thriftTable) throws TableLoadingException {
96  if (thriftTable.isSetLoad_status()) {
97  // Since the load status is set, it indicates the table is incomplete due to
98  // an error loading the table metadata. The error message in the load status
99  // should provide details on why. By convention, the final error message should
100  // be the remote (Catalog Server) call stack. This shouldn't be displayed to the
101  // user under normal circumstances, but needs to be recorded somewhere so append
102  // it to the call stack of the local TableLoadingException created here.
103  // TODO: Provide a mechanism (query option?) to optionally allow returning more
104  // detailed errors (including the full call stack(s)) to the user.
105  List<String> errorMsgs = thriftTable.getLoad_status().getError_msgs();
106  String callStackStr = "<None available>";
107  if (errorMsgs.size() > 1) callStackStr = errorMsgs.remove(errorMsgs.size() - 1);
108 
109  String errorMsg = Joiner.on("\n").join(errorMsgs);
110  // The errorMsg will always be prefixed with "ExceptionClassName: ". Since we treat
111  // all errors as TableLoadingExceptions, the prefix "TableLoadingException" is
112  // redundant and can be stripped out.
113  errorMsg = errorMsg.replaceFirst("^TableLoadingException: ", "");
114  TableLoadingException loadingException = new TableLoadingException(errorMsg);
115  List<StackTraceElement> stackTrace =
116  Lists.newArrayList(loadingException.getStackTrace());
117  stackTrace.add(new StackTraceElement("========",
118  "<Remote stack trace on catalogd>: " + callStackStr, "", -1));
119  loadingException.setStackTrace(
120  stackTrace.toArray(new StackTraceElement[stackTrace.size()]));
121  this.cause_ = loadingException;
122  }
123  }
124 
126  String name) {
127  return new IncompleteTable(id, db, name, null);
128  }
129 
131  String name, ImpalaException e) {
132  return new IncompleteTable(id, db, name, e);
133  }
134 }
static IncompleteTable createFailedMetadataLoadTable(TableId id, Db db, String name, ImpalaException e)
static IncompleteTable createUninitializedTable(TableId id, Db db, String name)
void load(Table oldValue, HiveMetaStoreClient client, org.apache.hadoop.hive.metastore.api.Table msTbl)
static String throwableToString(Throwable t)
Definition: JniUtil.java:49
TTableDescriptor toThriftDescriptor(Set< Long > referencedPartitions)
IncompleteTable(TableId id, Db db, String name, ImpalaException cause)
Table(TableId id, org.apache.hadoop.hive.metastore.api.Table msTable, Db db, String name, String owner)
Definition: Table.java:91
string name
Definition: cpu-info.cc:50