Skip to content

Commit

Permalink
Add product tests for full acid reads
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham Tagra authored and dain committed Feb 19, 2020
1 parent e498a33 commit 9b917d1
Showing 1 changed file with 66 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
*/
package io.prestosql.tests.hive.acid;

import io.prestosql.tempto.query.QueryResult;
import io.prestosql.tests.hive.HiveProductTest;
import org.testng.SkipException;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import static io.prestosql.tempto.assertions.QueryAssert.Row.row;
import static io.prestosql.tempto.assertions.QueryAssert.assertThat;
import static io.prestosql.tempto.query.QueryExecutor.query;
import static io.prestosql.tests.TestGroups.HIVE_TRANSACTIONAL;
Expand All @@ -26,23 +29,78 @@
public class TestFullAcidTableRead
extends HiveProductTest
{
@Test(groups = {STORAGE_FORMATS, HIVE_TRANSACTIONAL})
public void testRead()
@Test(groups = {STORAGE_FORMATS, HIVE_TRANSACTIONAL}, dataProvider = "isTablePartitioned")
public void testRead(boolean isPartitioned)
{
if (getHiveVersionMajor() < 3) {
throw new SkipException("Presto Hive transactional tables are supported with Hive version 3 or above");
}

String tableName = "full_acid_read";
onHive().executeQuery("" +
"CREATE TABLE " + tableName + "(a bigint)" +
"STORED AS ORC TBLPROPERTIES ('transactional'='true')");
String tableName = isPartitioned ? "full_acid_read_partitioned" : "full_acid_read";
createTable(tableName, isPartitioned);

try {
assertThat(() -> query("SELECT * FROM " + tableName))
.failsWithMessage("Full ACID tables are not supported: default." + tableName);
onHive().executeQuery("INSERT OVERWRITE TABLE " + tableName + getHivePartitionString(isPartitioned) + " VALUES (21, 1)");

String selectFromOnePartitionsSql = "SELECT col, fcol FROM " + tableName + " ORDER BY col";
QueryResult onePartitionQueryResult = query(selectFromOnePartitionsSql);
assertThat(onePartitionQueryResult).containsOnly(row(21, 1));

onHive().executeQuery("INSERT INTO TABLE " + tableName + getHivePartitionString(isPartitioned) + " VALUES (22, 2)");
onePartitionQueryResult = query(selectFromOnePartitionsSql);
assertThat(onePartitionQueryResult).containsExactly(row(21, 1), row(22, 2));

// test filtering
onePartitionQueryResult = query("SELECT col, fcol FROM " + tableName + " WHERE fcol = 1 ORDER BY col");
assertThat(onePartitionQueryResult).containsOnly(row(21, 1));

// delete a row
onHive().executeQuery("DELETE FROM " + tableName + " WHERE fcol=2");
onePartitionQueryResult = query(selectFromOnePartitionsSql);
assertThat(onePartitionQueryResult).containsOnly(row(21, 1));

// update the existing row
onHive().executeQuery("UPDATE " + tableName + " SET col = 23 " + addPartitionPredicate(isPartitioned, "fcol = 1"));
onePartitionQueryResult = query(selectFromOnePartitionsSql);
assertThat(onePartitionQueryResult).containsOnly(row(23, 1));
}
finally {
onHive().executeQuery("DROP TABLE " + tableName);
}
}

private static String getHivePartitionString(boolean isPartitioned)
{
if (!isPartitioned) {
return "";
}

return " PARTITION (part_col=2) ";
}

private static String addPartitionPredicate(boolean isPartitioned, String columnPredicate)
{
String predicate = " WHERE " + columnPredicate;
if (isPartitioned) {
predicate += " AND part_col = 2 ";
}
return predicate;
}

private static void createTable(String tableName, boolean isPartitioned)
{
onHive().executeQuery("CREATE TABLE IF NOT EXISTS " + tableName + " (col INT, fcol INT) " +
(isPartitioned ? "PARTITIONED BY (part_col INT) " : "") +
"STORED AS ORC " +
"TBLPROPERTIES ('transactional'='true') ");
}

@DataProvider
public Object[][] isTablePartitioned()
{
return new Object[][] {
{true},
{false}
};
}
}

0 comments on commit 9b917d1

Please sign in to comment.