private PartitionWithoutSD buildPartitionWithoutSD(List<String> values, int index) throws MetaException { PartitionWithoutSD partition = new PartitionWithoutSD(); partition.setCreateTime(DEFAULT_CREATE_TIME); partition.setLastAccessTime(DEFAULT_CREATE_TIME); partition.setValues(values); Map<String, String> parameters = new HashMap<>(); parameters.put(DEFAULT_PARAM_KEY + index, DEFAULT_PARAM_VALUE + index); partition.setParameters(parameters); partition.setRelativePath("partwithoutsd" + index); return partition; }
@Test(expected = MetaException.class) public void testAddPartitionSpecWithSharedSDNullLocation() throws Exception { createTable(); PartitionWithoutSD partition = buildPartitionWithoutSD(Lists.newArrayList("2002"), 0); partition.setRelativePath("year2002"); String location = null; PartitionSpecProxy partitionSpecProxy = buildPartitionSpecWithSharedSD(Lists.newArrayList(partition), buildSD(location)); client.add_partitions_pspec(partitionSpecProxy); }
@Test(expected = MetaException.class) public void testAddPartitionSpecWithSharedSDEmptyLocation() throws Exception { createTable(); PartitionWithoutSD partition = buildPartitionWithoutSD(Lists.newArrayList("2002"), 0); partition.setRelativePath("year2002"); PartitionSpecProxy partitionSpecProxy = buildPartitionSpecWithSharedSD(Lists.newArrayList(partition), buildSD("")); client.add_partitions_pspec(partitionSpecProxy); }
partitionWithoutSD.setCreateTime(partition.getCreateTime()); partitionWithoutSD.setLastAccessTime(partition.getLastAccessTime()); partitionWithoutSD.setRelativePath( (isUnsetKey || !partition.getSd().isSetLocation()) ? null : partition.getSd() .getLocation().substring(tablePath.length()));
@Test(expected = MetaException.class) public void testAddPartitionSpecWithSharedSDInvalidSD() throws Exception { Table table = createTable(); PartitionWithoutSD partition = buildPartitionWithoutSD(Lists.newArrayList("2002"), 0); partition.setRelativePath("year2002"); StorageDescriptor sd = new StorageDescriptor(); sd.setLocation(table.getSd().getLocation() + "/nullLocationTest/"); PartitionSpecProxy partitionSpecProxy = buildPartitionSpecWithSharedSD(Lists.newArrayList(partition), sd); client.add_partitions_pspec(partitionSpecProxy); }
@Test public void testAddPartitionSpecWithSharedSDEmptyValue() throws Exception { Table table = createTable(); PartitionWithoutSD partition = new PartitionWithoutSD(); partition.setRelativePath("addpartspectest"); partition.setValues(Lists.newArrayList("")); String location = table.getSd().getLocation() + "/nullValueTest/"; PartitionSpecProxy partitionSpecProxy = buildPartitionSpecWithSharedSD(Lists.newArrayList(partition), buildSD(location)); client.add_partitions_pspec(partitionSpecProxy); List<String> partitionNames = client.listPartitionNames(DB_NAME, TABLE_NAME, MAX); Assert.assertNotNull(partitionNames); Assert.assertTrue(partitionNames.size() == 1); Assert.assertEquals("year=__HIVE_DEFAULT_PARTITION__", partitionNames.get(0)); }
@Test(expected=MetaException.class) public void testAddPartitionSpecWithSharedSDNoValue() throws Exception { Table table = createTable(); PartitionWithoutSD partition = new PartitionWithoutSD(); partition.setRelativePath("addpartspectest"); String location = table.getSd().getLocation() + "/nullValueTest/"; PartitionSpecProxy partitionSpecProxy = buildPartitionSpecWithSharedSD(Lists.newArrayList(partition), buildSD(location)); client.add_partitions_pspec(partitionSpecProxy); }
@Test public void testAddPartitionSpecWithSharedSDNoRelativePath() throws Exception { Table table = createTable(); PartitionWithoutSD partition1 = buildPartitionWithoutSD(Lists.newArrayList("2007"), 0); PartitionWithoutSD partition2 = buildPartitionWithoutSD(Lists.newArrayList("2008"), 0); partition1.setRelativePath(null); partition2.setRelativePath(null); String location = table.getSd().getLocation() + "/noRelativePath/"; PartitionSpecProxy partitionSpecProxy = buildPartitionSpecWithSharedSD( Lists.newArrayList(partition1, partition2), buildSD(location)); client.add_partitions_pspec(partitionSpecProxy); Partition resultPart1 = client.getPartition(DB_NAME, TABLE_NAME, Lists.newArrayList("2007")); Assert.assertEquals(location + "null", resultPart1.getSd().getLocation()); Assert.assertTrue(metaStore.isPathExists(new Path(resultPart1.getSd().getLocation()))); Partition resultPart2 = client.getPartition(DB_NAME, TABLE_NAME, Lists.newArrayList("2008")); Assert.assertEquals(location + "null", resultPart2.getSd().getLocation()); Assert.assertTrue(metaStore.isPathExists(new Path(resultPart2.getSd().getLocation()))); }
unsetRelativePath(); } else { setRelativePath((String)value);
@Test public void testAddPartitionSpecWithSharedSDWithoutRelativePath() throws Exception { Table table = createTable(); PartitionWithoutSD partition = buildPartitionWithoutSD(Lists.newArrayList("2014"), 0); partition.setRelativePath(null); String location = table.getSd().getLocation() + "/sharedSDTest/"; PartitionSpecProxy partitionSpecProxy = buildPartitionSpecWithSharedSD(Lists.newArrayList(partition), buildSD(location)); client.add_partitions_pspec(partitionSpecProxy); Partition part = client.getPartition(DB_NAME, TABLE_NAME, "year=2014"); Assert.assertNotNull(part); Assert.assertEquals(table.getSd().getLocation() + "/sharedSDTest/null", part.getSd().getLocation()); Assert.assertTrue(metaStore.isPathExists(new Path(part.getSd().getLocation()))); }
unsetRelativePath(); } else { setRelativePath((String)value);
unsetRelativePath(); } else { setRelativePath((String)value);