use of org.apache.hadoop.hive.metastore.api.SchemaVersion in project hive by apache.
the class TestHiveMetaStoreSchemaMethods method multipleSchemaVersions.
// Test that adding multiple versions of the same schema
@Test
public void multipleSchemaVersions() throws TException {
String schemaName = uniqueSchemaName();
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName).build();
client.createISchema(schema);
SchemaVersion schemaVersion = new SchemaVersionBuilder().versionOf(schema).setVersion(1).addCol("a", ColumnType.BIGINT_TYPE_NAME).build();
client.addSchemaVersion(schemaVersion);
schemaVersion = new SchemaVersionBuilder().versionOf(schema).setVersion(2).addCol("a", ColumnType.BIGINT_TYPE_NAME).addCol("b", ColumnType.DATE_TYPE_NAME).build();
client.addSchemaVersion(schemaVersion);
schemaVersion = new SchemaVersionBuilder().versionOf(schema).setVersion(3).addCol("a", ColumnType.BIGINT_TYPE_NAME).addCol("b", ColumnType.DATE_TYPE_NAME).addCol("c", ColumnType.TIMESTAMP_TYPE_NAME).build();
client.addSchemaVersion(schemaVersion);
Assert.assertEquals(3, (int) preEvents.get(PreEventContext.PreEventType.ADD_SCHEMA_VERSION));
Assert.assertEquals(3, (int) events.get(EventMessage.EventType.ADD_SCHEMA_VERSION));
Assert.assertEquals(3, (int) transactionalEvents.get(EventMessage.EventType.ADD_SCHEMA_VERSION));
schemaVersion = client.getSchemaLatestVersion(DEFAULT_DATABASE_NAME, schemaName);
Assert.assertEquals(3, schemaVersion.getVersion());
Assert.assertEquals(3, schemaVersion.getColsSize());
List<FieldSchema> cols = schemaVersion.getCols();
Collections.sort(cols);
Assert.assertEquals("a", cols.get(0).getName());
Assert.assertEquals("b", cols.get(1).getName());
Assert.assertEquals("c", cols.get(2).getName());
Assert.assertEquals(ColumnType.BIGINT_TYPE_NAME, cols.get(0).getType());
Assert.assertEquals(ColumnType.DATE_TYPE_NAME, cols.get(1).getType());
Assert.assertEquals(ColumnType.TIMESTAMP_TYPE_NAME, cols.get(2).getType());
Assert.assertEquals(1, (int) preEvents.get(PreEventContext.PreEventType.READ_SCHEMA_VERSION));
List<SchemaVersion> versions = client.getSchemaAllVersions(DEFAULT_DATABASE_NAME, schemaName);
Assert.assertEquals(2, (int) preEvents.get(PreEventContext.PreEventType.READ_SCHEMA_VERSION));
Assert.assertEquals(3, versions.size());
versions.sort(Comparator.comparingInt(SchemaVersion::getVersion));
Assert.assertEquals(1, versions.get(0).getVersion());
Assert.assertEquals(1, versions.get(0).getColsSize());
Assert.assertEquals(ColumnType.BIGINT_TYPE_NAME, versions.get(0).getCols().get(0).getType());
Assert.assertEquals(2, versions.get(1).getVersion());
Assert.assertEquals(2, versions.get(1).getColsSize());
cols = versions.get(1).getCols();
Collections.sort(cols);
Assert.assertEquals("a", cols.get(0).getName());
Assert.assertEquals("b", cols.get(1).getName());
Assert.assertEquals(ColumnType.BIGINT_TYPE_NAME, cols.get(0).getType());
Assert.assertEquals(ColumnType.DATE_TYPE_NAME, cols.get(1).getType());
Assert.assertEquals(3, versions.get(2).getVersion());
Assert.assertEquals(3, versions.get(2).getColsSize());
cols = versions.get(2).getCols();
Collections.sort(cols);
Assert.assertEquals("a", cols.get(0).getName());
Assert.assertEquals("b", cols.get(1).getName());
Assert.assertEquals("c", cols.get(2).getName());
Assert.assertEquals(ColumnType.BIGINT_TYPE_NAME, cols.get(0).getType());
Assert.assertEquals(ColumnType.DATE_TYPE_NAME, cols.get(1).getType());
Assert.assertEquals(ColumnType.TIMESTAMP_TYPE_NAME, cols.get(2).getType());
}
use of org.apache.hadoop.hive.metastore.api.SchemaVersion in project hive by apache.
the class TestHiveMetaStoreSchemaMethods method setVersionState.
@Test
public void setVersionState() throws TException {
String schemaName = uniqueSchemaName();
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName).build();
client.createISchema(schema);
SchemaVersion schemaVersion = new SchemaVersionBuilder().versionOf(schema).setVersion(1).addCol("a", ColumnType.BINARY_TYPE_NAME).build();
client.addSchemaVersion(schemaVersion);
schemaVersion = client.getSchemaVersion(DEFAULT_DATABASE_NAME, schemaName, 1);
Assert.assertNull(schemaVersion.getState());
client.setSchemaVersionState(DEFAULT_DATABASE_NAME, schemaName, 1, SchemaVersionState.INITIATED);
Assert.assertEquals(1, (int) preEvents.get(PreEventContext.PreEventType.ALTER_SCHEMA_VERSION));
Assert.assertEquals(1, (int) events.get(EventMessage.EventType.ALTER_SCHEMA_VERSION));
Assert.assertEquals(1, (int) transactionalEvents.get(EventMessage.EventType.ALTER_SCHEMA_VERSION));
schemaVersion = client.getSchemaVersion(DEFAULT_DATABASE_NAME, schemaName, 1);
Assert.assertEquals(SchemaVersionState.INITIATED, schemaVersion.getState());
client.setSchemaVersionState(DEFAULT_DATABASE_NAME, schemaName, 1, SchemaVersionState.REVIEWED);
Assert.assertEquals(2, (int) preEvents.get(PreEventContext.PreEventType.ALTER_SCHEMA_VERSION));
Assert.assertEquals(2, (int) events.get(EventMessage.EventType.ALTER_SCHEMA_VERSION));
Assert.assertEquals(2, (int) transactionalEvents.get(EventMessage.EventType.ALTER_SCHEMA_VERSION));
schemaVersion = client.getSchemaVersion(DEFAULT_DATABASE_NAME, schemaName, 1);
Assert.assertEquals(SchemaVersionState.REVIEWED, schemaVersion.getState());
}
use of org.apache.hadoop.hive.metastore.api.SchemaVersion in project hive by apache.
the class TestHiveMetaStoreSchemaMethods method addDuplicateSchemaVersion.
@Test(expected = AlreadyExistsException.class)
public void addDuplicateSchemaVersion() throws TException {
String schemaName = uniqueSchemaName();
int version = 1;
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName).build();
client.createISchema(schema);
SchemaVersion schemaVersion = new SchemaVersionBuilder().versionOf(schema).setVersion(version).addCol("a", ColumnType.INT_TYPE_NAME).addCol("b", ColumnType.FLOAT_TYPE_NAME).build();
client.addSchemaVersion(schemaVersion);
client.addSchemaVersion(schemaVersion);
}
use of org.apache.hadoop.hive.metastore.api.SchemaVersion in project hive by apache.
the class TestHiveMetaStoreSchemaMethods method setVersionStateOtherDb.
@Test
public void setVersionStateOtherDb() throws TException {
String dbName = "other_db_set_state";
Database db = new DatabaseBuilder().setName(dbName).build();
client.createDatabase(db);
String schemaName = uniqueSchemaName();
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName).setDbName(dbName).build();
client.createISchema(schema);
SchemaVersion schemaVersion = new SchemaVersionBuilder().versionOf(schema).setVersion(1).addCol("a", ColumnType.BINARY_TYPE_NAME).build();
client.addSchemaVersion(schemaVersion);
schemaVersion = client.getSchemaVersion(dbName, schemaName, 1);
Assert.assertNull(schemaVersion.getState());
client.setSchemaVersionState(dbName, schemaName, 1, SchemaVersionState.INITIATED);
Assert.assertEquals(1, (int) preEvents.get(PreEventContext.PreEventType.ALTER_SCHEMA_VERSION));
Assert.assertEquals(1, (int) events.get(EventMessage.EventType.ALTER_SCHEMA_VERSION));
Assert.assertEquals(1, (int) transactionalEvents.get(EventMessage.EventType.ALTER_SCHEMA_VERSION));
schemaVersion = client.getSchemaVersion(dbName, schemaName, 1);
Assert.assertEquals(SchemaVersionState.INITIATED, schemaVersion.getState());
client.setSchemaVersionState(dbName, schemaName, 1, SchemaVersionState.REVIEWED);
Assert.assertEquals(2, (int) preEvents.get(PreEventContext.PreEventType.ALTER_SCHEMA_VERSION));
Assert.assertEquals(2, (int) events.get(EventMessage.EventType.ALTER_SCHEMA_VERSION));
Assert.assertEquals(2, (int) transactionalEvents.get(EventMessage.EventType.ALTER_SCHEMA_VERSION));
schemaVersion = client.getSchemaVersion(dbName, schemaName, 1);
Assert.assertEquals(SchemaVersionState.REVIEWED, schemaVersion.getState());
}
use of org.apache.hadoop.hive.metastore.api.SchemaVersion 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
}
}
Aggregations