Changeset: e30fddb940f0 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/e30fddb940f0
Modified Files:
sql/backends/monet5/sql_result.c
sql/test/copy/Tests/decimal_separators.test
Branch: default
Log Message:
Implement DECIMAL AS for interval types
diffs (133 lines):
diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -405,7 +405,11 @@ sec_frstr(Column *c, int type, const cha
neg = 0;
s++;
}
- for (i = 0; i < (19 - 3) && *s && *s != '.'; i++, s++) {
+ for (i = 0; i < (19 - 3) && *s && *s != c->decsep; i++, s++) {
+ if (c->decskip && *s == c->decskip) {
+ i--;
+ continue;
+ }
if (!isdigit((unsigned char) *s))
return NULL;
res *= 10;
@@ -413,10 +417,14 @@ sec_frstr(Column *c, int type, const cha
}
i = 0;
if (*s) {
- if (*s != '.')
+ if (*s != c->decsep)
return NULL;
s++;
for (; *s && i < 3; i++, s++) {
+ if (c->decskip && *s == c->decskip) {
+ i--;
+ continue;
+ }
if (!isdigit((unsigned char) *s))
return NULL;
res *= 10;
@@ -624,8 +632,8 @@ mvc_import_table(Client cntxt, BAT ***ba
} else if (col->type.type->eclass == EC_SEC) {
fmt[i].tostr = &dec_tostr;
fmt[i].frstr = &sec_frstr;
- fmt[i].decsep = '.'; // not sure if it should
be affected by DECIMAL DELIMITERS clause
- fmt[i].decskip = '\0';
+ fmt[i].decsep = decsep[0]; // apply DECIMAL
DELIMITERS clause
+ fmt[i].decskip = decskip[0];
}
fmt[i].size = ATOMsize(fmt[i].adt);
}
diff --git a/sql/test/copy/Tests/decimal_separators.test
b/sql/test/copy/Tests/decimal_separators.test
--- a/sql/test/copy/Tests/decimal_separators.test
+++ b/sql/test/copy/Tests/decimal_separators.test
@@ -4,6 +4,12 @@ START TRANSACTION
statement ok
CREATE TABLE decimals(id INT, d DECIMAL(8,2))
+statement ok
+CREATE TABLE secs(id INT, i INTERVAL SECOND)
+
+statement ok
+CREATE TABLE days(id INT, i INTERVAL DAY)
+
--
-- this is the default behavior
--
@@ -87,3 +93,73 @@ 123.45
statement ok
DELETE FROM decimals
+
+
+--
+-- interval types, default behavior
+--
+
+statement ok
+COPY 2 RECORDS INTO secs FROM STDIN
+<COPY_INTO_DATA>
+1|1.000
+2|1800.000
+
+query T
+SELECT i FROM secs ORDER BY id
+----
+0:00:01
+0:30:00
+
+statement ok
+DELETE FROM secs
+
+-- is this really how we copy day intervals from csv?
+statement ok
+COPY 2 RECORDS INTO days FROM STDIN
+<COPY_INTO_DATA>
+1|86400
+2|1814400.00
+
+query T
+SELECT i FROM days ORDER BY id
+----
+1
+21
+
+statement ok
+DELETE FROM days
+
+--
+-- interval types, behavior with decimal comma and thousands separator
+--
+
+statement ok
+COPY 2 RECORDS INTO secs FROM STDIN DECIMAL AS ',', '_'
+<COPY_INTO_DATA>
+1|1,00_0
+2|1_800,00_0
+
+query T
+SELECT i FROM secs ORDER BY id
+----
+0:00:01
+0:30:00
+
+statement ok
+DELETE FROM secs
+
+statement ok
+COPY 2 RECORDS INTO days FROM STDIN DECIMAL AS ',', '_'
+<COPY_INTO_DATA>
+1|86_400
+2|1_814_400,00
+
+query T
+SELECT i FROM days ORDER BY id
+----
+1
+21
+
+statement ok
+DELETE FROM days
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]