public SchemaVersionBuilder versionOf(ISchema schema) { this.catName = schema.getCatName(); this.dbName = schema.getDbName(); this.schemaName = schema.getName(); return this; }
@Override public void createISchema(ISchema schema) throws AlreadyExistsException, MetaException, NoSuchObjectException { boolean committed = false; MISchema mSchema = convertToMISchema(schema); try { openTransaction(); if (getMISchema(schema.getCatName(), schema.getDbName(), schema.getName()) != null) { throw new AlreadyExistsException("Schema with name " + schema.getDbName() + "." + schema.getName() + " already exists"); } pm.makePersistent(mSchema); committed = commitTransaction(); } finally { if (!committed) { rollbackTransaction(); } } }
public Object getFieldValue(_Fields field) { switch (field) { case SCHEMA_TYPE: return getSchemaType(); case NAME: return getName(); case CAT_NAME: return getCatName(); case DB_NAME: return getDbName(); case COMPATIBILITY: return getCompatibility(); case VALIDATION_LEVEL: return getValidationLevel(); case CAN_EVOLVE: return isCanEvolve(); case SCHEMA_GROUP: return getSchemaGroup(); case DESCRIPTION: return getDescription(); } throw new IllegalStateException(); }
@Override public void create_ischema(ISchema schema) throws TException { startFunction("create_ischema", ": " + schema.getName()); boolean success = false; Exception ex = null;
private MISchema convertToMISchema(ISchema schema) throws NoSuchObjectException { return new MISchema(schema.getSchemaType().getValue(), normalizeIdentifier(schema.getName()), getMDatabase(schema.getCatName(), schema.getDbName()), schema.getCompatibility().getValue(), schema.getValidationLevel().getValue(), schema.isCanEvolve(), schema.isSetSchemaGroup() ? schema.getSchemaGroup() : null, schema.isSetDescription() ? schema.getDescription() : null); }
@Test(expected = NoSuchObjectException.class) public void mapSerDeNoSuchSchemaVersion() throws TException { SerDeInfo serDeInfo = new SerDeInfo(uniqueSerdeName(), "lib", Collections.emptyMap()); ISchema schema = new ISchemaBuilder() .setSchemaType(SchemaType.AVRO) .setName(uniqueSchemaName()) .build(); client.createISchema(schema); client.mapSchemaVersionToSerde(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schema.getName(), 3, serDeInfo.getName()); }
client.addSerDe(serDeInfo); client.mapSchemaVersionToSerde(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schema.getName(), schemaVersion.getVersion(), serDeInfo.getName()); schemaVersion = client.getSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schema.getName(), schemaVersion.getVersion()); Assert.assertEquals(serDeInfo.getName(), schemaVersion.getSerDe().getName()); client.addSchemaVersion(schemaVersion); schemaVersion = client.getSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schema.getName(), 2); Assert.assertEquals(serDeName, schemaVersion.getSerDe().getName()); client.mapSchemaVersionToSerde(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schema.getName(), 2, serDeInfo.getName()); schemaVersion = client.getSchemaVersion(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schema.getName(), 2); Assert.assertEquals(serDeInfo.getName(), schemaVersion.getSerDe().getName());
Assert.assertEquals(schemaName, schema.getName()); Assert.assertEquals(DEFAULT_CATALOG_NAME, schema.getCatName()); Assert.assertEquals(DEFAULT_DATABASE_NAME, schema.getDbName()); Assert.assertEquals(schemaName, schema.getName()); Assert.assertEquals(SchemaCompatibility.BOTH, schema.getCompatibility()); Assert.assertEquals(SchemaValidation.ALL, schema.getValidationLevel());
client.addSerDe(serDeInfo); client.mapSchemaVersionToSerde(catName, dbName, schema.getName(), schemaVersion.getVersion(), serDeInfo.getName()); schemaVersion = client.getSchemaVersion(catName, dbName, schema.getName(), schemaVersion.getVersion()); Assert.assertEquals(serDeInfo.getName(), schemaVersion.getSerDe().getName()); client.addSchemaVersion(schemaVersion); schemaVersion = client.getSchemaVersion(catName, dbName, schema.getName(), 2); Assert.assertEquals(serDeName, schemaVersion.getSerDe().getName()); client.mapSchemaVersionToSerde(catName, dbName, schema.getName(), 2, serDeInfo.getName()); schemaVersion = client.getSchemaVersion(catName, dbName, schema.getName(), 2); Assert.assertEquals(serDeInfo.getName(), schemaVersion.getSerDe().getName());
@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()); }
@Test(expected = AlreadyExistsException.class) public void schemaAlreadyExists() throws TException { String schemaName = uniqueSchemaName(); ISchema schema = new ISchemaBuilder() .setSchemaType(SchemaType.HIVE) .setName(schemaName) .build(); client.createISchema(schema); 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 client.createISchema(schema); }
@Test(expected = AlreadyExistsException.class) public void schemaAlreadyExists() throws TException { Database db = createUniqueDatabaseForTest(); String schemaName = "schema2"; ISchema schema = new ISchemaBuilder() .setSchemaType(SchemaType.HIVE) .setName(schemaName) .inDb(db) .build(); objectStore.createISchema(schema); schema = objectStore.getISchema(new ISchemaName(db.getCatalogName(), db.getName(), 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); }
Assert.assertEquals(schemaName, schema.getName()); Assert.assertEquals(catName, schema.getCatName()); Assert.assertEquals(dbName, schema.getDbName()); Assert.assertEquals(schemaName, schema.getName()); Assert.assertEquals(catName, schema.getCatName()); Assert.assertEquals(dbName, schema.getDbName());
Assert.assertEquals(schemaName, schema.getName()); Assert.assertEquals(SchemaCompatibility.FORWARD, schema.getCompatibility()); Assert.assertEquals(SchemaValidation.LATEST, schema.getValidationLevel()); Assert.assertEquals(schemaName, schema.getName()); Assert.assertEquals(SchemaCompatibility.BOTH, schema.getCompatibility()); Assert.assertEquals(SchemaValidation.ALL, schema.getValidationLevel());
public SchemaVersionBuilder versionOf(ISchema schema) { this.catName = schema.getCatName(); this.dbName = schema.getDbName(); this.schemaName = schema.getName(); return this; }
@Override public void createISchema(ISchema schema) throws AlreadyExistsException, MetaException, NoSuchObjectException { boolean committed = false; MISchema mSchema = convertToMISchema(schema); try { openTransaction(); if (getMISchema(schema.getCatName(), schema.getDbName(), schema.getName()) != null) { throw new AlreadyExistsException("Schema with name " + schema.getDbName() + "." + schema.getName() + " already exists"); } pm.makePersistent(mSchema); committed = commitTransaction(); } finally { if (!committed) { rollbackTransaction(); } } }
@Override public void create_ischema(ISchema schema) throws TException { startFunction("create_ischema", ": " + schema.getName()); boolean success = false; Exception ex = null;
private MISchema convertToMISchema(ISchema schema) throws NoSuchObjectException { return new MISchema(schema.getSchemaType().getValue(), normalizeIdentifier(schema.getName()), getMDatabase(schema.getCatName(), schema.getDbName()), schema.getCompatibility().getValue(), schema.getValidationLevel().getValue(), schema.isCanEvolve(), schema.isSetSchemaGroup() ? schema.getSchemaGroup() : null, schema.isSetDescription() ? schema.getDescription() : null); }