Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ImpaladTestCatalog.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.testutil;
16 
24 import com.google.common.base.Preconditions;
25 
30 public class ImpaladTestCatalog extends ImpaladCatalog {
31  // Used to load missing table metadata when running the FE tests.
33 
34  public ImpaladTestCatalog() {
35  this(AuthorizationConfig.createAuthDisabledConfig());
36  }
37 
42  super();
43  CatalogServiceCatalog catalogServerCatalog =
44  CatalogServiceTestCatalog.createWithAuth(authzConfig.getSentryConfig());
45  // Bootstrap the catalog by adding all dbs, tables, and functions.
46  for (String dbName: catalogServerCatalog.getDbNames(null)) {
47  // Adding DB should include all tables/fns in that database.
48  addDb(catalogServerCatalog.getDb(dbName));
49  }
50  authPolicy_ = ((CatalogServiceTestCatalog) catalogServerCatalog).getAuthPolicy();
51  srcCatalog_ = catalogServerCatalog;
52  setIsReady();
53  }
54 
55  @Override
56  public HdfsCachePool getHdfsCachePool(String poolName) {
57  return srcCatalog_.getHdfsCachePool(poolName);
58  }
59 
63  public void reset() throws CatalogException {
64  srcCatalog_.reset();
65  }
66 
70  @Override
71  public Table getTable(String dbName, String tableName)
72  throws CatalogException {
73  Table existingTbl = super.getTable(dbName, tableName);
74  // Table doesn't exist or is already loaded. Just return it.
75  if (existingTbl == null || existingTbl.isLoaded()) return existingTbl;
76 
77  // The table was not yet loaded. Load it in to the catalog and try getTable()
78  // again.
79  Table newTbl = srcCatalog_.getOrLoadTable(dbName, tableName);
80  Preconditions.checkNotNull(newTbl);
81  Preconditions.checkState(newTbl.isLoaded());
82  Db db = getDb(dbName);
83  Preconditions.checkNotNull(db);
84  db.addTable(newTbl);
85  return super.getTable(dbName, tableName);
86  }
87 }
Table getTable(String dbName, String tableName)
ImpaladTestCatalog(AuthorizationConfig authzConfig)
List< String > getDbNames(String dbPattern)
Definition: Catalog.java:136
AuthorizationPolicy authPolicy_
Definition: Catalog.java:67
void addDb(TDatabase thriftDb, long catalogVersion)