Search in sources :

Example 6 with ISchemaBuilder

use of org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder in project hive by apache.

the class TestHiveMetaStoreSchemaMethods method setVersionStateNoSuchVersion.

@Test(expected = NoSuchObjectException.class)
public void setVersionStateNoSuchVersion() throws TException {
    String schemaName = uniqueSchemaName();
    ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName).build();
    client.createISchema(schema);
    client.setSchemaVersionState(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, 1, SchemaVersionState.INITIATED);
}
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 7 with ISchemaBuilder

use of org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder 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_CATALOG_NAME, 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_CATALOG_NAME, 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());
}
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) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) SchemaVersionBuilder(org.apache.hadoop.hive.metastore.client.builder.SchemaVersionBuilder) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 8 with ISchemaBuilder

use of org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder 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_CATALOG_NAME, DEFAULT_DATABASE_NAME, schema.getName(), schemaVersion.getVersion(), uniqueSerdeName());
}
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 9 with ISchemaBuilder

use of org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder in project hive by apache.

the class TestHiveMetaStoreSchemaMethods method latestSchemaVersionBogusCatalog.

@Test(expected = NoSuchObjectException.class)
public void latestSchemaVersionBogusCatalog() throws TException {
    String schemaName = uniqueSchemaName();
    ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName).build();
    client.createISchema(schema);
    client.getSchemaLatestVersion("bogus", 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 10 with ISchemaBuilder

use of org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder 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_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, 1);
    Assert.assertNull(schemaVersion.getState());
    client.setSchemaVersionState(DEFAULT_CATALOG_NAME, 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_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, 1);
    Assert.assertEquals(SchemaVersionState.INITIATED, schemaVersion.getState());
    client.setSchemaVersionState(DEFAULT_CATALOG_NAME, 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_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, 1);
    Assert.assertEquals(SchemaVersionState.REVIEWED, schemaVersion.getState());
}
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)

Aggregations

MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)36 ISchema (org.apache.hadoop.hive.metastore.api.ISchema)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