use of org.apache.hadoop.hive.metastore.api.SchemaVersionDescriptor in project hive by apache.
the class TestHiveMetaStoreSchemaMethods method schemaQuery.
@Test
public void schemaQuery() throws TException {
String dbName = "schema_query_db";
Database db = new DatabaseBuilder().setName(dbName).create(client, conf);
String schemaName1 = uniqueSchemaName();
ISchema schema1 = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setDbName(dbName).setName(schemaName1).build();
client.createISchema(schema1);
String schemaName2 = uniqueSchemaName();
ISchema schema2 = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setDbName(dbName).setName(schemaName2).build();
client.createISchema(schema2);
SchemaVersion schemaVersion1_1 = new SchemaVersionBuilder().versionOf(schema1).setVersion(1).addCol("alpha", ColumnType.BIGINT_TYPE_NAME).addCol("beta", ColumnType.DATE_TYPE_NAME).build();
client.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();
client.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();
client.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();
client.addSchemaVersion(schemaVersion2_2);
// Query that should return nothing
FindSchemasByColsRqst rqst = new FindSchemasByColsRqst();
rqst.setColName("x");
rqst.setColNamespace("y");
rqst.setType("z");
FindSchemasByColsResp rsp = client.getSchemaByCols(rqst);
Assert.assertEquals(0, rsp.getSchemaVersionsSize());
// Query that should fetch one column
rqst = new FindSchemasByColsRqst();
rqst.setColName("gamma");
rsp = client.getSchemaByCols(rqst);
Assert.assertEquals(1, rsp.getSchemaVersionsSize());
Assert.assertEquals(schemaName1, rsp.getSchemaVersions().get(0).getSchema().getSchemaName());
Assert.assertEquals(dbName, rsp.getSchemaVersions().get(0).getSchema().getDbName());
Assert.assertEquals(2, rsp.getSchemaVersions().get(0).getVersion());
// fetch 2 in same schema
rqst = new FindSchemasByColsRqst();
rqst.setColName("beta");
rsp = client.getSchemaByCols(rqst);
Assert.assertEquals(2, rsp.getSchemaVersionsSize());
List<SchemaVersionDescriptor> results = new ArrayList<>(rsp.getSchemaVersions());
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
rqst = new FindSchemasByColsRqst();
rqst.setColName("alpha");
rsp = client.getSchemaByCols(rqst);
Assert.assertEquals(4, rsp.getSchemaVersionsSize());
results = new ArrayList<>(rsp.getSchemaVersions());
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
rqst = new FindSchemasByColsRqst();
rqst.setColNamespace("namespace=x");
rsp = client.getSchemaByCols(rqst);
Assert.assertEquals(2, rsp.getSchemaVersionsSize());
results = new ArrayList<>(rsp.getSchemaVersions());
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
rqst = new FindSchemasByColsRqst();
rqst.setColName("alpha");
rqst.setType(ColumnType.SMALLINT_TYPE_NAME);
rsp = client.getSchemaByCols(rqst);
Assert.assertEquals(2, rsp.getSchemaVersionsSize());
results = new ArrayList<>(rsp.getSchemaVersions());
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
rqst = new FindSchemasByColsRqst();
rqst.setColName("alpha");
rqst.setType(ColumnType.STRING_TYPE_NAME);
rsp = client.getSchemaByCols(rqst);
Assert.assertEquals(0, rsp.getSchemaVersionsSize());
}
use of org.apache.hadoop.hive.metastore.api.SchemaVersionDescriptor in project hive by apache.
the class TestObjectStoreSchemaMethods method addDuplicateSchemaVersion.
@Test(expected = AlreadyExistsException.class)
public void addDuplicateSchemaVersion() throws TException {
Database db = createUniqueDatabaseForTest();
String schemaName = "schema1234";
int version = 1;
SchemaVersion schemaVersion = objectStore.getSchemaVersion(new SchemaVersionDescriptor(new ISchemaName(db.getCatalogName(), db.getName(), schemaName), version));
Assert.assertNull(schemaVersion);
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName).inDb(db).build();
objectStore.createISchema(schema);
schemaVersion = new SchemaVersionBuilder().versionOf(schema).setVersion(version).addCol("a", ColumnType.INT_TYPE_NAME).addCol("b", ColumnType.FLOAT_TYPE_NAME).build();
objectStore.addSchemaVersion(schemaVersion);
objectStore.addSchemaVersion(schemaVersion);
}
use of org.apache.hadoop.hive.metastore.api.SchemaVersionDescriptor in project hive by apache.
the class TestObjectStoreSchemaMethods method addSchemaVersion.
@Test
public void addSchemaVersion() throws TException {
Database db = createUniqueDatabaseForTest();
String schemaName = "schema37";
int version = 1;
SchemaVersion schemaVersion = objectStore.getSchemaVersion(new SchemaVersionDescriptor(new ISchemaName(db.getCatalogName(), db.getName(), schemaName), version));
Assert.assertNull(schemaVersion);
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName).inDb(db).build();
objectStore.createISchema(schema);
String description = "very descriptive";
String schemaText = "this should look like json, but oh well";
String fingerprint = "this should be an md5 string";
String versionName = "why would I name a version?";
long creationTime = 10;
String serdeName = "serde_for_schema37";
String serializer = "org.apache.hadoop.hive.metastore.test.Serializer";
String deserializer = "org.apache.hadoop.hive.metastore.test.Deserializer";
String serdeDescription = "how do you describe a serde?";
schemaVersion = new SchemaVersionBuilder().versionOf(schema).setVersion(version).addCol("a", ColumnType.INT_TYPE_NAME).addCol("b", ColumnType.FLOAT_TYPE_NAME).setCreatedAt(creationTime).setState(SchemaVersionState.INITIATED).setDescription(description).setSchemaText(schemaText).setFingerprint(fingerprint).setName(versionName).setSerdeName(serdeName).setSerdeSerializerClass(serializer).setSerdeDeserializerClass(deserializer).setSerdeDescription(serdeDescription).build();
objectStore.addSchemaVersion(schemaVersion);
schemaVersion = objectStore.getSchemaVersion(new SchemaVersionDescriptor(new ISchemaName(db.getCatalogName(), db.getName(), schemaName), version));
Assert.assertNotNull(schemaVersion);
Assert.assertEquals(schemaName, schemaVersion.getSchema().getSchemaName());
Assert.assertEquals(db.getName(), schemaVersion.getSchema().getDbName());
Assert.assertEquals(db.getCatalogName(), schemaVersion.getSchema().getCatName());
Assert.assertEquals(version, schemaVersion.getVersion());
Assert.assertEquals(creationTime, schemaVersion.getCreatedAt());
Assert.assertEquals(SchemaVersionState.INITIATED, schemaVersion.getState());
Assert.assertEquals(description, schemaVersion.getDescription());
Assert.assertEquals(schemaText, schemaVersion.getSchemaText());
Assert.assertEquals(fingerprint, schemaVersion.getFingerprint());
Assert.assertEquals(versionName, schemaVersion.getName());
Assert.assertEquals(serdeName, schemaVersion.getSerDe().getName());
Assert.assertEquals(serializer, schemaVersion.getSerDe().getSerializerClass());
Assert.assertEquals(deserializer, schemaVersion.getSerDe().getDeserializerClass());
Assert.assertEquals(serdeDescription, schemaVersion.getSerDe().getDescription());
Assert.assertEquals(2, schemaVersion.getColsSize());
List<FieldSchema> cols = schemaVersion.getCols();
Collections.sort(cols);
Assert.assertEquals("a", cols.get(0).getName());
Assert.assertEquals(ColumnType.INT_TYPE_NAME, cols.get(0).getType());
Assert.assertEquals("b", cols.get(1).getName());
Assert.assertEquals(ColumnType.FLOAT_TYPE_NAME, cols.get(1).getType());
objectStore.dropSchemaVersion(new SchemaVersionDescriptor(new ISchemaName(db.getCatalogName(), db.getName(), schemaName), version));
schemaVersion = objectStore.getSchemaVersion(new SchemaVersionDescriptor(new ISchemaName(db.getCatalogName(), db.getName(), schemaName), version));
Assert.assertNull(schemaVersion);
}
use of org.apache.hadoop.hive.metastore.api.SchemaVersionDescriptor in project hive by apache.
the class TestObjectStoreSchemaMethods method alterSchemaVersion.
@Test
public void alterSchemaVersion() throws TException {
Database db = createUniqueDatabaseForTest();
String schemaName = "schema371234";
int version = 1;
SchemaVersion schemaVersion = objectStore.getSchemaVersion(new SchemaVersionDescriptor(new ISchemaName(db.getCatalogName(), db.getName(), schemaName), version));
Assert.assertNull(schemaVersion);
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).setName(schemaName).inDb(db).build();
objectStore.createISchema(schema);
schemaVersion = new SchemaVersionBuilder().versionOf(schema).setVersion(version).addCol("a", ColumnType.INT_TYPE_NAME).addCol("b", ColumnType.FLOAT_TYPE_NAME).setState(SchemaVersionState.INITIATED).build();
objectStore.addSchemaVersion(schemaVersion);
schemaVersion = objectStore.getSchemaVersion(new SchemaVersionDescriptor(new ISchemaName(db.getCatalogName(), db.getName(), schemaName), version));
Assert.assertNotNull(schemaVersion);
Assert.assertEquals(schemaName, schemaVersion.getSchema().getSchemaName());
Assert.assertEquals(db.getName(), schemaVersion.getSchema().getDbName());
Assert.assertEquals(db.getCatalogName(), schemaVersion.getSchema().getCatName());
Assert.assertEquals(version, schemaVersion.getVersion());
Assert.assertEquals(SchemaVersionState.INITIATED, schemaVersion.getState());
schemaVersion.setState(SchemaVersionState.REVIEWED);
String serdeName = "serde for " + schemaName;
SerDeInfo serde = new SerDeInfo(serdeName, "", Collections.emptyMap());
String serializer = "org.apache.hadoop.hive.metastore.test.Serializer";
String deserializer = "org.apache.hadoop.hive.metastore.test.Deserializer";
serde.setSerializerClass(serializer);
serde.setDeserializerClass(deserializer);
schemaVersion.setSerDe(serde);
objectStore.alterSchemaVersion(new SchemaVersionDescriptor(new ISchemaName(db.getCatalogName(), db.getName(), schemaName), version), schemaVersion);
schemaVersion = objectStore.getSchemaVersion(new SchemaVersionDescriptor(new ISchemaName(db.getCatalogName(), db.getName(), schemaName), version));
Assert.assertNotNull(schemaVersion);
Assert.assertEquals(schemaName, schemaVersion.getSchema().getSchemaName());
Assert.assertEquals(db.getName(), schemaVersion.getSchema().getDbName());
Assert.assertEquals(db.getCatalogName(), schemaVersion.getSchema().getCatName());
Assert.assertEquals(version, schemaVersion.getVersion());
Assert.assertEquals(SchemaVersionState.REVIEWED, schemaVersion.getState());
Assert.assertEquals(serdeName, schemaVersion.getSerDe().getName());
Assert.assertEquals(serializer, schemaVersion.getSerDe().getSerializerClass());
Assert.assertEquals(deserializer, schemaVersion.getSerDe().getDeserializerClass());
}
use of org.apache.hadoop.hive.metastore.api.SchemaVersionDescriptor 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_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName), version), schemaVersion);
}
Aggregations