Search in sources :

Example 86 with MetaException

use of org.apache.hadoop.hive.metastore.api.MetaException in project hive by apache.

the class ObjectStore method getSchemaVersionsByColumns.

@Override
public List<SchemaVersion> getSchemaVersionsByColumns(String colName, String colNamespace, String type) throws MetaException {
    if (colName == null && colNamespace == null) {
        // Don't allow a query that returns everything, it will blow stuff up.
        throw new MetaException("You must specify column name or column namespace, else your query " + "may be too large");
    }
    boolean committed = false;
    Query query = null;
    try {
        openTransaction();
        if (colName != null)
            colName = normalizeIdentifier(colName);
        if (type != null)
            type = normalizeIdentifier(type);
        Map<String, String> parameters = new HashMap<>(3);
        StringBuilder sql = new StringBuilder("select SCHEMA_VERSION_ID from " + "SCHEMA_VERSION, COLUMNS_V2 where SCHEMA_VERSION.CD_ID = COLUMNS_V2.CD_ID ");
        if (colName != null) {
            sql.append("and COLUMNS_V2.COLUMN_NAME = :colName ");
            parameters.put("colName", colName);
        }
        if (colNamespace != null) {
            sql.append("and COLUMNS_V2.COMMENT = :colComment ");
            parameters.put("colComment", colNamespace);
        }
        if (type != null) {
            sql.append("and COLUMNS_V2.TYPE_NAME = :colType ");
            parameters.put("colType", type);
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("getSchemaVersionsByColumns going to execute query " + sql.toString());
            LOG.debug("With parameters");
            for (Map.Entry<String, String> p : parameters.entrySet()) {
                LOG.debug(p.getKey() + " : " + p.getValue());
            }
        }
        query = pm.newQuery("javax.jdo.query.SQL", sql.toString());
        query.setClass(MSchemaVersion.class);
        List<MSchemaVersion> mSchemaVersions = query.setNamedParameters(parameters).executeList();
        if (mSchemaVersions == null || mSchemaVersions.isEmpty())
            return Collections.emptyList();
        pm.retrieveAll(mSchemaVersions);
        List<SchemaVersion> schemaVersions = new ArrayList<>(mSchemaVersions.size());
        for (MSchemaVersion mSchemaVersion : mSchemaVersions) {
            pm.retrieveAll(mSchemaVersion.getCols());
            if (mSchemaVersion.getSerDe() != null)
                pm.retrieve(mSchemaVersion.getSerDe());
            schemaVersions.add(convertToSchemaVersion(mSchemaVersion));
        }
        committed = commitTransaction();
        return schemaVersions;
    } finally {
        rollbackAndCleanup(committed, query);
    }
}
Also used : MSchemaVersion(org.apache.hadoop.hive.metastore.model.MSchemaVersion) Query(javax.jdo.Query) SchemaVersion(org.apache.hadoop.hive.metastore.api.SchemaVersion) MSchemaVersion(org.apache.hadoop.hive.metastore.model.MSchemaVersion) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Map(java.util.Map) WeakValueMap(org.datanucleus.util.WeakValueMap) MRoleMap(org.apache.hadoop.hive.metastore.model.MRoleMap) HashMap(java.util.HashMap) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 87 with MetaException

use of org.apache.hadoop.hive.metastore.api.MetaException in project hive by apache.

the class ObjectStore method addPartitions.

@Override
public boolean addPartitions(String dbName, String tblName, PartitionSpecProxy partitionSpec, boolean ifNotExists) throws InvalidObjectException, MetaException {
    boolean success = false;
    openTransaction();
    try {
        List<MTablePrivilege> tabGrants = null;
        List<MTableColumnPrivilege> tabColumnGrants = null;
        MTable table = this.getMTable(dbName, tblName);
        if ("TRUE".equalsIgnoreCase(table.getParameters().get("PARTITION_LEVEL_PRIVILEGE"))) {
            tabGrants = this.listAllTableGrants(dbName, tblName);
            tabColumnGrants = this.listTableAllColumnGrants(dbName, tblName);
        }
        if (!partitionSpec.getTableName().equals(tblName) || !partitionSpec.getDbName().equals(dbName)) {
            throw new MetaException("Partition does not belong to target table " + dbName + "." + tblName + ": " + partitionSpec);
        }
        PartitionSpecProxy.PartitionIterator iterator = partitionSpec.getPartitionIterator();
        int now = (int) (System.currentTimeMillis() / 1000);
        while (iterator.hasNext()) {
            Partition part = iterator.next();
            if (isValidPartition(part, ifNotExists)) {
                MPartition mpart = convertToMPart(part, true);
                pm.makePersistent(mpart);
                if (tabGrants != null) {
                    for (MTablePrivilege tab : tabGrants) {
                        pm.makePersistent(new MPartitionPrivilege(tab.getPrincipalName(), tab.getPrincipalType(), mpart, tab.getPrivilege(), now, tab.getGrantor(), tab.getGrantorType(), tab.getGrantOption()));
                    }
                }
                if (tabColumnGrants != null) {
                    for (MTableColumnPrivilege col : tabColumnGrants) {
                        pm.makePersistent(new MPartitionColumnPrivilege(col.getPrincipalName(), col.getPrincipalType(), mpart, col.getColumnName(), col.getPrivilege(), now, col.getGrantor(), col.getGrantorType(), col.getGrantOption()));
                    }
                }
            }
        }
        success = commitTransaction();
    } finally {
        if (!success) {
            rollbackTransaction();
        }
    }
    return success;
}
Also used : MPartition(org.apache.hadoop.hive.metastore.model.MPartition) Partition(org.apache.hadoop.hive.metastore.api.Partition) MPartitionColumnPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) SQLCheckConstraint(org.apache.hadoop.hive.metastore.api.SQLCheckConstraint) SQLDefaultConstraint(org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint) SQLNotNullConstraint(org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint) MTable(org.apache.hadoop.hive.metastore.model.MTable) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege) PartitionSpecProxy(org.apache.hadoop.hive.metastore.partition.spec.PartitionSpecProxy) MTablePrivilege(org.apache.hadoop.hive.metastore.model.MTablePrivilege) MTableColumnPrivilege(org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) MPartition(org.apache.hadoop.hive.metastore.model.MPartition)

Example 88 with MetaException

use of org.apache.hadoop.hive.metastore.api.MetaException in project hive by apache.

the class ObjectStore method alterFunction.

@Override
public void alterFunction(String dbName, String funcName, Function newFunction) throws InvalidObjectException, MetaException {
    boolean success = false;
    try {
        openTransaction();
        funcName = normalizeIdentifier(funcName);
        dbName = normalizeIdentifier(dbName);
        MFunction newf = convertToMFunction(newFunction);
        if (newf == null) {
            throw new InvalidObjectException("new function is invalid");
        }
        MFunction oldf = getMFunction(dbName, funcName);
        if (oldf == null) {
            throw new MetaException("function " + funcName + " doesn't exist");
        }
        // For now only alter name, owner, class name, type
        oldf.setFunctionName(normalizeIdentifier(newf.getFunctionName()));
        oldf.setDatabase(newf.getDatabase());
        oldf.setOwnerName(newf.getOwnerName());
        oldf.setOwnerType(newf.getOwnerType());
        oldf.setClassName(newf.getClassName());
        oldf.setFunctionType(newf.getFunctionType());
        // commit the changes
        success = commitTransaction();
    } finally {
        if (!success) {
            rollbackTransaction();
        }
    }
}
Also used : MFunction(org.apache.hadoop.hive.metastore.model.MFunction) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 89 with MetaException

use of org.apache.hadoop.hive.metastore.api.MetaException in project hive by apache.

the class ObjectStore method getMPartitionColumnStatistics.

private List<MPartitionColumnStatistics> getMPartitionColumnStatistics(Table table, List<String> partNames, List<String> colNames, QueryWrapper queryWrapper) throws NoSuchObjectException, MetaException {
    boolean committed = false;
    try {
        openTransaction();
        // ToDo: we need verify the partition column instead
        try {
            validateTableCols(table, colNames);
        } catch (MetaException me) {
            LOG.warn("The table does not have the same column definition as its partition.");
        }
        Query query = queryWrapper.query = pm.newQuery(MPartitionColumnStatistics.class);
        String paramStr = "java.lang.String t1, java.lang.String t2";
        String filter = "tableName == t1 && dbName == t2 && (";
        Object[] params = new Object[colNames.size() + partNames.size() + 2];
        int i = 0;
        params[i++] = table.getTableName();
        params[i++] = table.getDbName();
        int firstI = i;
        for (String s : partNames) {
            filter += ((i == firstI) ? "" : " || ") + "partitionName == p" + i;
            paramStr += ", java.lang.String p" + i;
            params[i++] = s;
        }
        filter += ") && (";
        firstI = i;
        for (String s : colNames) {
            filter += ((i == firstI) ? "" : " || ") + "colName == c" + i;
            paramStr += ", java.lang.String c" + i;
            params[i++] = s;
        }
        filter += ")";
        query.setFilter(filter);
        query.declareParameters(paramStr);
        query.setOrdering("partitionName ascending");
        @SuppressWarnings("unchecked") List<MPartitionColumnStatistics> result = (List<MPartitionColumnStatistics>) query.executeWithArray(params);
        pm.retrieveAll(result);
        committed = commitTransaction();
        return result;
    } catch (Exception ex) {
        LOG.error("Error retrieving statistics via jdo", ex);
        if (ex instanceof MetaException) {
            throw (MetaException) ex;
        }
        throw new MetaException(ex.getMessage());
    } finally {
        if (!committed) {
            rollbackTransaction();
            return Lists.newArrayList();
        }
    }
}
Also used : Query(javax.jdo.Query) LinkedList(java.util.LinkedList) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) List(java.util.List) MPartitionColumnStatistics(org.apache.hadoop.hive.metastore.model.MPartitionColumnStatistics) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) SQLCheckConstraint(org.apache.hadoop.hive.metastore.api.SQLCheckConstraint) SQLDefaultConstraint(org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint) SQLNotNullConstraint(org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) IOException(java.io.IOException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) JDOCanRetryException(javax.jdo.JDOCanRetryException) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException) UnknownPartitionException(org.apache.hadoop.hive.metastore.api.UnknownPartitionException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) JDOException(javax.jdo.JDOException) MissingTableException(org.datanucleus.store.rdbms.exceptions.MissingTableException) SQLException(java.sql.SQLException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) JDODataStoreException(javax.jdo.JDODataStoreException) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 90 with MetaException

use of org.apache.hadoop.hive.metastore.api.MetaException in project hive by apache.

the class ObjectStore method dropPartitions.

@Override
public void dropPartitions(String dbName, String tblName, List<String> partNames) throws MetaException, NoSuchObjectException {
    if (CollectionUtils.isEmpty(partNames)) {
        return;
    }
    boolean success = false;
    openTransaction();
    try {
        // Delete all things.
        dropPartitionGrantsNoTxn(dbName, tblName, partNames);
        dropPartitionAllColumnGrantsNoTxn(dbName, tblName, partNames);
        dropPartitionColumnStatisticsNoTxn(dbName, tblName, partNames);
        // CDs are reused; go thry partition SDs, detach all CDs from SDs, then remove unused CDs.
        for (MColumnDescriptor mcd : detachCdsFromSdsNoTxn(dbName, tblName, partNames)) {
            removeUnusedColumnDescriptor(mcd);
        }
        dropPartitionsNoTxn(dbName, tblName, partNames);
        if (!(success = commitTransaction())) {
            // Should not happen?
            throw new MetaException("Failed to drop partitions");
        }
    } finally {
        if (!success) {
            rollbackTransaction();
        }
    }
}
Also used : MColumnDescriptor(org.apache.hadoop.hive.metastore.model.MColumnDescriptor) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

MetaException (org.apache.hadoop.hive.metastore.api.MetaException)318 IOException (java.io.IOException)123 ArrayList (java.util.ArrayList)95 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)74 TException (org.apache.thrift.TException)67 Table (org.apache.hadoop.hive.metastore.api.Table)59 Partition (org.apache.hadoop.hive.metastore.api.Partition)57 SQLException (java.sql.SQLException)55 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)53 Path (org.apache.hadoop.fs.Path)45 Connection (java.sql.Connection)36 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)34 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)32 Statement (java.sql.Statement)31 Test (org.junit.Test)30 List (java.util.List)25 Database (org.apache.hadoop.hive.metastore.api.Database)25 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)25 ResultSet (java.sql.ResultSet)22 UnknownDBException (org.apache.hadoop.hive.metastore.api.UnknownDBException)22