use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.
the class AbstractTestQueries method testShowFunctions.
@Test
public void testShowFunctions() {
MaterializedResult result = computeActual("SHOW FUNCTIONS");
ImmutableMultimap<String, MaterializedRow> functions = Multimaps.index(result.getMaterializedRows(), input -> {
assertEquals(input.getFieldCount(), 6);
return (String) input.getField(0);
});
assertTrue(functions.containsKey("avg"), "Expected function names " + functions + " to contain 'avg'");
assertEquals(functions.get("avg").asList().size(), 4);
assertEquals(functions.get("avg").asList().get(0).getField(1), "decimal(p,s)");
assertEquals(functions.get("avg").asList().get(0).getField(2), "decimal(p,s)");
assertEquals(functions.get("avg").asList().get(0).getField(3), "aggregate");
assertEquals(functions.get("avg").asList().get(1).getField(1), "double");
assertEquals(functions.get("avg").asList().get(1).getField(2), "bigint");
assertEquals(functions.get("avg").asList().get(1).getField(3), "aggregate");
assertEquals(functions.get("avg").asList().get(2).getField(1), "double");
assertEquals(functions.get("avg").asList().get(2).getField(2), "double");
assertEquals(functions.get("avg").asList().get(2).getField(3), "aggregate");
assertEquals(functions.get("avg").asList().get(3).getField(1), "real");
assertEquals(functions.get("avg").asList().get(3).getField(2), "real");
assertEquals(functions.get("avg").asList().get(3).getField(3), "aggregate");
assertTrue(functions.containsKey("abs"), "Expected function names " + functions + " to contain 'abs'");
assertEquals(functions.get("abs").asList().get(0).getField(3), "scalar");
assertEquals(functions.get("abs").asList().get(0).getField(4), true);
assertTrue(functions.containsKey("rand"), "Expected function names " + functions + " to contain 'rand'");
assertEquals(functions.get("rand").asList().get(0).getField(3), "scalar");
assertEquals(functions.get("rand").asList().get(0).getField(4), false);
assertTrue(functions.containsKey("rank"), "Expected function names " + functions + " to contain 'rank'");
assertEquals(functions.get("rank").asList().get(0).getField(3), "window");
assertTrue(functions.containsKey("rank"), "Expected function names " + functions + " to contain 'split_part'");
assertEquals(functions.get("split_part").asList().get(0).getField(1), "varchar(x)");
assertEquals(functions.get("split_part").asList().get(0).getField(2), "varchar(x), varchar(y), bigint");
assertEquals(functions.get("split_part").asList().get(0).getField(3), "scalar");
assertFalse(functions.containsKey("like"), "Expected function names " + functions + " not to contain 'like'");
}
use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.
the class AbstractTestDistributedQueries method testAddColumn.
@Test
public void testAddColumn() {
assertUpdate("CREATE TABLE test_add_column AS SELECT 123 x", 1);
assertUpdate("CREATE TABLE test_add_column_a AS SELECT 234 x, 111 a", 1);
assertUpdate("CREATE TABLE test_add_column_ab AS SELECT 345 x, 222 a, 33.3 b", 1);
assertQueryFails("ALTER TABLE test_add_column ADD COLUMN x bigint", ".* Column 'x' already exists");
assertQueryFails("ALTER TABLE test_add_column ADD COLUMN X bigint", ".* Column 'X' already exists");
assertUpdate("ALTER TABLE test_add_column ADD COLUMN a bigint");
assertUpdate("INSERT INTO test_add_column SELECT * FROM test_add_column_a", 1);
MaterializedResult materializedRows = computeActual("SELECT x, a FROM test_add_column ORDER BY x");
assertEquals(materializedRows.getMaterializedRows().get(0).getField(0), 123);
assertEquals(materializedRows.getMaterializedRows().get(0).getField(1), null);
assertEquals(materializedRows.getMaterializedRows().get(1).getField(0), 234);
assertEquals(materializedRows.getMaterializedRows().get(1).getField(1), 111L);
assertUpdate("ALTER TABLE test_add_column ADD COLUMN b double");
assertUpdate("INSERT INTO test_add_column SELECT * FROM test_add_column_ab", 1);
materializedRows = computeActual("SELECT x, a, b FROM test_add_column ORDER BY x");
assertEquals(materializedRows.getMaterializedRows().get(0).getField(0), 123);
assertEquals(materializedRows.getMaterializedRows().get(0).getField(1), null);
assertEquals(materializedRows.getMaterializedRows().get(0).getField(2), null);
assertEquals(materializedRows.getMaterializedRows().get(1).getField(0), 234);
assertEquals(materializedRows.getMaterializedRows().get(1).getField(1), 111L);
assertEquals(materializedRows.getMaterializedRows().get(1).getField(2), null);
assertEquals(materializedRows.getMaterializedRows().get(2).getField(0), 345);
assertEquals(materializedRows.getMaterializedRows().get(2).getField(1), 222L);
assertEquals(materializedRows.getMaterializedRows().get(2).getField(2), 33.3);
assertUpdate("DROP TABLE test_add_column");
assertUpdate("DROP TABLE test_add_column_a");
assertUpdate("DROP TABLE test_add_column_ab");
assertFalse(getQueryRunner().tableExists(getSession(), "test_add_column"));
assertFalse(getQueryRunner().tableExists(getSession(), "test_add_column_a"));
assertFalse(getQueryRunner().tableExists(getSession(), "test_add_column_ab"));
}
use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.
the class AbstractTestDistributedQueries method testResetSession.
@Test
public void testResetSession() {
MaterializedResult result = computeActual(getSession(), "RESET SESSION test_string");
assertTrue((Boolean) getOnlyElement(result).getField(0));
assertEquals(result.getResetSessionProperties(), ImmutableSet.of("test_string"));
result = computeActual(getSession(), format("RESET SESSION %s.connector_string", TESTING_CATALOG));
assertTrue((Boolean) getOnlyElement(result).getField(0));
assertEquals(result.getResetSessionProperties(), ImmutableSet.of(TESTING_CATALOG + ".connector_string"));
}
use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.
the class AbstractTestDistributedQueries method testSetSession.
@Test
public void testSetSession() {
MaterializedResult result = computeActual("SET SESSION test_string = 'bar'");
assertTrue((Boolean) getOnlyElement(result).getField(0));
assertEquals(result.getSetSessionProperties(), ImmutableMap.of("test_string", "bar"));
result = computeActual(format("SET SESSION %s.connector_long = 999", TESTING_CATALOG));
assertTrue((Boolean) getOnlyElement(result).getField(0));
assertEquals(result.getSetSessionProperties(), ImmutableMap.of(TESTING_CATALOG + ".connector_long", "999"));
result = computeActual(format("SET SESSION %s.connector_string = 'baz'", TESTING_CATALOG));
assertTrue((Boolean) getOnlyElement(result).getField(0));
assertEquals(result.getSetSessionProperties(), ImmutableMap.of(TESTING_CATALOG + ".connector_string", "baz"));
result = computeActual(format("SET SESSION %s.connector_string = 'ban' || 'ana'", TESTING_CATALOG));
assertTrue((Boolean) getOnlyElement(result).getField(0));
assertEquals(result.getSetSessionProperties(), ImmutableMap.of(TESTING_CATALOG + ".connector_string", "banana"));
result = computeActual(format("SET SESSION %s.connector_long = 444", TESTING_CATALOG));
assertTrue((Boolean) getOnlyElement(result).getField(0));
assertEquals(result.getSetSessionProperties(), ImmutableMap.of(TESTING_CATALOG + ".connector_long", "444"));
result = computeActual(format("SET SESSION %s.connector_long = 111 + 111", TESTING_CATALOG));
assertTrue((Boolean) getOnlyElement(result).getField(0));
assertEquals(result.getSetSessionProperties(), ImmutableMap.of(TESTING_CATALOG + ".connector_long", "222"));
result = computeActual(format("SET SESSION %s.connector_boolean = 111 < 3", TESTING_CATALOG));
assertTrue((Boolean) getOnlyElement(result).getField(0));
assertEquals(result.getSetSessionProperties(), ImmutableMap.of(TESTING_CATALOG + ".connector_boolean", "false"));
result = computeActual(format("SET SESSION %s.connector_double = 11.1", TESTING_CATALOG));
assertTrue((Boolean) getOnlyElement(result).getField(0));
assertEquals(result.getSetSessionProperties(), ImmutableMap.of(TESTING_CATALOG + ".connector_double", "11.1"));
}
use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.
the class AbstractTestDistributedQueries method testCreateTableAsSelect.
@Test
public void testCreateTableAsSelect() {
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 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"));
assertCreateTableAsSelect("test_select", "SELECT orderdate, orderkey, totalprice FROM orders", "SELECT count(*) FROM orders");
assertCreateTableAsSelect("test_group", "SELECT orderstatus, sum(totalprice) x FROM orders GROUP BY orderstatus", "SELECT count(DISTINCT orderstatus) FROM orders");
assertCreateTableAsSelect("test_join", "SELECT count(*) x FROM lineitem JOIN orders ON lineitem.orderkey = orders.orderkey", "SELECT 1");
assertCreateTableAsSelect("test_limit", "SELECT orderkey FROM orders ORDER BY orderkey LIMIT 10", "SELECT 10");
assertCreateTableAsSelect("test_unicode", "SELECT '☃' unicode", "SELECT 1");
assertCreateTableAsSelect("test_with_data", "SELECT * FROM orders WITH DATA", "SELECT * FROM orders", "SELECT count(*) FROM orders");
assertCreateTableAsSelect("test_with_no_data", "SELECT * FROM orders WITH NO DATA", "SELECT * FROM orders LIMIT 0", "SELECT 0");
// Tests for CREATE TABLE with UNION ALL: exercises PushTableWriteThroughUnion optimizer
assertCreateTableAsSelect("test_union_all", "SELECT orderdate, orderkey, totalprice FROM orders WHERE orderkey % 2 = 0 UNION ALL " + "SELECT orderdate, orderkey, totalprice FROM orders WHERE orderkey % 2 = 1", "SELECT orderdate, orderkey, totalprice FROM orders", "SELECT count(*) FROM orders");
assertCreateTableAsSelect(Session.builder(getSession()).setSystemProperty("redistribute_writes", "true").build(), "test_union_all", "SELECT orderdate, orderkey, totalprice FROM orders UNION ALL " + "SELECT DATE '2000-01-01', 1234567890, 1.23", "SELECT orderdate, orderkey, totalprice FROM orders UNION ALL " + "SELECT DATE '2000-01-01', 1234567890, 1.23", "SELECT count(*) + 1 FROM orders");
assertCreateTableAsSelect(Session.builder(getSession()).setSystemProperty("redistribute_writes", "false").build(), "test_union_all", "SELECT orderdate, orderkey, totalprice FROM orders UNION ALL " + "SELECT DATE '2000-01-01', 1234567890, 1.23", "SELECT orderdate, orderkey, totalprice FROM orders UNION ALL " + "SELECT DATE '2000-01-01', 1234567890, 1.23", "SELECT count(*) + 1 FROM orders");
assertExplainAnalyze("EXPLAIN ANALYZE CREATE TABLE analyze_test AS SELECT orderstatus FROM orders");
assertQuery("SELECT * from analyze_test", "SELECT orderstatus FROM orders");
assertUpdate("DROP TABLE analyze_test");
}
Aggregations