Search in sources :

Example 66 with MaterializedResult

use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.

the class TestWindowOperator method testLastValuePartition.

@Test
public void testLastValuePartition() throws Exception {
    List<Page> input = rowPagesBuilder(VARCHAR, VARCHAR, BIGINT, BOOLEAN, VARCHAR).row("b", "A1", 1L, true, "").row("a", "A2", 1L, false, "").row("a", "B1", 2L, true, "").pageBreak().row("b", "C1", 2L, false, "").row("a", "C2", 3L, true, "").row("c", "A3", 1L, true, "").build();
    WindowOperatorFactory operatorFactory = createFactoryUnbounded(ImmutableList.of(VARCHAR, VARCHAR, BIGINT, BOOLEAN, VARCHAR), Ints.asList(0, 1, 2, 3), LAST_VALUE, Ints.asList(0), Ints.asList(2), ImmutableList.copyOf(new SortOrder[] { SortOrder.ASC_NULLS_LAST }));
    MaterializedResult expected = resultBuilder(driverContext.getSession(), VARCHAR, VARCHAR, BIGINT, BOOLEAN, VARCHAR).row("a", "A2", 1L, false, "C2").row("a", "B1", 2L, true, "C2").row("a", "C2", 3L, true, "C2").row("b", "A1", 1L, true, "C1").row("b", "C1", 2L, false, "C1").row("c", "A3", 1L, true, "A3").build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : WindowOperatorFactory(com.facebook.presto.operator.WindowOperator.WindowOperatorFactory) SortOrder(com.facebook.presto.spi.block.SortOrder) Page(com.facebook.presto.spi.Page) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 67 with MaterializedResult

use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.

the class TestWindowOperator method testFullyPreGroupedAndFullySortedPartition.

@Test
public void testFullyPreGroupedAndFullySortedPartition() throws Exception {
    List<Page> input = rowPagesBuilder(BIGINT, VARCHAR, BIGINT, VARCHAR).pageBreak().row(1L, "a", 100L, "A").pageBreak().row(2L, "a", 101L, "A").pageBreak().row(2L, "b", 102L, "A").row(2L, "b", 103L, "A").row(2L, "b", 104L, "B").row(1L, "b", 105L, "A").pageBreak().row(1L, "b", 106L, "A").row(3L, "c", 107L, "A").build();
    WindowOperatorFactory operatorFactory = createFactoryUnbounded(ImmutableList.of(BIGINT, VARCHAR, BIGINT, VARCHAR), Ints.asList(0, 1, 2, 3), ROW_NUMBER, Ints.asList(1, 0), Ints.asList(0, 1), Ints.asList(3), ImmutableList.of(SortOrder.ASC_NULLS_LAST), 1);
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, VARCHAR, BIGINT, VARCHAR, BIGINT).row(1L, "a", 100L, "A", 1L).row(2L, "a", 101L, "A", 1L).row(2L, "b", 102L, "A", 1L).row(2L, "b", 103L, "A", 2L).row(2L, "b", 104L, "B", 3L).row(1L, "b", 105L, "A", 1L).row(1L, "b", 106L, "A", 2L).row(3L, "c", 107L, "A", 1L).build();
    // Since fully grouped and sorted already, should respect original input order
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : WindowOperatorFactory(com.facebook.presto.operator.WindowOperator.WindowOperatorFactory) Page(com.facebook.presto.spi.Page) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 68 with MaterializedResult

use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.

the class FunctionAssertions method executeFilterWithAll.

private List<Boolean> executeFilterWithAll(String filter, Session session, boolean executeWithNoInputColumns, ExpressionCompiler compiler) {
    requireNonNull(filter, "filter is null");
    Expression filterExpression = createExpression(filter, metadata, SYMBOL_TYPES);
    List<Boolean> results = new ArrayList<>();
    // execute as standalone operator
    OperatorFactory operatorFactory = compileFilterProject(filterExpression, TRUE_LITERAL, compiler);
    results.add(executeFilter(operatorFactory, session));
    if (executeWithNoInputColumns) {
        // execute as standalone operator
        operatorFactory = compileFilterWithNoInputColumns(filterExpression, compiler);
        results.add(executeFilterWithNoInputColumns(operatorFactory, session));
    }
    // interpret
    boolean interpretedValue = executeFilter(interpretedFilterProject(filterExpression, TRUE_LITERAL, session));
    results.add(interpretedValue);
    // execute over normal operator
    SourceOperatorFactory scanProjectOperatorFactory = compileScanFilterProject(filterExpression, TRUE_LITERAL, compiler);
    boolean scanOperatorValue = executeFilter(scanProjectOperatorFactory, createNormalSplit(), session);
    results.add(scanOperatorValue);
    // execute over record set
    boolean recordValue = executeFilter(scanProjectOperatorFactory, createRecordSetSplit(), session);
    results.add(recordValue);
    // If the filter does not need bound values, execute query using full engine
    if (!needsBoundValue(filterExpression)) {
        MaterializedResult result = runner.execute("SELECT TRUE WHERE " + filter);
        assertEquals(result.getTypes().size(), 1);
        Boolean queryResult;
        if (result.getMaterializedRows().isEmpty()) {
            queryResult = false;
        } else {
            assertEquals(result.getMaterializedRows().size(), 1);
            queryResult = (Boolean) Iterables.getOnlyElement(result.getMaterializedRows()).getField(0);
        }
        results.add(queryResult);
    }
    return results;
}
Also used : RowExpression(com.facebook.presto.sql.relational.RowExpression) CanonicalizeExpressions.canonicalizeExpression(com.facebook.presto.sql.planner.optimizations.CanonicalizeExpressions.canonicalizeExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) Expression(com.facebook.presto.sql.tree.Expression) SourceOperatorFactory(com.facebook.presto.operator.SourceOperatorFactory) OperatorFactory(com.facebook.presto.operator.OperatorFactory) ArrayList(java.util.ArrayList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MaterializedResult(com.facebook.presto.testing.MaterializedResult) SourceOperatorFactory(com.facebook.presto.operator.SourceOperatorFactory)

Example 69 with MaterializedResult

use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.

the class TestAtopSmoke method assertThatQueryReturnsValue.

private void assertThatQueryReturnsValue(@Language("SQL") String sql, Object expected) {
    MaterializedResult rows = queryRunner.execute(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);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow)

Example 70 with MaterializedResult

use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.

the class TestAccumuloDistributedQueries method testCreateTableAsSelect.

@Override
public void testCreateTableAsSelect() {
    // This test is overridden due to Function "UUID" not found errors
    // Some test cases from the base class are removed
    assertUpdate("CREATE TABLE test_create_table_as_if_not_exists (a bigint, b double)");
    assertTrue(getQueryRunner().tableExists(getSession(), "test_create_table_as_if_not_exists"));
    assertTableColumnNames("test_create_table_as_if_not_exists", "a", "b");
    MaterializedResult materializedRows = computeActual("CREATE TABLE IF NOT EXISTS test_create_table_as_if_not_exists AS SELECT UUID() AS uuid, orderkey, discount FROM lineitem");
    assertEquals(materializedRows.getRowCount(), 0);
    assertTrue(getQueryRunner().tableExists(getSession(), "test_create_table_as_if_not_exists"));
    assertTableColumnNames("test_create_table_as_if_not_exists", "a", "b");
    assertUpdate("DROP TABLE test_create_table_as_if_not_exists");
    assertFalse(getQueryRunner().tableExists(getSession(), "test_create_table_as_if_not_exists"));
    this.assertCreateTableAsSelect("test_group", "SELECT orderstatus, sum(totalprice) x FROM orders GROUP BY orderstatus", "SELECT count(DISTINCT orderstatus) FROM orders");
    this.assertCreateTableAsSelect("test_with_data", "SELECT * FROM orders WITH DATA", "SELECT * FROM orders", "SELECT count(*) FROM orders");
    this.assertCreateTableAsSelect("test_with_no_data", "SELECT * FROM orders WITH NO DATA", "SELECT * FROM orders LIMIT 0", "SELECT 0");
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult)

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