use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.
the class TestShardCompactor method extractColumns.
private static MaterializedResult extractColumns(MaterializedResult materializedRows, List<Integer> indexes, List<Type> types) {
ImmutableList.Builder<MaterializedRow> rows = ImmutableList.builder();
for (MaterializedRow row : materializedRows) {
Object[] values = new Object[indexes.size()];
for (int i = 0; i < indexes.size(); i++) {
values[i] = row.getField(indexes.get(i));
}
rows.add(new MaterializedRow(MaterializedResult.DEFAULT_PRECISION, values));
}
return new MaterializedResult(rows.build(), types);
}
use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.
the class TestShardCompactor method getMaterializedRows.
private MaterializedResult getMaterializedRows(List<UUID> uuids, List<Long> columnIds, List<Type> columnTypes) throws IOException {
MaterializedResult.Builder rows = MaterializedResult.resultBuilder(SESSION, columnTypes);
for (UUID uuid : uuids) {
try (ConnectorPageSource pageSource = getPageSource(columnIds, columnTypes, uuid)) {
MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, columnTypes);
rows.rows(result.getMaterializedRows());
}
}
return rows.build();
}
use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.
the class TestOrcStorageManager method testReader.
@Test
public void testReader() throws Exception {
OrcStorageManager manager = createOrcStorageManager();
List<Long> columnIds = ImmutableList.of(2L, 4L, 6L, 7L, 8L, 9L);
List<Type> columnTypes = ImmutableList.of(BIGINT, createVarcharType(10), VARBINARY, DATE, BOOLEAN, DOUBLE);
byte[] bytes1 = octets(0x00, 0xFE, 0xFF);
byte[] bytes3 = octets(0x01, 0x02, 0x19, 0x80);
StoragePageSink sink = createStoragePageSink(manager, columnIds, columnTypes);
Object[][] doubles = { { 881L, "-inf", null, null, null, Double.NEGATIVE_INFINITY }, { 882L, "+inf", null, null, null, Double.POSITIVE_INFINITY }, { 883L, "nan", null, null, null, Double.NaN }, { 884L, "min", null, null, null, Double.MIN_VALUE }, { 885L, "max", null, null, null, Double.MAX_VALUE }, { 886L, "pzero", null, null, null, 0.0 }, { 887L, "nzero", null, null, null, -0.0 } };
List<Page> pages = rowPagesBuilder(columnTypes).row(123L, "hello", wrappedBuffer(bytes1), sqlDate(2001, 8, 22).getDays(), true, 123.45).row(null, null, null, null, null, null).row(456L, "bye", wrappedBuffer(bytes3), sqlDate(2005, 4, 22).getDays(), false, 987.65).rows(doubles).build();
sink.appendPages(pages);
List<ShardInfo> shards = getFutureValue(sink.commit());
assertEquals(shards.size(), 1);
UUID uuid = Iterables.getOnlyElement(shards).getShardUuid();
MaterializedResult expected = resultBuilder(SESSION, columnTypes).row(123L, "hello", sqlBinary(bytes1), sqlDate(2001, 8, 22), true, 123.45).row(null, null, null, null, null, null).row(456L, "bye", sqlBinary(bytes3), sqlDate(2005, 4, 22), false, 987.65).rows(doubles).build();
// no tuple domain (all)
TupleDomain<RaptorColumnHandle> tupleDomain = TupleDomain.all();
try (ConnectorPageSource pageSource = getPageSource(manager, columnIds, columnTypes, uuid, tupleDomain)) {
MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, columnTypes);
assertEquals(result.getRowCount(), expected.getRowCount());
assertEquals(result, expected);
}
// tuple domain within the column range
tupleDomain = TupleDomain.fromFixedValues(ImmutableMap.<RaptorColumnHandle, NullableValue>builder().put(new RaptorColumnHandle("test", "c1", 2, BIGINT), NullableValue.of(BIGINT, 124L)).build());
try (ConnectorPageSource pageSource = getPageSource(manager, columnIds, columnTypes, uuid, tupleDomain)) {
MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, columnTypes);
assertEquals(result.getRowCount(), expected.getRowCount());
}
// tuple domain outside the column range
tupleDomain = TupleDomain.fromFixedValues(ImmutableMap.<RaptorColumnHandle, NullableValue>builder().put(new RaptorColumnHandle("test", "c1", 2, BIGINT), NullableValue.of(BIGINT, 122L)).build());
try (ConnectorPageSource pageSource = getPageSource(manager, columnIds, columnTypes, uuid, tupleDomain)) {
MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, columnTypes);
assertEquals(result.getRowCount(), 0);
}
}
use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.
the class TestMinimalFunctionality method testTableHasData.
@Test
public void testTableHasData() throws Exception {
MaterializedResult result = queryRunner.execute("SELECT count(1) from " + tableName);
MaterializedResult expected = MaterializedResult.resultBuilder(SESSION, BigintType.BIGINT).row(0L).build();
assertEquals(result, expected);
int count = 1000;
populateData(count);
result = queryRunner.execute("SELECT count(1) from " + tableName);
expected = MaterializedResult.resultBuilder(SESSION, BigintType.BIGINT).row((long) count).build();
assertEquals(result, expected);
}
use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.
the class AbstractTestQueries method testNonDeterministicFilter.
@Test
public void testNonDeterministicFilter() {
MaterializedResult materializedResult = computeActual("SELECT u FROM ( SELECT if(rand() > 0.5, 0, 1) AS u ) WHERE u <> u");
assertEquals(materializedResult.getRowCount(), 0);
materializedResult = computeActual("SELECT u, v FROM ( SELECT if(rand() > 0.5, 0, 1) AS u, 4*4 as v ) WHERE u <> u and v > 10");
assertEquals(materializedResult.getRowCount(), 0);
materializedResult = computeActual("SELECT u, v, w FROM ( SELECT if(rand() > 0.5, 0, 1) AS u, 4*4 as v, 'abc' as w ) WHERE v > 10");
assertEquals(materializedResult.getRowCount(), 1);
}
Aggregations