use of org.intellij.lang.annotations.Language 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 org.intellij.lang.annotations.Language in project presto by prestodb.
the class WindowAssertions method assertWindowQuery.
public static void assertWindowQuery(@Language("SQL") String sql, MaterializedResult expected, LocalQueryRunner localQueryRunner) {
@Language("SQL") String query = format("" + "SELECT orderkey, orderstatus,\n%s\n" + "FROM (%s) x", sql, VALUES);
MaterializedResult actual = localQueryRunner.execute(query);
assertEqualsIgnoreOrder(actual.getMaterializedRows(), expected.getMaterializedRows());
}
use of org.intellij.lang.annotations.Language in project presto by prestodb.
the class TestAbstractIcebergSmoke method testCreatePartitionedTableAs.
private void testCreatePartitionedTableAs(Session session, FileFormat fileFormat) {
@Language("SQL") String createTable = "" + "CREATE TABLE test_create_partitioned_table_as " + "WITH (" + "format = '" + fileFormat + "', " + "partitioning = ARRAY['ORDER_STATUS', 'Ship_Priority', 'Bucket(order_key,9)']" + ") " + "AS " + "SELECT orderkey AS order_key, shippriority AS ship_priority, orderstatus AS order_status " + "FROM tpch.tiny.orders";
assertUpdate(session, createTable, "SELECT count(*) from orders");
String createTableSql = format("" + "CREATE TABLE %s.%s.%s (\n" + " \"order_key\" bigint,\n" + " \"ship_priority\" integer,\n" + " \"order_status\" varchar\n" + ")\n" + "WITH (\n" + " format = '" + fileFormat + "',\n" + " partitioning = ARRAY['order_status','ship_priority','bucket(order_key, 9)']\n" + ")", getSession().getCatalog().get(), getSession().getSchema().get(), "test_create_partitioned_table_as");
MaterializedResult actualResult = computeActual("SHOW CREATE TABLE test_create_partitioned_table_as");
assertEquals(getOnlyElement(actualResult.getOnlyColumnAsSet()), createTableSql);
assertQuery(session, "SELECT * from test_create_partitioned_table_as", "SELECT orderkey, shippriority, orderstatus FROM orders");
dropTable(session, "test_create_partitioned_table_as");
}
use of org.intellij.lang.annotations.Language in project presto by prestodb.
the class TestAbstractIcebergSmoke method testCreatePartitionedTable.
private void testCreatePartitionedTable(Session session, FileFormat fileFormat) {
@Language("SQL") String createTable = "" + "CREATE TABLE test_partitioned_table (" + " _string VARCHAR" + ", _bigint BIGINT" + ", _integer INTEGER" + ", _real REAL" + ", _double DOUBLE" + ", _boolean BOOLEAN" + ", _decimal_short DECIMAL(3,2)" + ", _decimal_long DECIMAL(30,10)" + ", _date DATE" + ") " + "WITH (" + "format = '" + fileFormat + "', " + "partitioning = ARRAY[" + " '_string'," + " '_integer'," + " '_bigint'," + " '_boolean'," + " '_real'," + " '_double'," + " '_decimal_short', " + " '_decimal_long'," + " '_date']" + ")";
assertUpdate(session, createTable);
MaterializedResult result = computeActual("SELECT * from test_partitioned_table");
assertEquals(result.getRowCount(), 0);
@Language("SQL") String select = "" + "SELECT" + " 'foo' _string" + ", CAST(123 AS BIGINT) _bigint" + ", 456 _integer" + ", CAST('123.45' AS REAL) _real" + ", CAST('3.14' AS DOUBLE) _double" + ", true _boolean" + ", CAST('3.14' AS DECIMAL(3,2)) _decimal_short" + ", CAST('12345678901234567890.0123456789' AS DECIMAL(30,10)) _decimal_long" + ", CAST('2017-05-01' AS DATE) _date";
assertUpdate(session, "INSERT INTO test_partitioned_table " + select, 1);
assertQuery(session, "SELECT * from test_partitioned_table", select);
assertQuery(session, "" + "SELECT * FROM test_partitioned_table WHERE" + " 'foo' = _string" + " AND 456 = _integer" + " AND CAST(123 AS BIGINT) = _bigint" + " AND true = _boolean" + " AND CAST('3.14' AS DECIMAL(3,2)) = _decimal_short" + " AND CAST('12345678901234567890.0123456789' AS DECIMAL(30,10)) = _decimal_long" + " AND CAST('2017-05-01' AS DATE) = _date", select);
dropTable(session, "test_partitioned_table");
}
use of org.intellij.lang.annotations.Language in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method insertTable.
public void insertTable(Session session, HiveStorageFormat storageFormat) throws Exception {
@Language("SQL") String createTable = "" + "CREATE TABLE test_insert_format_table " + "(" + " _string VARCHAR," + " _varchar VARCHAR(65535)," + " _char CHAR(10)," + " _bigint BIGINT," + " _integer INTEGER," + " _smallint SMALLINT," + " _tinyint TINYINT," + " _real REAL," + " _double DOUBLE," + " _boolean BOOLEAN," + " _decimal_short DECIMAL(3,2)," + " _decimal_long DECIMAL(30,10)" + ") " + "WITH (format = '" + storageFormat + "') ";
if (storageFormat == HiveStorageFormat.AVRO) {
createTable = createTable.replace(" _smallint SMALLINT,", " _smallint INTEGER,");
createTable = createTable.replace(" _tinyint TINYINT,", " _tinyint INTEGER,");
}
assertUpdate(session, createTable);
TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_insert_format_table");
assertEquals(tableMetadata.getMetadata().getProperties().get(STORAGE_FORMAT_PROPERTY), storageFormat);
assertColumnType(tableMetadata, "_string", createUnboundedVarcharType());
assertColumnType(tableMetadata, "_varchar", createVarcharType(65535));
assertColumnType(tableMetadata, "_char", createCharType(10));
@Language("SQL") String select = "SELECT" + " 'foo' _string" + ", 'bar' _varchar" + ", CAST('boo' AS CHAR(10)) _char" + ", 1 _bigint" + ", CAST(42 AS INTEGER) _integer" + ", CAST(43 AS SMALLINT) _smallint" + ", CAST(44 AS TINYINT) _tinyint" + ", CAST('123.45' AS REAL) _real" + ", CAST('3.14' AS DOUBLE) _double" + ", true _boolean" + ", CAST('3.14' AS DECIMAL(3,2)) _decimal_short" + ", CAST('12345678901234567890.0123456789' AS DECIMAL(30,10)) _decimal_long";
if (storageFormat == HiveStorageFormat.AVRO) {
select = select.replace(" CAST (43 AS SMALLINT) _smallint,", " 3 _smallint,");
select = select.replace(" CAST (44 AS TINYINT) _tinyint,", " 4 _tinyint,");
}
assertUpdate(session, "INSERT INTO test_insert_format_table " + select, 1);
assertQuery(session, "SELECT * from test_insert_format_table", select);
assertUpdate(session, "INSERT INTO test_insert_format_table (_tinyint, _smallint, _integer, _bigint, _real, _double) SELECT CAST(1 AS TINYINT), CAST(2 AS SMALLINT), 3, 4, cast(14.3 as REAL), 14.3", 1);
assertQuery(session, "SELECT * from test_insert_format_table where _bigint = 4", "SELECT null, null, null, 4, 3, 2, 1, 14.3, 14.3, null, null, null");
assertQuery(session, "SELECT * from test_insert_format_table where _real = CAST(14.3 as REAL)", "SELECT null, null, null, 4, 3, 2, 1, 14.3, 14.3, null, null, null");
assertUpdate(session, "INSERT INTO test_insert_format_table (_double, _bigint) SELECT 2.72, 3", 1);
assertQuery(session, "SELECT * from test_insert_format_table where _bigint = 3", "SELECT null, null, null, 3, null, null, null, null, 2.72, null, null, null");
assertUpdate(session, "INSERT INTO test_insert_format_table (_decimal_short, _decimal_long) SELECT DECIMAL '2.72', DECIMAL '98765432101234567890.0123456789'", 1);
assertQuery(session, "SELECT * from test_insert_format_table where _decimal_long = DECIMAL '98765432101234567890.0123456789'", "SELECT null, null, null, null, null, null, null, null, null, null, 2.72, 98765432101234567890.0123456789");
assertUpdate(session, "DROP TABLE test_insert_format_table");
assertFalse(getQueryRunner().tableExists(session, "test_insert_format_table"));
}
Aggregations