use of org.apache.hadoop.hive.metastore.api.ISchema in project hive by apache.
the class TestHiveMetaStoreSchemaMethods method getAllSchemaButNoVersions.
@Test(expected = NoSuchObjectException.class)
public void getAllSchemaButNoVersions() throws TException {
String schemaName = uniqueSchemaName();
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName).build();
client.createISchema(schema);
client.getSchemaAllVersions(DEFAULT_DATABASE_NAME, schemaName);
}
use of org.apache.hadoop.hive.metastore.api.ISchema in project hive by apache.
the class TestHiveMetaStoreSchemaMethods method mapNonExistentSerdeToSchemaVersion.
@Test(expected = NoSuchObjectException.class)
public void mapNonExistentSerdeToSchemaVersion() throws TException {
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(uniqueSchemaName()).build();
client.createISchema(schema);
SchemaVersion schemaVersion = new SchemaVersionBuilder().versionOf(schema).setVersion(1).addCol("x", ColumnType.BOOLEAN_TYPE_NAME).build();
client.addSchemaVersion(schemaVersion);
client.mapSchemaVersionToSerde(DEFAULT_DATABASE_NAME, schema.getName(), schemaVersion.getVersion(), uniqueSerdeName());
}
use of org.apache.hadoop.hive.metastore.api.ISchema in project hive by apache.
the class TestHiveMetaStoreSchemaMethods method iSchemaOtherDatabase.
@Test
public void iSchemaOtherDatabase() throws TException {
String dbName = "other_db";
Database db = new DatabaseBuilder().setName(dbName).build();
client.createDatabase(db);
String schemaName = uniqueSchemaName();
String schemaGroup = "group1";
String description = "This is a description";
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName).setDbName(dbName).setCompatibility(SchemaCompatibility.FORWARD).setValidationLevel(SchemaValidation.LATEST).setCanEvolve(false).setSchemaGroup(schemaGroup).setDescription(description).build();
client.createISchema(schema);
schema = client.getISchema(dbName, schemaName);
Assert.assertEquals(SchemaType.AVRO, schema.getSchemaType());
Assert.assertEquals(schemaName, schema.getName());
Assert.assertEquals(dbName, 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(dbName, schemaName, schema);
schema = client.getISchema(dbName, schemaName);
Assert.assertEquals(SchemaType.AVRO, schema.getSchemaType());
Assert.assertEquals(schemaName, schema.getName());
Assert.assertEquals(dbName, schema.getDbName());
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(dbName, schemaName);
try {
client.getISchema(dbName, 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 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_DATABASE_NAME, schemaName, 2);
}
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_DATABASE_NAME, schema.getName(), schemaVersion.getVersion(), serDeInfo.getName());
schemaVersion = client.getSchemaVersion(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_DATABASE_NAME, schema.getName(), 2);
Assert.assertEquals(serDeName, schemaVersion.getSerDe().getName());
serDeInfo = new SerDeInfo(uniqueSerdeName(), "y", Collections.emptyMap());
client.addSerDe(serDeInfo);
client.mapSchemaVersionToSerde(DEFAULT_DATABASE_NAME, schema.getName(), 2, serDeInfo.getName());
schemaVersion = client.getSchemaVersion(DEFAULT_DATABASE_NAME, schema.getName(), 2);
Assert.assertEquals(serDeInfo.getName(), schemaVersion.getSerDe().getName());
}
Aggregations