Search in sources :

Example 6 with PrimaryKeysRequest

use of org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest in project hive by apache.

the class TestPrimaryKey method createGetDrop2Column.

@Test
public void createGetDrop2Column() throws TException {
    // Make sure get on a table with no key returns empty list
    Table table = testTables[1];
    PrimaryKeysRequest rqst = new PrimaryKeysRequest(table.getDbName(), table.getTableName());
    rqst.setCatName(table.getCatName());
    List<SQLPrimaryKey> fetched = client.getPrimaryKeys(rqst);
    Assert.assertTrue(fetched.isEmpty());
    String constraintName = "cgd2cpk";
    // Multi-column.  Also covers table in non-default database
    List<SQLPrimaryKey> pk = new SQLPrimaryKeyBuilder().onTable(table).addColumn("col1").addColumn("col2").setEnable(false).setConstraintName(constraintName).setValidate(true).setRely(true).build(metaStore.getConf());
    client.addPrimaryKey(pk);
    rqst = new PrimaryKeysRequest(table.getDbName(), table.getTableName());
    rqst.setCatName(table.getCatName());
    fetched = client.getPrimaryKeys(rqst);
    Assert.assertEquals(pk, fetched);
    // Drop a named primary key
    client.dropConstraint(table.getCatName(), table.getDbName(), table.getTableName(), constraintName);
    rqst = new PrimaryKeysRequest(table.getDbName(), table.getTableName());
    rqst.setCatName(table.getCatName());
    fetched = client.getPrimaryKeys(rqst);
    Assert.assertTrue(fetched.isEmpty());
    // Make sure I can add it back
    client.addPrimaryKey(pk);
}
Also used : SQLPrimaryKeyBuilder(org.apache.hadoop.hive.metastore.client.builder.SQLPrimaryKeyBuilder) SQLPrimaryKey(org.apache.hadoop.hive.metastore.api.SQLPrimaryKey) Table(org.apache.hadoop.hive.metastore.api.Table) PrimaryKeysRequest(org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 7 with PrimaryKeysRequest

use of org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest in project hive by apache.

the class TestPrimaryKey method createGetDrop.

@Test
public void createGetDrop() 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);
    rqst = new PrimaryKeysRequest(table.getDbName(), table.getTableName());
    rqst.setCatName(table.getCatName());
    fetched = client.getPrimaryKeys(rqst);
    pk.get(0).setPk_name(fetched.get(0).getPk_name());
    Assert.assertEquals(pk, fetched);
    // Drop a primary key
    client.dropConstraint(table.getCatName(), table.getDbName(), table.getTableName(), pk.get(0).getPk_name());
    rqst = new PrimaryKeysRequest(table.getDbName(), table.getTableName());
    rqst.setCatName(table.getCatName());
    fetched = client.getPrimaryKeys(rqst);
    Assert.assertTrue(fetched.isEmpty());
    // Make sure I can add it back
    client.addPrimaryKey(pk);
}
Also used : SQLPrimaryKeyBuilder(org.apache.hadoop.hive.metastore.client.builder.SQLPrimaryKeyBuilder) SQLPrimaryKey(org.apache.hadoop.hive.metastore.api.SQLPrimaryKey) Table(org.apache.hadoop.hive.metastore.api.Table) PrimaryKeysRequest(org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 8 with PrimaryKeysRequest

use of org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest in project hive by apache.

the class TestPrimaryKey method createTableWithConstraintsPkInOtherCatalog.

@Test
public void createTableWithConstraintsPkInOtherCatalog() throws TException {
    Table table = new TableBuilder().setTableName("table_in_other_catalog_with_constraints").inDb(inOtherCatalog).addCol("col1", "int").addCol("col2", "varchar(32)").build(metaStore.getConf());
    List<SQLPrimaryKey> pk = new SQLPrimaryKeyBuilder().onTable(table).addColumn("col1").build(metaStore.getConf());
    client.createTableWithConstraints(table, pk, null, null, null, null, null);
    PrimaryKeysRequest rqst = new PrimaryKeysRequest(table.getDbName(), table.getTableName());
    rqst.setCatName(table.getCatName());
    List<SQLPrimaryKey> fetched = client.getPrimaryKeys(rqst);
    pk.get(0).setPk_name(fetched.get(0).getPk_name());
    Assert.assertEquals(pk, fetched);
    client.dropConstraint(table.getCatName(), table.getDbName(), table.getTableName(), pk.get(0).getPk_name());
    rqst = new PrimaryKeysRequest(table.getDbName(), table.getTableName());
    rqst.setCatName(table.getCatName());
    fetched = client.getPrimaryKeys(rqst);
    Assert.assertTrue(fetched.isEmpty());
}
Also used : SQLPrimaryKeyBuilder(org.apache.hadoop.hive.metastore.client.builder.SQLPrimaryKeyBuilder) SQLPrimaryKey(org.apache.hadoop.hive.metastore.api.SQLPrimaryKey) Table(org.apache.hadoop.hive.metastore.api.Table) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) PrimaryKeysRequest(org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 9 with PrimaryKeysRequest

use of org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest in project hive by apache.

the class ObjectStore method getPrimaryKeys.

@Override
public List<SQLPrimaryKey> getPrimaryKeys(String catName, String db_name, String tbl_name) throws MetaException {
    PrimaryKeysRequest request = new PrimaryKeysRequest(db_name, tbl_name);
    request.setCatName(catName);
    return getPrimaryKeys(request);
}
Also used : PrimaryKeysRequest(org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest)

Example 10 with PrimaryKeysRequest

use of org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest in project hive by apache.

the class NonCatCallsWithCatalog method primaryKeyAndForeignKey.

@Test
public void primaryKeyAndForeignKey() throws TException {
    Table parentTable = testTables[2];
    Table table = testTables[3];
    String constraintName = "othercatfk";
    // Single column unnamed primary key in default catalog and database
    List<SQLPrimaryKey> pk = new SQLPrimaryKeyBuilder().onTable(parentTable).addColumn("test_col1").build(conf);
    client.addPrimaryKey(pk);
    List<SQLForeignKey> fk = new SQLForeignKeyBuilder().fromPrimaryKey(pk).onTable(table).addColumn("test_col1").setConstraintName(constraintName).build(conf);
    client.addForeignKey(fk);
    PrimaryKeysRequest pkRqst = new PrimaryKeysRequest(parentTable.getDbName(), parentTable.getTableName());
    pkRqst.setCatName(parentTable.getCatName());
    List<SQLPrimaryKey> pkFetched = client.getPrimaryKeys(pkRqst);
    Assert.assertEquals(1, pkFetched.size());
    Assert.assertEquals(expectedCatalog(), pkFetched.get(0).getCatName());
    Assert.assertEquals(parentTable.getDbName(), pkFetched.get(0).getTable_db());
    Assert.assertEquals(parentTable.getTableName(), pkFetched.get(0).getTable_name());
    Assert.assertEquals("test_col1", pkFetched.get(0).getColumn_name());
    Assert.assertEquals(1, pkFetched.get(0).getKey_seq());
    Assert.assertTrue(pkFetched.get(0).isEnable_cstr());
    Assert.assertFalse(pkFetched.get(0).isValidate_cstr());
    Assert.assertFalse(pkFetched.get(0).isRely_cstr());
    Assert.assertEquals(parentTable.getCatName(), pkFetched.get(0).getCatName());
    ForeignKeysRequest rqst = new ForeignKeysRequest(parentTable.getDbName(), parentTable.getTableName(), table.getDbName(), table.getTableName());
    rqst.setCatName(table.getCatName());
    List<SQLForeignKey> fetched = client.getForeignKeys(rqst);
    Assert.assertEquals(1, fetched.size());
    Assert.assertEquals(table.getDbName(), fetched.get(0).getFktable_db());
    Assert.assertEquals(table.getTableName(), fetched.get(0).getFktable_name());
    Assert.assertEquals(expectedCatalog(), fetched.get(0).getCatName());
    Assert.assertEquals("test_col1", fetched.get(0).getFkcolumn_name());
    Assert.assertEquals(parentTable.getDbName(), fetched.get(0).getPktable_db());
    Assert.assertEquals(parentTable.getTableName(), fetched.get(0).getPktable_name());
    Assert.assertEquals("test_col1", fetched.get(0).getFkcolumn_name());
    Assert.assertEquals(1, fetched.get(0).getKey_seq());
    Assert.assertEquals(parentTable.getTableName() + "_primary_key", fetched.get(0).getPk_name());
    Assert.assertEquals(constraintName, fetched.get(0).getFk_name());
    String table0FkName = fetched.get(0).getFk_name();
    Assert.assertTrue(fetched.get(0).isEnable_cstr());
    Assert.assertFalse(fetched.get(0).isValidate_cstr());
    Assert.assertFalse(fetched.get(0).isRely_cstr());
    Assert.assertEquals(table.getCatName(), fetched.get(0).getCatName());
    // Drop a foreign key
    client.dropConstraint(table.getDbName(), table.getTableName(), table0FkName);
    rqst = new ForeignKeysRequest(parentTable.getDbName(), parentTable.getTableName(), table.getDbName(), table.getTableName());
    rqst.setCatName(table.getCatName());
    fetched = client.getForeignKeys(rqst);
    Assert.assertTrue(fetched.isEmpty());
}
Also used : SQLPrimaryKeyBuilder(org.apache.hadoop.hive.metastore.client.builder.SQLPrimaryKeyBuilder) SQLForeignKeyBuilder(org.apache.hadoop.hive.metastore.client.builder.SQLForeignKeyBuilder) ForeignKeysRequest(org.apache.hadoop.hive.metastore.api.ForeignKeysRequest) SQLPrimaryKey(org.apache.hadoop.hive.metastore.api.SQLPrimaryKey) Table(org.apache.hadoop.hive.metastore.api.Table) SQLForeignKey(org.apache.hadoop.hive.metastore.api.SQLForeignKey) PrimaryKeysRequest(org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest) Test(org.junit.Test)

Aggregations

PrimaryKeysRequest (org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest)16 SQLPrimaryKey (org.apache.hadoop.hive.metastore.api.SQLPrimaryKey)15 Test (org.junit.Test)13 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)9 Table (org.apache.hadoop.hive.metastore.api.Table)8 SQLPrimaryKeyBuilder (org.apache.hadoop.hive.metastore.client.builder.SQLPrimaryKeyBuilder)8 ForeignKeysRequest (org.apache.hadoop.hive.metastore.api.ForeignKeysRequest)3 SQLForeignKey (org.apache.hadoop.hive.metastore.api.SQLForeignKey)3 TableBuilder (org.apache.hadoop.hive.metastore.client.builder.TableBuilder)3 IMetaStoreClient (org.apache.hadoop.hive.metastore.IMetaStoreClient)2 CheckConstraintsRequest (org.apache.hadoop.hive.metastore.api.CheckConstraintsRequest)2 DefaultConstraintsRequest (org.apache.hadoop.hive.metastore.api.DefaultConstraintsRequest)2 NotNullConstraintsRequest (org.apache.hadoop.hive.metastore.api.NotNullConstraintsRequest)2 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)2 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)2 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)2 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)2 UniqueConstraintsRequest (org.apache.hadoop.hive.metastore.api.UniqueConstraintsRequest)2 SQLForeignKeyBuilder (org.apache.hadoop.hive.metastore.client.builder.SQLForeignKeyBuilder)2 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)2