private PrimaryKeyInfo getPrimaryKeys(String dbName, String tblName, boolean onlyReliable) throws HiveException { try { List<SQLPrimaryKey> primaryKeys = getMSC().getPrimaryKeys(new PrimaryKeysRequest(dbName, tblName)); if (onlyReliable && primaryKeys != null && !primaryKeys.isEmpty()) { primaryKeys = primaryKeys.stream() .filter(pk -> pk.isRely_cstr()) .collect(Collectors.toList()); } return new PrimaryKeyInfo(primaryKeys, tblName, dbName); } catch (Exception e) { throw new HiveException(e); } }
public List<SQLPrimaryKey> getPrimaryKeyList(String dbName, String tblName) throws HiveException, NoSuchObjectException { try { return getMSC().getPrimaryKeys(new PrimaryKeysRequest(dbName, tblName)); } catch (NoSuchObjectException e) { throw e; } catch (Exception e) { throw new HiveException(e); } }
/** * Get all primary key columns associated with the table. * * @param dbName Database Name * @param tblName Table Name * @return Primary Key associated with the table. * @throws HiveException */ public PrimaryKeyInfo getPrimaryKeys(String dbName, String tblName) throws HiveException { try { List<SQLPrimaryKey> primaryKeys = getMSC().getPrimaryKeys(new PrimaryKeysRequest(dbName, tblName)); return new PrimaryKeyInfo(primaryKeys, tblName, dbName); } catch (Exception e) { throw new HiveException(e); } }
@Test public void getNoSuchTable() throws TException { PrimaryKeysRequest rqst = new PrimaryKeysRequest(DEFAULT_DATABASE_NAME, "nosuch"); List<SQLPrimaryKey> pk = client.getPrimaryKeys(rqst); Assert.assertTrue(pk.isEmpty()); }
@Test public void getNoSuchDb() throws TException { PrimaryKeysRequest rqst = new PrimaryKeysRequest("nosuch", testTables[0].getTableName()); List<SQLPrimaryKey> pk = client.getPrimaryKeys(rqst); Assert.assertTrue(pk.isEmpty()); }
IMetaStoreClient metastoreClient = getParentSession().getMetaStoreClient(); PrimaryKeysRequest sqlReq = new PrimaryKeysRequest(schemaName, tableName); List<SQLPrimaryKey> pks = metastoreClient.getPrimaryKeys(sqlReq); if (pks == null) { return;
@Test public void getNoSuchCatalog() throws TException { PrimaryKeysRequest rqst = new PrimaryKeysRequest(testTables[0].getTableName(), testTables[0].getTableName()); rqst.setCatName("nosuch"); List<SQLPrimaryKey> pk = client.getPrimaryKeys(rqst); Assert.assertTrue(pk.isEmpty()); }
List<SQLPrimaryKey> primaryKeys = metastoreClient.getPrimaryKeys(new PrimaryKeysRequest(dbName, table.getTableName())); Set<String> pkColNames = new HashSet<>(); for(SQLPrimaryKey key : primaryKeys) {
new PrimaryKeysRequest(testTables[2].getDbName(), testTables[2].getTableName()); rqst.setCatName(testTables[2].getCatName()); List<SQLPrimaryKey> fetched = client.getPrimaryKeys(rqst); Assert.assertTrue(fetched.isEmpty()); fetched = client.getPrimaryKeys(rqst); Assert.assertEquals(1, fetched.size()); Assert.assertEquals(testTables[2].getDbName(), fetched.get(0).getTable_db()); rqst = new PrimaryKeysRequest(testTables[2].getDbName(), testTables[2].getTableName()); rqst.setCatName(testTables[2].getCatName()); fetched = client.getPrimaryKeys(rqst); Assert.assertTrue(fetched.isEmpty());
new PrimaryKeysRequest(table.getDbName(), table.getTableName()); rqst.setCatName(table.getCatName()); List<SQLPrimaryKey> fetched = client.getPrimaryKeys(rqst); Assert.assertTrue(fetched.isEmpty()); fetched = client.getPrimaryKeys(rqst); Assert.assertEquals(1, fetched.size()); Assert.assertEquals(table.getDbName(), fetched.get(0).getTable_db()); rqst = new PrimaryKeysRequest(table.getDbName(), table.getTableName()); rqst.setCatName(table.getCatName()); fetched = client.getPrimaryKeys(rqst); Assert.assertTrue(fetched.isEmpty());
new PrimaryKeysRequest(table.getDbName(), table.getTableName()); rqst.setCatName(table.getCatName()); List<SQLPrimaryKey> fetched = client.getPrimaryKeys(rqst); Assert.assertTrue(fetched.isEmpty()); fetched = client.getPrimaryKeys(rqst); Assert.assertEquals(2, fetched.size()); Assert.assertEquals(table.getDbName(), fetched.get(0).getTable_db()); rqst = new PrimaryKeysRequest(table.getDbName(), table.getTableName()); rqst.setCatName(table.getCatName()); fetched = client.getPrimaryKeys(rqst); Assert.assertTrue(fetched.isEmpty());
PrimaryKeysRequest rqst = new PrimaryKeysRequest(table.getDbName(), table.getTableName()); rqst.setCatName(table.getCatName()); List<SQLPrimaryKey> fetched = client.getPrimaryKeys(rqst); Assert.assertEquals(1, fetched.size()); Assert.assertEquals(table.getDbName(), fetched.get(0).getTable_db()); rqst = new PrimaryKeysRequest(table.getDbName(), table.getTableName()); rqst.setCatName(table.getCatName()); fetched = client.getPrimaryKeys(rqst); Assert.assertTrue(fetched.isEmpty());
PrimaryKeysRequest rqst = new PrimaryKeysRequest(table.getDbName(), table.getTableName()); rqst.setCatName(table.getCatName()); List<SQLPrimaryKey> fetched = client.getPrimaryKeys(rqst); Assert.assertEquals(1, fetched.size()); Assert.assertEquals(table.getDbName(), fetched.get(0).getTable_db()); rqst = new PrimaryKeysRequest(table.getDbName(), table.getTableName()); rqst.setCatName(table.getCatName()); fetched = client.getPrimaryKeys(rqst); Assert.assertTrue(fetched.isEmpty());
parentTable.getTableName()); pkRqst.setCatName(parentTable.getCatName()); List<SQLPrimaryKey> pkFetched = client.getPrimaryKeys(pkRqst); Assert.assertEquals(1, pkFetched.size()); Assert.assertEquals(expectedCatalog(), pkFetched.get(0).getCatName());
@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")); } }
parentTable.getTableName()); pkRqst.setCatName(parentTable.getCatName()); List<SQLPrimaryKey> pkFetched = client.getPrimaryKeys(pkRqst); Assert.assertEquals(1, pkFetched.size()); Assert.assertEquals(expectedCatalog(), pkFetched.get(0).getCatName());
List<SQLPrimaryKey> primaryKeys = metastoreClient.getPrimaryKeys(new PrimaryKeysRequest(dbName, table.getTableName())); Set<String> pkColNames = new HashSet<>(); for(SQLPrimaryKey key : primaryKeys) {
@Override public void runInternal() throws HiveSQLException { setState(OperationState.RUNNING); try { IMetaStoreClient metastoreClient = getParentSession().getMetaStoreClient(); PrimaryKeysRequest sqlReq = new PrimaryKeysRequest(schemaName, tableName); List<SQLPrimaryKey> pks = metastoreClient.getPrimaryKeys(sqlReq); if (pks == null) { return; } for (SQLPrimaryKey pk : pks) { rowSet.addRow(new Object[] {catalogName, pk.getTable_db(), pk.getTable_name(), pk.getColumn_name(), pk.getKey_seq(), pk.getPk_name()}); } setState(OperationState.FINISHED); } catch (Exception e) { setState(OperationState.ERROR); throw new HiveSQLException(e); } }