use of org.apache.hadoop.hive.metastore.api.ISchema in project hive by apache.
the class TestHiveMetaStoreSchemaMethods method getLatestSchemaButNoVersions.
@Test(expected = NoSuchObjectException.class)
public void getLatestSchemaButNoVersions() throws TException {
String schemaName = uniqueSchemaName();
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName).build();
client.createISchema(schema);
client.getSchemaLatestVersion(DEFAULT_DATABASE_NAME, schemaName);
}
use of org.apache.hadoop.hive.metastore.api.ISchema in project hive by apache.
the class TestHiveMetaStoreSchemaMethods method mapSerdeToSchemaVersionOtherDb.
@Test
public void mapSerdeToSchemaVersionOtherDb() throws TException {
String dbName = "map_other_db";
Database db = new DatabaseBuilder().setName(dbName).build();
client.createDatabase(db);
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setDbName(dbName).setName(uniqueSchemaName()).build();
client.createISchema(schema);
// Create schema with no serde, then map it
SchemaVersion schemaVersion = new SchemaVersionBuilder().versionOf(schema).setVersion(1).addCol("x", ColumnType.BOOLEAN_TYPE_NAME).build();
client.addSchemaVersion(schemaVersion);
SerDeInfo serDeInfo = new SerDeInfo(uniqueSerdeName(), "lib", Collections.emptyMap());
client.addSerDe(serDeInfo);
client.mapSchemaVersionToSerde(dbName, schema.getName(), schemaVersion.getVersion(), serDeInfo.getName());
schemaVersion = client.getSchemaVersion(dbName, schema.getName(), schemaVersion.getVersion());
Assert.assertEquals(serDeInfo.getName(), schemaVersion.getSerDe().getName());
// Create schema with a serde, then remap it
String serDeName = uniqueSerdeName();
schemaVersion = new SchemaVersionBuilder().versionOf(schema).setVersion(2).addCol("x", ColumnType.BOOLEAN_TYPE_NAME).setSerdeName(serDeName).setSerdeLib("x").build();
client.addSchemaVersion(schemaVersion);
schemaVersion = client.getSchemaVersion(dbName, schema.getName(), 2);
Assert.assertEquals(serDeName, schemaVersion.getSerDe().getName());
serDeInfo = new SerDeInfo(uniqueSerdeName(), "y", Collections.emptyMap());
client.addSerDe(serDeInfo);
client.mapSchemaVersionToSerde(dbName, schema.getName(), 2, serDeInfo.getName());
schemaVersion = client.getSchemaVersion(dbName, schema.getName(), 2);
Assert.assertEquals(serDeInfo.getName(), schemaVersion.getSerDe().getName());
}
use of org.apache.hadoop.hive.metastore.api.ISchema 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.ISchema 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.ISchema 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("bogus", schemaName);
}
Aggregations