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);
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; }
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()); }
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); } } }
public HiveObjectRef buildPartitionReference(Partition part) { return new HiveObjectRef(HiveObjectType.PARTITION, part.getDbName(), part.getTableName(), part.getValues(), null); }
@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()); }
@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); }
@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); }
@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)); }
@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()))); }
@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])); }
@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)); }
@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)); }
@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)); }
@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()); }
@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()); }
@Test(expected = InvalidOperationException.class) public void testRenamePartitionNoTable() throws Exception { client.renamePartition(DB_NAME, TABLE_NAME, Lists.newArrayList("2018", "01", "16"), new Partition()); }
@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()); }
@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()); }
@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)); }