Search in sources :

Example 26 with SQLDefaultConstraint

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

the class TestDefaultConstraint method createGetDrop.

@Test
public void createGetDrop() throws TException {
    Table table = testTables[0];
    // Make sure get on a table with no key returns empty list
    DefaultConstraintsRequest rqst = new DefaultConstraintsRequest(table.getCatName(), table.getDbName(), table.getTableName());
    List<SQLDefaultConstraint> fetched = client.getDefaultConstraints(rqst);
    Assert.assertTrue(fetched.isEmpty());
    // Single column unnamed primary key in default catalog and database
    List<SQLDefaultConstraint> dv = new SQLDefaultConstraintBuilder().onTable(table).addColumn("col1").setDefaultVal(0).build(metaStore.getConf());
    client.addDefaultConstraint(dv);
    rqst = new DefaultConstraintsRequest(table.getCatName(), table.getDbName(), table.getTableName());
    fetched = client.getDefaultConstraints(rqst);
    dv.get(0).setDc_name(fetched.get(0).getDc_name());
    Assert.assertEquals(dv, fetched);
    // Drop a primary key
    client.dropConstraint(table.getCatName(), table.getDbName(), table.getTableName(), dv.get(0).getDc_name());
    rqst = new DefaultConstraintsRequest(table.getCatName(), table.getDbName(), table.getTableName());
    fetched = client.getDefaultConstraints(rqst);
    Assert.assertTrue(fetched.isEmpty());
    // Make sure I can add it back
    client.addDefaultConstraint(dv);
}
Also used : DefaultConstraintsRequest(org.apache.hadoop.hive.metastore.api.DefaultConstraintsRequest) SQLDefaultConstraintBuilder(org.apache.hadoop.hive.metastore.client.builder.SQLDefaultConstraintBuilder) Table(org.apache.hadoop.hive.metastore.api.Table) SQLDefaultConstraint(org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Aggregations

SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)26 Test (org.junit.Test)13 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)12 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)12 DefaultConstraintsRequest (org.apache.hadoop.hive.metastore.api.DefaultConstraintsRequest)11 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)11 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)10 SQLDefaultConstraintBuilder (org.apache.hadoop.hive.metastore.client.builder.SQLDefaultConstraintBuilder)9 ArrayList (java.util.ArrayList)8 SQLPrimaryKey (org.apache.hadoop.hive.metastore.api.SQLPrimaryKey)8 SQLForeignKey (org.apache.hadoop.hive.metastore.api.SQLForeignKey)7 Table (org.apache.hadoop.hive.metastore.api.Table)7 TableName (org.apache.hadoop.hive.common.TableName)3 AllTableConstraintsRequest (org.apache.hadoop.hive.metastore.api.AllTableConstraintsRequest)3 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)3 SQLPrimaryKeyBuilder (org.apache.hadoop.hive.metastore.client.builder.SQLPrimaryKeyBuilder)3 SQLUniqueConstraintBuilder (org.apache.hadoop.hive.metastore.client.builder.SQLUniqueConstraintBuilder)3 AddDefaultConstraintMessage (org.apache.hadoop.hive.metastore.messaging.AddDefaultConstraintMessage)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2