Skip to content

Commit cdb7bd0

Browse files
committed
Allowing omitting the "T" separator from a datetime string
Our customers have issue using spark to create a dataframe on a datetime column, because spark interpolates the provided datetime string, but drops the "T" separator when filling the range. It seems that omitting the "T" character is fairly acceptable, and ISO 8601 does allow it to be omitted in a few cases. This is a very simple patch to allow it. Signed-off-by: Rivers Zhang <[email protected]>
1 parent 59ba446 commit cdb7bd0

File tree

8 files changed

+23
-3
lines changed

8 files changed

+23
-3
lines changed

db/types.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7262,7 +7262,7 @@ static int _isISO8601(const char *str, int len)
72627262
/* (month<1 || month>12)*/ \
72637263
\
72647264
/*get day*/ \
7265-
day = getInt(in, len, &offset, &ltoken, 1, 2, "-T", &skipped); \
7265+
day = getInt(in, len, &offset, &ltoken, 1, 2, "-T ", &skipped); \
72667266
if (!ltoken) \
72677267
return CONV_WRONG_MDAY; \
72687268
/*(day <1 || !is_valid_days(year, month, day))*/ \
@@ -7307,8 +7307,14 @@ static int _isISO8601(const char *str, int len)
73077307
ss = 0; \
73087308
} else \
73097309
mm = 0; \
7310-
} else \
7310+
} else { \
73117311
hh = 0; \
7312+
/* Need to compensate if the last separator is a space */ \
7313+
/* Because we expect the timezone string to have a leading space */ \
7314+
/* See a few lines above for the same logic in parsing the fraction */ \
7315+
if (in[offset - 1] == ' ') \
7316+
offset--; /*incremented afterwards*/ \
7317+
} \
73127318
\
73137319
/* fill in the blanks*/ \
73147320
out->tm.tm_year = year - 1900; \

tests/datetime.test/t25.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(rows inserted=1)
2+
(rows inserted=1)
3+
(d="1970-01-01T000000.000 UTC")
4+
(d="1970-08-17T001501.000 UTC")
5+
(epoch=0)
6+
(epoch=19700101)

tests/datetime.test/t25.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
SET TIMEZONE UTC
2+
DROP TABLE IF EXISTS t25
3+
CREATE TABLE t25(d datetime)$$
4+
INSERT INTO t25 VALUES("1970-01-01 00:00:00 UTC")
5+
INSERT INTO t25 VALUES("19700101")
6+
SELECT d FROM t25
7+
SELECT CAST(d AS INT) AS epoch FROM t25
8+
DROP TABLE t25
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/udf.test/runit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
set -x
3-
for t in *.req; do
3+
for t in `ls *.req | sort`; do
44
cdb2sql --tabs --script --cdb2cfg ${CDB2_CONFIG} ${1} default - 2> ${t}.output 1>&2 < ${t}
55
set -e
66
diff ${t}.expected ${t}.output

0 commit comments

Comments
 (0)