Skip to content

Commit

Permalink
[SPARK-31476][SQL][FOLLOWUP] Add tests for extract('field', source)
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

SPARK-31476 has supported `extract('field', source)` as side-effect, so this PR intends to add some tests for the function in `SQLQueryTestSuite`.

### Why are the changes needed?

For better test coverage.

### Does this PR introduce any user-facing change?

No.

### How was this patch tested?

Added tests.

Closes #28276 from maropu/SPARK-31476-FOLLOWUP.

Authored-by: Takeshi Yamamuro <yamamuro@apache.org>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit 820733a)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
  • Loading branch information
maropu authored and cloud-fan committed Apr 23, 2020
1 parent 5c1e0d0 commit 6e76310
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 2 deletions.
16 changes: 15 additions & 1 deletion sql/core/src/test/resources/sql-tests/inputs/extract.sql
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,18 @@ select date_part(c, c) from t;
select date_part(null, c) from t;

select date_part(i, i) from t;
select date_part(null, i) from t;
select date_part(null, i) from t;

-- In SPARK-31476, we've supported extract('field', source), too
select extract('year', c) from t;
select extract('quarter', c) from t;
select extract('month', c) from t;
select extract('week', c) from t;
select extract('day', c) from t;
select extract('days', c) from t;
select extract('dayofweek', c) from t;
select extract('dow', c) from t;
select extract('doy', c) from t;
select extract('hour', c) from t;
select extract('minute', c) from t;
select extract('second', c) from t;
98 changes: 97 additions & 1 deletion sql/core/src/test/resources/sql-tests/results/extract.sql.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 84
-- Number of queries: 96


-- !query
Expand Down Expand Up @@ -677,3 +677,99 @@ select date_part(null, i) from t
struct<date_part(NULL, t.`i`):double>
-- !query output
NULL


-- !query
select extract('year', c) from t
-- !query schema
struct<extract('year' FROM t.`c`):int>
-- !query output
2011


-- !query
select extract('quarter', c) from t
-- !query schema
struct<extract('quarter' FROM t.`c`):int>
-- !query output
2


-- !query
select extract('month', c) from t
-- !query schema
struct<extract('month' FROM t.`c`):int>
-- !query output
5


-- !query
select extract('week', c) from t
-- !query schema
struct<extract('week' FROM t.`c`):int>
-- !query output
18


-- !query
select extract('day', c) from t
-- !query schema
struct<extract('day' FROM t.`c`):int>
-- !query output
6


-- !query
select extract('days', c) from t
-- !query schema
struct<extract('days' FROM t.`c`):int>
-- !query output
6


-- !query
select extract('dayofweek', c) from t
-- !query schema
struct<extract('dayofweek' FROM t.`c`):int>
-- !query output
6


-- !query
select extract('dow', c) from t
-- !query schema
struct<extract('dow' FROM t.`c`):int>
-- !query output
6


-- !query
select extract('doy', c) from t
-- !query schema
struct<extract('doy' FROM t.`c`):int>
-- !query output
126


-- !query
select extract('hour', c) from t
-- !query schema
struct<extract('hour' FROM t.`c`):int>
-- !query output
7


-- !query
select extract('minute', c) from t
-- !query schema
struct<extract('minute' FROM t.`c`):int>
-- !query output
8


-- !query
select extract('second', c) from t
-- !query schema
struct<extract('second' FROM t.`c`):decimal(8,6)>
-- !query output
9.123456

0 comments on commit 6e76310

Please sign in to comment.