use of org.apache.hadoop.hive.metastore.api.SchemaVersion in project hive by apache.
the class TestObjectStoreSchemaMethods method alterNonExistentSchemaVersion.
@Test(expected = NoSuchObjectException.class)
public void alterNonExistentSchemaVersion() throws MetaException, AlreadyExistsException, NoSuchObjectException {
String schemaName = "schema3723asdflj";
int version = 37;
SchemaVersion schemaVersion = new SchemaVersionBuilder().setSchemaName(schemaName).setDbName(DEFAULT_DATABASE_NAME).setVersion(version).addCol("a", ColumnType.INT_TYPE_NAME).addCol("b", ColumnType.FLOAT_TYPE_NAME).setState(SchemaVersionState.INITIATED).build();
objectStore.alterSchemaVersion(new SchemaVersionDescriptor(new ISchemaName(DEFAULT_DATABASE_NAME, schemaName), version), schemaVersion);
}
use of org.apache.hadoop.hive.metastore.api.SchemaVersion in project hive by apache.
the class TestObjectStoreSchemaMethods method schemaQuery.
@Test
public void schemaQuery() throws TException {
String dbName = createUniqueDatabaseForTest();
String schemaName1 = "a_schema1";
ISchema schema1 = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName1).setDbName(dbName).build();
objectStore.createISchema(schema1);
String schemaName2 = "a_schema2";
ISchema schema2 = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName2).setDbName(dbName).build();
objectStore.createISchema(schema2);
SchemaVersion schemaVersion1_1 = new SchemaVersionBuilder().versionOf(schema1).setVersion(1).addCol("alpha", ColumnType.BIGINT_TYPE_NAME).addCol("beta", ColumnType.DATE_TYPE_NAME).build();
objectStore.addSchemaVersion(schemaVersion1_1);
SchemaVersion schemaVersion1_2 = new SchemaVersionBuilder().versionOf(schema1).setVersion(2).addCol("alpha", ColumnType.BIGINT_TYPE_NAME).addCol("beta", ColumnType.DATE_TYPE_NAME).addCol("gamma", ColumnType.BIGINT_TYPE_NAME, "namespace=x").build();
objectStore.addSchemaVersion(schemaVersion1_2);
SchemaVersion schemaVersion2_1 = new SchemaVersionBuilder().versionOf(schema2).setVersion(1).addCol("ALPHA", ColumnType.SMALLINT_TYPE_NAME).addCol("delta", ColumnType.DOUBLE_TYPE_NAME).build();
objectStore.addSchemaVersion(schemaVersion2_1);
SchemaVersion schemaVersion2_2 = new SchemaVersionBuilder().versionOf(schema2).setVersion(2).addCol("ALPHA", ColumnType.SMALLINT_TYPE_NAME).addCol("delta", ColumnType.DOUBLE_TYPE_NAME).addCol("epsilon", ColumnType.STRING_TYPE_NAME, "namespace=x").build();
objectStore.addSchemaVersion(schemaVersion2_2);
// Query that should return nothing
List<SchemaVersion> results = objectStore.getSchemaVersionsByColumns("x", "y", "z");
Assert.assertEquals(0, results.size());
// Query that should fetch one column
results = objectStore.getSchemaVersionsByColumns("gamma", null, null);
Assert.assertEquals(1, results.size());
Assert.assertEquals(schemaName1, results.get(0).getSchema().getSchemaName());
Assert.assertEquals(dbName, results.get(0).getSchema().getDbName());
Assert.assertEquals(2, results.get(0).getVersion());
// fetch 2 in same schema
results = objectStore.getSchemaVersionsByColumns("beta", null, null);
Assert.assertEquals(2, results.size());
Collections.sort(results);
Assert.assertEquals(schemaName1, results.get(0).getSchema().getSchemaName());
Assert.assertEquals(dbName, results.get(0).getSchema().getDbName());
Assert.assertEquals(1, results.get(0).getVersion());
Assert.assertEquals(schemaName1, results.get(1).getSchema().getSchemaName());
Assert.assertEquals(dbName, results.get(1).getSchema().getDbName());
Assert.assertEquals(2, results.get(1).getVersion());
// fetch across schemas
results = objectStore.getSchemaVersionsByColumns("alpha", null, null);
Assert.assertEquals(4, results.size());
Collections.sort(results);
Assert.assertEquals(schemaName1, results.get(0).getSchema().getSchemaName());
Assert.assertEquals(dbName, results.get(0).getSchema().getDbName());
Assert.assertEquals(1, results.get(0).getVersion());
Assert.assertEquals(schemaName1, results.get(1).getSchema().getSchemaName());
Assert.assertEquals(dbName, results.get(1).getSchema().getDbName());
Assert.assertEquals(2, results.get(1).getVersion());
Assert.assertEquals(schemaName2, results.get(2).getSchema().getSchemaName());
Assert.assertEquals(dbName, results.get(2).getSchema().getDbName());
Assert.assertEquals(1, results.get(2).getVersion());
Assert.assertEquals(schemaName2, results.get(3).getSchema().getSchemaName());
Assert.assertEquals(dbName, results.get(3).getSchema().getDbName());
Assert.assertEquals(2, results.get(3).getVersion());
// fetch by namespace
results = objectStore.getSchemaVersionsByColumns(null, "namespace=x", null);
Assert.assertEquals(2, results.size());
Collections.sort(results);
Assert.assertEquals(schemaName1, results.get(0).getSchema().getSchemaName());
Assert.assertEquals(dbName, results.get(0).getSchema().getDbName());
Assert.assertEquals(2, results.get(0).getVersion());
Assert.assertEquals(schemaName2, results.get(1).getSchema().getSchemaName());
Assert.assertEquals(dbName, results.get(1).getSchema().getDbName());
Assert.assertEquals(2, results.get(1).getVersion());
// fetch by name and type
results = objectStore.getSchemaVersionsByColumns("alpha", null, ColumnType.SMALLINT_TYPE_NAME);
Assert.assertEquals(2, results.size());
Collections.sort(results);
Assert.assertEquals(schemaName2, results.get(0).getSchema().getSchemaName());
Assert.assertEquals(dbName, results.get(0).getSchema().getDbName());
Assert.assertEquals(1, results.get(0).getVersion());
Assert.assertEquals(schemaName2, results.get(1).getSchema().getSchemaName());
Assert.assertEquals(dbName, results.get(1).getSchema().getDbName());
Assert.assertEquals(2, results.get(1).getVersion());
// Make sure matching name but wrong type doesn't return
results = objectStore.getSchemaVersionsByColumns("alpha", null, ColumnType.STRING_TYPE_NAME);
Assert.assertEquals(0, results.size());
}
use of org.apache.hadoop.hive.metastore.api.SchemaVersion in project hive by apache.
the class TestObjectStoreSchemaMethods method createVersionOfNonExistentSchema.
@Test(expected = NoSuchObjectException.class)
public void createVersionOfNonExistentSchema() throws MetaException, AlreadyExistsException, NoSuchObjectException, InvalidObjectException {
SchemaVersion schemaVersion = new SchemaVersionBuilder().setSchemaName("noSchemaOfThisNameExists").setDbName(DEFAULT_DATABASE_NAME).setVersion(1).addCol("a", ColumnType.STRING_TYPE_NAME).build();
objectStore.addSchemaVersion(schemaVersion);
}
use of org.apache.hadoop.hive.metastore.api.SchemaVersion 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);
}
}
Aggregations