Search in sources :

Example 31 with ISchemaBuilder

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

the class TestHiveMetaStoreSchemaMethods method latestSchemaVersionBogusDb.

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

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

the class TestObjectStoreSchemaMethods method schemaQuery.

@Test
public void schemaQuery() throws TException {
    Database db = createUniqueDatabaseForTest();
    String schemaName1 = "a_schema1";
    ISchema schema1 = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName1).inDb(db).build();
    objectStore.createISchema(schema1);
    String schemaName2 = "a_schema2";
    ISchema schema2 = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName2).inDb(db).build();
    objectStore.createISchema(schema2);
    SchemaVersion schemaVersion1_1 = new SchemaVersionBuilder().versionOf(schema1).setVersion(1).addCol("alpha", ColumnType.BIGINT_TYPE_NAME).addCol("beta", ColumnType.DATE_TYPE_NAME).build();
    objectStore.addSchemaVersion(schemaVersion1_1);
    SchemaVersion schemaVersion1_2 = new SchemaVersionBuilder().versionOf(schema1).setVersion(2).addCol("alpha", ColumnType.BIGINT_TYPE_NAME).addCol("beta", ColumnType.DATE_TYPE_NAME).addCol("gamma", ColumnType.BIGINT_TYPE_NAME, "namespace=x").build();
    objectStore.addSchemaVersion(schemaVersion1_2);
    SchemaVersion schemaVersion2_1 = new SchemaVersionBuilder().versionOf(schema2).setVersion(1).addCol("ALPHA", ColumnType.SMALLINT_TYPE_NAME).addCol("delta", ColumnType.DOUBLE_TYPE_NAME).build();
    objectStore.addSchemaVersion(schemaVersion2_1);
    SchemaVersion schemaVersion2_2 = new SchemaVersionBuilder().versionOf(schema2).setVersion(2).addCol("ALPHA", ColumnType.SMALLINT_TYPE_NAME).addCol("delta", ColumnType.DOUBLE_TYPE_NAME).addCol("epsilon", ColumnType.STRING_TYPE_NAME, "namespace=x").build();
    objectStore.addSchemaVersion(schemaVersion2_2);
    // Query that should return nothing
    List<SchemaVersion> results = objectStore.getSchemaVersionsByColumns("x", "y", "z");
    Assert.assertEquals(0, results.size());
    // Query that should fetch one column
    results = objectStore.getSchemaVersionsByColumns("gamma", null, null);
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(schemaName1, results.get(0).getSchema().getSchemaName());
    Assert.assertEquals(db.getName(), results.get(0).getSchema().getDbName());
    Assert.assertEquals(db.getCatalogName(), results.get(0).getSchema().getCatName());
    Assert.assertEquals(2, results.get(0).getVersion());
    // fetch 2 in same schema
    results = objectStore.getSchemaVersionsByColumns("beta", null, null);
    Assert.assertEquals(2, results.size());
    Collections.sort(results);
    Assert.assertEquals(schemaName1, results.get(0).getSchema().getSchemaName());
    Assert.assertEquals(db.getName(), results.get(0).getSchema().getDbName());
    Assert.assertEquals(db.getCatalogName(), results.get(0).getSchema().getCatName());
    Assert.assertEquals(1, results.get(0).getVersion());
    Assert.assertEquals(schemaName1, results.get(1).getSchema().getSchemaName());
    Assert.assertEquals(db.getName(), results.get(1).getSchema().getDbName());
    Assert.assertEquals(db.getCatalogName(), results.get(1).getSchema().getCatName());
    Assert.assertEquals(2, results.get(1).getVersion());
    // fetch across schemas
    results = objectStore.getSchemaVersionsByColumns("alpha", null, null);
    Assert.assertEquals(4, results.size());
    Collections.sort(results);
    Assert.assertEquals(schemaName1, results.get(0).getSchema().getSchemaName());
    Assert.assertEquals(db.getName(), results.get(0).getSchema().getDbName());
    Assert.assertEquals(db.getCatalogName(), results.get(0).getSchema().getCatName());
    Assert.assertEquals(1, results.get(0).getVersion());
    Assert.assertEquals(schemaName1, results.get(1).getSchema().getSchemaName());
    Assert.assertEquals(db.getName(), results.get(1).getSchema().getDbName());
    Assert.assertEquals(db.getCatalogName(), results.get(1).getSchema().getCatName());
    Assert.assertEquals(2, results.get(1).getVersion());
    Assert.assertEquals(schemaName2, results.get(2).getSchema().getSchemaName());
    Assert.assertEquals(db.getName(), results.get(2).getSchema().getDbName());
    Assert.assertEquals(db.getCatalogName(), results.get(2).getSchema().getCatName());
    Assert.assertEquals(1, results.get(2).getVersion());
    Assert.assertEquals(schemaName2, results.get(3).getSchema().getSchemaName());
    Assert.assertEquals(db.getName(), results.get(3).getSchema().getDbName());
    Assert.assertEquals(db.getCatalogName(), results.get(3).getSchema().getCatName());
    Assert.assertEquals(2, results.get(3).getVersion());
    // fetch by namespace
    results = objectStore.getSchemaVersionsByColumns(null, "namespace=x", null);
    Assert.assertEquals(2, results.size());
    Collections.sort(results);
    Assert.assertEquals(schemaName1, results.get(0).getSchema().getSchemaName());
    Assert.assertEquals(db.getName(), results.get(0).getSchema().getDbName());
    Assert.assertEquals(db.getCatalogName(), results.get(0).getSchema().getCatName());
    Assert.assertEquals(2, results.get(0).getVersion());
    Assert.assertEquals(schemaName2, results.get(1).getSchema().getSchemaName());
    Assert.assertEquals(db.getName(), results.get(1).getSchema().getDbName());
    Assert.assertEquals(db.getCatalogName(), results.get(1).getSchema().getCatName());
    Assert.assertEquals(2, results.get(1).getVersion());
    // fetch by name and type
    results = objectStore.getSchemaVersionsByColumns("alpha", null, ColumnType.SMALLINT_TYPE_NAME);
    Assert.assertEquals(2, results.size());
    Collections.sort(results);
    Assert.assertEquals(schemaName2, results.get(0).getSchema().getSchemaName());
    Assert.assertEquals(db.getName(), results.get(0).getSchema().getDbName());
    Assert.assertEquals(db.getCatalogName(), results.get(0).getSchema().getCatName());
    Assert.assertEquals(1, results.get(0).getVersion());
    Assert.assertEquals(schemaName2, results.get(1).getSchema().getSchemaName());
    Assert.assertEquals(db.getName(), results.get(1).getSchema().getDbName());
    Assert.assertEquals(db.getCatalogName(), results.get(1).getSchema().getCatName());
    Assert.assertEquals(2, results.get(1).getVersion());
    // Make sure matching name but wrong type doesn't return
    results = objectStore.getSchemaVersionsByColumns("alpha", null, ColumnType.STRING_TYPE_NAME);
    Assert.assertEquals(0, results.size());
}
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) Database(org.apache.hadoop.hive.metastore.api.Database) SchemaVersionBuilder(org.apache.hadoop.hive.metastore.client.builder.SchemaVersionBuilder) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 33 with ISchemaBuilder

use of org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder 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_CATALOG_NAME, 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 34 with ISchemaBuilder

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

the class TestObjectStoreSchemaMethods method iSchema.

@Test
public void iSchema() throws TException {
    Database db = createUniqueDatabaseForTest();
    ISchema schema = objectStore.getISchema(new ISchemaName(db.getCatalogName(), db.getName(), "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).inDb(db).setCompatibility(SchemaCompatibility.FORWARD).setValidationLevel(SchemaValidation.LATEST).setCanEvolve(false).setSchemaGroup(schemaGroup).setDescription(description).build();
    objectStore.createISchema(schema);
    schema = objectStore.getISchema(new ISchemaName(db.getCatalogName(), db.getName(), 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(db.getCatalogName(), db.getName(), schemaName), schema);
    schema = objectStore.getISchema(new ISchemaName(db.getCatalogName(), db.getName(), 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(db.getCatalogName(), db.getName(), schemaName));
    schema = objectStore.getISchema(new ISchemaName(db.getCatalogName(), db.getName(), schemaName));
    Assert.assertNull(schema);
}
Also used : ISchemaBuilder(org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder) ISchema(org.apache.hadoop.hive.metastore.api.ISchema) Database(org.apache.hadoop.hive.metastore.api.Database) ISchemaName(org.apache.hadoop.hive.metastore.api.ISchemaName) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 35 with ISchemaBuilder

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

the class TestObjectStoreSchemaMethods method schemaWithInvalidDatabase.

@Test(expected = NoSuchObjectException.class)
public void schemaWithInvalidDatabase() throws MetaException, AlreadyExistsException, NoSuchObjectException {
    ISchema schema = new ISchemaBuilder().setName("thisSchemaDoesntHaveADb").setDbName("no.such.database").setSchemaType(SchemaType.AVRO).build();
    objectStore.createISchema(schema);
}
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)

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