/*** * @param addUniqueConstraintEvent add unique constraint event * @throws MetaException */ @Override public void onAddUniqueConstraint(AddUniqueConstraintEvent addUniqueConstraintEvent) throws MetaException { List<SQLUniqueConstraint> cols = addUniqueConstraintEvent.getUniqueConstraintCols(); if (cols.size() > 0) { AddUniqueConstraintMessage msg = MessageBuilder.getInstance() .buildAddUniqueConstraintMessage(addUniqueConstraintEvent.getUniqueConstraintCols()); NotificationEvent event = new NotificationEvent(0, now(), EventType.ADD_UNIQUECONSTRAINT.toString(), msgEncoder.getSerializer().serialize(msg) ); event.setCatName(cols.get(0).isSetCatName() ? cols.get(0).getCatName() : DEFAULT_CATALOG_NAME); event.setDbName(cols.get(0).getTable_db()); event.setTableName(cols.get(0).getTable_name()); process(event, addUniqueConstraintEvent); } }
public Object getFieldValue(_Fields field) { switch (field) { case CAT_NAME: return getCatName(); case TABLE_DB: return getTable_db(); case TABLE_NAME: return getTable_name(); case COLUMN_NAME: return getColumn_name(); case KEY_SEQ: return getKey_seq(); case UK_NAME: return getUk_name(); case ENABLE_CSTR: return isEnable_cstr(); case VALIDATE_CSTR: return isValidate_cstr(); case RELY_CSTR: return isRely_cstr(); } throw new IllegalStateException(); }
final String catName = normalizeIdentifier(uks.get(i).getCatName()); final String tableDB = normalizeIdentifier(uks.get(i).getTable_db()); final String tableName = normalizeIdentifier(uks.get(i).getTable_name());
@Test public void uniqueConstraint() throws TException { String constraintName = "ocuc"; // Table in non 'hive' catalog List<SQLUniqueConstraint> uc = new SQLUniqueConstraintBuilder() .onTable(testTables[2]) .addColumn("test_col1") .setConstraintName(constraintName) .build(conf); client.addUniqueConstraint(uc); UniqueConstraintsRequest rqst = new UniqueConstraintsRequest(testTables[2].getCatName(), testTables[2].getDbName(), testTables[2].getTableName()); List<SQLUniqueConstraint> fetched = client.getUniqueConstraints(rqst); Assert.assertEquals(1, fetched.size()); Assert.assertEquals(testTables[2].getDbName(), fetched.get(0).getTable_db()); Assert.assertEquals(testTables[2].getTableName(), fetched.get(0).getTable_name()); Assert.assertEquals("test_col1", fetched.get(0).getColumn_name()); Assert.assertEquals(1, fetched.get(0).getKey_seq()); Assert.assertEquals(constraintName, fetched.get(0).getUk_name()); Assert.assertTrue(fetched.get(0).isEnable_cstr()); Assert.assertFalse(fetched.get(0).isValidate_cstr()); Assert.assertFalse(fetched.get(0).isRely_cstr()); Assert.assertEquals(testTables[2].getCatName(), fetched.get(0).getCatName()); Assert.assertEquals(expectedCatalog(), fetched.get(0).getCatName()); client.dropConstraint(testTables[2].getDbName(), testTables[2].getTableName(), constraintName); rqst = new UniqueConstraintsRequest(testTables[2].getCatName(), testTables[2].getDbName(), testTables[2].getTableName()); fetched = client.getUniqueConstraints(rqst); Assert.assertTrue(fetched.isEmpty()); }
@Test public void inOtherCatalog() throws TException { String constraintName = "ocuc"; // Table in non 'hive' catalog List<SQLUniqueConstraint> uc = new SQLUniqueConstraintBuilder() .onTable(testTables[2]) .addColumn("col1") .setConstraintName(constraintName) .build(metaStore.getConf()); client.addUniqueConstraint(uc); UniqueConstraintsRequest rqst = new UniqueConstraintsRequest(testTables[2].getCatName(), testTables[2].getDbName(), testTables[2].getTableName()); List<SQLUniqueConstraint> fetched = client.getUniqueConstraints(rqst); Assert.assertEquals(1, fetched.size()); Assert.assertEquals(testTables[2].getDbName(), fetched.get(0).getTable_db()); Assert.assertEquals(testTables[2].getTableName(), fetched.get(0).getTable_name()); Assert.assertEquals("col1", fetched.get(0).getColumn_name()); Assert.assertEquals(1, fetched.get(0).getKey_seq()); Assert.assertEquals(constraintName, fetched.get(0).getUk_name()); Assert.assertTrue(fetched.get(0).isEnable_cstr()); Assert.assertFalse(fetched.get(0).isValidate_cstr()); Assert.assertFalse(fetched.get(0).isRely_cstr()); Assert.assertEquals(testTables[2].getCatName(), fetched.get(0).getCatName()); client.dropConstraint(testTables[2].getCatName(), testTables[2].getDbName(), testTables[2].getTableName(), constraintName); rqst = new UniqueConstraintsRequest(testTables[2].getCatName(), testTables[2].getDbName(), testTables[2].getTableName()); fetched = client.getUniqueConstraints(rqst); Assert.assertTrue(fetched.isEmpty()); }
Assert.assertFalse(fetched.get(0).isValidate_cstr()); Assert.assertFalse(fetched.get(0).isRely_cstr()); Assert.assertEquals(table.getCatName(), fetched.get(0).getCatName());
Assert.assertFalse(fetched.get(0).isValidate_cstr()); Assert.assertFalse(fetched.get(0).isRely_cstr()); Assert.assertEquals(table.getCatName(), fetched.get(0).getCatName());
Assert.assertFalse(fetched.get(0).isValidate_cstr()); Assert.assertFalse(fetched.get(0).isRely_cstr()); Assert.assertEquals(table.getCatName(), fetched.get(0).getCatName());
Assert.assertFalse(ucFetched.get(0).isValidate_cstr()); Assert.assertFalse(ucFetched.get(0).isRely_cstr()); Assert.assertEquals(table.getCatName(), ucFetched.get(0).getCatName());
/*** * @param addUniqueConstraintEvent add unique constraint event * @throws MetaException */ @Override public void onAddUniqueConstraint(AddUniqueConstraintEvent addUniqueConstraintEvent) throws MetaException { List<SQLUniqueConstraint> cols = addUniqueConstraintEvent.getUniqueConstraintCols(); if (cols.size() > 0) { NotificationEvent event = new NotificationEvent(0, now(), EventType.ADD_UNIQUECONSTRAINT.toString(), msgFactory .buildAddUniqueConstraintMessage(addUniqueConstraintEvent.getUniqueConstraintCols()).toString()); event.setCatName(cols.get(0).isSetCatName() ? cols.get(0).getCatName() : DEFAULT_CATALOG_NAME); event.setDbName(cols.get(0).getTable_db()); event.setTableName(cols.get(0).getTable_name()); process(event, addUniqueConstraintEvent); } }
public Object getFieldValue(_Fields field) { switch (field) { case CAT_NAME: return getCatName(); case TABLE_DB: return getTable_db(); case TABLE_NAME: return getTable_name(); case COLUMN_NAME: return getColumn_name(); case KEY_SEQ: return getKey_seq(); case UK_NAME: return getUk_name(); case ENABLE_CSTR: return isEnable_cstr(); case VALIDATE_CSTR: return isValidate_cstr(); case RELY_CSTR: return isRely_cstr(); } throw new IllegalStateException(); }
final String catName = normalizeIdentifier(uks.get(i).getCatName()); final String tableDB = normalizeIdentifier(uks.get(i).getTable_db()); final String tableName = normalizeIdentifier(uks.get(i).getTable_name());