Search in sources :

Example 31 with SQLUniqueConstraint

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

the class TestUniqueConstraint method inOtherCatalog.

@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(uc, fetched);
    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());
}
Also used : SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) UniqueConstraintsRequest(org.apache.hadoop.hive.metastore.api.UniqueConstraintsRequest) SQLUniqueConstraintBuilder(org.apache.hadoop.hive.metastore.client.builder.SQLUniqueConstraintBuilder) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 32 with SQLUniqueConstraint

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

the class TestUniqueConstraint method addNoSuchTable.

@Test
public void addNoSuchTable() throws TException {
    try {
        List<SQLUniqueConstraint> uc = new SQLUniqueConstraintBuilder().setTableName("nosuch").addColumn("col2").build(metaStore.getConf());
        client.addUniqueConstraint(uc);
        Assert.fail();
    } catch (InvalidObjectException | TApplicationException e) {
    // NOP
    }
}
Also used : SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) SQLUniqueConstraintBuilder(org.apache.hadoop.hive.metastore.client.builder.SQLUniqueConstraintBuilder) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) TApplicationException(org.apache.thrift.TApplicationException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Aggregations

SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)32 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)16 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)15 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)15 Test (org.junit.Test)14 SQLPrimaryKey (org.apache.hadoop.hive.metastore.api.SQLPrimaryKey)13 ArrayList (java.util.ArrayList)11 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)11 SQLForeignKey (org.apache.hadoop.hive.metastore.api.SQLForeignKey)11 UniqueConstraintsRequest (org.apache.hadoop.hive.metastore.api.UniqueConstraintsRequest)11 SQLUniqueConstraintBuilder (org.apache.hadoop.hive.metastore.client.builder.SQLUniqueConstraintBuilder)10 Table (org.apache.hadoop.hive.metastore.api.Table)7 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)5 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)4 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)3 SQLDefaultConstraintBuilder (org.apache.hadoop.hive.metastore.client.builder.SQLDefaultConstraintBuilder)3 SQLPrimaryKeyBuilder (org.apache.hadoop.hive.metastore.client.builder.SQLPrimaryKeyBuilder)3 TableBuilder (org.apache.hadoop.hive.metastore.client.builder.TableBuilder)3 AddUniqueConstraintMessage (org.apache.hadoop.hive.metastore.messaging.AddUniqueConstraintMessage)3 Table (org.apache.hadoop.hive.ql.metadata.Table)3