Search in sources :

Example 36 with Function

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;
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) ResourceUri(org.apache.hadoop.hive.metastore.api.ResourceUri)

Example 37 with Function

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);
    }
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) IOException(java.io.IOException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 38 with Function

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());
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) ResourceUri(org.apache.hadoop.hive.metastore.api.ResourceUri) Hive(org.apache.hadoop.hive.ql.metadata.Hive) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 39 with Function

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.");
        }
    }
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) SerDeException(org.apache.hadoop.hive.serde2.SerDeException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) HiveMetaException(org.apache.hadoop.hive.metastore.HiveMetaException) FileNotFoundException(java.io.FileNotFoundException) JDODataStoreException(javax.jdo.JDODataStoreException) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 40 with Function

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;
}
Also used : RegexStringComparator(org.apache.hadoop.hbase.filter.RegexStringComparator) Function(org.apache.hadoop.hive.metastore.api.Function) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) FirstKeyOnlyFilter(org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter) Filter(org.apache.hadoop.hbase.filter.Filter) CompareFilter(org.apache.hadoop.hbase.filter.CompareFilter) BloomFilter(org.apache.hive.common.util.BloomFilter) ArrayList(java.util.ArrayList) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

Function (org.apache.hadoop.hive.metastore.api.Function)69 Test (org.junit.Test)47 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)38 ResourceUri (org.apache.hadoop.hive.metastore.api.ResourceUri)17 TTransportException (org.apache.thrift.transport.TTransportException)11 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)9 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)8 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)6 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)6 FunctionBuilder (org.apache.hadoop.hive.metastore.client.builder.FunctionBuilder)6 Database (org.apache.hadoop.hive.metastore.api.Database)4 NotificationEvent (org.apache.hadoop.hive.metastore.api.NotificationEvent)4 TApplicationException (org.apache.thrift.TApplicationException)4 TException (org.apache.thrift.TException)4 HashSet (java.util.HashSet)3 Path (org.apache.hadoop.fs.Path)3 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)3 Partition (org.apache.hadoop.hive.metastore.api.Partition)3 SQLException (java.sql.SQLException)2