15 package com.cloudera.impala.catalog;
17 import java.util.HashMap;
18 import java.util.List;
21 import org.apache.log4j.Logger;
24 import com.cloudera.impala.thrift.TCatalogObjectType;
25 import com.cloudera.impala.thrift.TDatabase;
26 import com.cloudera.impala.thrift.TFunctionCategory;
28 import com.google.common.base.Preconditions;
29 import com.google.common.collect.Lists;
45 private static final Logger
LOG = Logger.getLogger(Db.class);
57 private final HashMap<String, List<Function>>
functions_;
64 thriftDb_ =
new TDatabase(name.toLowerCase());
67 functions_ =
new HashMap<String, List<Function>>();
76 return new Db(db.getDb_name(), parentCatalog);
81 public String
getName() {
return thriftDb_.getDb_name(); }
83 return TCatalogObjectType.DATABASE;
90 tableCache_.add(table);
97 return Lists.newArrayList(tableCache_.keySet());
101 return tableCache_.contains(tableName.toLowerCase());
109 return tableCache_.get(tblName);
116 return tableCache_.remove(tableName.toLowerCase());
124 return functions_.size();
133 return functions_.get(
name) != null;
142 List<Function> fns = functions_.get(desc.functionName());
143 if (fns == null)
return null;
147 if (f.compare(desc,
Function.CompareMode.IS_IDENTICAL))
return f;
149 if (mode ==
Function.CompareMode.IS_IDENTICAL)
return null;
153 if (f.compare(desc,
Function.CompareMode.IS_INDISTINGUISHABLE))
return f;
155 if (mode ==
Function.CompareMode.IS_INDISTINGUISHABLE)
return null;
159 if (f.compare(desc,
Function.CompareMode.IS_SUPERTYPE_OF))
return f;
167 for (List<Function> fns:
functions_.values()) {
169 if (f.signatureString().equals(signatureString))
return f;
180 Preconditions.checkState(fn.dbName().equals(
getName()));
186 List<Function> fns = functions_.get(fn.functionName());
188 fns = Lists.newArrayList();
189 functions_.put(fn.functionName(), fns);
202 if (fn == null)
return null;
203 List<Function> fns = functions_.get(desc.functionName());
204 Preconditions.checkNotNull(fns);
237 String closeFnSymbol,
boolean varArgs,
Type retType,
Type ... args) {
240 fnName, Lists.newArrayList(args), varArgs, retType,
241 symbol, prepareFnSymbol, closeFnSymbol,
false));
249 Preconditions.checkState(fn != null);
268 List<Function> functions = Lists.newArrayList();
270 for (Map.Entry<String, List<Function>> fns:
functions_.entrySet()) {
271 if (fnPattern.
matches(fns.getKey())) {
273 if (!fn.userVisible())
continue;
275 || (category == TFunctionCategory.SCALAR && fn instanceof
ScalarFunction)
276 || (category == TFunctionCategory.AGGREGATE
279 || (category == TFunctionCategory.ANALYTIC
List< String > getAllTableNames()
final Catalog parentCatalog_
void addTable(Table table)
final CatalogObjectCache< Table > tableCache_
void addScalarBuiltin(String fnName, String symbol, boolean varArgs, Type retType, Type...args)
TCatalogObjectType getCatalogObjectType()
Table removeTable(String tableName)
boolean containsTable(String tableName)
static final long INITIAL_CATALOG_VERSION
Table getTable(String tblName)
static ScalarFunction createBuiltin(String name, ArrayList< Type > argTypes, boolean hasVarArgs, Type retType, String symbol, String prepareFnSymbol, String closeFnSymbol, boolean isOperator)
Function removeFunction(Function desc)
boolean addFunction(Function fn)
Function removeFunction(String signatureStr)
boolean matches(String candidate)
HashMap< String, List< Function > > getAllFunctions()
List< Function > getFunctions(TFunctionCategory category, PatternMatcher fnPattern)
Function getFunction(String signatureString)
static Db fromTDatabase(TDatabase db, Catalog parentCatalog)
void addBuiltin(Function fn)
void setCatalogVersion(long newVersion)
Db(String name, Catalog catalog)
boolean containsFunction(String name)
final TDatabase thriftDb_
Catalog getParentCatalog()
Function getFunction(Function desc, Function.CompareMode mode)
final HashMap< String, List< Function > > functions_
void addScalarBuiltin(String fnName, String symbol, String prepareFnSymbol, String closeFnSymbol, boolean varArgs, Type retType, Type...args)
void setIsSystemDb(boolean b)