use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class TestRaptorIntegrationSmokeTest method testTableStatsSystemTable.
@SuppressWarnings("OverlyStrongTypeCast")
@Test
public void testTableStatsSystemTable() throws Exception {
// basic sanity tests
assertQuery("" + "SELECT table_schema, table_name, sum(row_count)\n" + "FROM system.table_stats\n" + "WHERE table_schema = 'tpch'\n" + " AND table_name IN ('orders', 'lineitem')\n" + "GROUP BY 1, 2", "" + "SELECT 'tpch', 'orders', (SELECT count(*) FROM orders)\n" + "UNION ALL\n" + "SELECT 'tpch', 'lineitem', (SELECT count(*) FROM lineitem)");
assertQuery("" + "SELECT\n" + " bool_and(row_count >= shard_count)\n" + ", bool_and(update_time >= create_time)\n" + ", bool_and(table_version >= 1)\n" + "FROM system.table_stats\n" + "WHERE row_count > 0", "SELECT true, true, true");
// create empty table
assertUpdate("CREATE TABLE test_table_stats (x bigint)");
@Language("SQL") String sql = "" + "SELECT create_time, update_time, table_version," + " shard_count, row_count, uncompressed_size\n" + "FROM system.table_stats\n" + "WHERE table_schema = 'tpch'\n" + " AND table_name = 'test_table_stats'";
MaterializedRow row = getOnlyElement(computeActual(sql).getMaterializedRows());
Timestamp createTime = (Timestamp) row.getField(0);
Timestamp updateTime1 = (Timestamp) row.getField(1);
assertEquals(createTime, updateTime1);
// table_version
assertEquals(row.getField(2), 1L);
// shard_count
assertEquals(row.getField(3), 0L);
// row_count
assertEquals(row.getField(4), 0L);
// uncompressed_size
long size1 = (long) row.getField(5);
// insert
assertUpdate("INSERT INTO test_table_stats VALUES (1), (2), (3), (4)", 4);
row = getOnlyElement(computeActual(sql).getMaterializedRows());
assertEquals(row.getField(0), createTime);
Timestamp updateTime2 = (Timestamp) row.getField(1);
assertLessThan(updateTime1, updateTime2);
// table_version
assertEquals(row.getField(2), 2L);
// shard_count
assertGreaterThanOrEqual((Long) row.getField(3), 1L);
// row_count
assertEquals(row.getField(4), 4L);
// uncompressed_size
long size2 = (long) row.getField(5);
assertGreaterThan(size2, size1);
// delete
assertUpdate("DELETE FROM test_table_stats WHERE x IN (2, 4)", 2);
row = getOnlyElement(computeActual(sql).getMaterializedRows());
assertEquals(row.getField(0), createTime);
Timestamp updateTime3 = (Timestamp) row.getField(1);
assertLessThan(updateTime2, updateTime3);
// table_version
assertEquals(row.getField(2), 3L);
// shard_count
assertGreaterThanOrEqual((Long) row.getField(3), 1L);
// row_count
assertEquals(row.getField(4), 2L);
// uncompressed_Size
long size3 = (long) row.getField(5);
assertLessThan(size3, size2);
// add column
assertUpdate("ALTER TABLE test_table_stats ADD COLUMN y bigint");
row = getOnlyElement(computeActual(sql).getMaterializedRows());
assertEquals(row.getField(0), createTime);
assertLessThan(updateTime3, (Timestamp) row.getField(1));
// table_version
assertEquals(row.getField(2), 4L);
// row_count
assertEquals(row.getField(4), 2L);
// uncompressed_size
assertEquals(row.getField(5), size3);
// cleanup
assertUpdate("DROP TABLE test_table_stats");
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class TestRaptorIntegrationSmokeTest method testShardingByTemporalDateColumn.
@Test
public void testShardingByTemporalDateColumn() throws Exception {
// Make sure we have at least 2 different orderdate.
assertEquals(computeActual("SELECT count(DISTINCT orderdate) >= 2 FROM orders WHERE orderdate < date '1992-02-08'").getOnlyValue(), true);
assertUpdate("CREATE TABLE test_shard_temporal_date " + "WITH (temporal_column = 'orderdate') AS " + "SELECT orderdate, orderkey " + "FROM orders " + "WHERE orderdate < date '1992-02-08'", "SELECT count(*) " + "FROM orders " + "WHERE orderdate < date '1992-02-08'");
MaterializedResult results = computeActual("SELECT orderdate, \"$shard_uuid\" FROM test_shard_temporal_date");
// Each shard will only contain data of one date.
SetMultimap<String, Date> shardDateMap = HashMultimap.create();
for (MaterializedRow row : results.getMaterializedRows()) {
shardDateMap.put((String) row.getField(1), (Date) row.getField(0));
}
for (Collection<Date> dates : shardDateMap.asMap().values()) {
assertEquals(dates.size(), 1);
}
// Make sure we have all the rows
assertQuery("SELECT orderdate, orderkey FROM test_shard_temporal_date", "SELECT orderdate, orderkey FROM orders WHERE orderdate < date '1992-02-08'");
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class TestRaptorIntegrationSmokeTest method testTablesSystemTable.
@Test
public void testTablesSystemTable() {
assertUpdate("" + "CREATE TABLE system_tables_test0 (c00 timestamp, c01 varchar, c02 double, c03 bigint, c04 bigint)");
assertUpdate("" + "CREATE TABLE system_tables_test1 (c10 timestamp, c11 varchar, c12 double, c13 bigint, c14 bigint) " + "WITH (temporal_column = 'c10')");
assertUpdate("" + "CREATE TABLE system_tables_test2 (c20 timestamp, c21 varchar, c22 double, c23 bigint, c24 bigint) " + "WITH (temporal_column = 'c20', ordering = ARRAY['c22', 'c21'])");
assertUpdate("" + "CREATE TABLE system_tables_test3 (c30 timestamp, c31 varchar, c32 double, c33 bigint, c34 bigint) " + "WITH (temporal_column = 'c30', bucket_count = 40, bucketed_on = ARRAY ['c34', 'c33'])");
assertUpdate("" + "CREATE TABLE system_tables_test4 (c40 timestamp, c41 varchar, c42 double, c43 bigint, c44 bigint) " + "WITH (temporal_column = 'c40', ordering = ARRAY['c41', 'c42'], distribution_name = 'test_distribution', bucket_count = 50, bucketed_on = ARRAY ['c43', 'c44'])");
assertUpdate("" + "CREATE TABLE system_tables_test5 (c50 timestamp, c51 varchar, c52 double, c53 bigint, c54 bigint) " + "WITH (ordering = ARRAY['c51', 'c52'], distribution_name = 'test_distribution', bucket_count = 50, bucketed_on = ARRAY ['c53', 'c54'], organized = true)");
MaterializedResult actualResults = computeActual("SELECT * FROM system.tables");
assertEquals(actualResults.getTypes(), ImmutableList.builder().add(// table_schema
VARCHAR).add(// table_name
VARCHAR).add(// temporal_column
VARCHAR).add(// ordering_columns
new ArrayType(VARCHAR)).add(// distribution_name
VARCHAR).add(// bucket_count
BIGINT).add(// bucket_columns
new ArrayType(VARCHAR)).add(// organized
BOOLEAN).build());
Map<String, MaterializedRow> map = actualResults.getMaterializedRows().stream().filter(row -> ((String) row.getField(1)).startsWith("system_tables_test")).collect(ImmutableCollectors.toImmutableMap(row -> ((String) row.getField(1))));
assertEquals(map.size(), 6);
assertEquals(map.get("system_tables_test0").getFields(), asList("tpch", "system_tables_test0", null, null, null, null, null, Boolean.FALSE));
assertEquals(map.get("system_tables_test1").getFields(), asList("tpch", "system_tables_test1", "c10", null, null, null, null, Boolean.FALSE));
assertEquals(map.get("system_tables_test2").getFields(), asList("tpch", "system_tables_test2", "c20", ImmutableList.of("c22", "c21"), null, null, null, Boolean.FALSE));
assertEquals(map.get("system_tables_test3").getFields(), asList("tpch", "system_tables_test3", "c30", null, null, 40L, ImmutableList.of("c34", "c33"), Boolean.FALSE));
assertEquals(map.get("system_tables_test4").getFields(), asList("tpch", "system_tables_test4", "c40", ImmutableList.of("c41", "c42"), "test_distribution", 50L, ImmutableList.of("c43", "c44"), Boolean.FALSE));
assertEquals(map.get("system_tables_test5").getFields(), asList("tpch", "system_tables_test5", null, ImmutableList.of("c51", "c52"), "test_distribution", 50L, ImmutableList.of("c53", "c54"), Boolean.TRUE));
actualResults = computeActual("SELECT * FROM system.tables WHERE table_schema = 'tpch'");
long actualRowCount = actualResults.getMaterializedRows().stream().filter(row -> ((String) row.getField(1)).startsWith("system_tables_test")).count();
assertEquals(actualRowCount, 6);
actualResults = computeActual("SELECT * FROM system.tables WHERE table_name = 'system_tables_test3'");
assertEquals(actualResults.getMaterializedRows().size(), 1);
actualResults = computeActual("SELECT * FROM system.tables WHERE table_schema = 'tpch' and table_name = 'system_tables_test3'");
assertEquals(actualResults.getMaterializedRows().size(), 1);
actualResults = computeActual("" + "SELECT distribution_name, bucket_count, bucketing_columns, ordering_columns, temporal_column, organized " + "FROM system.tables " + "WHERE table_schema = 'tpch' and table_name = 'system_tables_test3'");
assertEquals(actualResults.getTypes(), ImmutableList.of(VARCHAR, BIGINT, new ArrayType(VARCHAR), new ArrayType(VARCHAR), VARCHAR, BOOLEAN));
assertEquals(actualResults.getMaterializedRows().size(), 1);
assertUpdate("DROP TABLE system_tables_test0");
assertUpdate("DROP TABLE system_tables_test1");
assertUpdate("DROP TABLE system_tables_test2");
assertUpdate("DROP TABLE system_tables_test3");
assertUpdate("DROP TABLE system_tables_test4");
assertUpdate("DROP TABLE system_tables_test5");
assertEquals(computeActual("SELECT * FROM system.tables WHERE table_schema IN ('foo', 'bar')").getRowCount(), 0);
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class TestRaptorIntegrationSmokeTest method testShardUuidHiddenColumn.
@Test
public void testShardUuidHiddenColumn() throws Exception {
assertUpdate("CREATE TABLE test_shard_uuid AS SELECT orderdate, orderkey FROM orders", "SELECT count(*) FROM orders");
MaterializedResult actualResults = computeActual("SELECT *, \"$shard_uuid\" FROM test_shard_uuid");
assertEquals(actualResults.getTypes(), ImmutableList.of(DATE, BIGINT, SHARD_UUID_COLUMN_TYPE));
UUID arbitraryUuid = null;
for (MaterializedRow row : actualResults.getMaterializedRows()) {
Object uuid = row.getField(2);
assertInstanceOf(uuid, String.class);
arbitraryUuid = UUID.fromString((String) uuid);
}
assertNotNull(arbitraryUuid);
actualResults = computeActual(format("SELECT * FROM test_shard_uuid where \"$shard_uuid\" = '%s'", arbitraryUuid));
assertNotEquals(actualResults.getMaterializedRows().size(), 0);
actualResults = computeActual("SELECT * FROM test_shard_uuid where \"$shard_uuid\" = 'foo'");
assertEquals(actualResults.getMaterializedRows().size(), 0);
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class AbstractTestHiveClient method doTestTransactionDeleteInsert.
protected void doTestTransactionDeleteInsert(HiveStorageFormat storageFormat, SchemaTableName tableName, boolean allowInsertExisting, List<TransactionDeleteInsertTestCase> testCases) throws Exception {
// There are 4 types of operations on a partition: add, drop, alter (drop then add), insert existing.
// There are 12 partitions in this test, 3 for each type.
// 3 is chosen to verify that cleanups, commit aborts, rollbacks are always as complete as possible regardless of failure.
MaterializedResult beforeData = MaterializedResult.resultBuilder(SESSION, BIGINT, createUnboundedVarcharType(), createUnboundedVarcharType()).row(110L, "a", "alter1").row(120L, "a", "insert1").row(140L, "a", "drop1").row(210L, "b", "drop2").row(310L, "c", "alter2").row(320L, "c", "alter3").row(510L, "e", "drop3").row(610L, "f", "insert2").row(620L, "f", "insert3").build();
Domain domainToDrop = Domain.create(ValueSet.of(createUnboundedVarcharType(), utf8Slice("alter1"), utf8Slice("alter2"), utf8Slice("alter3"), utf8Slice("drop1"), utf8Slice("drop2"), utf8Slice("drop3")), false);
List<MaterializedRow> extraRowsForInsertExisting = ImmutableList.of();
if (allowInsertExisting) {
extraRowsForInsertExisting = MaterializedResult.resultBuilder(SESSION, BIGINT, createUnboundedVarcharType(), createUnboundedVarcharType()).row(121L, "a", "insert1").row(611L, "f", "insert2").row(621L, "f", "insert3").build().getMaterializedRows();
}
MaterializedResult insertData = MaterializedResult.resultBuilder(SESSION, BIGINT, createUnboundedVarcharType(), createUnboundedVarcharType()).row(111L, "a", "alter1").row(131L, "a", "add1").row(221L, "b", "add2").row(311L, "c", "alter2").row(321L, "c", "alter3").row(411L, "d", "add3").rows(extraRowsForInsertExisting).build();
MaterializedResult afterData = MaterializedResult.resultBuilder(SESSION, BIGINT, createUnboundedVarcharType(), createUnboundedVarcharType()).row(120L, "a", "insert1").row(610L, "f", "insert2").row(620L, "f", "insert3").rows(insertData.getMaterializedRows()).build();
boolean dirtyState = true;
for (TransactionDeleteInsertTestCase testCase : testCases) {
if (dirtyState) {
// re-initialize the table
dropTable(tableName);
createEmptyTable(tableName, storageFormat, ImmutableList.of(new Column("col1", HIVE_LONG, Optional.empty())), ImmutableList.of(new Column("pk1", HIVE_STRING, Optional.empty()), new Column("pk2", HIVE_STRING, Optional.empty())));
insertData(tableName, beforeData);
dirtyState = false;
}
try {
doTestTransactionDeleteInsert(storageFormat, tableName, domainToDrop, insertData, testCase.isExpectCommitedData() ? afterData : beforeData, testCase.getTag(), testCase.isExpectQuerySucceed(), testCase.getConflictTrigger());
} catch (AssertionError e) {
throw new AssertionError(format("Test case: %s", testCase.toString()), e);
}
if (testCase.isExpectCommitedData()) {
dirtyState = true;
}
}
}
Aggregations