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(); }
case SCHEMA_TYPE: if (value == null) { unsetSchemaType(); } else { setSchemaType((SchemaType)value); unsetName(); } else { setName((String)value); unsetCatName(); } else { setCatName((String)value); unsetDbName(); } else { setDbName((String)value); unsetCompatibility(); } else { setCompatibility((SchemaCompatibility)value); unsetValidationLevel(); } else { setValidationLevel((SchemaValidation)value); unsetCanEvolve(); } else { setCanEvolve((Boolean)value);
public SchemaVersionBuilder versionOf(ISchema schema) { this.catName = schema.getCatName(); this.dbName = schema.getDbName(); this.schemaName = schema.getName(); return this; }
public ISchema build() throws MetaException { if (schemaType == null || name == null) { throw new MetaException("You must provide a schemaType and name"); } ISchema iSchema = new ISchema(schemaType, name, catName, dbName, compatibility, validationLevel, canEvolve); if (schemaGroup != null) iSchema.setSchemaGroup(schemaGroup); if (description != null) iSchema.setDescription(description); return iSchema; } }
Assert.assertEquals(1, (int)preEvents.get(PreEventContext.PreEventType.READ_ISCHEMA)); Assert.assertEquals(SchemaType.AVRO, schema.getSchemaType()); Assert.assertEquals(schemaName, schema.getName()); Assert.assertEquals(DEFAULT_CATALOG_NAME, schema.getCatName()); Assert.assertEquals(DEFAULT_DATABASE_NAME, schema.getDbName()); 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()); schema.setCompatibility(SchemaCompatibility.BOTH); schema.setValidationLevel(SchemaValidation.ALL); schema.setCanEvolve(true); schema.setSchemaGroup(schemaGroup); schema.setDescription(description); client.alterISchema(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, schemaName, schema); Assert.assertEquals(1, (int)preEvents.get(PreEventContext.PreEventType.ALTER_ISCHEMA)); 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());
@Override public void alterISchema(ISchemaName schemaName, ISchema newSchema) throws NoSuchObjectException, MetaException { boolean committed = false; try { openTransaction(); MISchema oldMSchema = getMISchema(schemaName.getCatName(), schemaName.getDbName(), schemaName.getSchemaName()); if (oldMSchema == null) { throw new NoSuchObjectException("Schema " + schemaName + " does not exist"); } // Don't support changing name or type oldMSchema.setCompatibility(newSchema.getCompatibility().getValue()); oldMSchema.setValidationLevel(newSchema.getValidationLevel().getValue()); oldMSchema.setCanEvolve(newSchema.isCanEvolve()); if (newSchema.isSetSchemaGroup()) { oldMSchema.setSchemaGroup(newSchema.getSchemaGroup()); } if (newSchema.isSetDescription()) { oldMSchema.setDescription(newSchema.getDescription()); } committed = commitTransaction(); } finally { if (!committed) { rollbackTransaction(); } } }
@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); }
@Override public void create_ischema(ISchema schema) throws TException { startFunction("create_ischema", ": " + schema.getName()); boolean success = false; Exception ex = null;
Assert.assertEquals(SchemaType.AVRO, schema.getSchemaType()); Assert.assertEquals(schemaName, schema.getName()); Assert.assertEquals(catName, schema.getCatName()); Assert.assertEquals(dbName, schema.getDbName()); 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()); schema.setCompatibility(SchemaCompatibility.BOTH); schema.setValidationLevel(SchemaValidation.ALL); schema.setCanEvolve(true); schema.setSchemaGroup(schemaGroup); schema.setDescription(description); client.alterISchema(catName, dbName, schemaName, schema); Assert.assertEquals(SchemaType.AVRO, schema.getSchemaType()); Assert.assertEquals(schemaName, schema.getName()); Assert.assertEquals(catName, schema.getCatName()); Assert.assertEquals(dbName, schema.getDbName()); 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());
@Override public void alterISchema(ISchemaName schemaName, ISchema newSchema) throws NoSuchObjectException, MetaException { boolean committed = false; try { openTransaction(); MISchema oldMSchema = getMISchema(schemaName.getCatName(), schemaName.getDbName(), schemaName.getSchemaName()); if (oldMSchema == null) { throw new NoSuchObjectException("Schema " + schemaName + " does not exist"); } // Don't support changing name or type oldMSchema.setCompatibility(newSchema.getCompatibility().getValue()); oldMSchema.setValidationLevel(newSchema.getValidationLevel().getValue()); oldMSchema.setCanEvolve(newSchema.isCanEvolve()); if (newSchema.isSetSchemaGroup()) { oldMSchema.setSchemaGroup(newSchema.getSchemaGroup()); } if (newSchema.isSetDescription()) { oldMSchema.setDescription(newSchema.getDescription()); } committed = commitTransaction(); } finally { if (!committed) { rollbackTransaction(); } } }
@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); }
@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(); } } }
private ISchema convertToISchema(MISchema mSchema) { if (mSchema == null) { return null; } ISchema schema = new ISchema(SchemaType.findByValue(mSchema.getSchemaType()), mSchema.getName(), mSchema.getDb().getCatalogName(), mSchema.getDb().getName(), SchemaCompatibility.findByValue(mSchema.getCompatibility()), SchemaValidation.findByValue(mSchema.getValidationLevel()), mSchema.getCanEvolve()); if (mSchema.getDescription() != null) { schema.setDescription(mSchema.getDescription()); } if (mSchema.getSchemaGroup() != null) { schema.setSchemaGroup(mSchema.getSchemaGroup()); } return schema; }
@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()); }
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()); 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); 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());
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); }
public SchemaVersionBuilder versionOf(ISchema schema) { this.catName = schema.getCatName(); this.dbName = schema.getDbName(); this.schemaName = schema.getName(); return this; }
private ISchema convertToISchema(MISchema mSchema) { if (mSchema == null) { return null; } ISchema schema = new ISchema(SchemaType.findByValue(mSchema.getSchemaType()), mSchema.getName(), mSchema.getDb().getCatalogName(), mSchema.getDb().getName(), SchemaCompatibility.findByValue(mSchema.getCompatibility()), SchemaValidation.findByValue(mSchema.getValidationLevel()), mSchema.getCanEvolve()); if (mSchema.getDescription() != null) { schema.setDescription(mSchema.getDescription()); } if (mSchema.getSchemaGroup() != null) { schema.setSchemaGroup(mSchema.getSchemaGroup()); } return schema; }
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());
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); }