Search in sources :

Example 21 with SchemaVersion

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

the class TestObjectStoreSchemaMethods method alterNonExistentSchemaVersion.

@Test(expected = NoSuchObjectException.class)
public void alterNonExistentSchemaVersion() throws MetaException, AlreadyExistsException, NoSuchObjectException {
    String schemaName = "schema3723asdflj";
    int version = 37;
    SchemaVersion schemaVersion = new SchemaVersionBuilder().setSchemaName(schemaName).setDbName(DEFAULT_DATABASE_NAME).setVersion(version).addCol("a", ColumnType.INT_TYPE_NAME).addCol("b", ColumnType.FLOAT_TYPE_NAME).setState(SchemaVersionState.INITIATED).build();
    objectStore.alterSchemaVersion(new SchemaVersionDescriptor(new ISchemaName(DEFAULT_DATABASE_NAME, schemaName), version), schemaVersion);
}
Also used : SchemaVersion(org.apache.hadoop.hive.metastore.api.SchemaVersion) SchemaVersionDescriptor(org.apache.hadoop.hive.metastore.api.SchemaVersionDescriptor) SchemaVersionBuilder(org.apache.hadoop.hive.metastore.client.builder.SchemaVersionBuilder) ISchemaName(org.apache.hadoop.hive.metastore.api.ISchemaName) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 22 with SchemaVersion

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

the class TestObjectStoreSchemaMethods method schemaQuery.

@Test
public void schemaQuery() throws TException {
    String dbName = createUniqueDatabaseForTest();
    String schemaName1 = "a_schema1";
    ISchema schema1 = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName1).setDbName(dbName).build();
    objectStore.createISchema(schema1);
    String schemaName2 = "a_schema2";
    ISchema schema2 = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName2).setDbName(dbName).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(dbName, results.get(0).getSchema().getDbName());
    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(dbName, results.get(0).getSchema().getDbName());
    Assert.assertEquals(1, results.get(0).getVersion());
    Assert.assertEquals(schemaName1, results.get(1).getSchema().getSchemaName());
    Assert.assertEquals(dbName, results.get(1).getSchema().getDbName());
    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(dbName, results.get(0).getSchema().getDbName());
    Assert.assertEquals(1, results.get(0).getVersion());
    Assert.assertEquals(schemaName1, results.get(1).getSchema().getSchemaName());
    Assert.assertEquals(dbName, results.get(1).getSchema().getDbName());
    Assert.assertEquals(2, results.get(1).getVersion());
    Assert.assertEquals(schemaName2, results.get(2).getSchema().getSchemaName());
    Assert.assertEquals(dbName, results.get(2).getSchema().getDbName());
    Assert.assertEquals(1, results.get(2).getVersion());
    Assert.assertEquals(schemaName2, results.get(3).getSchema().getSchemaName());
    Assert.assertEquals(dbName, results.get(3).getSchema().getDbName());
    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(dbName, results.get(0).getSchema().getDbName());
    Assert.assertEquals(2, results.get(0).getVersion());
    Assert.assertEquals(schemaName2, results.get(1).getSchema().getSchemaName());
    Assert.assertEquals(dbName, results.get(1).getSchema().getDbName());
    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(dbName, results.get(0).getSchema().getDbName());
    Assert.assertEquals(1, results.get(0).getVersion());
    Assert.assertEquals(schemaName2, results.get(1).getSchema().getSchemaName());
    Assert.assertEquals(dbName, results.get(1).getSchema().getDbName());
    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) SchemaVersionBuilder(org.apache.hadoop.hive.metastore.client.builder.SchemaVersionBuilder) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 23 with SchemaVersion

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

the class TestObjectStoreSchemaMethods method createVersionOfNonExistentSchema.

@Test(expected = NoSuchObjectException.class)
public void createVersionOfNonExistentSchema() throws MetaException, AlreadyExistsException, NoSuchObjectException, InvalidObjectException {
    SchemaVersion schemaVersion = new SchemaVersionBuilder().setSchemaName("noSchemaOfThisNameExists").setDbName(DEFAULT_DATABASE_NAME).setVersion(1).addCol("a", ColumnType.STRING_TYPE_NAME).build();
    objectStore.addSchemaVersion(schemaVersion);
}
Also used : SchemaVersion(org.apache.hadoop.hive.metastore.api.SchemaVersion) SchemaVersionBuilder(org.apache.hadoop.hive.metastore.client.builder.SchemaVersionBuilder) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 24 with SchemaVersion

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

the class ObjectStore method getAllSchemaVersion.

@Override
public List<SchemaVersion> getAllSchemaVersion(ISchemaName schemaName) throws MetaException {
    boolean committed = false;
    Query query = null;
    try {
        openTransaction();
        String name = normalizeIdentifier(schemaName.getSchemaName());
        String dbName = normalizeIdentifier(schemaName.getDbName());
        query = pm.newQuery(MSchemaVersion.class, "iSchema.name == schemaName && iSchema.db.name == dbName");
        query.declareParameters("java.lang.String schemaName, java.lang.String dbName");
        query.setOrdering("version descending");
        List<MSchemaVersion> mSchemaVersions = query.setParameters(name, dbName).executeList();
        pm.retrieveAll(mSchemaVersions);
        if (mSchemaVersions == null || mSchemaVersions.isEmpty())
            return null;
        List<SchemaVersion> schemaVersions = new ArrayList<>(mSchemaVersions.size());
        for (MSchemaVersion mSchemaVersion : mSchemaVersions) {
            pm.retrieveAll(mSchemaVersion.getCols());
            if (mSchemaVersion.getSerDe() != null)
                pm.retrieve(mSchemaVersion.getSerDe());
            schemaVersions.add(convertToSchemaVersion(mSchemaVersion));
        }
        committed = commitTransaction();
        return schemaVersions;
    } finally {
        rollbackAndCleanup(committed, query);
    }
}
Also used : MSchemaVersion(org.apache.hadoop.hive.metastore.model.MSchemaVersion) Query(javax.jdo.Query) SchemaVersion(org.apache.hadoop.hive.metastore.api.SchemaVersion) MSchemaVersion(org.apache.hadoop.hive.metastore.model.MSchemaVersion) ArrayList(java.util.ArrayList)

Aggregations

SchemaVersion (org.apache.hadoop.hive.metastore.api.SchemaVersion)24 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)19 SchemaVersionBuilder (org.apache.hadoop.hive.metastore.client.builder.SchemaVersionBuilder)19 Test (org.junit.Test)19 ISchema (org.apache.hadoop.hive.metastore.api.ISchema)16 ISchemaBuilder (org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder)16 ISchemaName (org.apache.hadoop.hive.metastore.api.ISchemaName)6 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)5 SchemaVersionDescriptor (org.apache.hadoop.hive.metastore.api.SchemaVersionDescriptor)5 Database (org.apache.hadoop.hive.metastore.api.Database)4 DatabaseBuilder (org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder)4 MSchemaVersion (org.apache.hadoop.hive.metastore.model.MSchemaVersion)4 ArrayList (java.util.ArrayList)3 Query (javax.jdo.Query)3 SerDeInfo (org.apache.hadoop.hive.metastore.api.SerDeInfo)3 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FindSchemasByColsResp (org.apache.hadoop.hive.metastore.api.FindSchemasByColsResp)1