Add Hive integration test for overwrite existing partitions
@@ -1152,6 +1152,63 @@ public class TestHiveIntegrationSmokeTest
assertFalse(getQueryRunner().tableExists(session, tableName));
}
+ @Test
+ public void testInsertPartitionedTableOverwriteExistingPartition()
+ {
+ testInsertPartitionedTableOverwriteExistingPartition(
+ Session.builder(getSession())
+ .setCatalogSessionProperty(catalog, "insert_existing_partitions_behavior", "OVERWRITE")
+ .build(),
+ HiveStorageFormat.ORC);
+ }
+
+ private void testInsertPartitionedTableOverwriteExistingPartition(Session session, HiveStorageFormat storageFormat)
+ {
+ String tableName = "test_insert_partitioned_table_overwrite_existing_partition";
+
+ @Language("SQL") String createTable = "" +
+ "CREATE TABLE " + tableName + " " +
+ "(" +
+ " order_key BIGINT," +
+ " comment VARCHAR," +
+ " order_status VARCHAR" +
+ ") " +
+ "WITH (" +
+ "format = '" + storageFormat + "', " +
+ "partitioned_by = ARRAY[ 'order_status' ]" +
+ ") ";
+
+ assertUpdate(session, createTable);
+
+ TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, tableName);
+ assertEquals(tableMetadata.getMetadata().getProperties().get(STORAGE_FORMAT_PROPERTY), storageFormat);
+ assertEquals(tableMetadata.getMetadata().getProperties().get(PARTITIONED_BY_PROPERTY), ImmutableList.of("order_status"));
+
+ for (int i = 0; i < 3; i++) {
+ assertUpdate(
+ session,
+ format(
+ "INSERT INTO " + tableName + " " +
+ "SELECT orderkey, comment, orderstatus " +
+ "FROM tpch.tiny.orders " +
+ "WHERE orderkey %% 3 = %d",
+ i),
+ format("SELECT count(*) from orders where orderkey %% 3 = %d", i));
+
+ // verify the partitions
+ List<?> partitions = getPartitions(tableName);
+ assertEquals(partitions.size(), 3);
+
+ assertQuery(
+ session,
+ "SELECT * from " + tableName,
+ format("SELECT orderkey, comment, orderstatus FROM orders where orderkey %% 3 = %d", i));
+ }
+ assertUpdate(session, "DROP TABLE " + tableName);
+
+ assertFalse(getQueryRunner().tableExists(session, tableName));
+ }
+
@Test
public void testNullPartitionValues()
{
