use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.
the class TestListPartitions method createTestTable.
protected Table createTestTable(IMetaStoreClient client, String dbName, String tableName, List<String> partCols, boolean setPartitionLevelPrivilages) throws TException {
TableBuilder builder = new TableBuilder().setDbName(dbName).setTableName(tableName).addCol("id", "int").addCol("name", "string");
partCols.forEach(col -> builder.addPartCol(col, "string"));
Table table = builder.build(metaStore.getConf());
if (setPartitionLevelPrivilages) {
table.putToParameters("PARTITION_LEVEL_PRIVILEGE", "true");
}
client.createTable(table);
return table;
}
use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.
the class TestListPartitions method otherCatalog.
@Test
@ConditionalIgnoreOnSessionHiveMetastoreClient
public void otherCatalog() throws TException {
String catName = "list_partition_catalog";
Catalog cat = new CatalogBuilder().setName(catName).setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)).build();
client.createCatalog(cat);
String dbName = "list_partition_database_in_other_catalog";
Database db = new DatabaseBuilder().setName(dbName).setCatalogName(catName).create(client, metaStore.getConf());
String tableName = "table_in_other_catalog";
Table table = new TableBuilder().inDb(db).setTableName(tableName).addCol("id", "int").addCol("name", "string").addPartCol("partcol", "string").create(client, metaStore.getConf());
Partition[] parts = new Partition[5];
for (int i = 0; i < parts.length; i++) {
parts[i] = new PartitionBuilder().inTable(table).addValue("a" + i).build(metaStore.getConf());
}
client.add_partitions(Arrays.asList(parts));
List<Partition> fetched = client.listPartitions(catName, dbName, tableName, -1);
Assert.assertEquals(parts.length, fetched.size());
Assert.assertEquals(catName, fetched.get(0).getCatName());
fetched = client.listPartitions(catName, dbName, tableName, Collections.singletonList("a0"), -1);
Assert.assertEquals(1, fetched.size());
Assert.assertEquals(catName, fetched.get(0).getCatName());
PartitionSpecProxy proxy = client.listPartitionSpecs(catName, dbName, tableName, -1);
Assert.assertEquals(parts.length, proxy.size());
Assert.assertEquals(catName, proxy.getCatName());
fetched = client.listPartitionsByFilter(catName, dbName, tableName, "partcol=\"a0\"", -1);
Assert.assertEquals(1, fetched.size());
Assert.assertEquals(catName, fetched.get(0).getCatName());
proxy = client.listPartitionSpecsByFilter(catName, dbName, tableName, "partcol=\"a0\"", -1);
Assert.assertEquals(1, proxy.size());
Assert.assertEquals(catName, proxy.getCatName());
Assert.assertEquals(1, client.getNumPartitionsByFilter(catName, dbName, tableName, "partcol=\"a0\""));
List<String> names = client.listPartitionNames(catName, dbName, tableName, 57);
Assert.assertEquals(parts.length, names.size());
names = client.listPartitionNames(catName, dbName, tableName, Collections.singletonList("a0"), Short.MAX_VALUE + 1);
Assert.assertEquals(1, names.size());
PartitionValuesRequest rqst = new PartitionValuesRequest(dbName, tableName, Lists.newArrayList(new FieldSchema("partcol", "string", "")));
rqst.setCatName(catName);
PartitionValuesResponse rsp = client.listPartitionValues(rqst);
Assert.assertEquals(5, rsp.getPartitionValuesSize());
}
use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.
the class TestNotNullConstraint 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<SQLNotNullConstraint> nn = new SQLNotNullConstraintBuilder().onTable(table).addColumn("col1").setConstraintName(constraintName).build(metaStore.getConf());
client.createTableWithConstraints(table, null, null, null, nn, null, null);
NotNullConstraintsRequest rqst = new NotNullConstraintsRequest(table.getCatName(), table.getDbName(), table.getTableName());
List<SQLNotNullConstraint> fetched = client.getNotNullConstraints(rqst);
Assert.assertEquals(nn, fetched);
client.dropConstraint(table.getCatName(), table.getDbName(), table.getTableName(), constraintName);
rqst = new NotNullConstraintsRequest(table.getCatName(), table.getDbName(), table.getTableName());
fetched = client.getNotNullConstraints(rqst);
Assert.assertTrue(fetched.isEmpty());
}
use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.
the class TestTablesGetExists method otherCatalog.
// Tests for getTable in other catalogs are covered in TestTablesCreateDropAlterTruncate.
@Test
public void otherCatalog() throws TException {
String catName = "get_exists_tables_in_other_catalogs";
Catalog cat = new CatalogBuilder().setName(catName).setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)).build();
client.createCatalog(cat);
String dbName = "db_in_other_catalog";
// For this one don't specify a location to make sure it gets put in the catalog directory
Database db = new DatabaseBuilder().setName(dbName).setCatalogName(catName).create(client, metaStore.getConf());
String[] tableNames = new String[4];
for (int i = 0; i < tableNames.length; i++) {
tableNames[i] = "table_in_other_catalog_" + i;
new TableBuilder().inDb(db).setTableName(tableNames[i]).addCol("col1_" + i, ColumnType.STRING_TYPE_NAME).addCol("col2_" + i, ColumnType.INT_TYPE_NAME).create(client, metaStore.getConf());
}
Set<String> tables = new HashSet<>(client.getTables(catName, dbName, "*e_in_other_*"));
Assert.assertEquals(4, tables.size());
for (String tableName : tableNames) Assert.assertTrue(tables.contains(tableName));
List<String> fetchedNames = client.getTables(catName, dbName, "*_3");
Assert.assertEquals(1, fetchedNames.size());
Assert.assertEquals(tableNames[3], fetchedNames.get(0));
Assert.assertTrue("Table exists", client.tableExists(catName, dbName, tableNames[0]));
Assert.assertFalse("Table not exists", client.tableExists(catName, dbName, "non_existing_table"));
}
use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.
the class TestUniqueConstraint 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<SQLUniqueConstraint> uc = new SQLUniqueConstraintBuilder().onTable(table).addColumn("col1").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);
uc.get(0).setUk_name(fetched.get(0).getUk_name());
Assert.assertEquals(uc, fetched);
client.dropConstraint(table.getCatName(), table.getDbName(), table.getTableName(), uc.get(0).getUk_name());
rqst = new UniqueConstraintsRequest(table.getCatName(), table.getDbName(), table.getTableName());
fetched = client.getUniqueConstraints(rqst);
Assert.assertTrue(fetched.isEmpty());
}
Aggregations