Search in sources :

Example 11 with MaterializedResult

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);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow)

Example 12 with MaterializedResult

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();
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) UUID(java.util.UUID) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource)

Example 13 with MaterializedResult

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);
    }
}
Also used : RaptorColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle) NullableValue(com.facebook.presto.spi.predicate.NullableValue) Page(com.facebook.presto.spi.Page) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) VarcharType.createVarcharType(com.facebook.presto.spi.type.VarcharType.createVarcharType) Type(com.facebook.presto.spi.type.Type) OptionalLong(java.util.OptionalLong) UUID(java.util.UUID) MaterializedResult(com.facebook.presto.testing.MaterializedResult) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo) Test(org.testng.annotations.Test)

Example 14 with MaterializedResult

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);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 15 with MaterializedResult

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);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Aggregations

MaterializedResult (com.facebook.presto.testing.MaterializedResult)298 Test (org.testng.annotations.Test)255 Page (com.facebook.presto.spi.Page)75 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)54 MaterializedRow (com.facebook.presto.testing.MaterializedRow)52 Type (com.facebook.presto.spi.type.Type)43 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)35 Session (com.facebook.presto.Session)23 TestingTaskContext (com.facebook.presto.testing.TestingTaskContext)21 AbstractTestIntegrationSmokeTest (com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)20 ImmutableList (com.google.common.collect.ImmutableList)20 ColumnHandle (com.facebook.presto.spi.ColumnHandle)19 ConnectorSession (com.facebook.presto.spi.ConnectorSession)18 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)18 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)17 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)17 ImmutableMap (com.google.common.collect.ImmutableMap)17 List (java.util.List)17 BIGINT (com.facebook.presto.spi.type.BigintType.BIGINT)16 Path (org.apache.hadoop.fs.Path)14