Search in sources :

Example 31 with ISchema

use of org.apache.hadoop.hive.metastore.api.ISchema in project hive by apache.

the class TestObjectStoreSchemaMethods method schemaAlreadyExists.

@Test(expected = AlreadyExistsException.class)
public void schemaAlreadyExists() throws TException {
    String dbName = createUniqueDatabaseForTest();
    String schemaName = "schema2";
    ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.HIVE).setName(schemaName).setDbName(dbName).build();
    objectStore.createISchema(schema);
    schema = objectStore.getISchema(new ISchemaName(dbName, schemaName));
    Assert.assertNotNull(schema);
    Assert.assertEquals(SchemaType.HIVE, schema.getSchemaType());
    Assert.assertEquals(schemaName, schema.getName());
    Assert.assertEquals(SchemaCompatibility.BACKWARD, schema.getCompatibility());
    Assert.assertEquals(SchemaValidation.ALL, schema.getValidationLevel());
    Assert.assertTrue(schema.isCanEvolve());
    // This second attempt to create it should throw
    objectStore.createISchema(schema);
}
Also used : ISchemaBuilder(org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder) ISchema(org.apache.hadoop.hive.metastore.api.ISchema) ISchemaName(org.apache.hadoop.hive.metastore.api.ISchemaName) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 32 with ISchema

use of org.apache.hadoop.hive.metastore.api.ISchema in project hive by apache.

the class TestObjectStoreSchemaMethods method alterNonExistentSchema.

@Test(expected = NoSuchObjectException.class)
public void alterNonExistentSchema() throws MetaException, NoSuchObjectException {
    String schemaName = "noSuchSchema";
    ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.HIVE).setName(schemaName).setDescription("a new description").build();
    objectStore.alterISchema(new ISchemaName(DEFAULT_DATABASE_NAME, schemaName), schema);
}
Also used : ISchemaBuilder(org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder) ISchema(org.apache.hadoop.hive.metastore.api.ISchema) ISchemaName(org.apache.hadoop.hive.metastore.api.ISchemaName) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 33 with ISchema

use of org.apache.hadoop.hive.metastore.api.ISchema in project hive by apache.

the class TestObjectStoreSchemaMethods method iSchema.

@Test
public void iSchema() throws TException {
    String dbName = createUniqueDatabaseForTest();
    ISchema schema = objectStore.getISchema(new ISchemaName(dbName, "no.such.schema"));
    Assert.assertNull(schema);
    String schemaName = "schema1";
    String schemaGroup = "group1";
    String description = "This is a description";
    schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName).setDbName(dbName).setCompatibility(SchemaCompatibility.FORWARD).setValidationLevel(SchemaValidation.LATEST).setCanEvolve(false).setSchemaGroup(schemaGroup).setDescription(description).build();
    objectStore.createISchema(schema);
    schema = objectStore.getISchema(new ISchemaName(dbName, schemaName));
    Assert.assertNotNull(schema);
    Assert.assertEquals(SchemaType.AVRO, schema.getSchemaType());
    Assert.assertEquals(schemaName, schema.getName());
    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);
    objectStore.alterISchema(new ISchemaName(dbName, schemaName), schema);
    schema = objectStore.getISchema(new ISchemaName(dbName, schemaName));
    Assert.assertNotNull(schema);
    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());
    objectStore.dropISchema(new ISchemaName(dbName, schemaName));
    schema = objectStore.getISchema(new ISchemaName(dbName, schemaName));
    Assert.assertNull(schema);
}
Also used : ISchemaBuilder(org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder) ISchema(org.apache.hadoop.hive.metastore.api.ISchema) ISchemaName(org.apache.hadoop.hive.metastore.api.ISchemaName) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 34 with ISchema

use of org.apache.hadoop.hive.metastore.api.ISchema in project hive by apache.

the class ObjectStore method getISchema.

@Override
public ISchema getISchema(ISchemaName schemaName) throws MetaException {
    boolean committed = false;
    try {
        openTransaction();
        ISchema schema = convertToISchema(getMISchema(schemaName.getDbName(), schemaName.getSchemaName()));
        committed = commitTransaction();
        return schema;
    } finally {
        if (!committed)
            rollbackTransaction();
    }
}
Also used : MISchema(org.apache.hadoop.hive.metastore.model.MISchema) ISchema(org.apache.hadoop.hive.metastore.api.ISchema)

Aggregations

ISchema (org.apache.hadoop.hive.metastore.api.ISchema)34 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)33 ISchemaBuilder (org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder)33 Test (org.junit.Test)33 SchemaVersion (org.apache.hadoop.hive.metastore.api.SchemaVersion)16 SchemaVersionBuilder (org.apache.hadoop.hive.metastore.client.builder.SchemaVersionBuilder)16 ISchemaName (org.apache.hadoop.hive.metastore.api.ISchemaName)7 Database (org.apache.hadoop.hive.metastore.api.Database)5 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)5 DatabaseBuilder (org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder)5 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 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