use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.
the class HBaseUtils method deserializeFunction.
/**
* Deserialize a function. This method should be used when the function and db name are
* already known.
* @param dbName name of the database the function is in
* @param functionName name of the function
* @param value serialized value of the function
* @return function as an object
* @throws InvalidProtocolBufferException
*/
static Function deserializeFunction(String dbName, String functionName, byte[] value) throws InvalidProtocolBufferException {
Function func = new Function();
func.setDbName(dbName);
func.setFunctionName(functionName);
HbaseMetastoreProto.Function protoFunc = HbaseMetastoreProto.Function.parseFrom(value);
if (protoFunc.hasClassName())
func.setClassName(protoFunc.getClassName());
if (protoFunc.hasOwnerName())
func.setOwnerName(protoFunc.getOwnerName());
if (protoFunc.hasOwnerType()) {
func.setOwnerType(convertPrincipalTypes(protoFunc.getOwnerType()));
}
func.setCreateTime((int) protoFunc.getCreateTime());
if (protoFunc.hasFunctionType()) {
func.setFunctionType(convertFunctionTypes(protoFunc.getFunctionType()));
}
for (HbaseMetastoreProto.Function.ResourceUri protoUri : protoFunc.getResourceUrisList()) {
func.addToResourceUris(new ResourceUri(convertResourceTypes(protoUri.getResourceType()), protoUri.getUri()));
}
return func;
}
use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.
the class HBaseStore method getFunction.
@Override
public Function getFunction(String dbName, String funcName) throws MetaException {
boolean commit = false;
openTransaction();
try {
Function func = getHBase().getFunction(dbName, funcName);
commit = true;
return func;
} catch (IOException e) {
LOG.error("Unable to get function" + e);
throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
} finally {
commitOrRoleBack(commit);
}
}
use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.
the class FunctionLocalizer method startLocalizeAllFunctions.
public void startLocalizeAllFunctions() throws HiveException {
Hive hive = Hive.get(false);
// Do not allow embedded metastore in LLAP unless we are in test.
try {
hive.getMSC(HiveConf.getBoolVar(conf, ConfVars.HIVE_IN_TEST), true);
} catch (MetaException e) {
throw new HiveException(e);
}
List<Function> fns = hive.getAllFunctions();
for (Function fn : fns) {
String fqfn = fn.getDbName() + "." + fn.getFunctionName();
List<ResourceUri> resources = fn.getResourceUris();
// Nothing to localize.
if (resources == null || resources.isEmpty())
continue;
FnResources result = new FnResources();
resourcesByFn.put(fqfn, result);
workQueue.add(new LocalizeFn(fqfn, resources, result, fn.getClassName(), false));
}
workQueue.add(new RefreshClassloader());
}
use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.
the class Hive method reloadFunctions.
public void reloadFunctions() throws HiveException {
HashSet<String> registryFunctions = new HashSet<String>(FunctionRegistry.getFunctionNames(".+\\..+"));
for (Function function : getAllFunctions()) {
String functionName = function.getFunctionName();
try {
LOG.info("Registering function " + functionName + " " + function.getClassName());
String qualFunc = FunctionUtils.qualifyFunctionName(functionName, function.getDbName());
FunctionRegistry.registerPermanentFunction(qualFunc, function.getClassName(), false, FunctionTask.toFunctionResource(function.getResourceUris()));
registryFunctions.remove(qualFunc);
} catch (Exception e) {
LOG.warn("Failed to register persistent function " + functionName + ":" + function.getClassName() + ". Ignore and continue.");
}
}
// unregister functions from local system registry that are not in getAllFunctions()
for (String functionName : registryFunctions) {
try {
FunctionRegistry.unregisterPermanentFunction(functionName);
} catch (Exception e) {
LOG.warn("Failed to unregister persistent function " + functionName + "on reload. Ignore and continue.");
}
}
}
use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.
the class HBaseReadWrite method scanFunctions.
/**
* Get a list of functions.
* @param dbName Name of the database to search in.
* @param regex Regular expression to use in searching for function names. It is expected to
* be a Java regular expression. If it is null then all functions will be returned.
* @return list of functions matching the regular expression.
* @throws IOException
*/
List<Function> scanFunctions(String dbName, String regex) throws IOException {
byte[] keyPrefix = null;
if (dbName != null) {
keyPrefix = HBaseUtils.buildKeyWithTrailingSeparator(dbName);
}
Filter filter = null;
if (regex != null) {
filter = new RowFilter(CompareFilter.CompareOp.EQUAL, new RegexStringComparator(regex));
}
Iterator<Result> iter = scan(FUNC_TABLE, keyPrefix, HBaseUtils.getEndPrefix(keyPrefix), CATALOG_CF, CATALOG_COL, filter);
List<Function> functions = new ArrayList<>();
while (iter.hasNext()) {
Result result = iter.next();
functions.add(HBaseUtils.deserializeFunction(result.getRow(), result.getValue(CATALOG_CF, CATALOG_COL)));
}
return functions;
}
Aggregations