Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: acceptance test and test cleanup for TimeTZ #43023

Merged
merged 1 commit into from
Dec 17, 2019
Merged
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
9 changes: 9 additions & 0 deletions pkg/acceptance/testdata/java/src/main/java/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ public void testTime() throws Exception {
Assert.assertEquals("01:02:03.456", actual);
}

@Test
public void testTimeTZ() throws Exception {
PreparedStatement stmt = conn.prepareStatement("SELECT '01:02:03.456-07:00'::TIMETZ");
ResultSet rs = stmt.executeQuery();
rs.next();
String actual = new SimpleDateFormat("HH:mm:ss.SSSZ").format(rs.getTime(1));
Assert.assertEquals("08:02:03.456+0000", actual);
}

@Test
public void testUUID() throws Exception {
UUID uuid = UUID.randomUUID();
Expand Down
113 changes: 113 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/timetz
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,116 @@ query R
SELECT extract(epoch from timetz '12:00:00+04')
----
28800

# Adapted from `src/test/regress/expected/timetz.out` in postgres
subtest regress_postgres

statement ok
CREATE TABLE TIMETZ_TBL (id serial primary key, f1 time(2) with time zone)

# Changed PDT/PST/EDT -> zone offsets, as pgdate does not support abbreviations.
statement ok
INSERT INTO TIMETZ_TBL (f1) VALUES ('00:01-07')

statement ok
INSERT INTO TIMETZ_TBL (f1) VALUES ('01:00-07')

statement ok
INSERT INTO TIMETZ_TBL (f1) VALUES ('02:03-07')

statement ok
INSERT INTO TIMETZ_TBL (f1) VALUES ('07:07-05')

statement ok
INSERT INTO TIMETZ_TBL (f1) VALUES ('08:08-04')

statement ok
INSERT INTO TIMETZ_TBL (f1) VALUES ('11:59-07')

statement ok
INSERT INTO TIMETZ_TBL (f1) VALUES ('12:00-07')

statement ok
INSERT INTO TIMETZ_TBL (f1) VALUES ('12:01-07')

statement ok
INSERT INTO TIMETZ_TBL (f1) VALUES ('23:59-07')

statement ok
INSERT INTO TIMETZ_TBL (f1) VALUES ('11:59:59.99 PM-07')

statement ok
INSERT INTO TIMETZ_TBL (f1) VALUES ('2003-03-07 15:36:39 America/New_York')

statement ok
INSERT INTO TIMETZ_TBL (f1) VALUES ('2003-07-07 15:36:39 America/New_York')

# pgdate supports this, but postgres does not.
# INSERT INTO TIMETZ_TBL (f1) VALUES ('15:36:39 America/New_York')

# this should fail (timezone not specified without a date)
query error could not parse "1970-01-01 15:36:39 m2" as TimeTZ
INSERT INTO TIMETZ_TBL (f1) VALUES ('15:36:39 m2')

# this should fail (dynamic timezone abbreviation without a date)
query error could not parse "1970-01-01 15:36:39 MSK m2" as TimeTZ
INSERT INTO TIMETZ_TBL (f1) VALUES ('15:36:39 MSK m2')

query T
SELECT f1::string AS "Time TZ" FROM TIMETZ_TBL ORDER BY id
----
00:01:00-07:00:00
01:00:00-07:00:00
02:03:00-07:00:00
07:07:00-05:00:00
08:08:00-04:00:00
11:59:00-07:00:00
12:00:00-07:00:00
12:01:00-07:00:00
23:59:00-07:00:00
23:59:59.99-07:00:00
15:36:39-05:00:00
15:36:39-04:00:00

query T
SELECT f1::string AS "Three" FROM TIMETZ_TBL WHERE f1 < '05:06:07-07' ORDER BY id
----
00:01:00-07:00:00
01:00:00-07:00:00
02:03:00-07:00:00

query T
SELECT f1::string AS "Seven" FROM TIMETZ_TBL WHERE f1 > '05:06:07-07' ORDER BY id
----
07:07:00-05:00:00
08:08:00-04:00:00
11:59:00-07:00:00
12:00:00-07:00:00
12:01:00-07:00:00
23:59:00-07:00:00
23:59:59.99-07:00:00
15:36:39-05:00:00
15:36:39-04:00:00

query T
SELECT f1::string AS "None" FROM TIMETZ_TBL WHERE f1 < '00:00-07' ORDER BY id
----

query T
SELECT f1::string AS "Ten" FROM TIMETZ_TBL WHERE f1 >= '00:00-07' ORDER BY id
----
00:01:00-07:00:00
01:00:00-07:00:00
02:03:00-07:00:00
07:07:00-05:00:00
08:08:00-04:00:00
11:59:00-07:00:00
12:00:00-07:00:00
12:01:00-07:00:00
23:59:00-07:00:00
23:59:59.99-07:00:00
15:36:39-05:00:00
15:36:39-04:00:00

query error pq: unsupported binary operator: <timetz\(2\)> \+ <timetz>
SELECT f1 + time with time zone '00:01' AS "Illegal" FROM TIMETZ_TBL ORDER BY id
3 changes: 1 addition & 2 deletions pkg/util/timetz/timetz.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ func ParseTimeTZ(now time.Time, s string, precision time.Duration) (TimeTZ, erro
t, err := pgdate.ParseTimestamp(now, pgdate.ParseModeYMD, s)
if err != nil {
// Build our own error message to avoid exposing the dummy date.
return TimeTZ{}, pgerror.Wrapf(
err,
return TimeTZ{}, pgerror.Newf(
pgcode.InvalidTextRepresentation,
"could not parse %q as TimeTZ",
s,
Expand Down