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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations