Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions sql/core/src/test/resources/sql-tests/inputs/udf/udf-having.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- This test file was converted from having.sql.
-- Note that currently registered UDF returns a string. So there are some differences, for instance
-- in string cast within UDF in Scala and Python.

create temporary view hav as select * from values
("one", 1),
("two", 2),
("three", 3),
("one", 5)
as hav(k, v);

-- having clause
SELECT udf(k) AS k, udf(sum(v)) FROM hav GROUP BY k HAVING udf(sum(v)) > 2;

-- having condition contains grouping column
SELECT udf(count(udf(k))) FROM hav GROUP BY v + 1 HAVING v + 1 = udf(2);

-- SPARK-11032: resolve having correctly
SELECT udf(MIN(t.v)) FROM (SELECT * FROM hav WHERE v > 0) t HAVING(udf(COUNT(udf(1))) > 0);

-- SPARK-20329: make sure we handle timezones correctly
SELECT udf(a + b) FROM VALUES (1L, 2), (3L, 4) AS T(a, b) GROUP BY a + b HAVING a + b > udf(1);
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 5


-- !query 0
create temporary view hav as select * from values
("one", 1),
("two", 2),
("three", 3),
("one", 5)
as hav(k, v)
-- !query 0 schema
struct<>
-- !query 0 output



-- !query 1
SELECT udf(k) AS k, udf(sum(v)) FROM hav GROUP BY k HAVING udf(sum(v)) > 2
-- !query 1 schema
struct<k:string,udf(sum(cast(v as bigint))):string>
-- !query 1 output
one 6
three 3


-- !query 2
SELECT udf(count(udf(k))) FROM hav GROUP BY v + 1 HAVING v + 1 = udf(2)
-- !query 2 schema
struct<udf(count(udf(k))):string>
-- !query 2 output
1


-- !query 3
SELECT udf(MIN(t.v)) FROM (SELECT * FROM hav WHERE v > 0) t HAVING(udf(COUNT(udf(1))) > 0)
-- !query 3 schema
struct<udf(min(v)):string>
-- !query 3 output
1


-- !query 4
SELECT udf(a + b) FROM VALUES (1L, 2), (3L, 4) AS T(a, b) GROUP BY a + b HAVING a + b > udf(1)
-- !query 4 schema
struct<udf((a + cast(b as bigint))):string>
-- !query 4 output
3
7