use of org.apache.hadoop.hive.metastore.api.ISchema in project hive by apache.
the class TestHiveMetaStoreSchemaMethods method schemaAlreadyExists.
@Test(expected = AlreadyExistsException.class)
public void schemaAlreadyExists() throws TException {
String schemaName = uniqueSchemaName();
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.HIVE).setName(schemaName).build();
client.createISchema(schema);
schema = client.getISchema(DEFAULT_DATABASE_NAME, schemaName);
Assert.assertNotNull(schema);
Assert.assertEquals(SchemaType.HIVE, schema.getSchemaType());
Assert.assertEquals(schemaName, schema.getName());
Assert.assertEquals(SchemaCompatibility.BACKWARD, schema.getCompatibility());
Assert.assertEquals(SchemaValidation.ALL, schema.getValidationLevel());
Assert.assertTrue(schema.isCanEvolve());
// This second attempt to create it should throw
client.createISchema(schema);
}
use of org.apache.hadoop.hive.metastore.api.ISchema in project hive by apache.
the class TestHiveMetaStoreSchemaMethods method addSchemaVersion.
@Test
public void addSchemaVersion() throws TException {
String schemaName = uniqueSchemaName();
int version = 1;
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName).build();
client.createISchema(schema);
String description = "very descriptive";
String schemaText = "this should look like json, but oh well";
String fingerprint = "this should be an md5 string";
String versionName = "why would I name a version?";
long creationTime = 10;
String serdeName = "serde_for_schema37";
String serializer = "org.apache.hadoop.hive.metastore.test.Serializer";
String deserializer = "org.apache.hadoop.hive.metastore.test.Deserializer";
String serdeDescription = "how do you describe a serde?";
SchemaVersion schemaVersion = new SchemaVersionBuilder().versionOf(schema).setVersion(version).addCol("a", ColumnType.INT_TYPE_NAME).addCol("b", ColumnType.FLOAT_TYPE_NAME).setCreatedAt(creationTime).setState(SchemaVersionState.INITIATED).setDescription(description).setSchemaText(schemaText).setFingerprint(fingerprint).setName(versionName).setSerdeName(serdeName).setSerdeSerializerClass(serializer).setSerdeDeserializerClass(deserializer).setSerdeDescription(serdeDescription).build();
client.addSchemaVersion(schemaVersion);
Assert.assertEquals(1, (int) preEvents.get(PreEventContext.PreEventType.ADD_SCHEMA_VERSION));
Assert.assertEquals(1, (int) events.get(EventMessage.EventType.ADD_SCHEMA_VERSION));
Assert.assertEquals(1, (int) transactionalEvents.get(EventMessage.EventType.ADD_SCHEMA_VERSION));
schemaVersion = client.getSchemaVersion(DEFAULT_DATABASE_NAME, schemaName, version);
Assert.assertNotNull(schemaVersion);
Assert.assertEquals(schemaName, schemaVersion.getSchema().getSchemaName());
Assert.assertEquals(DEFAULT_DATABASE_NAME, schemaVersion.getSchema().getDbName());
Assert.assertEquals(version, schemaVersion.getVersion());
Assert.assertEquals(creationTime, schemaVersion.getCreatedAt());
Assert.assertEquals(SchemaVersionState.INITIATED, schemaVersion.getState());
Assert.assertEquals(description, schemaVersion.getDescription());
Assert.assertEquals(schemaText, schemaVersion.getSchemaText());
Assert.assertEquals(fingerprint, schemaVersion.getFingerprint());
Assert.assertEquals(versionName, schemaVersion.getName());
Assert.assertEquals(serdeName, schemaVersion.getSerDe().getName());
Assert.assertEquals(serializer, schemaVersion.getSerDe().getSerializerClass());
Assert.assertEquals(deserializer, schemaVersion.getSerDe().getDeserializerClass());
Assert.assertEquals(serdeDescription, schemaVersion.getSerDe().getDescription());
Assert.assertEquals(2, schemaVersion.getColsSize());
List<FieldSchema> cols = schemaVersion.getCols();
Collections.sort(cols);
Assert.assertEquals("a", cols.get(0).getName());
Assert.assertEquals(ColumnType.INT_TYPE_NAME, cols.get(0).getType());
Assert.assertEquals("b", cols.get(1).getName());
Assert.assertEquals(ColumnType.FLOAT_TYPE_NAME, cols.get(1).getType());
Assert.assertEquals(1, (int) preEvents.get(PreEventContext.PreEventType.READ_SCHEMA_VERSION));
client.dropSchemaVersion(DEFAULT_DATABASE_NAME, schemaName, version);
Assert.assertEquals(1, (int) preEvents.get(PreEventContext.PreEventType.DROP_SCHEMA_VERSION));
Assert.assertEquals(1, (int) events.get(EventMessage.EventType.DROP_SCHEMA_VERSION));
Assert.assertEquals(1, (int) transactionalEvents.get(EventMessage.EventType.DROP_SCHEMA_VERSION));
try {
client.getSchemaVersion(DEFAULT_DATABASE_NAME, schemaName, version);
Assert.fail();
} catch (NoSuchObjectException e) {
// all good
}
}
use of org.apache.hadoop.hive.metastore.api.ISchema in project hive by apache.
the class TestHiveMetaStoreSchemaMethods method mapSerDeNoSuchSchemaVersion.
@Test(expected = NoSuchObjectException.class)
public void mapSerDeNoSuchSchemaVersion() throws TException {
SerDeInfo serDeInfo = new SerDeInfo(uniqueSerdeName(), "lib", Collections.emptyMap());
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(uniqueSchemaName()).build();
client.createISchema(schema);
client.mapSchemaVersionToSerde(DEFAULT_DATABASE_NAME, schema.getName(), 3, serDeInfo.getName());
}
use of org.apache.hadoop.hive.metastore.api.ISchema 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.ISchema 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