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
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract class CountLike extends DeclarativeAggregate {
usage = """
_FUNC_(*) - Returns the total number of retrieved rows, including rows containing null.

_FUNC_(expr) - Returns the number of rows for which the supplied expression is non-null.
_FUNC_(expr[, expr...]) - Returns the number of rows for which the supplied expression(s) are all non-null.

_FUNC_(DISTINCT expr[, expr...]) - Returns the number of rows for which the supplied expression(s) are unique and non-null.
""")
Expand Down
27 changes: 27 additions & 0 deletions sql/core/src/test/resources/sql-tests/inputs/count.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- 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
count(*), count(1), count(null), count(a), count(b), count(a + b), count((a, b))
FROM testData;

-- distinct count with single expression
SELECT
count(DISTINCT 1),
count(DISTINCT null),
count(DISTINCT a),
count(DISTINCT b),
count(DISTINCT (a + b)),
count(DISTINCT (a, b))
FROM testData;

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

Choose a reason for hiding this comment

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

Please also include count(*)


-- distinct count with multiple expressions
SELECT
count(DISTINCT a, b), count(DISTINCT b, a), count(DISTINCT *), count(DISTINCT testData.*)
FROM testData;
55 changes: 55 additions & 0 deletions sql/core/src/test/resources/sql-tests/results/count.sql.out
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
count(*), count(1), count(null), count(a), count(b), count(a + b), count((a, b))
FROM testData
-- !query 1 schema
struct<count(1):bigint,count(1):bigint,count(NULL):bigint,count(a):bigint,count(b):bigint,count((a + b)):bigint,count(named_struct(a, a, b, b)):bigint>
-- !query 1 output
7 7 0 5 5 4 7


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


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


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