Search in sources :

Example 6 with MSchemaVersion

use of org.apache.hadoop.hive.metastore.model.MSchemaVersion in project hive by apache.

the class ObjectStore method alterSchemaVersion.

@Override
public void alterSchemaVersion(SchemaVersionDescriptor version, SchemaVersion newVersion) throws NoSuchObjectException, MetaException {
    boolean committed = false;
    try {
        openTransaction();
        MSchemaVersion oldMSchemaVersion = getMSchemaVersion(version.getSchema().getDbName(), version.getSchema().getSchemaName(), version.getVersion());
        if (oldMSchemaVersion == null) {
            throw new NoSuchObjectException("No schema version " + version + " exists");
        }
        // We only support changing the SerDe mapping and the state.
        if (newVersion.isSetSerDe())
            oldMSchemaVersion.setSerDe(convertToMSerDeInfo(newVersion.getSerDe()));
        if (newVersion.isSetState())
            oldMSchemaVersion.setState(newVersion.getState().getValue());
        committed = commitTransaction();
    } finally {
        if (!committed)
            commitTransaction();
    }
}
Also used : MSchemaVersion(org.apache.hadoop.hive.metastore.model.MSchemaVersion) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Example 7 with MSchemaVersion

use of org.apache.hadoop.hive.metastore.model.MSchemaVersion in project hive by apache.

the class ObjectStore method getAllSchemaVersion.

@Override
public List<SchemaVersion> getAllSchemaVersion(ISchemaName schemaName) throws MetaException {
    boolean committed = false;
    Query query = null;
    try {
        openTransaction();
        String name = normalizeIdentifier(schemaName.getSchemaName());
        String dbName = normalizeIdentifier(schemaName.getDbName());
        query = pm.newQuery(MSchemaVersion.class, "iSchema.name == schemaName && iSchema.db.name == dbName");
        query.declareParameters("java.lang.String schemaName, java.lang.String dbName");
        query.setOrdering("version descending");
        List<MSchemaVersion> mSchemaVersions = query.setParameters(name, dbName).executeList();
        pm.retrieveAll(mSchemaVersions);
        if (mSchemaVersions == null || mSchemaVersions.isEmpty())
            return null;
        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) ArrayList(java.util.ArrayList)

Aggregations

MSchemaVersion (org.apache.hadoop.hive.metastore.model.MSchemaVersion)7 Query (javax.jdo.Query)4 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)3 SchemaVersion (org.apache.hadoop.hive.metastore.api.SchemaVersion)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 MRoleMap (org.apache.hadoop.hive.metastore.model.MRoleMap)1 WeakValueMap (org.datanucleus.util.WeakValueMap)1