Search in sources :

Example 1 with ISchema

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
    }
}
Also used : ISchemaBuilder(org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder) ISchema(org.apache.hadoop.hive.metastore.api.ISchema) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 2 with ISchema

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);
}
Also used : ISchemaBuilder(org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder) ISchema(org.apache.hadoop.hive.metastore.api.ISchema) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 3 with ISchema

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());
}
Also used : ISchemaBuilder(org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder) SchemaVersion(org.apache.hadoop.hive.metastore.api.SchemaVersion) ISchema(org.apache.hadoop.hive.metastore.api.ISchema) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) SchemaVersionBuilder(org.apache.hadoop.hive.metastore.client.builder.SchemaVersionBuilder) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 4 with ISchema

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);
}
Also used : ISchemaBuilder(org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder) SchemaVersion(org.apache.hadoop.hive.metastore.api.SchemaVersion) ISchema(org.apache.hadoop.hive.metastore.api.ISchema) SchemaVersionBuilder(org.apache.hadoop.hive.metastore.client.builder.SchemaVersionBuilder) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 5 with ISchema

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());
}
Also used : DatabaseBuilder(org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder) ISchemaBuilder(org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder) SchemaVersion(org.apache.hadoop.hive.metastore.api.SchemaVersion) CatalogBuilder(org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder) ISchema(org.apache.hadoop.hive.metastore.api.ISchema) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) Database(org.apache.hadoop.hive.metastore.api.Database) SchemaVersionBuilder(org.apache.hadoop.hive.metastore.client.builder.SchemaVersionBuilder) Catalog(org.apache.hadoop.hive.metastore.api.Catalog) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Aggregations

ISchema (org.apache.hadoop.hive.metastore.api.ISchema)37 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)36 ISchemaBuilder (org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder)36 Test (org.junit.Test)36 SchemaVersion (org.apache.hadoop.hive.metastore.api.SchemaVersion)16 SchemaVersionBuilder (org.apache.hadoop.hive.metastore.client.builder.SchemaVersionBuilder)16 Database (org.apache.hadoop.hive.metastore.api.Database)12 ISchemaName (org.apache.hadoop.hive.metastore.api.ISchemaName)7 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)5 DatabaseBuilder (org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder)5 Catalog (org.apache.hadoop.hive.metastore.api.Catalog)4 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)4 SchemaVersionDescriptor (org.apache.hadoop.hive.metastore.api.SchemaVersionDescriptor)4 SerDeInfo (org.apache.hadoop.hive.metastore.api.SerDeInfo)4 CatalogBuilder (org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder)4 ArrayList (java.util.ArrayList)1 FindSchemasByColsResp (org.apache.hadoop.hive.metastore.api.FindSchemasByColsResp)1 FindSchemasByColsRqst (org.apache.hadoop.hive.metastore.api.FindSchemasByColsRqst)1 MISchema (org.apache.hadoop.hive.metastore.model.MISchema)1