Search in sources :

Example 1 with InvalidObjectException

use of org.apache.hadoop.hive.metastore.api.InvalidObjectException 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 = HiveStringUtils.normalizeIdentifier(funcName);
        dbName = HiveStringUtils.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(HiveStringUtils.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 2 with InvalidObjectException

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

the class ObjectStore method convertToMPart.

/**
   * Convert a Partition object into an MPartition, which is an object backed by the db
   * If the Partition's set of columns is the same as the parent table's AND useTableCD
   * is true, then this partition's storage descriptor's column descriptor will point
   * to the same one as the table's storage descriptor.
   * @param part the partition to convert
   * @param useTableCD whether to try to use the parent table's column descriptor.
   * @return the model partition object
   * @throws InvalidObjectException
   * @throws MetaException
   */
private MPartition convertToMPart(Partition part, boolean useTableCD) throws InvalidObjectException, MetaException {
    if (part == null) {
        return null;
    }
    MTable mt = getMTable(part.getDbName(), part.getTableName());
    if (mt == null) {
        throw new InvalidObjectException("Partition doesn't have a valid table or database name");
    }
    // If this partition's set of columns is the same as the parent table's,
    // use the parent table's, so we do not create a duplicate column descriptor,
    // thereby saving space
    MStorageDescriptor msd;
    if (useTableCD && mt.getSd() != null && mt.getSd().getCD() != null && mt.getSd().getCD().getCols() != null && part.getSd() != null && convertToFieldSchemas(mt.getSd().getCD().getCols()).equals(part.getSd().getCols())) {
        msd = convertToMStorageDescriptor(part.getSd(), mt.getSd().getCD());
    } else {
        msd = convertToMStorageDescriptor(part.getSd());
    }
    return new MPartition(Warehouse.makePartName(convertToFieldSchemas(mt.getPartitionKeys()), part.getValues()), mt, part.getValues(), part.getCreateTime(), part.getLastAccessTime(), msd, part.getParameters());
}
Also used : MTable(org.apache.hadoop.hive.metastore.model.MTable) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) MStorageDescriptor(org.apache.hadoop.hive.metastore.model.MStorageDescriptor) MPartition(org.apache.hadoop.hive.metastore.model.MPartition)

Example 3 with InvalidObjectException

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

the class ObjectStore method alterPartition.

@Override
public void alterPartition(String dbname, String name, List<String> part_vals, Partition newPart) throws InvalidObjectException, MetaException {
    boolean success = false;
    Exception e = null;
    try {
        openTransaction();
        alterPartitionNoTxn(dbname, name, part_vals, newPart);
        // commit the changes
        success = commitTransaction();
    } catch (Exception exception) {
        e = exception;
    } finally {
        if (!success) {
            rollbackTransaction();
            MetaException metaException = new MetaException("The transaction for alter partition did not commit successfully.");
            if (e != null) {
                metaException.initCause(e);
            }
            throw metaException;
        }
    }
}
Also used : JDOException(javax.jdo.JDOException) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) MissingTableException(org.datanucleus.store.rdbms.exceptions.MissingTableException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) 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) JDODataStoreException(javax.jdo.JDODataStoreException) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) UnknownPartitionException(org.apache.hadoop.hive.metastore.api.UnknownPartitionException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 4 with InvalidObjectException

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

the class ObjectStore method addForeignKeys.

private void addForeignKeys(List<SQLForeignKey> fks, boolean retrieveCD) throws InvalidObjectException, MetaException {
    List<MConstraint> mpkfks = new ArrayList<MConstraint>();
    String currentConstraintName = null;
    for (int i = 0; i < fks.size(); i++) {
        AttachedMTableInfo nParentTable = getMTable(fks.get(i).getPktable_db(), fks.get(i).getPktable_name(), retrieveCD);
        MTable parentTable = nParentTable.mtbl;
        if (parentTable == null) {
            throw new InvalidObjectException("Parent table not found: " + fks.get(i).getPktable_name());
        }
        AttachedMTableInfo nChildTable = getMTable(fks.get(i).getFktable_db(), fks.get(i).getFktable_name(), retrieveCD);
        MTable childTable = nChildTable.mtbl;
        if (childTable == null) {
            throw new InvalidObjectException("Child table not found: " + fks.get(i).getFktable_name());
        }
        MColumnDescriptor parentCD = retrieveCD ? nParentTable.mcd : parentTable.getSd().getCD();
        List<MFieldSchema> parentCols = parentCD == null ? null : parentCD.getCols();
        int parentIntegerIndex = getColumnIndexFromTableColumns(parentCols, fks.get(i).getPkcolumn_name());
        if (parentIntegerIndex == -1) {
            throw new InvalidObjectException("Parent column not found: " + fks.get(i).getPkcolumn_name());
        }
        MColumnDescriptor childCD = retrieveCD ? nChildTable.mcd : childTable.getSd().getCD();
        List<MFieldSchema> childCols = childCD.getCols();
        int childIntegerIndex = getColumnIndexFromTableColumns(childCols, fks.get(i).getFkcolumn_name());
        if (childIntegerIndex == -1) {
            throw new InvalidObjectException("Child column not found: " + fks.get(i).getFkcolumn_name());
        }
        if (fks.get(i).getFk_name() == null) {
            // the uniqueness of the generated constraint name.
            if (fks.get(i).getKey_seq() == 1) {
                currentConstraintName = generateConstraintName(fks.get(i).getFktable_db(), fks.get(i).getFktable_name(), fks.get(i).getPktable_db(), fks.get(i).getPktable_name(), fks.get(i).getPkcolumn_name(), fks.get(i).getFkcolumn_name(), "fk");
            }
        } else {
            currentConstraintName = fks.get(i).getFk_name();
        }
        Integer updateRule = fks.get(i).getUpdate_rule();
        Integer deleteRule = fks.get(i).getDelete_rule();
        int enableValidateRely = (fks.get(i).isEnable_cstr() ? 4 : 0) + (fks.get(i).isValidate_cstr() ? 2 : 0) + (fks.get(i).isRely_cstr() ? 1 : 0);
        MConstraint mpkfk = new MConstraint(currentConstraintName, MConstraint.FOREIGN_KEY_CONSTRAINT, fks.get(i).getKey_seq(), deleteRule, updateRule, enableValidateRely, parentTable, childTable, parentCD, childCD, childIntegerIndex, parentIntegerIndex);
        mpkfks.add(mpkfk);
    }
    pm.makePersistentAll(mpkfks);
}
Also used : MTable(org.apache.hadoop.hive.metastore.model.MTable) MFieldSchema(org.apache.hadoop.hive.metastore.model.MFieldSchema) ArrayList(java.util.ArrayList) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) MColumnDescriptor(org.apache.hadoop.hive.metastore.model.MColumnDescriptor) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint)

Example 5 with InvalidObjectException

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

the class ObjectStore method convertToMTable.

private MTable convertToMTable(Table tbl) throws InvalidObjectException, MetaException {
    if (tbl == null) {
        return null;
    }
    MDatabase mdb = null;
    try {
        mdb = getMDatabase(tbl.getDbName());
    } catch (NoSuchObjectException e) {
        LOG.error(StringUtils.stringifyException(e));
        throw new InvalidObjectException("Database " + tbl.getDbName() + " doesn't exist.");
    }
    // If the table has property EXTERNAL set, update table type
    // accordingly
    String tableType = tbl.getTableType();
    boolean isExternal = "TRUE".equals(tbl.getParameters().get("EXTERNAL"));
    if (TableType.MANAGED_TABLE.toString().equals(tableType)) {
        if (isExternal) {
            tableType = TableType.EXTERNAL_TABLE.toString();
        }
    }
    if (TableType.EXTERNAL_TABLE.toString().equals(tableType)) {
        if (!isExternal) {
            tableType = TableType.MANAGED_TABLE.toString();
        }
    }
    // A new table is always created with a new column descriptor
    return new MTable(HiveStringUtils.normalizeIdentifier(tbl.getTableName()), mdb, convertToMStorageDescriptor(tbl.getSd()), tbl.getOwner(), tbl.getCreateTime(), tbl.getLastAccessTime(), tbl.getRetention(), convertToMFieldSchemas(tbl.getPartitionKeys()), tbl.getParameters(), tbl.getViewOriginalText(), tbl.getViewExpandedText(), tbl.isRewriteEnabled(), tableType);
}
Also used : MDatabase(org.apache.hadoop.hive.metastore.model.MDatabase) MTable(org.apache.hadoop.hive.metastore.model.MTable) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException)

Aggregations

InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)36 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)21 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)21 Table (org.apache.hadoop.hive.metastore.api.Table)14 TException (org.apache.thrift.TException)14 ArrayList (java.util.ArrayList)13 Partition (org.apache.hadoop.hive.metastore.api.Partition)11 IOException (java.io.IOException)8 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)8 InvalidInputException (org.apache.hadoop.hive.metastore.api.InvalidInputException)8 MTable (org.apache.hadoop.hive.metastore.model.MTable)8 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)7 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)6 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)5 List (java.util.List)5 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)4 UnknownDBException (org.apache.hadoop.hive.metastore.api.UnknownDBException)4 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)4 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)3 SerDeInfo (org.apache.hadoop.hive.metastore.api.SerDeInfo)3