public void addPrimaryKey(List<SQLPrimaryKey> primaryKeyCols) throws HiveException, NoSuchObjectException { try { getMSC().addPrimaryKey(primaryKeyCols); } catch (Exception e) { throw new HiveException(e); } }
public void addPrimaryKey(List<SQLPrimaryKey> primaryKeyCols) throws HiveException, NoSuchObjectException { try { getMSC().addPrimaryKey(primaryKeyCols); } catch (Exception e) { throw new HiveException(e); } }
@Test public void addNoSuchTable() throws TException { try { List<SQLPrimaryKey> pk = new SQLPrimaryKeyBuilder() .setTableName("nosuch") .addColumn("col2") .build(metaStore.getConf()); client.addPrimaryKey(pk); Assert.fail(); } catch (InvalidObjectException|TApplicationException e) { // NOP } }
@Test public void doubleAddPrimaryKey() throws TException { Table table = testTables[0]; // Make sure get on a table with no key returns empty list PrimaryKeysRequest rqst = new PrimaryKeysRequest(table.getDbName(), table.getTableName()); rqst.setCatName(table.getCatName()); List<SQLPrimaryKey> fetched = client.getPrimaryKeys(rqst); Assert.assertTrue(fetched.isEmpty()); // Single column unnamed primary key in default catalog and database List<SQLPrimaryKey> pk = new SQLPrimaryKeyBuilder() .onTable(table) .addColumn("col1") .build(metaStore.getConf()); client.addPrimaryKey(pk); try { pk = new SQLPrimaryKeyBuilder() .onTable(table) .addColumn("col2") .build(metaStore.getConf()); client.addPrimaryKey(pk); Assert.fail(); } catch (MetaException e) { Assert.assertTrue(e.getMessage().contains("Primary key already exists for")); } }
.addColumn("col1") .build(metaStore.getConf()); client.addPrimaryKey(pk); client.addPrimaryKey(pk);
.setRely(true) .build(metaStore.getConf()); client.addPrimaryKey(pk); client.addPrimaryKey(pk);
.setConstraintName(constraintName) .build(metaStore.getConf()); client.addPrimaryKey(pk);
.addColumn("col1") .build(metaStore.getConf()); client.addPrimaryKey(pk);
.addColumn("test_col1") .build(conf); client.addPrimaryKey(pk);
.addColumn("col1") .build(metaStore.getConf()); client.addPrimaryKey(pk);
.addColumn("col2") .build(metaStore.getConf()); client.addPrimaryKey(pk);
.addColumn("col1") .build(metaStore.getConf()); client.addPrimaryKey(pk);
.addColumn("col1") .build(metaStore.getConf()); client.addPrimaryKey(pk);
@Test public void addNoSuchTable() throws TException { Table parentTable = testTables[0]; List<SQLPrimaryKey> pk = new SQLPrimaryKeyBuilder() .onTable(parentTable) .addColumn("col1") .build(metaStore.getConf()); client.addPrimaryKey(pk); try { List<SQLForeignKey> fk = new SQLForeignKeyBuilder() .setTableName("nosuch") .fromPrimaryKey(pk) .addColumn("col2") .build(metaStore.getConf()); client.addForeignKey(fk); Assert.fail(); } catch (InvalidObjectException |TApplicationException e) { // NOP } }
.build(conf); for (SQLPrimaryKey pkcol : parentPk) pkcol.unsetCatName(); client.addPrimaryKey(parentPk);
@Test public void foreignKeyAcrossCatalogs() throws TException { Table parentTable = testTables[2]; Table table = testTables[0]; // Single column unnamed primary key in default catalog and database List<SQLPrimaryKey> pk = new SQLPrimaryKeyBuilder() .onTable(parentTable) .addColumn("col1") .build(metaStore.getConf()); client.addPrimaryKey(pk); try { List<SQLForeignKey> fk = new SQLForeignKeyBuilder() .fromPrimaryKey(pk) .onTable(table) .addColumn("col1") .build(metaStore.getConf()); client.addForeignKey(fk); Assert.fail(); } catch (InvalidObjectException |TApplicationException e) { // NOP } }
@Test public void addNoSuchDb() throws TException { Table parentTable = testTables[0]; List<SQLPrimaryKey> pk = new SQLPrimaryKeyBuilder() .onTable(parentTable) .addColumn("col1") .build(metaStore.getConf()); client.addPrimaryKey(pk); try { List<SQLForeignKey> fk = new SQLForeignKeyBuilder() .setTableName(testTables[0].getTableName()) .setDbName("nosuch") .fromPrimaryKey(pk) .addColumn("col2") .build(metaStore.getConf()); client.addForeignKey(fk); Assert.fail(); } catch (InvalidObjectException |TApplicationException e) { // NOP } }
@Test public void addNoSuchCatalog() throws TException { Table parentTable = testTables[0]; List<SQLPrimaryKey> pk = new SQLPrimaryKeyBuilder() .onTable(parentTable) .addColumn("col1") .build(metaStore.getConf()); client.addPrimaryKey(pk); try { List<SQLForeignKey> fk = new SQLForeignKeyBuilder() .setTableName(testTables[0].getTableName()) .setDbName(testTables[0].getDbName()) .setCatName("nosuch") .fromPrimaryKey(pk) .addColumn("col2") .build(metaStore.getConf()); client.addForeignKey(fk); Assert.fail(); } catch (InvalidObjectException |TApplicationException e) { // NOP } }