use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class TestMemorySmoke method assertThatQueryReturnsValue.
private void assertThatQueryReturnsValue(String sql, Object expected, Session session) {
MaterializedResult rows = session == null ? queryRunner.execute(sql) : queryRunner.execute(session, sql);
MaterializedRow materializedRow = Iterables.getOnlyElement(rows);
int fieldCount = materializedRow.getFieldCount();
assertTrue(fieldCount == 1, format("Expected only one column, but got '%d'", fieldCount));
Object value = materializedRow.getField(0);
assertEquals(value, expected);
assertTrue(Iterables.getOnlyElement(rows).getFieldCount() == 1);
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method doTestPathHiddenColumn.
private void doTestPathHiddenColumn(Session session, HiveStorageFormat storageFormat) {
@Language("SQL") String createTable = "CREATE TABLE test_path " + "WITH (" + "format = '" + storageFormat + "'," + "partitioned_by = ARRAY['col1']" + ") AS " + "SELECT * FROM (VALUES " + "(0, 0), (3, 0), (6, 0), " + "(1, 1), (4, 1), (7, 1), " + "(2, 2), (5, 2) " + " ) t(col0, col1) ";
assertUpdate(session, createTable, 8);
assertTrue(getQueryRunner().tableExists(getSession(), "test_path"));
TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_path");
assertEquals(tableMetadata.getMetadata().getProperties().get(STORAGE_FORMAT_PROPERTY), storageFormat);
List<String> columnNames = ImmutableList.of("col0", "col1", PATH_COLUMN_NAME);
List<ColumnMetadata> columnMetadatas = tableMetadata.getColumns();
assertEquals(columnMetadatas.size(), columnNames.size());
for (int i = 0; i < columnMetadatas.size(); i++) {
ColumnMetadata columnMetadata = columnMetadatas.get(i);
assertEquals(columnMetadata.getName(), columnNames.get(i));
if (columnMetadata.getName().equals(PATH_COLUMN_NAME)) {
// $path should be hidden column
assertTrue(columnMetadata.isHidden());
}
}
assertEquals(getPartitions("test_path").size(), 3);
MaterializedResult results = computeActual(session, format("SELECT *, \"%s\" FROM test_path", PATH_COLUMN_NAME));
Map<Integer, String> partitionPathMap = new HashMap<>();
for (int i = 0; i < results.getRowCount(); i++) {
MaterializedRow row = results.getMaterializedRows().get(i);
int col0 = (int) row.getField(0);
int col1 = (int) row.getField(1);
String pathName = (String) row.getField(2);
String parentDirectory = new Path(pathName).getParent().toString();
assertTrue(pathName.length() > 0);
assertEquals((int) (col0 % 3), col1);
if (partitionPathMap.containsKey(col1)) {
// the rows in the same partition should be in the same partition directory
assertEquals(partitionPathMap.get(col1), parentDirectory);
} else {
partitionPathMap.put(col1, parentDirectory);
}
}
assertEquals(partitionPathMap.size(), 3);
assertUpdate(session, "DROP TABLE test_path");
assertFalse(getQueryRunner().tableExists(session, "test_path"));
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class AbstractTestQueries method testNonDeterministicJoinPredicatePushdown.
@Test
public void testNonDeterministicJoinPredicatePushdown() {
MaterializedResult materializedResult = computeActual("" + "SELECT COUNT(*)\n" + "FROM (\n" + " SELECT DISTINCT *\n" + " FROM (\n" + " SELECT 'abc' as col1a, 500 as col1b FROM lineitem limit 1\n" + " ) table1\n" + " JOIN (\n" + " SELECT 'abc' as col2a FROM lineitem limit 1000000\n" + " ) table2\n" + " ON table1.col1a = table2.col2a\n" + " WHERE rand() * 1000 > table1.col1b\n" + ")");
MaterializedRow row = getOnlyElement(materializedResult.getMaterializedRows());
assertEquals(row.getFieldCount(), 1);
long count = (Long) row.getField(0);
// Technically non-deterministic unit test but has essentially a next to impossible chance of a false positive
assertTrue(count > 0 && count < 1000000);
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class TestRaptorIntegrationSmokeTest method testShardingByTemporalDateColumnBucketed.
@Test
public void testShardingByTemporalDateColumnBucketed() 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_bucketed " + "WITH (temporal_column = 'orderdate', bucket_count = 10, bucketed_on = ARRAY ['orderkey']) 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_bucketed");
// 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_bucketed", "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 testShardingByTemporalTimestampColumnBucketed.
@Test
public void testShardingByTemporalTimestampColumnBucketed() 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_timestamp_bucketed(col1 BIGINT, col2 TIMESTAMP) " + "WITH (temporal_column = 'col2', bucket_count = 3, bucketed_on = ARRAY ['col1'])");
int rows = 100;
StringJoiner joiner = new StringJoiner(", ", "INSERT INTO test_shard_temporal_timestamp_bucketed VALUES ", "");
for (int i = 0; i < rows; i++) {
joiner.add(format("(%s, TIMESTAMP '2016-08-08 01:00' + interval '%s' hour)", i, i));
}
assertUpdate(joiner.toString(), format("VALUES(%s)", rows));
MaterializedResult results = computeActual("" + "SELECT format_datetime(col2, 'yyyyMMdd'), \"$shard_uuid\" " + "FROM test_shard_temporal_timestamp_bucketed");
assertEquals(results.getRowCount(), rows);
// Each shard will only contain data of one date.
SetMultimap<String, String> shardDateMap = HashMultimap.create();
for (MaterializedRow row : results.getMaterializedRows()) {
shardDateMap.put((String) row.getField(1), (String) row.getField(0));
}
for (Collection<String> dates : shardDateMap.asMap().values()) {
assertEquals(dates.size(), 1);
}
// Ensure one shard can contain different timestamps from the same day
assertLessThan(shardDateMap.size(), rows);
}
Aggregations