Changeset: 46cd9a4bdae3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/46cd9a4bdae3
Added Files:
sql/test/bincopy/Tests/bincopy_default_values.SQL.py
Modified Files:
sql/server/rel_updates.c
sql/test/bincopy/Tests/All
sql/test/bincopy/Tests/bincopy_support.py
Branch: copyintobinary
Log Message:
COPY BINARY INTO should also apply default values
diffs (109 lines):
diff --git a/sql/server/rel_updates.c b/sql/server/rel_updates.c
--- a/sql/server/rel_updates.c
+++ b/sql/server/rel_updates.c
@@ -1746,7 +1746,6 @@ bincopyfrom(sql_query *query, dlist *qna
sql_exp *import;
sql_subfunc *f = sql_find_func(sql, "sys", "copyfrom", 3, F_UNION,
true, NULL);
list *collist;
- int i;
assert(f);
if (!copy_allowed(sql, 1))
@@ -1773,35 +1772,25 @@ bincopyfrom(sql_query *query, dlist *qna
exp_atom_int(sql->sa, onclient)),
exp_atom_bool(sql->sa, do_byteswap));
- // create the list of files that is passed to the function as parameter
- for (i = 0; i < ol_length(t->columns); i++) {
- // we have one file per column, however, because we have column
selection that file might be NULL
- // first, check if this column number is present in the passed
in the parameters
- int found = 0;
- dn = files->h;
- for (n = collist->h; n && dn; n = n->next, dn = dn->next) {
- sql_column *c = n->data;
- if (i == c->colnr) {
- // this column number was present in the input
arguments; pass in the file name
- append(args, exp_atom_str(sql->sa,
dn->data.sval, &strtpe));
- found = 1;
- break;
- }
- }
- if (!found) {
- // this column was not present in the input arguments;
pass in NULL
- append(args, exp_atom_str(sql->sa, NULL, &strtpe));
- }
+ for (dn = files->h; dn; dn = dn->next) {
+ char *filename = dn->data.sval;
+ append(args, exp_atom_str(sql->sa, filename, &strtpe));
}
import = exp_op(sql->sa, args, f);
exps = new_exp_list(sql->sa);
- for (n = ol_first_node(t->columns); n; n = n->next) {
+ for (n = collist->h; n; n = n->next) {
sql_column *c = n->data;
append(exps, exp_column(sql->sa, t->base.name, c->base.name,
&c->type, CARD_MULTI, c->null, is_column_unique(c), 0));
}
res = rel_table_func(sql->sa, NULL, import, exps, TABLE_PROD_FUNC);
+
+ exps = rel_inserts(sql, t, res, collist, 1, 1, "COPY BINARY INTO");
+ if(!exps)
+ return NULL;
+ res = rel_project(sql->sa, res, exps);
+
res = rel_insert_table(query, t, t->base.name, res);
return res;
}
diff --git a/sql/test/bincopy/Tests/All b/sql/test/bincopy/Tests/All
--- a/sql/test/bincopy/Tests/All
+++ b/sql/test/bincopy/Tests/All
@@ -42,6 +42,7 @@ bincopy_uuids_on_client
bincopy_uuids_on_server
bincopy_invalid_json
+bincopy_default_values
bincopy_little_endians_on_client
bincopy_little_endians_on_server
diff --git a/sql/test/bincopy/Tests/bincopy_default_values.SQL.py
b/sql/test/bincopy/Tests/bincopy_default_values.SQL.py
new file mode 100644
--- /dev/null
+++ b/sql/test/bincopy/Tests/bincopy_default_values.SQL.py
@@ -0,0 +1,9 @@
+#!/usr/bin/env python3
+
+import sys
+import os
+sys.path.append(os.getenv('TSTSRCDIR'))
+from bincopy_support import run_test
+from bincopy_support import DEFAULT_VALUES as testcode
+
+run_test('client', testcode)
diff --git a/sql/test/bincopy/Tests/bincopy_support.py
b/sql/test/bincopy/Tests/bincopy_support.py
--- a/sql/test/bincopy/Tests/bincopy_support.py
+++ b/sql/test/bincopy/Tests/bincopy_support.py
@@ -647,3 +647,23 @@ ORDER BY t_s, s_i, i_b, f_d
LIMIT 4;
;
""", [f"true,true,true,true,{NRECS}"])
+
+
+DEFAULT_VALUES = ("""
+CREATE SEQUENCE seq START WITH 10;
+CREATE TABLE foo(
+ s SERIAL,
+ d INT DEFAULT 42,
+ n INT DEFAULT NEXT VALUE FOR seq,
+ i INT
+);
+
+COPY BINARY INTO foo(i)
+FROM @ints@ @ON@;
+
+SELECT
+ COUNT(DISTINCT s) AS distinct_s,
+ SUM(d) AS sum_d,
+ SUM(n) AS sum_n
+FROM foo;
+""", [f"{NRECS},{42*NRECS},{8 * NRECS + NRECS * (NRECS + 1) // 2 }"])
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]