@Test public void testExchangePartitionDifferentValuesInPartSpec() throws Exception { Map<String, String> partitionSpecs = new HashMap<>(); partitionSpecs.put(YEAR_COL_NAME, "2017"); partitionSpecs.put("honap", "march"); partitionSpecs.put("nap", "22"); client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), destTable.getDbName(), destTable.getTableName()); checkExchangedPartitions(sourceTable, destTable, Lists.newArrayList(partitions[0], partitions[1], partitions[2], partitions[3])); checkRemainingPartitions(sourceTable, destTable, Lists.newArrayList(partitions[4])); }
@Test public void testExchangePartitionLessValueInPartSpec() throws Exception { Map<String, String> partitionSpecs = new HashMap<>(); partitionSpecs.put(YEAR_COL_NAME, "2017"); partitionSpecs.put(MONTH_COL_NAME, "march"); client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), destTable.getDbName(), destTable.getTableName()); checkExchangedPartitions(sourceTable, destTable, Lists.newArrayList(partitions[0], partitions[1])); checkRemainingPartitions(sourceTable, destTable, Lists.newArrayList(partitions[2], partitions[3], partitions[4])); }
@Test(expected = MetaException.class) public void testExchangePartitionEmptyPartSpec() throws Exception { Map<String, String> partitionSpecs = new HashMap<>(); client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), destTable.getDbName(), destTable.getTableName()); }
@Test public void testExchangePartitionYearAndMonthSet() throws Exception { Map<String, String> partitionSpecs = getPartitionSpec(Lists.newArrayList("2017", "march", "")); client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), destTable.getDbName(), destTable.getTableName()); checkExchangedPartitions(sourceTable, destTable, Lists.newArrayList(partitions[0], partitions[1])); checkRemainingPartitions(sourceTable, destTable, Lists.newArrayList(partitions[2], partitions[3], partitions[4])); }
@Test(expected = MetaException.class) public void testExchangePartitionDifferentPartColTypesInTables() throws Exception { List<FieldSchema> cols = new ArrayList<>(); cols.add(new FieldSchema(YEAR_COL_NAME, STRING_COL_TYPE, "year part col")); cols.add(new FieldSchema(MONTH_COL_NAME, INT_COL_TYPE, "month part col")); cols.add(new FieldSchema(DAY_COL_NAME, STRING_COL_TYPE, "day part col")); Table dest = createTable(DB_NAME, "test_dest_table", cols, null); Map<String, String> partitionSpecs = getPartitionSpec(partitions[1]); client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), dest.getDbName(), dest.getTableName()); }
@Test(expected = MetaException.class) public void testExchangePartitionNonExistingDestTable() throws Exception { Map<String, String> partitionSpecs = getPartitionSpec(partitions[1]); client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), DB_NAME, "nonexistingtable"); }
@Test(expected = MetaException.class) public void testExchangePartitionNullPartSpec() throws Exception { client.exchange_partition(null, sourceTable.getDbName(), sourceTable.getTableName(), null, destTable.getTableName()); }
@Test(expected = MetaException.class) public void testExchangePartitionNullSourceTable() throws Exception { Map<String, String> partitionSpecs = getPartitionSpec(partitions[1]); client.exchange_partition(partitionSpecs, DB_NAME, null, destTable.getDbName(), destTable.getTableName()); }
@Test(expected = MetaException.class) public void testExchangePartitionNoPartExists() throws Exception { Map<String, String> partitionSpecs = getPartitionSpec(Lists.newArrayList("2017", "march", "25")); client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), destTable.getDbName(), destTable.getTableName()); }
@Test(expected = MetaException.class) public void testExchangePartitionDifferentPartColsInTables() throws Exception { List<FieldSchema> cols = new ArrayList<>(); cols.add(new FieldSchema(YEAR_COL_NAME, STRING_COL_TYPE, "year part col")); cols.add(new FieldSchema(MONTH_COL_NAME, STRING_COL_TYPE, "month part col")); Table dest = createTable(DB_NAME, "test_dest_table", cols, null); Map<String, String> partitionSpecs = getPartitionSpec(partitions[1]); client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), dest.getDbName(), dest.getTableName()); }
@Test(expected = MetaException.class) public void testExchangePartitionPartAlreadyExists() throws Exception { Partition partition = buildPartition(destTable, Lists.newArrayList("2017", "march", "22"), null); client.add_partition(partition); Map<String, String> partitionSpecs = getPartitionSpec(partitions[1]); client.exchange_partition(partitionSpecs, DB_NAME, sourceTable.getTableName(), DB_NAME, destTable.getTableName()); }
@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 testExchangePartitionDifferentColNameInTables() throws Exception { List<FieldSchema> cols = new ArrayList<>(); cols.add(new FieldSchema("id", INT_COL_TYPE, "test col id")); cols.add(new FieldSchema("test_value", STRING_COL_TYPE, "test col value")); Table dest = createTable(DB_NAME, "test_dest_table", getYearMonthAndDayPartCols(), cols, null); Map<String, String> partitionSpecs = getPartitionSpec(partitions[1]); client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), dest.getDbName(), dest.getTableName()); }
@Test(expected = MetaException.class) public void testExchangePartitionEmptyDestDB() throws Exception { Map<String, String> partitionSpecs = getPartitionSpec(partitions[1]); client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), "", destTable.getTableName()); }
@Test(expected = MetaException.class) public void testExchangePartitionNullDestDB() throws Exception { Map<String, String> partitionSpecs = getPartitionSpec(partitions[1]); client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), null, destTable.getTableName()); }
@Test(expected = MetaException.class) public void testExchangePartitionEmptySourceDB() throws Exception { Map<String, String> partitionSpecs = getPartitionSpec(partitions[1]); client.exchange_partition(partitionSpecs, "", sourceTable.getTableName(), destTable.getDbName(), destTable.getTableName()); }
@Test(expected = MetaException.class) public void testExchangePartitionNonExistingSourceDB() throws Exception { Map<String, String> partitionSpecs = getPartitionSpec(partitions[1]); client.exchange_partition(partitionSpecs, "nonexistingdb", sourceTable.getTableName(), destTable.getDbName(), destTable.getTableName()); }
@Test(expected = MetaException.class) public void testExchangePartitionNonExistingDestDB() throws Exception { Map<String, String> partitionSpecs = getPartitionSpec(partitions[1]); client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), "nonexistingdb", destTable.getTableName()); }
@Test public void testExchangePartition() throws Exception { Map<String, String> partitionSpecs = getPartitionSpec(partitions[1]); 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[1])); checkRemainingPartitions(sourceTable, destTable, Lists.newArrayList(partitions[0], partitions[2], partitions[3], partitions[4])); }
@Test(expected = MetaException.class) public void testExchangePartitionNonExistingPartLocation() throws Exception { Map<String, String> partitionSpecs = getPartitionSpec(partitions[1]); metaStore.cleanWarehouseDirs(); client.exchange_partition(partitionSpecs, sourceTable.getDbName(), sourceTable.getTableName(), destTable.getDbName(), destTable.getTableName()); }