use of org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder in project hive by apache.
the class TestHiveMetaStoreSchemaMethods method latestSchemaVersionBogusDb.
@Test(expected = NoSuchObjectException.class)
public void latestSchemaVersionBogusDb() throws TException {
String schemaName = uniqueSchemaName();
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName).build();
client.createISchema(schema);
client.getSchemaLatestVersion(DEFAULT_CATALOG_NAME, "bogus", schemaName);
}
use of org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder in project hive by apache.
the class TestObjectStoreSchemaMethods method schemaQuery.
@Test
public void schemaQuery() throws TException {
Database db = createUniqueDatabaseForTest();
String schemaName1 = "a_schema1";
ISchema schema1 = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName1).inDb(db).build();
objectStore.createISchema(schema1);
String schemaName2 = "a_schema2";
ISchema schema2 = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName2).inDb(db).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(db.getName(), results.get(0).getSchema().getDbName());
Assert.assertEquals(db.getCatalogName(), results.get(0).getSchema().getCatName());
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(db.getName(), results.get(0).getSchema().getDbName());
Assert.assertEquals(db.getCatalogName(), results.get(0).getSchema().getCatName());
Assert.assertEquals(1, results.get(0).getVersion());
Assert.assertEquals(schemaName1, results.get(1).getSchema().getSchemaName());
Assert.assertEquals(db.getName(), results.get(1).getSchema().getDbName());
Assert.assertEquals(db.getCatalogName(), results.get(1).getSchema().getCatName());
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(db.getName(), results.get(0).getSchema().getDbName());
Assert.assertEquals(db.getCatalogName(), results.get(0).getSchema().getCatName());
Assert.assertEquals(1, results.get(0).getVersion());
Assert.assertEquals(schemaName1, results.get(1).getSchema().getSchemaName());
Assert.assertEquals(db.getName(), results.get(1).getSchema().getDbName());
Assert.assertEquals(db.getCatalogName(), results.get(1).getSchema().getCatName());
Assert.assertEquals(2, results.get(1).getVersion());
Assert.assertEquals(schemaName2, results.get(2).getSchema().getSchemaName());
Assert.assertEquals(db.getName(), results.get(2).getSchema().getDbName());
Assert.assertEquals(db.getCatalogName(), results.get(2).getSchema().getCatName());
Assert.assertEquals(1, results.get(2).getVersion());
Assert.assertEquals(schemaName2, results.get(3).getSchema().getSchemaName());
Assert.assertEquals(db.getName(), results.get(3).getSchema().getDbName());
Assert.assertEquals(db.getCatalogName(), results.get(3).getSchema().getCatName());
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(db.getName(), results.get(0).getSchema().getDbName());
Assert.assertEquals(db.getCatalogName(), results.get(0).getSchema().getCatName());
Assert.assertEquals(2, results.get(0).getVersion());
Assert.assertEquals(schemaName2, results.get(1).getSchema().getSchemaName());
Assert.assertEquals(db.getName(), results.get(1).getSchema().getDbName());
Assert.assertEquals(db.getCatalogName(), results.get(1).getSchema().getCatName());
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(db.getName(), results.get(0).getSchema().getDbName());
Assert.assertEquals(db.getCatalogName(), results.get(0).getSchema().getCatName());
Assert.assertEquals(1, results.get(0).getVersion());
Assert.assertEquals(schemaName2, results.get(1).getSchema().getSchemaName());
Assert.assertEquals(db.getName(), results.get(1).getSchema().getDbName());
Assert.assertEquals(db.getCatalogName(), results.get(1).getSchema().getCatName());
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.client.builder.ISchemaBuilder in project hive by apache.
the class TestObjectStoreSchemaMethods method alterNonExistentSchema.
@Test(expected = NoSuchObjectException.class)
public void alterNonExistentSchema() throws MetaException, NoSuchObjectException {
String schemaName = "noSuchSchema";
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.HIVE).setName(schemaName).setDescription("a new description").build();
objectStore.alterISchema(new ISchemaName(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName), schema);
}
use of org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder in project hive by apache.
the class TestObjectStoreSchemaMethods method iSchema.
@Test
public void iSchema() throws TException {
Database db = createUniqueDatabaseForTest();
ISchema schema = objectStore.getISchema(new ISchemaName(db.getCatalogName(), db.getName(), "no.such.schema"));
Assert.assertNull(schema);
String schemaName = "schema1";
String schemaGroup = "group1";
String description = "This is a description";
schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName).inDb(db).setCompatibility(SchemaCompatibility.FORWARD).setValidationLevel(SchemaValidation.LATEST).setCanEvolve(false).setSchemaGroup(schemaGroup).setDescription(description).build();
objectStore.createISchema(schema);
schema = objectStore.getISchema(new ISchemaName(db.getCatalogName(), db.getName(), schemaName));
Assert.assertNotNull(schema);
Assert.assertEquals(SchemaType.AVRO, schema.getSchemaType());
Assert.assertEquals(schemaName, schema.getName());
Assert.assertEquals(SchemaCompatibility.FORWARD, schema.getCompatibility());
Assert.assertEquals(SchemaValidation.LATEST, schema.getValidationLevel());
Assert.assertFalse(schema.isCanEvolve());
Assert.assertEquals(schemaGroup, schema.getSchemaGroup());
Assert.assertEquals(description, schema.getDescription());
schemaGroup = "new group";
description = "new description";
schema.setCompatibility(SchemaCompatibility.BOTH);
schema.setValidationLevel(SchemaValidation.ALL);
schema.setCanEvolve(true);
schema.setSchemaGroup(schemaGroup);
schema.setDescription(description);
objectStore.alterISchema(new ISchemaName(db.getCatalogName(), db.getName(), schemaName), schema);
schema = objectStore.getISchema(new ISchemaName(db.getCatalogName(), db.getName(), schemaName));
Assert.assertNotNull(schema);
Assert.assertEquals(SchemaType.AVRO, schema.getSchemaType());
Assert.assertEquals(schemaName, schema.getName());
Assert.assertEquals(SchemaCompatibility.BOTH, schema.getCompatibility());
Assert.assertEquals(SchemaValidation.ALL, schema.getValidationLevel());
Assert.assertTrue(schema.isCanEvolve());
Assert.assertEquals(schemaGroup, schema.getSchemaGroup());
Assert.assertEquals(description, schema.getDescription());
objectStore.dropISchema(new ISchemaName(db.getCatalogName(), db.getName(), schemaName));
schema = objectStore.getISchema(new ISchemaName(db.getCatalogName(), db.getName(), schemaName));
Assert.assertNull(schema);
}
use of org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder in project hive by apache.
the class TestObjectStoreSchemaMethods method schemaWithInvalidDatabase.
@Test(expected = NoSuchObjectException.class)
public void schemaWithInvalidDatabase() throws MetaException, AlreadyExistsException, NoSuchObjectException {
ISchema schema = new ISchemaBuilder().setName("thisSchemaDoesntHaveADb").setDbName("no.such.database").setSchemaType(SchemaType.AVRO).build();
objectStore.createISchema(schema);
}
Aggregations