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