Search in sources :

Example 1 with MSchemaVersion

use of org.apache.hadoop.hive.metastore.model.MSchemaVersion 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 2 with MSchemaVersion

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

the class ObjectStore method getLatestSchemaVersion.

@Override
public SchemaVersion getLatestSchemaVersion(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.setUnique(true);
        query.setOrdering("version descending");
        query.setRange(0, 1);
        MSchemaVersion mSchemaVersion = (MSchemaVersion) query.execute(name, dbName);
        pm.retrieve(mSchemaVersion);
        if (mSchemaVersion != null) {
            pm.retrieveAll(mSchemaVersion.getCols());
            if (mSchemaVersion.getSerDe() != null)
                pm.retrieve(mSchemaVersion.getSerDe());
        }
        SchemaVersion version = mSchemaVersion == null ? null : convertToSchemaVersion(mSchemaVersion);
        committed = commitTransaction();
        return version;
    } 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)

Example 3 with MSchemaVersion

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

the class ObjectStore method getMSchemaVersion.

private MSchemaVersion getMSchemaVersion(String dbName, String schemaName, int version) {
    Query query = null;
    try {
        dbName = normalizeIdentifier(dbName);
        schemaName = normalizeIdentifier(schemaName);
        query = pm.newQuery(MSchemaVersion.class, "iSchema.name == schemaName && iSchema.db.name == dbName && version == schemaVersion");
        query.declareParameters("java.lang.String schemaName, java.lang.String dbName, java.lang.Integer schemaVersion");
        query.setUnique(true);
        MSchemaVersion mSchemaVersion = (MSchemaVersion) query.execute(schemaName, dbName, version);
        pm.retrieve(mSchemaVersion);
        if (mSchemaVersion != null) {
            pm.retrieveAll(mSchemaVersion.getCols());
            if (mSchemaVersion.getSerDe() != null)
                pm.retrieve(mSchemaVersion.getSerDe());
        }
        return mSchemaVersion;
    } finally {
        if (query != null)
            query.closeAll();
    }
}
Also used : MSchemaVersion(org.apache.hadoop.hive.metastore.model.MSchemaVersion) Query(javax.jdo.Query)

Example 4 with MSchemaVersion

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

the class ObjectStore method addSchemaVersion.

@Override
public void addSchemaVersion(SchemaVersion schemaVersion) throws AlreadyExistsException, NoSuchObjectException, MetaException {
    boolean committed = false;
    MSchemaVersion mSchemaVersion = convertToMSchemaVersion(schemaVersion);
    try {
        openTransaction();
        // Make sure it doesn't already exist
        if (getMSchemaVersion(schemaVersion.getSchema().getDbName(), schemaVersion.getSchema().getSchemaName(), schemaVersion.getVersion()) != null) {
            throw new AlreadyExistsException("Schema name " + schemaVersion.getSchema() + " version " + schemaVersion.getVersion() + " already exists");
        }
        // Make sure the referenced Schema exists
        if (getMISchema(schemaVersion.getSchema().getDbName(), schemaVersion.getSchema().getSchemaName()) == null) {
            throw new NoSuchObjectException("Schema " + schemaVersion.getSchema() + " does not exist");
        }
        pm.makePersistent(mSchemaVersion);
        committed = commitTransaction();
    } finally {
        if (!committed)
            rollbackTransaction();
        ;
    }
}
Also used : MSchemaVersion(org.apache.hadoop.hive.metastore.model.MSchemaVersion) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Example 5 with MSchemaVersion

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

the class ObjectStore method dropSchemaVersion.

@Override
public void dropSchemaVersion(SchemaVersionDescriptor version) throws NoSuchObjectException, MetaException {
    boolean committed = false;
    try {
        openTransaction();
        MSchemaVersion mSchemaVersion = getMSchemaVersion(version.getSchema().getDbName(), version.getSchema().getSchemaName(), version.getVersion());
        if (mSchemaVersion != null) {
            pm.deletePersistentAll(mSchemaVersion);
        } else {
            throw new NoSuchObjectException("Schema version " + version + "does not exist");
        }
        committed = commitTransaction();
    } finally {
        if (!committed)
            rollbackTransaction();
    }
}
Also used : MSchemaVersion(org.apache.hadoop.hive.metastore.model.MSchemaVersion) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

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