use of org.apache.hadoop.hive.metastore.api.ISchema in project hive by apache.
the class TestHiveMetaStoreSchemaMethods method iSchema.
@Test
public void iSchema() throws TException {
String schemaName = uniqueSchemaName();
String schemaGroup = "group1";
String description = "This is a description";
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName).setCompatibility(SchemaCompatibility.FORWARD).setValidationLevel(SchemaValidation.LATEST).setCanEvolve(false).setSchemaGroup(schemaGroup).setDescription(description).build();
client.createISchema(schema);
Assert.assertEquals(1, (int) preEvents.get(PreEventContext.PreEventType.CREATE_ISCHEMA));
Assert.assertEquals(1, (int) events.get(EventMessage.EventType.CREATE_ISCHEMA));
Assert.assertEquals(1, (int) transactionalEvents.get(EventMessage.EventType.CREATE_ISCHEMA));
schema = client.getISchema(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName);
Assert.assertEquals(1, (int) preEvents.get(PreEventContext.PreEventType.READ_ISCHEMA));
Assert.assertEquals(SchemaType.AVRO, schema.getSchemaType());
Assert.assertEquals(schemaName, schema.getName());
Assert.assertEquals(DEFAULT_CATALOG_NAME, schema.getCatName());
Assert.assertEquals(DEFAULT_DATABASE_NAME, schema.getDbName());
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);
client.alterISchema(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, schema);
Assert.assertEquals(1, (int) preEvents.get(PreEventContext.PreEventType.ALTER_ISCHEMA));
Assert.assertEquals(1, (int) events.get(EventMessage.EventType.ALTER_ISCHEMA));
Assert.assertEquals(1, (int) transactionalEvents.get(EventMessage.EventType.ALTER_ISCHEMA));
schema = client.getISchema(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName);
Assert.assertEquals(2, (int) preEvents.get(PreEventContext.PreEventType.READ_ISCHEMA));
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());
client.dropISchema(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName);
Assert.assertEquals(1, (int) preEvents.get(PreEventContext.PreEventType.DROP_ISCHEMA));
Assert.assertEquals(1, (int) events.get(EventMessage.EventType.DROP_ISCHEMA));
Assert.assertEquals(1, (int) transactionalEvents.get(EventMessage.EventType.DROP_ISCHEMA));
try {
client.getISchema(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName);
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 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_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName);
}
use of org.apache.hadoop.hive.metastore.api.ISchema in project hive by apache.
the class TestHiveMetaStoreSchemaMethods method mapSerdeToSchemaVersion.
@Test
public void mapSerdeToSchemaVersion() throws TException {
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).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(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schema.getName(), schemaVersion.getVersion(), serDeInfo.getName());
schemaVersion = client.getSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, 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(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schema.getName(), 2);
Assert.assertEquals(serDeName, schemaVersion.getSerDe().getName());
serDeInfo = new SerDeInfo(uniqueSerdeName(), "y", Collections.emptyMap());
client.addSerDe(serDeInfo);
client.mapSchemaVersionToSerde(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schema.getName(), 2, serDeInfo.getName());
schemaVersion = client.getSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, 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 nonExistentSchemaVersionButOtherVersionsExist.
@Test(expected = NoSuchObjectException.class)
public void nonExistentSchemaVersionButOtherVersionsExist() 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.INT_TYPE_NAME).addCol("b", ColumnType.FLOAT_TYPE_NAME).build();
client.addSchemaVersion(schemaVersion);
client.getSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, 2);
}
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 catName = "other_cat_for_map_to";
Catalog cat = new CatalogBuilder().setName(catName).setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)).build();
client.createCatalog(cat);
String dbName = "map_other_db";
Database db = new DatabaseBuilder().setName(dbName).setCatalogName(catName).create(client, conf);
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).inDb(db).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(catName, dbName, schema.getName(), schemaVersion.getVersion(), serDeInfo.getName());
schemaVersion = client.getSchemaVersion(catName, 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(catName, dbName, schema.getName(), 2);
Assert.assertEquals(serDeName, schemaVersion.getSerDe().getName());
serDeInfo = new SerDeInfo(uniqueSerdeName(), "y", Collections.emptyMap());
client.addSerDe(serDeInfo);
client.mapSchemaVersionToSerde(catName, dbName, schema.getName(), 2, serDeInfo.getName());
schemaVersion = client.getSchemaVersion(catName, dbName, schema.getName(), 2);
Assert.assertEquals(serDeInfo.getName(), schemaVersion.getSerDe().getName());
}
Aggregations