本文整理了Java中org.apache.hadoop.hive.metastore.api.Partition
类的一些代码示例,展示了Partition
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Partition
类的具体详情如下:
包路径:org.apache.hadoop.hive.metastore.api.Partition
类名称:Partition
暂无
代码示例来源:origin: apache/hive
setTPartition(tPartition);
if (table.isView()) {
return;
if (table.isPartitioned()) {
try {
if (tPartition.getSd().getLocation() == null) {
if (table.getDataLocation() != null) {
Path partPath = new Path(table.getDataLocation(), Warehouse.makePartName(table.getPartCols(), tPartition.getValues()));
tPartition.getSd().setLocation(partPath.toString());
if (tPartition.getSd().getCols() == null) {
if (table.getCols() != null) {
tPartition.getSd().setCols(table.getCols());
throw new HiveException("Invalid partition for table " + table.getTableName(),
e);
代码示例来源:origin: apache/hive
public static org.apache.hadoop.hive.metastore.api.Partition createMetaPartitionObject(
Table tbl, Map<String, String> partSpec, Path location) throws HiveException {
List<String> pvals = new ArrayList<String>();
for (FieldSchema field : tbl.getPartCols()) {
String val = partSpec.get(field.getName());
if (val == null || val.isEmpty()) {
throw new HiveException("partition spec is invalid; field "
+ field.getName() + " does not exist or is empty");
}
pvals.add(val);
}
org.apache.hadoop.hive.metastore.api.Partition tpart =
new org.apache.hadoop.hive.metastore.api.Partition();
tpart.setDbName(tbl.getDbName());
tpart.setTableName(tbl.getTableName());
tpart.setValues(pvals);
if (!tbl.isView()) {
tpart.setSd(tbl.getSd().deepCopy());
tpart.getSd().setLocation((location != null) ? location.toString() : null);
}
return tpart;
}
代码示例来源:origin: apache/hive
public static Properties getPartitionMetadata(
org.apache.hadoop.hive.metastore.api.Partition partition,
org.apache.hadoop.hive.metastore.api.Table table) {
return MetaStoreUtils
.getSchema(partition.getSd(), partition.getSd(), partition
.getParameters(), table.getDbName(), table.getTableName(),
table.getPartitionKeys());
}
代码示例来源:origin: apache/hive
private void dropPartition(Partition partition, boolean ifExists, boolean deleteData)
throws HCatException, MetaException, TException {
try {
hmsClient.dropPartition(partition.getDbName(), partition.getTableName(), partition.getValues(), deleteData);
} catch (NoSuchObjectException e) {
if (!ifExists) {
throw new ObjectNotFoundException(
"NoSuchObjectException while dropping partition: " + partition.getValues(), e);
}
}
}
代码示例来源:origin: apache/hive
public HiveObjectRef buildPartitionReference(Partition part) {
return new HiveObjectRef(HiveObjectType.PARTITION, part.getDbName(), part.getTableName(),
part.getValues(), null);
}
代码示例来源:origin: apache/hive
@Test
public void testAddPartitionSpecSetRootPath() throws Exception {
Table table = createTable();
String rootPath = table.getSd().getLocation() + "/addPartSpecRootPath/";
String rootPath1 = table.getSd().getLocation() + "/someotherpath/";
Partition partition = buildPartition(DB_NAME, TABLE_NAME, "2007", rootPath + "part2007/");
PartitionSpecProxy partitionSpecProxy =
buildPartitionSpec(DB_NAME, TABLE_NAME, rootPath1, Lists.newArrayList(partition));
client.add_partitions_pspec(partitionSpecProxy);
Partition resultPart = client.getPartition(DB_NAME, TABLE_NAME, Lists.newArrayList("2007"));
Assert.assertEquals(rootPath + "part2007", resultPart.getSd().getLocation());
}
代码示例来源:origin: apache/hive
@Test(expected = MetaException.class)
public void testRenamePartitionChangeTblName() throws Exception {
List<List<String>> oldValues = createTable4PartColsParts(client);
List<Partition> oldParts = client.listPartitions(DB_NAME, TABLE_NAME, (short)-1);
Partition partToRename = oldParts.get(3);
partToRename.setValues(Lists.newArrayList("2018", "01", "16"));
partToRename.setTableName(TABLE_NAME + "_2");
client.renamePartition(DB_NAME, TABLE_NAME, oldValues.get(3), partToRename);
}
代码示例来源:origin: apache/hive
@Test
public void testDropPartitionNullPartDropOptions() throws Exception {
client.dropPartition(DB_NAME, TABLE_NAME, PARTITIONS[0].getValues(), null);
List<Partition> droppedPartitions = Lists.newArrayList(PARTITIONS[0]);
List<Partition> remainingPartitions = Lists.newArrayList(PARTITIONS[1], PARTITIONS[2]);
checkPartitionsAfterDelete(TABLE_NAME, droppedPartitions, remainingPartitions, true, false);
}
代码示例来源:origin: apache/hive
@Test
public void testDropPartitionDeleteParentDir() throws Exception {
client.dropPartition(DB_NAME, TABLE_NAME, PARTITIONS[0].getValues(), true);
client.dropPartition(DB_NAME, TABLE_NAME, PARTITIONS[1].getValues(), true);
List<Partition> droppedPartitions = Lists.newArrayList(PARTITIONS[0], PARTITIONS[1]);
List<Partition> remainingPartitions = Lists.newArrayList(PARTITIONS[2]);
checkPartitionsAfterDelete(TABLE_NAME, droppedPartitions, remainingPartitions, true, false);
Path parentPath = new Path(PARTITIONS[0].getSd().getLocation()).getParent();
Assert.assertFalse("The parent path '" + parentPath.toString() + "' should not exist.",
metaStore.isPathExists(parentPath));
}
代码示例来源:origin: apache/hive
@Test
public void testAddPartitionUpperCase() throws Exception {
String tableLocation = metaStore.getWarehouseRoot() + "/" + TABLE_NAME;
createTable(DB_NAME, TABLE_NAME, getMonthPartCol(), tableLocation);
Partition partition = buildPartition(Lists.newArrayList("APRIL"), getMonthPartCol(), 1);
client.add_partition(partition);
Partition part = client.getPartition(DB_NAME, TABLE_NAME, "month=APRIL");
Assert.assertNotNull(part);
Assert.assertEquals(TABLE_NAME, part.getTableName());
Assert.assertEquals(DB_NAME, part.getDbName());
Assert.assertEquals("APRIL", part.getValues().get(0));
Assert.assertEquals(tableLocation + "/month=APRIL", part.getSd().getLocation());
Assert.assertTrue(metaStore.isPathExists(new Path(part.getSd().getLocation())));
}
代码示例来源:origin: apache/hive
@Test
public void testExchangePartitionYearSet() throws Exception {
Map<String, String> partitionSpecs = getPartitionSpec(Lists.newArrayList("2017", "", ""));
Partition exchangedPartition =
client.exchange_partition(partitionSpecs, sourceTable.getDbName(),
sourceTable.getTableName(), destTable.getDbName(), destTable.getTableName());
Assert.assertEquals(new Partition(), exchangedPartition);
checkExchangedPartitions(sourceTable, destTable,
Lists.newArrayList(partitions[0], partitions[1], partitions[2], partitions[3]));
checkRemainingPartitions(sourceTable, destTable, Lists.newArrayList(partitions[4]));
}
代码示例来源:origin: apache/hive
@Test(expected = MetaException.class)
public void testAddPartitionsNullColNameInSd() throws Exception {
createTable();
Partition partition = buildPartition(DB_NAME, TABLE_NAME, DEFAULT_YEAR_VALUE);
partition.getSd().getCols().get(0).setName(null);
client.add_partitions(Lists.newArrayList(partition));
}
代码示例来源:origin: apache/hive
@Test(expected = MetaException.class)
public void testAlterPartitionsChangeDbName() throws Exception {
createTable4PartColsParts(client);
List<Partition> partitions = client.listPartitions(DB_NAME, TABLE_NAME, (short)-1);
Partition p = partitions.get(3);
p.setDbName(DB_NAME+"_changed");
client.alter_partitions(DB_NAME, TABLE_NAME, Lists.newArrayList(p));
}
代码示例来源:origin: apache/hive
@Test(expected = MetaException.class)
public void testAlterPartitionsChangeTableName() throws Exception {
createTable4PartColsParts(client);
List<Partition> partitions = client.listPartitions(DB_NAME, TABLE_NAME, (short)-1);
Partition p = partitions.get(3);
p.setTableName(TABLE_NAME+"_changed");
client.alter_partitions(DB_NAME, TABLE_NAME, Lists.newArrayList(p));
}
代码示例来源:origin: apache/hive
@Test
public void testAddPartitionsForViewNullPartLocation() throws Exception {
String tableName = "test_add_partition_view";
createView(tableName);
Partition partition = buildPartition(DB_NAME, tableName, DEFAULT_YEAR_VALUE);
partition.getSd().setLocation(null);
List<Partition> partitions = Lists.newArrayList(partition);
client.add_partitions(partitions);
Partition part = client.getPartition(DB_NAME, tableName, "year=2017");
Assert.assertNull(part.getSd().getLocation());
}
代码示例来源:origin: apache/hive
@Test
public void testAddPartitionSpecForViewNullPartLocation() throws Exception {
String tableName = "test_add_partition_view";
createView(tableName);
Partition partition = buildPartition(DB_NAME, tableName, DEFAULT_YEAR_VALUE);
partition.getSd().setLocation(null);
PartitionSpecProxy partitionSpecProxy =
buildPartitionSpec(DB_NAME, tableName, null, Lists.newArrayList(partition));
client.add_partitions_pspec(partitionSpecProxy);
Partition part = client.getPartition(DB_NAME, tableName, "year=2017");
Assert.assertNull(part.getSd().getLocation());
}
代码示例来源:origin: apache/hive
@Test(expected = InvalidOperationException.class)
public void testRenamePartitionNoTable() throws Exception {
client.renamePartition(DB_NAME, TABLE_NAME, Lists.newArrayList("2018", "01", "16"),
new Partition());
}
代码示例来源:origin: apache/hive
@Test
public void testAddPartitionsForViewNullPartSd() throws Exception {
String tableName = "test_add_partition_view";
createView(tableName);
Partition partition = buildPartition(DB_NAME, tableName, DEFAULT_YEAR_VALUE);
partition.setSd(null);
List<Partition> partitions = Lists.newArrayList(partition);
client.add_partitions(partitions);
Partition part = client.getPartition(DB_NAME, tableName, "year=2017");
Assert.assertNull(part.getSd());
}
代码示例来源:origin: apache/hive
@Test
public void testAddPartitionsWithSameNameCaseSensitive() throws Exception {
createTable(DB_NAME, TABLE_NAME, getMonthPartCol(),
metaStore.getWarehouseRoot() + "/" + TABLE_NAME);
Partition partition1 = buildPartition(Lists.newArrayList("may"), getMonthPartCol(), 1);
Partition partition2 = buildPartition(Lists.newArrayList("MAY"), getMonthPartCol(), 2);
client.add_partition(partition1);
client.add_partition(partition2);
Partition part = client.getPartition(DB_NAME, TABLE_NAME, "month=MAY");
Assert.assertEquals(DEFAULT_PARAM_VALUE + "2",
part.getParameters().get(DEFAULT_PARAM_KEY + "2"));
Assert.assertEquals(metaStore.getWarehouseRoot() + "/" + TABLE_NAME + "/month=MAY",
part.getSd().getLocation());
}
代码示例来源:origin: apache/hive
@Test(expected = MetaException.class)
public void testAddPartitionsEmptySerdeInfo() throws Exception {
createTable();
Partition partition = buildPartition(DB_NAME, TABLE_NAME, DEFAULT_YEAR_VALUE);
partition.getSd().setSerdeInfo(null);
client.add_partitions(Lists.newArrayList(partition));
}
内容来源于网络,如有侵权,请联系作者删除!