Skip to content

Commit 0680855

Browse files
committed
improve test coverage
1 parent ce2eff0 commit 0680855

File tree

4 files changed

+438
-3
lines changed

4 files changed

+438
-3
lines changed

sql/core/src/test/resources/sql-tests/inputs/datetime.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ select from_json('{"date":"26/October/2015"}', 'date Date', map('dateFormat', 'd
157157
select from_csv('26/October/2015', 'time Timestamp', map('timestampFormat', 'dd/MMMMM/yyyy'));
158158
select from_csv('26/October/2015', 'date Date', map('dateFormat', 'dd/MMMMM/yyyy'));
159159

160+
create temporary view dnf as select d, f from values
161+
('1986-05-23', 'yyyy-MM-dd'),
162+
('1986-05-23a', 'yyyy-MM-dd'),
163+
('1986-05-23', 'invalid'),
164+
('1986-05-23', null),
165+
(null, 'yyyy-MM-dd'),
166+
(null, 'invalid'),
167+
(null, null) t(d, f);
168+
160169
select date_format(null, null);
161170
select date_format(null, 'yyyy-MM-dd');
162171
select date_format(null, 'invalid');
@@ -172,13 +181,19 @@ select date_format(cast(null as timestamp ), 'yyyy-MM-dd');
172181
select date_format(timestamp '1986-05-23', null);
173182
select date_format(timestamp '1986-05-23', 'invalid');
174183
select date_format(timestamp '1986-05-23', 'yyyy-MM-dd');
184+
select date_format(d, f) from dnf where f != 'invalid' or d is null or f is null ;
185+
select date_format(d, f) from dnf where f = 'invalid';
175186

176187
select from_unixtime(null);
177188
select from_unixtime(null , null);
178189
select from_unixtime(12345 , null);
179190
select from_unixtime(null , 'invalid');
180191
select from_unixtime(null , 'yyyy-MM-dd');
181192
select from_unixtime(12345 , 'yyyy-MM-dd');
193+
select from_unixtime(12345, f) from dnf where f <> 'invalid';
194+
select from_unixtime(9223372036854775807L, f) from dnf where f <> 'invalid';
195+
select from_unixtime(12345, f) from dnf where f = 'invalid';
196+
select from_unixtime(null, f) from dnf;
182197

183198
select unix_timestamp() = unix_timestamp();
184199
select unix_timestamp(null);
@@ -195,11 +210,19 @@ select unix_timestamp('1986-05-23');
195210
select unix_timestamp('1986-05-23', null);
196211
select unix_timestamp('1986-05-23', 'invalid');
197212
select unix_timestamp('1986-05-23', 'yyyy-MM-dd');
213+
select unix_timestamp('1986-05-23a', 'yyyy-MM-dd');
198214
select unix_timestamp(cast(null as timestamp ), 'yyyy-MM-dd');
199215
select unix_timestamp(timestamp '1986-05-23');
200216
select unix_timestamp(timestamp '1986-05-23', null);
201217
select unix_timestamp(timestamp '1986-05-23', 'invalid');
202218
select unix_timestamp(timestamp '1986-05-23', 'yyyy-MM-dd');
219+
-- these test un-foldable codegen version for [[ToTimestamp]] interface, covers all of its implementations
220+
-- which are unix_timestamp, to_unix_timestamp, to_timestamp and to_date
221+
select unix_timestamp(d, f) from dnf where d = '1986-05-23a';
222+
select unix_timestamp(d, f) from dnf where d != '1986-05-23a' and (f != 'invalid' or d is null or f is null);
223+
select unix_timestamp(d, f) from dnf where f = 'invalid' and d is null;
224+
select unix_timestamp(d, f) from dnf where f = 'invalid' and d is not null;
225+
select unix_timestamp(cast(d as date), f), unix_timestamp(cast(d as timestamp), f) from dnf;
203226

204227
select to_unix_timestamp(null);
205228
select to_unix_timestamp(null, null);

sql/core/src/test/resources/sql-tests/results/ansi/datetime.sql.out

Lines changed: 139 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- Automatically generated by SQLQueryTestSuite
2-
-- Number of queries: 188
2+
-- Number of queries: 201
33

44

55
-- !query
@@ -986,6 +986,21 @@ org.apache.spark.SparkUpgradeException
986986
You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'dd/MMMMM/yyyy' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html
987987

988988

989+
-- !query
990+
create temporary view dnf as select d, f from values
991+
('1986-05-23', 'yyyy-MM-dd'),
992+
('1986-05-23a', 'yyyy-MM-dd'),
993+
('1986-05-23', 'invalid'),
994+
('1986-05-23', null),
995+
(null, 'yyyy-MM-dd'),
996+
(null, 'invalid'),
997+
(null, null) t(d, f)
998+
-- !query schema
999+
struct<>
1000+
-- !query output
1001+
1002+
1003+
9891004
-- !query
9901005
select date_format(null, null)
9911006
-- !query schema
@@ -1109,6 +1124,28 @@ struct<date_format(TIMESTAMP '1986-05-23 00:00:00', yyyy-MM-dd):string>
11091124
1986-05-23
11101125

11111126

1127+
-- !query
1128+
select date_format(d, f) from dnf where f != 'invalid' or d is null or f is null
1129+
-- !query schema
1130+
struct<date_format(CAST(d AS TIMESTAMP), f):string>
1131+
-- !query output
1132+
1986-05-23
1133+
NULL
1134+
NULL
1135+
NULL
1136+
NULL
1137+
NULL
1138+
1139+
1140+
-- !query
1141+
select date_format(d, f) from dnf where f = 'invalid'
1142+
-- !query schema
1143+
struct<>
1144+
-- !query output
1145+
java.lang.IllegalArgumentException
1146+
Illegal pattern character: n
1147+
1148+
11121149
-- !query
11131150
select from_unixtime(null)
11141151
-- !query schema
@@ -1157,6 +1194,49 @@ struct<from_unixtime(CAST(12345 AS BIGINT), yyyy-MM-dd):string>
11571194
1969-12-31
11581195

11591196

1197+
-- !query
1198+
select from_unixtime(12345, f) from dnf where f <> 'invalid'
1199+
-- !query schema
1200+
struct<from_unixtime(CAST(12345 AS BIGINT), f):string>
1201+
-- !query output
1202+
1969-12-31
1203+
1969-12-31
1204+
1969-12-31
1205+
1206+
1207+
-- !query
1208+
select from_unixtime(9223372036854775807L, f) from dnf where f <> 'invalid'
1209+
-- !query schema
1210+
struct<from_unixtime(9223372036854775807, f):string>
1211+
-- !query output
1212+
1969-12-31
1213+
1969-12-31
1214+
1969-12-31
1215+
1216+
1217+
-- !query
1218+
select from_unixtime(12345, f) from dnf where f = 'invalid'
1219+
-- !query schema
1220+
struct<>
1221+
-- !query output
1222+
java.lang.IllegalArgumentException
1223+
Illegal pattern character: n
1224+
1225+
1226+
-- !query
1227+
select from_unixtime(null, f) from dnf
1228+
-- !query schema
1229+
struct<from_unixtime(CAST(NULL AS BIGINT), f):string>
1230+
-- !query output
1231+
NULL
1232+
NULL
1233+
NULL
1234+
NULL
1235+
NULL
1236+
NULL
1237+
NULL
1238+
1239+
11601240
-- !query
11611241
select unix_timestamp() = unix_timestamp()
11621242
-- !query schema
@@ -1278,6 +1358,15 @@ struct<unix_timestamp(1986-05-23, yyyy-MM-dd):bigint>
12781358
517215600
12791359

12801360

1361+
-- !query
1362+
select unix_timestamp('1986-05-23a', 'yyyy-MM-dd')
1363+
-- !query schema
1364+
struct<>
1365+
-- !query output
1366+
org.apache.spark.SparkUpgradeException
1367+
You may get a different result due to the upgrading of Spark 3.0: Fail to parse '1986-05-23a' in the new parser. You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0, or set to CORRECTED and treat it as an invalid datetime string.
1368+
1369+
12811370
-- !query
12821371
select unix_timestamp(cast(null as timestamp ), 'yyyy-MM-dd')
12831372
-- !query schema
@@ -1318,6 +1407,55 @@ struct<unix_timestamp(TIMESTAMP '1986-05-23 00:00:00', yyyy-MM-dd):bigint>
13181407
517215600
13191408

13201409

1410+
-- !query
1411+
select unix_timestamp(d, f) from dnf where d = '1986-05-23a'
1412+
-- !query schema
1413+
struct<>
1414+
-- !query output
1415+
org.apache.spark.SparkUpgradeException
1416+
You may get a different result due to the upgrading of Spark 3.0: Fail to parse '1986-05-23a' in the new parser. You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0, or set to CORRECTED and treat it as an invalid datetime string.
1417+
1418+
1419+
-- !query
1420+
select unix_timestamp(d, f) from dnf where d != '1986-05-23a' and (f != 'invalid' or d is null or f is null)
1421+
-- !query schema
1422+
struct<unix_timestamp(d, f):bigint>
1423+
-- !query output
1424+
517215600
1425+
NULL
1426+
1427+
1428+
-- !query
1429+
select unix_timestamp(d, f) from dnf where f = 'invalid' and d is null
1430+
-- !query schema
1431+
struct<unix_timestamp(d, f):bigint>
1432+
-- !query output
1433+
NULL
1434+
1435+
1436+
-- !query
1437+
select unix_timestamp(d, f) from dnf where f = 'invalid' and d is not null
1438+
-- !query schema
1439+
struct<>
1440+
-- !query output
1441+
java.lang.IllegalArgumentException
1442+
Illegal pattern character: n
1443+
1444+
1445+
-- !query
1446+
select unix_timestamp(cast(d as date), f), unix_timestamp(cast(d as timestamp), f) from dnf
1447+
-- !query schema
1448+
struct<unix_timestamp(CAST(d AS DATE), f):bigint,unix_timestamp(CAST(d AS TIMESTAMP), f):bigint>
1449+
-- !query output
1450+
517215600 517215600
1451+
517215600 517215600
1452+
517215600 517215600
1453+
NULL NULL
1454+
NULL NULL
1455+
NULL NULL
1456+
NULL NULL
1457+
1458+
13211459
-- !query
13221460
select to_unix_timestamp(null)
13231461
-- !query schema

0 commit comments

Comments
 (0)