Search in sources :

Example 26 with MaterializedResult

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

the class TestAggregateWindowFunction method testSumEmptyWindow.

@Test
public void testSumEmptyWindow() throws Exception {
    MaterializedResult expected = resultBuilder(TEST_SESSION, INTEGER, VARCHAR, BIGINT).row(3, "F", null).row(5, "F", null).row(6, "F", null).row(33, "F", null).row(1, "O", null).row(2, "O", null).row(4, "O", null).row(7, "O", null).row(32, "O", null).row(34, "O", null).build();
    assertWindowQuery("sum(orderkey) OVER (PARTITION BY orderstatus ORDER BY orderkey " + "ROWS BETWEEN 2 PRECEDING AND 3 PRECEDING)", expected);
    assertWindowQuery("sum(orderkey) OVER (PARTITION BY orderstatus ORDER BY orderkey " + "ROWS BETWEEN 4 FOLLOWING AND 3 FOLLOWING)", expected);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 27 with MaterializedResult

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

the class TestAggregateWindowFunction method testSumCurrentRow.

@Test
public void testSumCurrentRow() throws Exception {
    MaterializedResult expected = resultBuilder(TEST_SESSION, INTEGER, VARCHAR, BIGINT).row(3, "F", 3L).row(5, "F", 5L).row(6, "F", 6L).row(33, "F", 33L).row(1, "O", 1L).row(2, "O", 2L).row(4, "O", 4L).row(7, "O", 7L).row(32, "O", 32L).row(34, "O", 34L).build();
    assertWindowQuery("sum(orderkey) OVER (PARTITION BY orderstatus ORDER BY orderkey " + "ROWS CURRENT ROW)", expected);
    assertWindowQuery("sum(orderkey) OVER (PARTITION BY orderstatus ORDER BY orderkey " + "ROWS BETWEEN CURRENT ROW AND CURRENT ROW)", expected);
    assertWindowQuery("sum(orderkey) OVER (PARTITION BY orderstatus ORDER BY orderkey " + "RANGE CURRENT ROW)", expected);
    assertWindowQuery("sum(orderkey) OVER (PARTITION BY orderstatus ORDER BY orderkey " + "RANGE BETWEEN CURRENT ROW AND CURRENT ROW)", expected);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 28 with MaterializedResult

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

the class TestAggregateWindowFunction method testSumOrdered.

@Test
public void testSumOrdered() {
    MaterializedResult expected = resultBuilder(TEST_SESSION, INTEGER, VARCHAR, BIGINT).row(3, "F", 3L).row(5, "F", 8L).row(6, "F", 14L).row(33, "F", 47L).row(1, "O", 1L).row(2, "O", 3L).row(4, "O", 7L).row(7, "O", 14L).row(32, "O", 46L).row(34, "O", 80L).build();
    MaterializedResult expectedNulls = resultBuilder(TEST_SESSION, BIGINT, VARCHAR, BIGINT).row(3L, "F", 3L).row(5L, "F", 8L).row(6L, "F", 14L).row(null, "F", 14L).row(34L, "O", 34L).row(null, "O", 34L).row(1L, null, 1L).row(7L, null, 8L).row(null, null, 8L).row(null, null, 8L).build();
    // default window frame
    @Language("SQL") String sql = "sum(orderkey) OVER (PARTITION BY orderstatus ORDER BY orderkey)";
    assertWindowQuery(sql, expected);
    assertWindowQueryWithNulls(sql, expectedNulls);
    // range frame with default end
    sql = "sum(orderkey) OVER (PARTITION BY orderstatus ORDER BY orderkey " + "RANGE UNBOUNDED PRECEDING)";
    assertWindowQuery(sql, expected);
    assertWindowQueryWithNulls(sql, expectedNulls);
    // range frame with explicit end
    sql = "sum(orderkey) OVER (PARTITION BY orderstatus ORDER BY orderkey " + "RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)";
    assertWindowQuery(sql, expected);
    assertWindowQueryWithNulls(sql, expectedNulls);
    // rows frame with default end
    sql = "sum(orderkey) OVER (PARTITION BY orderstatus ORDER BY orderkey " + "ROWS UNBOUNDED PRECEDING)";
    assertWindowQuery(sql, expected);
    assertWindowQueryWithNulls(sql, expectedNulls);
    // rows frame with explicit end
    sql = "sum(orderkey) OVER (PARTITION BY orderstatus ORDER BY orderkey " + "ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)";
    assertWindowQuery(sql, expected);
    assertWindowQueryWithNulls(sql, expectedNulls);
}
Also used : Language(org.intellij.lang.annotations.Language) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 29 with MaterializedResult

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

the class TestPagesIndexPageSorter method assertSorted.

private static void assertSorted(List<Page> inputPages, List<Page> expectedPages, List<Type> types, List<Integer> sortChannels, List<SortOrder> sortOrders, int expectedPositions) {
    long[] sortedAddresses = sorter.sort(types, inputPages, sortChannels, sortOrders, expectedPositions);
    List<Page> outputPages = createOutputPages(types, inputPages, sortedAddresses);
    MaterializedResult expected = toMaterializedResult(TEST_SESSION, types, expectedPages);
    MaterializedResult actual = toMaterializedResult(TEST_SESSION, types, outputPages);
    assertEquals(actual.getMaterializedRows(), expected.getMaterializedRows());
}
Also used : Page(com.facebook.presto.spi.Page) OperatorAssertion.toMaterializedResult(com.facebook.presto.operator.OperatorAssertion.toMaterializedResult) MaterializedResult(com.facebook.presto.testing.MaterializedResult)

Example 30 with MaterializedResult

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

the class TestPageSplitterUtil method testSplitPage.

@Test
public void testSplitPage() throws Exception {
    int positionCount = 10;
    int maxPageSizeInBytes = 100;
    List<Type> types = ImmutableList.of(BIGINT, BIGINT, BIGINT);
    Page largePage = SequencePageBuilder.createSequencePage(types, positionCount, 0, 1, 1);
    List<Page> pages = PageSplitterUtil.splitPage(largePage, maxPageSizeInBytes);
    assertGreaterThan(pages.size(), 1);
    assertPageSize(pages, maxPageSizeInBytes);
    assertPositionCount(pages, positionCount);
    MaterializedResult actual = toMaterializedResult(TEST_SESSION, types, pages);
    MaterializedResult expected = toMaterializedResult(TEST_SESSION, types, ImmutableList.of(largePage));
    assertEquals(actual, expected);
}
Also used : Type(com.facebook.presto.spi.type.Type) Page(com.facebook.presto.spi.Page) OperatorAssertion.toMaterializedResult(com.facebook.presto.operator.OperatorAssertion.toMaterializedResult) 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