use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.
the class TestHiveMetaStoreTxns method testGetLatestCommittedCompactionInfo.
@Test
public void testGetLatestCommittedCompactionInfo() throws Exception {
final String dbName = "mydb";
final String tblName = "mytable";
Database db = new DatabaseBuilder().setName(dbName).build(conf);
db.unsetCatalogName();
client.createDatabase(db);
Table tbl = new TableBuilder().setDbName(dbName).setTableName(tblName).addCol("id", "int").addCol("name", "string").setType(TableType.MANAGED_TABLE.name()).build(conf);
client.createTable(tbl);
tbl = client.getTable(dbName, tblName);
client.compact2(tbl.getDbName(), tbl.getTableName(), null, CompactionType.MINOR, new HashMap<>());
FindNextCompactRequest compactRequest = new FindNextCompactRequest();
compactRequest.setWorkerId("myworker");
OptionalCompactionInfoStruct optionalCi = client.findNextCompact(compactRequest);
client.markCleaned(optionalCi.getCi());
GetLatestCommittedCompactionInfoRequest rqst = new GetLatestCommittedCompactionInfoRequest();
// Test invalid inputs
final String invalidTblName = "invalid";
rqst.setDbname(dbName);
Assert.assertThrows(MetaException.class, () -> client.getLatestCommittedCompactionInfo(rqst));
rqst.setTablename(invalidTblName);
GetLatestCommittedCompactionInfoResponse response = client.getLatestCommittedCompactionInfo(rqst);
Assert.assertNotNull(response);
Assert.assertEquals(0, response.getCompactionsSize());
// Test normal inputs
rqst.setTablename(tblName);
response = client.getLatestCommittedCompactionInfo(rqst);
Assert.assertNotNull(response);
Assert.assertEquals(1, response.getCompactionsSize());
CompactionInfoStruct lci = response.getCompactions().get(0);
Assert.assertEquals(1, lci.getId());
Assert.assertNull(lci.getPartitionname());
Assert.assertEquals(CompactionType.MINOR, lci.getType());
}
use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.
the class TestHiveMetaStore method createMaterializedView.
private void createMaterializedView(String dbName, String tableName, Set<Table> tablesUsed) throws TException {
Set<SourceTable> sourceTables = new HashSet<>(tablesUsed.size());
for (Table table : tablesUsed) {
sourceTables.add(createSourceTable(table));
}
Table t = new TableBuilder().setDbName(dbName).setTableName(tableName).setType(TableType.MATERIALIZED_VIEW.name()).addMaterializedViewReferencedTables(sourceTables).addCol("foo", "string").addCol("bar", "string").create(client, conf);
}
use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.
the class NonCatCallsWithCatalog method getPartitions.
@Test
public void getPartitions() throws TException {
String dbName = "get_partition_database_in_other_catalog";
Database db = new DatabaseBuilder().setName(dbName).build(conf);
db.unsetCatalogName();
client.createDatabase(db);
String tableName = "table_in_other_catalog";
Table table = new TableBuilder().inDb(db).setTableName(tableName).addCol("id", "int").addCol("name", "string").addPartCol("partcol", "string").addTableParam("PARTITION_LEVEL_PRIVILEGE", "true").build(conf);
table.unsetCatName();
client.createTable(table);
Partition[] parts = new Partition[5];
for (int i = 0; i < parts.length; i++) {
parts[i] = new PartitionBuilder().inTable(table).addValue("a" + i).build(conf);
parts[i].unsetCatName();
}
client.add_partitions(Arrays.asList(parts));
Partition fetched = client.getPartition(dbName, tableName, Collections.singletonList("a0"));
Assert.assertEquals(expectedCatalog(), fetched.getCatName());
Assert.assertEquals("a0", fetched.getValues().get(0));
fetched = client.getPartition(dbName, tableName, "partcol=a0");
Assert.assertEquals(expectedCatalog(), fetched.getCatName());
Assert.assertEquals("a0", fetched.getValues().get(0));
List<Partition> fetchedParts = client.getPartitionsByNames(dbName, tableName, Arrays.asList("partcol=a0", "partcol=a1"));
Assert.assertEquals(2, fetchedParts.size());
Set<String> vals = new HashSet<>(fetchedParts.size());
for (Partition part : fetchedParts) {
vals.add(part.getValues().get(0));
}
Assert.assertTrue(vals.contains("a0"));
Assert.assertTrue(vals.contains("a1"));
}
use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.
the class NonCatCallsWithCatalog method setUp.
@Before
public void setUp() throws Exception {
conf = MetastoreConf.newMetastoreConf();
MetastoreConf.setBoolVar(this.conf, ConfVars.HIVE_IN_TEST, true);
MetastoreConf.setVar(conf, ConfVars.METASTORE_METADATA_TRANSFORMER_CLASS, " ");
MetaStoreTestUtils.setConfForStandloneMode(conf);
// Get new client
client = getClient();
List<String> databases = client.getAllDatabases();
for (String db : databases) {
if (!DEFAULT_DATABASE_NAME.equals(db)) {
client.dropDatabase(db, true, true, true);
}
}
// Drop every table in the default database
for (String tableName : client.getAllTables(DEFAULT_DATABASE_NAME)) {
client.dropTable(DEFAULT_DATABASE_NAME, tableName, true, true, true);
}
Database db = new DatabaseBuilder().setName(OTHER_DATABASE).build(conf);
db.unsetCatalogName();
client.createDatabase(db);
testTables[0] = new TableBuilder().setTableName("test_table").addCol("test_col1", "int").addCol("test_col2", "int").addCol("test_col3", "int").build(conf);
testTables[1] = new TableBuilder().setTableName("test_view").addCol("test_col1", "int").addCol("test_col2", "int").addCol("test_col3", "int").setType("VIRTUAL_VIEW").build(conf);
testTables[2] = new TableBuilder().setTableName("test_table_to_find_1").addCol("test_col1", "int").addCol("test_col2", "int").addCol("test_col3", "int").build(conf);
testTables[3] = new TableBuilder().setTableName("test_partitioned_table").addCol("test_col1", "int").addCol("test_col2", "int").addPartCol("test_part_col", "int").build(conf);
testTables[4] = new TableBuilder().setTableName("external_table_for_test").addCol("test_col", "int").setLocation(MetaStoreTestUtils.getTestWarehouseDir("/external/table_dir")).addTableParam("EXTERNAL", "TRUE").setType("EXTERNAL_TABLE").build(conf);
testTables[5] = new TableBuilder().setDbName(OTHER_DATABASE).setTableName("test_table").addCol("test_col", "int").build(conf);
for (Table t : testTables) {
t.unsetCatName();
client.createTable(t);
}
// Create partitions for the partitioned table
for (int i = 0; i < 3; i++) {
Partition p = new PartitionBuilder().inTable(testTables[3]).addValue("a" + i).build(conf);
p.unsetCatName();
client.add_partition(p);
}
}
use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.
the class NonCatCallsWithCatalog method createTableWithConstraints.
@Test
public void createTableWithConstraints() throws TException {
Table parentTable = testTables[2];
Table table = new TableBuilder().setTableName("table_in_other_catalog_with_constraints").addCol("col1", "int").addCol("col2", "varchar(32)").addCol("col3", "int").addCol("col4", "int").addCol("col5", "int").addCol("col6", "int").build(conf);
table.unsetCatName();
List<SQLPrimaryKey> parentPk = new SQLPrimaryKeyBuilder().onTable(parentTable).addColumn("test_col1").build(conf);
for (SQLPrimaryKey pkcol : parentPk) {
pkcol.unsetCatName();
}
client.addPrimaryKey(parentPk);
List<SQLPrimaryKey> pk = new SQLPrimaryKeyBuilder().onTable(table).addColumn("col2").build(conf);
for (SQLPrimaryKey pkcol : pk) {
pkcol.unsetCatName();
}
List<SQLForeignKey> fk = new SQLForeignKeyBuilder().fromPrimaryKey(parentPk).onTable(table).addColumn("col1").build(conf);
for (SQLForeignKey fkcol : fk) {
fkcol.unsetCatName();
}
List<SQLDefaultConstraint> dv = new SQLDefaultConstraintBuilder().onTable(table).addColumn("col3").setDefaultVal(0).build(conf);
for (SQLDefaultConstraint dccol : dv) {
dccol.unsetCatName();
}
List<SQLNotNullConstraint> nn = new SQLNotNullConstraintBuilder().onTable(table).addColumn("col4").build(conf);
for (SQLNotNullConstraint nncol : nn) {
nncol.unsetCatName();
}
List<SQLUniqueConstraint> uc = new SQLUniqueConstraintBuilder().onTable(table).addColumn("col5").build(conf);
for (SQLUniqueConstraint uccol : uc) {
uccol.unsetCatName();
}
List<SQLCheckConstraint> cc = new SQLCheckConstraintBuilder().onTable(table).addColumn("col6").setCheckExpression("> 0").build(conf);
for (SQLCheckConstraint cccol : cc) {
cccol.unsetCatName();
}
client.createTableWithConstraints(table, pk, fk, uc, nn, dv, cc);
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 fkRqst = new ForeignKeysRequest(parentTable.getDbName(), parentTable.getTableName(), table.getDbName(), table.getTableName());
fkRqst.setCatName(table.getCatName());
List<SQLForeignKey> fkFetched = client.getForeignKeys(fkRqst);
Assert.assertEquals(1, fkFetched.size());
Assert.assertEquals(expectedCatalog(), fkFetched.get(0).getCatName());
Assert.assertEquals(table.getDbName(), fkFetched.get(0).getFktable_db());
Assert.assertEquals(table.getTableName(), fkFetched.get(0).getFktable_name());
Assert.assertEquals("col1", fkFetched.get(0).getFkcolumn_name());
Assert.assertEquals(parentTable.getDbName(), fkFetched.get(0).getPktable_db());
Assert.assertEquals(parentTable.getTableName(), fkFetched.get(0).getPktable_name());
Assert.assertEquals(1, fkFetched.get(0).getKey_seq());
Assert.assertEquals(parentTable.getTableName() + "_primary_key", fkFetched.get(0).getPk_name());
Assert.assertTrue(fkFetched.get(0).isEnable_cstr());
Assert.assertFalse(fkFetched.get(0).isValidate_cstr());
Assert.assertFalse(fkFetched.get(0).isRely_cstr());
Assert.assertEquals(table.getCatName(), fkFetched.get(0).getCatName());
NotNullConstraintsRequest nnRqst = new NotNullConstraintsRequest(table.getCatName(), table.getDbName(), table.getTableName());
List<SQLNotNullConstraint> nnFetched = client.getNotNullConstraints(nnRqst);
Assert.assertEquals(1, nnFetched.size());
Assert.assertEquals(table.getDbName(), nnFetched.get(0).getTable_db());
Assert.assertEquals(table.getTableName(), nnFetched.get(0).getTable_name());
Assert.assertEquals("col4", nnFetched.get(0).getColumn_name());
Assert.assertEquals(table.getTableName() + "_not_null_constraint", nnFetched.get(0).getNn_name());
Assert.assertTrue(nnFetched.get(0).isEnable_cstr());
Assert.assertFalse(nnFetched.get(0).isValidate_cstr());
Assert.assertFalse(nnFetched.get(0).isRely_cstr());
Assert.assertEquals(table.getCatName(), nnFetched.get(0).getCatName());
UniqueConstraintsRequest ucRqst = new UniqueConstraintsRequest(table.getCatName(), table.getDbName(), table.getTableName());
List<SQLUniqueConstraint> ucFetched = client.getUniqueConstraints(ucRqst);
Assert.assertEquals(1, ucFetched.size());
Assert.assertEquals(table.getDbName(), ucFetched.get(0).getTable_db());
Assert.assertEquals(table.getTableName(), ucFetched.get(0).getTable_name());
Assert.assertEquals("col5", ucFetched.get(0).getColumn_name());
Assert.assertEquals(1, ucFetched.get(0).getKey_seq());
Assert.assertEquals(table.getTableName() + "_unique_constraint", ucFetched.get(0).getUk_name());
Assert.assertTrue(ucFetched.get(0).isEnable_cstr());
Assert.assertFalse(ucFetched.get(0).isValidate_cstr());
Assert.assertFalse(ucFetched.get(0).isRely_cstr());
Assert.assertEquals(table.getCatName(), ucFetched.get(0).getCatName());
DefaultConstraintsRequest dcRqst = new DefaultConstraintsRequest(table.getCatName(), table.getDbName(), table.getTableName());
List<SQLDefaultConstraint> dcFetched = client.getDefaultConstraints(dcRqst);
Assert.assertEquals(1, dcFetched.size());
Assert.assertEquals(expectedCatalog(), dcFetched.get(0).getCatName());
Assert.assertEquals(table.getDbName(), dcFetched.get(0).getTable_db());
Assert.assertEquals(table.getTableName(), dcFetched.get(0).getTable_name());
Assert.assertEquals("col3", dcFetched.get(0).getColumn_name());
Assert.assertEquals("0", dcFetched.get(0).getDefault_value());
Assert.assertEquals(table.getTableName() + "_default_value", dcFetched.get(0).getDc_name());
Assert.assertTrue(dcFetched.get(0).isEnable_cstr());
Assert.assertFalse(dcFetched.get(0).isValidate_cstr());
Assert.assertFalse(dcFetched.get(0).isRely_cstr());
Assert.assertEquals(table.getCatName(), dcFetched.get(0).getCatName());
CheckConstraintsRequest ccRqst = new CheckConstraintsRequest(table.getCatName(), table.getDbName(), table.getTableName());
List<SQLCheckConstraint> ccFetched = client.getCheckConstraints(ccRqst);
Assert.assertEquals(1, ccFetched.size());
Assert.assertEquals(expectedCatalog(), ccFetched.get(0).getCatName());
Assert.assertEquals(table.getDbName(), ccFetched.get(0).getTable_db());
Assert.assertEquals(table.getTableName(), ccFetched.get(0).getTable_name());
Assert.assertEquals("col6", ccFetched.get(0).getColumn_name());
Assert.assertEquals("> 0", ccFetched.get(0).getCheck_expression());
Assert.assertEquals(table.getTableName() + "_check_constraint", ccFetched.get(0).getDc_name());
Assert.assertTrue(ccFetched.get(0).isEnable_cstr());
Assert.assertFalse(ccFetched.get(0).isValidate_cstr());
Assert.assertFalse(ccFetched.get(0).isRely_cstr());
Assert.assertEquals(table.getCatName(), ccFetched.get(0).getCatName());
}
Aggregations