Search in sources :

Example 6 with UniqueConstraintsRequest

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

the class TestUniqueConstraint method getNoSuchDb.

@Test
public void getNoSuchDb() throws TException {
    UniqueConstraintsRequest rqst = new UniqueConstraintsRequest(DEFAULT_CATALOG_NAME, "nosuch", testTables[0].getTableName());
    List<SQLUniqueConstraint> uc = client.getUniqueConstraints(rqst);
    Assert.assertTrue(uc.isEmpty());
}
Also used : UniqueConstraintsRequest(org.apache.hadoop.hive.metastore.api.UniqueConstraintsRequest) SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 7 with UniqueConstraintsRequest

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

the class TestUniqueConstraint method createTableWithConstraintsPk.

@Test
public void createTableWithConstraintsPk() throws TException {
    String constraintName = "ctwcuc";
    Table table = new TableBuilder().setTableName("table_with_constraints").addCol("col1", "int").addCol("col2", "varchar(32)").build(metaStore.getConf());
    List<SQLUniqueConstraint> uc = new SQLUniqueConstraintBuilder().onTable(table).addColumn("col1").setConstraintName(constraintName).build(metaStore.getConf());
    client.createTableWithConstraints(table, null, null, uc, null, null, null);
    UniqueConstraintsRequest rqst = new UniqueConstraintsRequest(table.getCatName(), table.getDbName(), table.getTableName());
    List<SQLUniqueConstraint> fetched = client.getUniqueConstraints(rqst);
    Assert.assertEquals(uc, fetched);
    client.dropConstraint(table.getCatName(), table.getDbName(), table.getTableName(), constraintName);
    rqst = new UniqueConstraintsRequest(table.getCatName(), table.getDbName(), table.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) Table(org.apache.hadoop.hive.metastore.api.Table) SQLUniqueConstraintBuilder(org.apache.hadoop.hive.metastore.client.builder.SQLUniqueConstraintBuilder) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 8 with UniqueConstraintsRequest

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

the class NonCatCallsWithCatalog method uniqueConstraint.

@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());
}
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)

Example 9 with UniqueConstraintsRequest

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

the class TestUniqueConstraint method doubleAddUniqueConstraint.

@Test
public void doubleAddUniqueConstraint() throws TException {
    Table table = testTables[0];
    // Make sure get on a table with no key returns empty list
    UniqueConstraintsRequest rqst = new UniqueConstraintsRequest(table.getCatName(), table.getDbName(), table.getTableName());
    List<SQLUniqueConstraint> fetched = client.getUniqueConstraints(rqst);
    Assert.assertTrue(fetched.isEmpty());
    // Single column unnamed primary key in default catalog and database
    List<SQLUniqueConstraint> uc = new SQLUniqueConstraintBuilder().onTable(table).addColumn("col1").build(metaStore.getConf());
    client.addUniqueConstraint(uc);
    try {
        uc = new SQLUniqueConstraintBuilder().onTable(table).addColumn("col2").build(metaStore.getConf());
        client.addUniqueConstraint(uc);
        Assert.fail();
    } catch (InvalidObjectException | TApplicationException e) {
    // NOP
    }
}
Also used : UniqueConstraintsRequest(org.apache.hadoop.hive.metastore.api.UniqueConstraintsRequest) SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) Table(org.apache.hadoop.hive.metastore.api.Table) 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)

Example 10 with UniqueConstraintsRequest

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

the class TestUniqueConstraint method getNoSuchCatalog.

@Test
public void getNoSuchCatalog() throws TException {
    UniqueConstraintsRequest rqst = new UniqueConstraintsRequest("nosuch", testTables[0].getDbName(), testTables[0].getTableName());
    List<SQLUniqueConstraint> uc = client.getUniqueConstraints(rqst);
    Assert.assertTrue(uc.isEmpty());
}
Also used : UniqueConstraintsRequest(org.apache.hadoop.hive.metastore.api.UniqueConstraintsRequest) SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Aggregations

SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)11 UniqueConstraintsRequest (org.apache.hadoop.hive.metastore.api.UniqueConstraintsRequest)11 Test (org.junit.Test)11 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)8 SQLUniqueConstraintBuilder (org.apache.hadoop.hive.metastore.client.builder.SQLUniqueConstraintBuilder)7 Table (org.apache.hadoop.hive.metastore.api.Table)5 TableBuilder (org.apache.hadoop.hive.metastore.client.builder.TableBuilder)3 CheckConstraintsRequest (org.apache.hadoop.hive.metastore.api.CheckConstraintsRequest)2 DefaultConstraintsRequest (org.apache.hadoop.hive.metastore.api.DefaultConstraintsRequest)2 ForeignKeysRequest (org.apache.hadoop.hive.metastore.api.ForeignKeysRequest)2 NotNullConstraintsRequest (org.apache.hadoop.hive.metastore.api.NotNullConstraintsRequest)2 PrimaryKeysRequest (org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest)2 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)2 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)2 SQLForeignKey (org.apache.hadoop.hive.metastore.api.SQLForeignKey)2 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)2 SQLPrimaryKey (org.apache.hadoop.hive.metastore.api.SQLPrimaryKey)2 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)1 SQLCheckConstraintBuilder (org.apache.hadoop.hive.metastore.client.builder.SQLCheckConstraintBuilder)1 SQLDefaultConstraintBuilder (org.apache.hadoop.hive.metastore.client.builder.SQLDefaultConstraintBuilder)1