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
28 changes: 28 additions & 0 deletions sql/core/src/test/resources/sql-tests/inputs/udf/udf-count.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- This test file was converted from count.sql
-- Test data.
CREATE OR REPLACE TEMPORARY VIEW testData AS SELECT * FROM VALUES
(1, 1), (1, 2), (2, 1), (1, 1), (null, 2), (1, null), (null, null)
AS testData(a, b);

-- count with single expression
SELECT
udf(count(*)), udf(count(1)), udf(count(null)), udf(count(a)), udf(count(b)), udf(count(a + b)), udf(count((a, b)))
Copy link
Member

@HyukjinKwon HyukjinKwon Jul 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vinodkc, can make some other conbinations like udf(count(*)), count(udf(a)), udf(count(udf(a)))?

FROM testData;

-- distinct count with single expression
SELECT
udf(count(DISTINCT 1)),
udf(count(DISTINCT null)),
udf(count(DISTINCT a)),
udf(count(DISTINCT b)),
udf(count(DISTINCT (a + b))),
udf(count(DISTINCT (a, b)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too :-)

FROM testData;

-- count with multiple expressions
SELECT udf(count(a, b)), udf(count(b, a)), udf(count(testData.*)) FROM testData;

-- distinct count with multiple expressions
SELECT
udf(count(DISTINCT a, b)), udf(count(DISTINCT b, a)), udf(count(DISTINCT *)), udf(count(DISTINCT testData.*))
FROM testData;
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 5


-- !query 0
CREATE OR REPLACE TEMPORARY VIEW testData AS SELECT * FROM VALUES
(1, 1), (1, 2), (2, 1), (1, 1), (null, 2), (1, null), (null, null)
AS testData(a, b)
-- !query 0 schema
struct<>
-- !query 0 output



-- !query 1
SELECT
udf(count(*)), udf(count(1)), udf(count(null)), udf(count(a)), udf(count(b)), udf(count(a + b)), udf(count((a, b)))
FROM testData
-- !query 1 schema
struct<udf(count(1)):string,udf(count(1)):string,udf(count(null)):string,udf(count(a)):string,udf(count(b)):string,udf(count((a + b))):string,udf(count(named_struct(a, a, b, b))):string>
-- !query 1 output
7 7 0 5 5 4 7


-- !query 2
SELECT
udf(count(DISTINCT 1)),
udf(count(DISTINCT null)),
udf(count(DISTINCT a)),
udf(count(DISTINCT b)),
udf(count(DISTINCT (a + b))),
udf(count(DISTINCT (a, b)))
FROM testData
-- !query 2 schema
struct<udf(count(distinct 1)):string,udf(count(distinct null)):string,udf(count(distinct a)):string,udf(count(distinct b)):string,udf(count(distinct (a + b))):string,udf(count(distinct named_struct(a, a, b, b))):string>
-- !query 2 output
1 0 2 2 2 6


-- !query 3
SELECT udf(count(a, b)), udf(count(b, a)), udf(count(testData.*)) FROM testData
-- !query 3 schema
struct<udf(count(a, b)):string,udf(count(b, a)):string,udf(count(a, b)):string>
-- !query 3 output
4 4 4


-- !query 4
SELECT
udf(count(DISTINCT a, b)), udf(count(DISTINCT b, a)), udf(count(DISTINCT *)), udf(count(DISTINCT testData.*))
FROM testData
-- !query 4 schema
struct<udf(count(distinct a, b)):string,udf(count(distinct b, a)):string,udf(count(distinct a, b)):string,udf(count(distinct a, b)):string>
-- !query 4 output
3 3 3 3