use of org.apache.hadoop.hive.metastore.client.builder.SQLDefaultConstraintBuilder in project hive by apache.
the class TestDefaultConstraint 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<SQLDefaultConstraint> dv = new SQLDefaultConstraintBuilder().onTable(table).addColumn("col1").setDefaultVal(0).build(metaStore.getConf());
client.createTableWithConstraints(table, null, null, null, null, dv, null);
DefaultConstraintsRequest rqst = new DefaultConstraintsRequest(table.getCatName(), table.getDbName(), table.getTableName());
List<SQLDefaultConstraint> fetched = client.getDefaultConstraints(rqst);
dv.get(0).setDc_name(fetched.get(0).getDc_name());
Assert.assertEquals(dv, fetched);
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());
}
use of org.apache.hadoop.hive.metastore.client.builder.SQLDefaultConstraintBuilder in project hive by apache.
the class TestDefaultConstraint method createTableWithConstraintsPk.
@Test
public void createTableWithConstraintsPk() throws TException {
String constraintName = "ctwcdv";
Table table = new TableBuilder().setTableName("table_with_constraints").addCol("col1", "int").addCol("col2", "varchar(32)").build(metaStore.getConf());
List<SQLDefaultConstraint> dv = new SQLDefaultConstraintBuilder().onTable(table).addColumn("col1").setConstraintName(constraintName).setDefaultVal(0).build(metaStore.getConf());
client.createTableWithConstraints(table, null, null, null, null, dv, null);
DefaultConstraintsRequest rqst = new DefaultConstraintsRequest(table.getCatName(), table.getDbName(), table.getTableName());
List<SQLDefaultConstraint> fetched = client.getDefaultConstraints(rqst);
Assert.assertEquals(dv, fetched);
client.dropConstraint(table.getCatName(), table.getDbName(), table.getTableName(), constraintName);
rqst = new DefaultConstraintsRequest(table.getCatName(), table.getDbName(), table.getTableName());
fetched = client.getDefaultConstraints(rqst);
Assert.assertTrue(fetched.isEmpty());
}
use of org.apache.hadoop.hive.metastore.client.builder.SQLDefaultConstraintBuilder in project hive by apache.
the class TestDefaultConstraint method doubleAddUniqueConstraint.
@Test
public void doubleAddUniqueConstraint() 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);
try {
dv = new SQLDefaultConstraintBuilder().onTable(table).addColumn("col2").setDefaultVal("this string intentionally left empty").build(metaStore.getConf());
client.addDefaultConstraint(dv);
Assert.fail();
} catch (InvalidObjectException | TApplicationException e) {
// NOP
}
}
use of org.apache.hadoop.hive.metastore.client.builder.SQLDefaultConstraintBuilder 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);
}
Aggregations