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);
}
}
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);
}
}
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();
}
}
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();
;
}
}
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();
}
}
Aggregations