use of org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder in project hive by apache.
the class SessionHiveMetaStoreClient method appendPartition.
@Override
public Partition appendPartition(String catName, String dbName, String tableName, String partitionName) throws TException {
org.apache.hadoop.hive.metastore.api.Table table = getTempTable(dbName, tableName);
if (table == null) {
return super.appendPartition(catName, dbName, tableName, partitionName);
}
if (partitionName == null || partitionName.isEmpty()) {
throw new MetaException("The partition must be not null or empty.");
}
assertTempTablePartitioned(table);
Map<String, String> specFromName = makeSpecFromName(partitionName);
if (specFromName == null || specFromName.isEmpty()) {
throw new InvalidObjectException("Invalid partition name " + partitionName);
}
List<String> pVals = new ArrayList<>();
for (FieldSchema field : table.getPartitionKeys()) {
String val = specFromName.get(field.getName());
if (val == null) {
throw new InvalidObjectException("Partition name " + partitionName + " and table partition keys " + Arrays.toString(table.getPartitionKeys().toArray()) + " does not match");
}
pVals.add(val);
}
Partition partition = new PartitionBuilder().inTable(table).setValues(pVals).build(conf);
return appendPartitionToTempTable(table, partition);
}
use of org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder in project hive by apache.
the class TestSchemaToolCatalogOps method moveTable.
@Test
public void moveTable() throws TException, HiveMetaException {
String toCatName = "moveTableCat";
String toDbName = "moveTableDb";
String tableName = "moveTableTable";
String partVal = "moveTableKey";
new CatalogBuilder().setName(toCatName).setLocation("file:///tmp").create(client);
new DatabaseBuilder().setCatalogName(toCatName).setName(toDbName).create(client, conf);
Table table = new TableBuilder().setTableName(tableName).addCol("a", "int").addPartCol("p", "string").create(client, conf);
new PartitionBuilder().inTable(table).addValue(partVal).addToTable(client, conf);
String argsMoveTable = String.format("-moveTable %s -fromCatalog %s -toCatalog %s -fromDatabase %s -toDatabase %s", tableName, DEFAULT_CATALOG_NAME, toCatName, DEFAULT_DATABASE_NAME, toDbName);
execute(new SchemaToolTaskMoveTable(), argsMoveTable);
Table fetchedTable = client.getTable(toCatName, toDbName, tableName);
Assert.assertNotNull(fetchedTable);
Assert.assertEquals(toCatName.toLowerCase(), fetchedTable.getCatName());
Assert.assertEquals(toDbName.toLowerCase(), fetchedTable.getDbName());
Partition fetchedPart = client.getPartition(toCatName, toDbName, tableName, Collections.singletonList(partVal));
Assert.assertNotNull(fetchedPart);
Assert.assertEquals(toCatName.toLowerCase(), fetchedPart.getCatName());
Assert.assertEquals(toDbName.toLowerCase(), fetchedPart.getDbName());
Assert.assertEquals(tableName.toLowerCase(), fetchedPart.getTableName());
}
use of org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder in project hive by apache.
the class TestTenantBasedStorageHierarchy method addPartition.
private void addPartition(IMetaStoreClient client, Table table, List<String> values) throws TException {
PartitionBuilder partitionBuilder = new PartitionBuilder().inTable(table);
values.forEach(val -> partitionBuilder.addValue(val));
Partition p = partitionBuilder.build(conf);
// PartitionBuilder uses 0 as default whereas we use -1 for Tables.
p.getSd().setNumBuckets(-1);
client.add_partition(p);
}
use of org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder in project hive by apache.
the class TestHiveMetastoreTransformer method addPartition.
private void addPartition(IMetaStoreClient client, Table table, List<String> values) throws TException {
PartitionBuilder partitionBuilder = new PartitionBuilder().inTable(table);
values.forEach(val -> partitionBuilder.addValue(val));
Partition p = partitionBuilder.build(conf);
p.getSd().setNumBuckets(table.getSd().getNumBuckets());
client.add_partition(p);
}
use of org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder in project hive by apache.
the class TestAddPartitions method testAddPartitionNoValueInPartition.
@Test(expected = MetaException.class)
public void testAddPartitionNoValueInPartition() throws Exception {
createTable();
Partition partition = new PartitionBuilder().setDbName(DB_NAME).setTableName(TABLE_NAME).addCol(YEAR_COL_NAME, DEFAULT_COL_TYPE).setLocation(metaStore.getWarehouseRoot() + "/addparttest").build(metaStore.getConf());
client.add_partition(partition);
}
Aggregations