MonetDB: nested - improved parsing of strings

2025-02-07 Thread Niels Nes via checkin-list
Changeset: b90e8e296a4b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b90e8e296a4b
Modified Files:
sql/backends/monet5/sql_result.c
sql/test/nested/Tests/array.test
Branch: nested
Log Message:

improved parsing of strings


diffs (57 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
@@ -2147,7 +2147,22 @@ ARRAYparser(char *s, Column *cols, int n
throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) 
"missing ( at end of composite value");
} else {
/* handle literals */
-   char *ns = strchr(s, ',');
+   int skip = 0;
+   char *ns = NULL;
+   if (t->type->localtype == TYPE_str) {
+   /* todo improve properly skip "" strings. */
+   if (*s != '"')
+   throw(SQL, "SQLfrom_varchar", 
SQLSTATE(42000) "missing \" at start of string value");
+   s++;
+   ns = s;
+   while(*ns && *ns != '"')
+   ns++;
+   if (*ns != '"')
+   throw(SQL, "SQLfrom_varchar", 
SQLSTATE(42000) "missing \" at end of string value");
+   skip++;
+   } else {
+   ns = strchr(s, ',');
+   }
if (!ns) {
ns = strchr(s, '}');
}
@@ -2164,6 +2179,8 @@ ARRAYparser(char *s, Column *cols, int n
elm++;
*ns = sep;
s = ns;
+   if (skip)
+   s++;
}
/* insert msid */
if (elm >= 0 && BUNappend(cols[elm].c, &id, false) != 
GDK_SUCCEED)
diff --git a/sql/test/nested/Tests/array.test b/sql/test/nested/Tests/array.test
--- a/sql/test/nested/Tests/array.test
+++ b/sql/test/nested/Tests/array.test
@@ -56,7 +56,7 @@ query T nosort
 select * from bar
 
 {"left","right"}
-{"l1","r2"}
+{"l2","r2"}
 
 statement ok
 insert into bar values ('{"single"}'), ('{"a", "b", "c"}'), ('{"one", "two"}');
@@ -65,7 +65,7 @@ query T nosort
 select * from bar
 
 {"left","right"}
-{"l1","r2"}
+{"l2","r2"}
 {"single"}
 {"a","b","c"}
 {"one","two"}
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: Aug2024 - Avoid a data race.

2025-02-07 Thread Sjoerd Mullender via checkin-list
Changeset: c3fce99529f1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/c3fce99529f1
Modified Files:
sql/storage/bat/bat_storage.c
Branch: Aug2024
Log Message:

Avoid a data race.


diffs (35 lines):

diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c
--- a/sql/storage/bat/bat_storage.c
+++ b/sql/storage/bat/bat_storage.c
@@ -4618,7 +4618,6 @@ add_offsets(BUN slot, size_t nr, size_t 
 static int
 claim_segmentsV2(sql_trans *tr, sql_table *t, storage *s, size_t cnt, BUN 
*offset, BAT **offsets, bool locked)
 {
-   int in_transaction = segments_in_transaction(tr, t), ok = LOG_OK;
assert(s->segs);
ulng oldest = store_oldest(tr->store, NULL);
BUN slot = 0;
@@ -4626,6 +4625,7 @@ claim_segmentsV2(sql_trans *tr, sql_tabl
 
if (!locked)
lock_table(tr->store, t->base.id);
+   int in_transaction = segments_in_transaction(tr, t), ok = LOG_OK;
/* naive vacuum approach, iterator through segments, use deleted 
segments or create new segment at the end */
for (segment *seg = s->segs->h, *p = NULL; seg && cnt && ok == LOG_OK; 
p = seg, seg = ATOMIC_PTR_GET(&seg->next)) {
if (seg->deleted && seg->ts < oldest && seg->end > seg->start) 
{ /* reuse old deleted or rolled back append */
@@ -4707,7 +4707,6 @@ claim_segments(sql_trans *tr, sql_table 
 {
if (cnt > 1 && offsets)
return claim_segmentsV2(tr, t, s, cnt, offset, offsets, locked);
-   int in_transaction = segments_in_transaction(tr, t), ok = LOG_OK;
assert(s->segs);
ulng oldest = store_oldest(tr->store, NULL);
BUN slot = 0;
@@ -4715,6 +4714,7 @@ claim_segments(sql_trans *tr, sql_table 
 
if (!locked)
lock_table(tr->store, t->base.id);
+   int in_transaction = segments_in_transaction(tr, t), ok = LOG_OK;
/* naive vacuum approach, iterator through segments, check for large 
enough deleted segments
 * or create new segment at the end */
for (segment *seg = s->segs->h, *p = NULL; seg && ok == LOG_OK; p = 
seg, seg = ATOMIC_PTR_GET(&seg->next)) {
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: default - Merge branch odbc_loader into default.

2025-02-07 Thread Sjoerd Mullender via checkin-list
Changeset: a6ec18daf0b8 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a6ec18daf0b8
Branch: default
Log Message:

Merge branch odbc_loader into default.


diffs (truncated from 3977 to 300 lines):

diff --git a/clients/Tests/MAL-signatures-hge.test 
b/clients/Tests/MAL-signatures-hge.test
--- a/clients/Tests/MAL-signatures-hge.test
+++ b/clients/Tests/MAL-signatures-hge.test
@@ -47373,6 +47373,16 @@ tanh
 command mmath.tanh(X_0:flt):flt
 MATHunary_TANHflt
 (empty)
+monetdb
+epilogue
+command monetdb.epilogue():void
+MONETDBepilogue
+(empty)
+monetdb
+prelude
+pattern monetdb.prelude():void
+MONETDBprelude
+(empty)
 mtime
 addmonths
 command mtime.addmonths(X_0:date, X_1:int):date
@@ -49199,6 +49209,11 @@ unsafe pattern sql.next_value(X_0:str, X
 mvc_next_value
 return the next value of the sequence
 sql
+normalize_monetdb_url
+pattern sql.normalize_monetdb_url(X_0:str):str
+SQLnormalize_monetdb_url
+Normalize mapi:monetdb://, monetdb:// or monetdbs:// URL
+sql
 nth_value
 pattern sql.nth_value(X_0:any_1, X_1:lng, X_2:bit, X_3:bit, X_4:int, X_5:oid, 
X_6:oid):any_1
 SQLnth_value
diff --git a/clients/Tests/MAL-signatures.test 
b/clients/Tests/MAL-signatures.test
--- a/clients/Tests/MAL-signatures.test
+++ b/clients/Tests/MAL-signatures.test
@@ -35853,6 +35853,16 @@ tanh
 command mmath.tanh(X_0:flt):flt
 MATHunary_TANHflt
 (empty)
+monetdb
+epilogue
+command monetdb.epilogue():void
+MONETDBepilogue
+(empty)
+monetdb
+prelude
+pattern monetdb.prelude():void
+MONETDBprelude
+(empty)
 mtime
 addmonths
 command mtime.addmonths(X_0:date, X_1:int):date
@@ -37654,6 +37664,11 @@ unsafe pattern sql.next_value(X_0:str, X
 mvc_next_value
 return the next value of the sequence
 sql
+normalize_monetdb_url
+pattern sql.normalize_monetdb_url(X_0:str):str
+SQLnormalize_monetdb_url
+Normalize mapi:monetdb://, monetdb:// or monetdbs:// URL
+sql
 nth_value
 pattern sql.nth_value(X_0:any_1, X_1:lng, X_2:bit, X_3:bit, X_4:int, X_5:oid, 
X_6:oid):any_1
 SQLnth_value
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -745,19 +745,19 @@ mparm mparm_enumerate(int i);
 bool mparm_is_core(mparm parm);
 const char *mparm_name(mparm parm);
 mparm mparm_parse(const char *name);
-char *msetting_as_string(const msettings *mp, mparm parm);
+const char *msetting_as_string(const msettings *mp, mparm parm, char *scratch, 
size_t scratch_size);
 bool msetting_bool(const msettings *mp, mparm parm);
 long msetting_long(const msettings *mp, mparm parm);
 const char *msetting_parm_name(const msettings *mp, mparm parm);
 msettings_error msetting_parse(msettings *mp, mparm parm, const char *text);
 int msetting_parse_bool(const char *text);
 msettings_error msetting_set_bool(msettings *mp, mparm parm, bool value);
-msettings_error msetting_set_ignored(msettings *mp, const char *key, const 
char *value);
 msettings_error msetting_set_long(msettings *mp, mparm parm, long value);
 msettings_error msetting_set_named(msettings *mp, bool allow_core, const char 
*key, const char *value);
 msettings_error msetting_set_string(msettings *mp, mparm parm, const char 
*value) __attribute__((__nonnull__(3)));
 const char *msetting_string(const msettings *mp, mparm parm);
 msettings *msettings_clone(const msettings *mp);
+msettings *msettings_clone_with(msettings_allocator alloc, void *alloc_state, 
const msettings *mp);
 long msettings_connect_binary(const msettings *mp);
 const char *msettings_connect_certhash_digits(const msettings *mp);
 const char *msettings_connect_clientcert(const msettings *mp);
@@ -768,13 +768,16 @@ const char *msettings_connect_tcp(const 
 enum msetting_tls_verify msettings_connect_tls_verify(const msettings *mp);
 const char *msettings_connect_unix(const msettings *mp);
 msettings *msettings_create(void);
+msettings *msettings_create_with(msettings_allocator alloc, void *alloc_state);
 const msettings *msettings_default;
 msettings *msettings_destroy(msettings *mp);
+msettings_allocator msettings_get_allocator(const msettings *mp, void 
**put_alloc_state_here);
 bool msettings_malloc_failed(msettings_error err);
-bool msettings_parse_url(msettings *mp, const char *url, char **error_buffer);
+msettings_error msettings_parse_url(msettings *mp, const char *url);
 void msettings_reset(msettings *mp);
 void msettings_set_localizer(msettings *mp, const char *(*localizer)(const 
void *data, mparm parm), void *data);
-bool msettings_validate(msettings *mp, char **errmsg);
+msettings_error msettings_validate(msettings *mp);
+size_t msettings_write_url(const msettings *mp, char *buffer, size_t);
 const char *wsaerror(int);
 
 # monetdb5
@@ -1624,6 +1627,8 @@ str lng_num2dec_flt(flt *res, const lng 
 str lng_num2dec_int(int *res, const lng *v, const int *d2, const int *s2);
 str lng_num2dec_lng(lng *res, const lng *v, const int *d2, const int *s2);
 str lng_num2dec_sht(sht *res, const lng *v, const int *d2, const int *s2);
+const c

MonetDB: nested - Fixes test for composite type - we want to tes...

2025-02-07 Thread stefanos mavros via checkin-list
Changeset: 6a76552a4c1b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/6a76552a4c1b
Modified Files:
sql/test/nested/Tests/composite.test
Branch: nested
Log Message:

Fixes test for composite type - we want to test composite with basic types only


diffs (10 lines):

diff --git a/sql/test/nested/Tests/composite.test 
b/sql/test/nested/Tests/composite.test
--- a/sql/test/nested/Tests/composite.test
+++ b/sql/test/nested/Tests/composite.test
@@ -1,5 +1,5 @@
 statement ok
-create type myt as (n int, m text[])
+create type myt as (n int, m text)
 
 statement ok
 create table foo (c myt)
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: default - Approve upgrade code.

2025-02-07 Thread Sjoerd Mullender via checkin-list
Changeset: bad7f2f9d4be for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/bad7f2f9d4be
Modified Files:

sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.int128
sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out
sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out.int128
sql/test/emptydb-previous-upgrade-hge/Tests/upgrade.stable.out.int128
sql/test/emptydb-previous-upgrade/Tests/upgrade.stable.out
sql/test/emptydb-previous-upgrade/Tests/upgrade.stable.out.int128
sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out
sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.int128
sql/test/emptydb-upgrade-hge/Tests/upgrade.stable.out.int128
sql/test/emptydb-upgrade/Tests/upgrade.stable.out
sql/test/emptydb-upgrade/Tests/upgrade.stable.out.int128

sql/test/testdb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.int128
sql/test/testdb-previous-upgrade-chain/Tests/upgrade.stable.out
sql/test/testdb-previous-upgrade-chain/Tests/upgrade.stable.out.int128
sql/test/testdb-previous-upgrade-hge/Tests/upgrade.stable.out.int128
sql/test/testdb-previous-upgrade/Tests/upgrade.stable.out
sql/test/testdb-previous-upgrade/Tests/upgrade.stable.out.int128
sql/test/testdb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out
sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.int128
sql/test/testdb-upgrade-hge/Tests/upgrade.stable.out.int128
sql/test/testdb-upgrade/Tests/upgrade.stable.out
sql/test/testdb-upgrade/Tests/upgrade.stable.out.int128
Branch: default
Log Message:

Approve upgrade code.


diffs (truncated from 384 to 300 lines):

diff --git 
a/sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.int128 
b/sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.int128
--- 
a/sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.int128
+++ 
b/sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.int128
@@ -779,6 +779,12 @@ grant execute on function monthname(date
 update sys.functions set system = true where system <> true and name in 
('dayname', 'monthname') and schema_id = 2000 and type = (select 
function_type_id from sys.function_types where function_type_name = 'Scalar 
function');
 
 Running database upgrade commands:
+create function sys.normalize_monetdb_url(u string)
+returns string external name sql.normalize_monetdb_url;
+grant execute on function sys.normalize_monetdb_url(string) to public;
+update sys.functions set system = true where system <> true and name = 
'normalize_monetdb_url' and schema_id = 2000;
+update sys._tables set query = sys.normalize_monetdb_url(query) where type in 
(5,6);
+Running database upgrade commands:
 drop view sys.geometry_columns;
 create view sys.geometry_columns as
  select cast(null as varchar(1)) as f_table_catalog,
diff --git a/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out 
b/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out
--- a/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out
+++ b/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out
@@ -762,6 +762,12 @@ grant execute on function monthname(date
 update sys.functions set system = true where system <> true and name in 
('dayname', 'monthname') and schema_id = 2000 and type = (select 
function_type_id from sys.function_types where function_type_name = 'Scalar 
function');
 
 Running database upgrade commands:
+create function sys.normalize_monetdb_url(u string)
+returns string external name sql.normalize_monetdb_url;
+grant execute on function sys.normalize_monetdb_url(string) to public;
+update sys.functions set system = true where system <> true and name = 
'normalize_monetdb_url' and schema_id = 2000;
+update sys._tables set query = sys.normalize_monetdb_url(query) where type in 
(5,6);
+Running database upgrade commands:
 drop view sys.geometry_columns;
 create view sys.geometry_columns as
  select cast(null as varchar(1)) as f_table_catalog,
diff --git 
a/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out.int128 
b/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out.int128
--- a/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out.int128
+++ b/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out.int128
@@ -845,6 +845,12 @@ grant execute on function monthname(date
 update sys.functions set system = true where system <> true and name in 
('dayname', 'monthname') and schema_id = 2000 and type = (select 
function_type_id from sys.function_types where function_type_name = 'Scalar 
function');
 
 Running database upgrade commands:
+create function sys.normalize_monetdb_url(u string)
+returns str

MonetDB: nested - need .in file

2025-02-07 Thread Niels Nes via checkin-list
Changeset: e5c8c70703ee for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/e5c8c70703ee
Added Files:
sql/test/nested/Tests/json.test.in
Branch: nested
Log Message:

need .in file


diffs (3 lines):

diff --git a/sql/test/nested/Tests/json.test 
b/sql/test/nested/Tests/json.test.in
copy from sql/test/nested/Tests/json.test
copy to sql/test/nested/Tests/json.test.in
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - give error on missing file

2025-02-07 Thread Niels Nes via checkin-list
Changeset: ddb352e1859c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ddb352e1859c
Modified Files:
sql/backends/monet5/vaults/json/json.c
Branch: nested
Log Message:

give error on missing file


diffs (26 lines):

diff --git a/sql/backends/monet5/vaults/json/json.c 
b/sql/backends/monet5/vaults/json/json.c
--- a/sql/backends/monet5/vaults/json/json.c
+++ b/sql/backends/monet5/vaults/json/json.c
@@ -241,12 +241,18 @@ JSONread_json(Client cntxt, MalBlkPtr mb
const char* json_str = NULL;
JSON *jt = NULL;
BAT *b = NULL;
-   if (jfh) {
-   json_str = read_json_file(jfh);
-   json_close(jfh);
+   if (!jfh) {
+   sa_destroy(sa);
+   msg = createException(SQL, "json.read_json", "Failed to open 
file %s", fname);
+   return msg;
}
-   if (json_str)
+   json_str = read_json_file(jfh);
+   json_close(jfh);
+   if (json_str) {
+   printf("%s\n", json_str);
+   fflush(stdout);
jt = JSONparse(json_str);
+   }
if (jt) {
if (jt->error == NULL) {
b = COLnew(0, TYPE_json, 0, TRANSIENT);
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - use srcdir

2025-02-07 Thread Niels Nes via checkin-list
Changeset: 4e081814ece8 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/4e081814ece8
Modified Files:
sql/backends/monet5/vaults/json/json.c
sql/test/nested/Tests/json.test.in
Branch: nested
Log Message:

use srcdir
remove debug output


diffs (28 lines):

diff --git a/sql/backends/monet5/vaults/json/json.c 
b/sql/backends/monet5/vaults/json/json.c
--- a/sql/backends/monet5/vaults/json/json.c
+++ b/sql/backends/monet5/vaults/json/json.c
@@ -248,11 +248,8 @@ JSONread_json(Client cntxt, MalBlkPtr mb
}
json_str = read_json_file(jfh);
json_close(jfh);
-   if (json_str) {
-   printf("%s\n", json_str);
-   fflush(stdout);
+   if (json_str)
jt = JSONparse(json_str);
-   }
if (jt) {
if (jt->error == NULL) {
b = COLnew(0, TYPE_json, 0, TRANSIENT);
diff --git a/sql/test/nested/Tests/json.test.in 
b/sql/test/nested/Tests/json.test.in
--- a/sql/test/nested/Tests/json.test.in
+++ b/sql/test/nested/Tests/json.test.in
@@ -2,7 +2,7 @@ statement ok
 create type event as (id int, type varchar)
 
 query T
-select cast(t.json as event) from (select json from r'$TSTTRGDIR/events.json') 
t
+select cast(t.json as event) from (select json from r'$TSTSRCDIR/events.json') 
t
 
 
 statement ok
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - approved output

2025-02-07 Thread Niels Nes via checkin-list
Changeset: 24b0011e2568 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/24b0011e2568
Modified Files:
sql/test/nested/Tests/json.test.in
Branch: nested
Log Message:

approved output


diffs (18 lines):

diff --git a/sql/test/nested/Tests/json.test.in 
b/sql/test/nested/Tests/json.test.in
--- a/sql/test/nested/Tests/json.test.in
+++ b/sql/test/nested/Tests/json.test.in
@@ -1,9 +1,13 @@
 statement ok
 create type event as (id int, type varchar)
 
-query T
+query TT
 select cast(t.json as event) from (select json from r'$TSTSRCDIR/events.json') 
t
 
+49
+"click"
+50
+"scroll"
 
 statement ok
 drop type event
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - merged

2025-02-07 Thread Niels Nes via checkin-list
Changeset: 5ec910ff6013 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/5ec910ff6013
Branch: nested
Log Message:

merged


diffs (10 lines):

diff --git a/sql/test/nested/Tests/composite.test 
b/sql/test/nested/Tests/composite.test
--- a/sql/test/nested/Tests/composite.test
+++ b/sql/test/nested/Tests/composite.test
@@ -1,5 +1,5 @@
 statement ok
-create type myt as (n int, m text[])
+create type myt as (n int, m text)
 
 statement ok
 create table foo (c myt)
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - removed

2025-02-07 Thread Niels Nes via checkin-list
Changeset: 02d126f53b87 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/02d126f53b87
Removed Files:
sql/test/nested/Tests/json.test
Branch: nested
Log Message:

removed


diffs (14 lines):

diff --git a/sql/test/nested/Tests/json.test b/sql/test/nested/Tests/json.test
deleted file mode 100644
--- a/sql/test/nested/Tests/json.test
+++ /dev/null
@@ -1,9 +0,0 @@
-statement ok
-create type event as (id int, type varchar)
-
-query T
-select cast(t.json as event) from (select json from r'$TSTTRGDIR/events.json') 
t
-
-
-statement ok
-drop type event
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: odbc_loader - Closing branch odbc_loader.

2025-02-07 Thread Sjoerd Mullender via checkin-list
Changeset: ddb6c2b839d4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ddb6c2b839d4
Branch: odbc_loader
Log Message:

Closing branch odbc_loader.

___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - fix bat leak

2025-02-07 Thread Niels Nes via checkin-list
Changeset: e382b65c91b9 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/e382b65c91b9
Modified Files:
sql/backends/monet5/sql.c
Branch: nested
Log Message:

fix bat leak


diffs (27 lines):

diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -5766,7 +5766,7 @@ insert_json_object(char **msg, JSON *js,
}
}
 
-   if (elm > 0 && BUNappend(bats[w], &id, false) != GDK_SUCCEED)
+   if (t->multiset && elm > 0 && BUNappend(bats[w], &id, false) != 
GDK_SUCCEED)
elm = -3;
if (t->multiset == MS_ARRAY && elm > 0 && BUNappend(bats[w+1], &anr, 
false) != GDK_SUCCEED)
elm = -3;
@@ -5853,10 +5853,13 @@ SQLfrom_json(Client cntxt, MalBlkPtr mb,
BUN p, q;
BATloop(b, p, q) {
const char *json = (const char *) BUNtail(bi, p);
-   if ((msg = insert_json_str(json, bats, pci->retc, t )) 
!= MAL_SUCCEED)
+   if ((msg = insert_json_str(json, bats, pci->retc, t )) 
!= MAL_SUCCEED) {
+   BBPreclaim(b);
goto bailout;
+   }
}
bat_iterator_end(&bi);
+   BBPreclaim(b);
} else {
if (strcmp(BATatoms[mtype].name, "json") != 0)
throw(SQL, "SQLfrom_json", SQLSTATE(HY013) "Incorrect 
argument type");
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - loading webclicks from file WIP

2025-02-07 Thread svetlin via checkin-list
Changeset: 547aa1c106a4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/547aa1c106a4
Added Files:
sql/test/nested/Tests/webclicks.json
sql/test/nested/Tests/webclicks.test.in
Removed Files:
sql/test/nested/Tests/webclicks.test
Branch: nested
Log Message:

loading webclicks from file WIP


diffs (156 lines):

diff --git a/sql/test/nested/Tests/webclicks.json 
b/sql/test/nested/Tests/webclicks.json
new file mode 100644
--- /dev/null
+++ b/sql/test/nested/Tests/webclicks.json
@@ -0,0 +1,76 @@
+[{
+  "eventid": "996257967-103007874",
+  "event": "productDetail",
+  "timestamp": "2024-11-30 22:13:37.823000",
+  "location": {
+"list": [{
+  "element": {
+"key": "hash",
+"value": "da39a3ee5e6b4b0d3255bfef95601890afd80709"
+  }
+}, {
+  "element": {
+"key": "hostname",
+"value": "e13dacd9566ecf8efd4aff212960c02de20aa110"
+  }
+}, {
+  "element": {
+"key": "pageSubType",
+"value": "d5d4cd07616a542891b7ec2d0257b3a24b69856e"
+  }
+}, {
+  "element": {
+"key": "pageType",
+"value": "6b5cdf4073b8166e5cc01a2532469d2e356eebfd"
+  }
+}, {
+  "element": {
+"key": "pathname",
+"value": "0b28998c6a5efc0afb854752b1bba65f37c70230"
+  }
+}, {
+  "element": {
+"key": "protocol",
+"value": "c3437dbc7c1255d3a21d444d86ebf2e9234c22bd"
+  }
+}, {
+  "element": {
+"key": "referrer",
+"value": "27bbe94658bf6bd4c431052e2065de0457ec8546"
+  }
+}, {
+  "element": {
+"key": "search",
+"value": "da39a3ee5e6b4b0d3255bfef95601890afd80709"
+  }
+}, {
+  "element": {
+"key": "state",
+"value": "da39a3ee5e6b4b0d3255bfef95601890afd80709"
+  }
+}, {
+  "element": {
+"key": "title",
+"value": "d08339b839a6716a96334736c1c769091a0a8644"
+  }
+}]
+  },
+  "user": {
+"list": [{
+  "element": {
+"key": "customerId",
+"value": "d5d4cd07616a542891b7ec2d0257b3a24b69856e"
+  }
+}, {
+  "element": {
+"key": "customerType",
+"value": "d5d4cd07616a542891b7ec2d0257b3a24b69856e"
+  }
+}, {
+  "element": {
+"key": "isAuthenticated",
+"value": "7cb6efb98ba5972a9b5090dc2e517fe14d12cb04"
+  }
+}]
+  }
+}]
diff --git a/sql/test/nested/Tests/webclicks.test 
b/sql/test/nested/Tests/webclicks.test
deleted file mode 100644
--- a/sql/test/nested/Tests/webclicks.test
+++ /dev/null
@@ -1,24 +0,0 @@
-statement ok
-create type kv as (key varchar, value varchar)
-
-statement ok
-create type elem as (element kv)
-
-statement ok
-create type webusr as (list elem[])
-
-statement ok
-create type loc as (list elem[])
-
-statement ok
-create type event as (eventid varchar, event varchar, timestamp timestamp, 
location loc, "user" webusr)
-
-statement ok
-create table events(events event)
-
-statement ok
-insert into events values (('111', 'click', '2024-11-30 22:13:37.823000', 
array[('hostname', 'localhost')], array[('user','niels')]))
-
-#statement ok
-#insert into events values (('111', 'click', '2024-11-30 22:13:37.823000', 
(array[(('hostname', 'localhost'))]), null))
-
diff --git a/sql/test/nested/Tests/webclicks.test.in 
b/sql/test/nested/Tests/webclicks.test.in
new file mode 100644
--- /dev/null
+++ b/sql/test/nested/Tests/webclicks.test.in
@@ -0,0 +1,41 @@
+statement ok
+create type kv as (key varchar, value varchar)
+
+statement ok
+create type elem as (element kv)
+
+statement ok
+create type webusr as (list elem[])
+
+statement ok
+create type loc as (list elem[])
+
+statement ok
+create type event as (eventid varchar, event varchar, timestamp timestamp, 
location loc, "user" webusr)
+
+statement ok
+create table events(events event)
+
+statement ok
+insert into events values (('111', 'click', '2024-11-30 22:13:37.823000', 
array[('hostname', 'localhost')], array[('user','niels')]))
+
+#statement ok
+#insert into events values (('111', 'click', '2024-11-30 22:13:37.823000', 
(array[(('hostname', 'localhost'))]), null))
+
+#load from file
+query T
+select cast(t.json as event) from (select json from 
r'$TSTSRCDIR/webclicks.json') t
+
+
+# clean up
+statement ok
+drop table events cascade
+
+statement ok
+drop type loc
+
+statement ok
+drop type webusr
+
+statement ok
+drop type event
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - fixed test

2025-02-07 Thread Niels Nes via checkin-list
Changeset: 358db122e345 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/358db122e345
Modified Files:
sql/test/nested/Tests/simple.test
Branch: nested
Log Message:

fixed test


diffs (28 lines):

diff --git a/sql/test/nested/Tests/simple.test 
b/sql/test/nested/Tests/simple.test
--- a/sql/test/nested/Tests/simple.test
+++ b/sql/test/nested/Tests/simple.test
@@ -140,20 +140,20 @@ statement ok
 create type ipair AS (pleft varchar, pright integer)
 
 query ITIII nosort
-select  cast(json '[ { "pleft": "left", "pright": "1" }]' as ipair[])
+select  cast(json '[ { "pleft": "left", "pright": 1 }]' as ipair[])
 
 1
 "left"
-2240802
+1
 1
 1
 
 query ITIII nosort
-select  cast(json '[ { "pleft": "left", "pright": "1" }, { "pleft": "l1", 
"pright": "2" }]' as ipair[])
+select  cast(json '[ { "pleft": "left", "pright": 1 }, { "pleft": "l1", 
"pright": "2" }]' as ipair[])
 
 1
 "left"
-2240802
+1
 1
 1
 
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - merge upstream

2025-02-07 Thread svetlin via checkin-list
Changeset: e2a1cfbff798 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/e2a1cfbff798
Modified Files:
sql/backends/monet5/sql.c
Branch: nested
Log Message:

merge upstream


diffs (truncated from 532 to 300 lines):

diff --git a/clients/Tests/MAL-signatures-hge.test 
b/clients/Tests/MAL-signatures-hge.test
--- a/clients/Tests/MAL-signatures-hge.test
+++ b/clients/Tests/MAL-signatures-hge.test
@@ -3729,6 +3729,11 @@ pattern bat.appendBulk(X_0:bat[:any_1], 
 CMDBATappend_bulk
 append the arguments ins to i
 bat
+appendBulk
+pattern bat.appendBulk(X_0:bat[:any_1], X_1:bit, X_2:bit, 
X_3:bat[:any_1]...):bat[:any_1]
+CMDBATappend_bulk
+append the arguments ins to i
+bat
 delete
 command bat.delete(X_0:bat[:any_1], X_1:oid):bat[:any_1]
 BKCdelete
@@ -49165,7 +49170,7 @@ SQLfrom_json
 Reads json string into table of nested/multiset structures
 sql
 from_varchar
-pattern sql.from_varchar(X_0:str, X_1:ptr):bat[:any]...
+pattern sql.from_varchar(X_0:bat?[:str], X_1:ptr):bat[:any]...
 SQLfrom_varchar
 Reads string into table of nested/multiset structures
 sql
diff --git a/clients/Tests/MAL-signatures.test 
b/clients/Tests/MAL-signatures.test
--- a/clients/Tests/MAL-signatures.test
+++ b/clients/Tests/MAL-signatures.test
@@ -3164,6 +3164,11 @@ pattern bat.appendBulk(X_0:bat[:any_1], 
 CMDBATappend_bulk
 append the arguments ins to i
 bat
+appendBulk
+pattern bat.appendBulk(X_0:bat[:any_1], X_1:bit, X_2:bit, 
X_3:bat[:any_1]...):bat[:any_1]
+CMDBATappend_bulk
+append the arguments ins to i
+bat
 delete
 command bat.delete(X_0:bat[:any_1], X_1:oid):bat[:any_1]
 BKCdelete
@@ -37605,7 +37610,7 @@ SQLfrom_json
 Reads json string into table of nested/multiset structures
 sql
 from_varchar
-pattern sql.from_varchar(X_0:str, X_1:ptr):bat[:any]...
+pattern sql.from_varchar(X_0:bat?[:str], X_1:ptr):bat[:any]...
 SQLfrom_varchar
 Reads string into table of nested/multiset structures
 sql
diff --git a/monetdb5/modules/mal/batExtensions.c 
b/monetdb5/modules/mal/batExtensions.c
--- a/monetdb5/modules/mal/batExtensions.c
+++ b/monetdb5/modules/mal/batExtensions.c
@@ -200,8 +200,14 @@ CMDBATappend_bulk(Client cntxt, MalBlkPt
bat *r = getArgReference_bat(stk, pci, 0),
*bid = getArgReference_bat(stk, pci, 1);
bit force = *getArgReference_bit(stk, pci, 2);
+   bit ms = false;
+   int argc = 3;
+   if (getArgType(mb, pci, argc) == TYPE_bit && getArgType(mb, pci, argc + 
1) != TYPE_bit) {
+   ms = *getArgReference_bit(stk, pci, argc);
+   argc++;
+   }
BAT *b;
-   BUN inputs = (BUN) (pci->argc - 3), number_existing = 0, total = 0;
+   BUN inputs = (BUN) (pci->argc - argc), number_existing = 0, total = 0;
 
(void) cntxt;
if ((b = BATdescriptor(*bid)) == NULL)
@@ -210,9 +216,32 @@ CMDBATappend_bulk(Client cntxt, MalBlkPt
if (inputs > 0) {
number_existing = BATcount(b);
 
-   if (isaBatType(getArgType(mb, pci, 3))) {   /* use 
BATappend for the bulk case */
+   if (isaBatType(getArgType(mb, pci, argc))) {/* use 
BATappend for the bulk case */
gdk_return rt;
-   for (int i = 3, args = pci->argc; i < args; i++) {
+   if (ms) {
+   int nr = -1;
+   for (int i = argc, args = pci->argc; i < args; 
i++) {
+   BAT *d = 
BATdescriptor(*getArgReference_bat(stk, pci, i));
+   if (!d) {
+   BBPunfix(b->batCacheid);
+   throw(MAL, "bat.append_bulk",
+   SQLSTATE(HY002) 
RUNTIME_OBJECT_MISSING);
+   }
+   if (i > argc) {
+   int *t = Tloc(d, 0);
+   for(BUN n = 0; n < BATcount(d); 
n++)
+   t[n] += nr;
+   }
+   rt = BATappend(b, d, NULL, force);
+   nr = *(int*)Tloc(b, BATcount(b)-1);
+   BBPunfix(d->batCacheid);
+   if (rt != GDK_SUCCEED) {
+   BBPunfix(b->batCacheid);
+   throw(MAL, "bat.append_bulk", 
GDK_EXCEPTION);
+   }
+   }
+   } else
+   for (int i = argc, args = pci->argc; i < args; i++) {
BAT *d = 
BATdescriptor(*getArgReference_bat(stk, pci, i));
if (!d) {
BBPu

MonetDB: nested - fix test

2025-02-07 Thread svetlin via checkin-list
Changeset: b49fb6e1b92c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b49fb6e1b92c
Modified Files:
sql/test/nested/Tests/All
Branch: nested
Log Message:

fix test


diffs (10 lines):

diff --git a/sql/test/nested/Tests/All b/sql/test/nested/Tests/All
--- a/sql/test/nested/Tests/All
+++ b/sql/test/nested/Tests/All
@@ -1,5 +1,5 @@
 simple
 basic
-json
+fileloader
 webclicks
 array
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - convert to underlaying type from json before i...

2025-02-07 Thread svetlin via checkin-list
Changeset: 3467d8919016 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/3467d8919016
Modified Files:
sql/backends/monet5/sql.c
Branch: nested
Log Message:

convert to underlaying type from json before inserting WIP


diffs (87 lines):

diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -5711,6 +5711,32 @@ insert_json(JSON *js, BAT *bats, int nr,
 static int insert_json_object(char **msg, JSON *js, BAT **bats, int nr, int 
elm, int id, int anr, sql_subtype *t);
 static int insert_json_array(char **msg, JSON *js, BAT **bats, int nr, int 
elm, int id, int oanr, sql_subtype *t);
 
+static ValPtr
+jsonv2local(const ValPtr t, char *v)
+{
+   // TODO add remaining types
+   switch (t->vtype) {
+   case TYPE_int:
+   t->val.ival = strtol(v, NULL, 10);
+   break;
+   case TYPE_lng:
+   t->val.lval = strtol(v, NULL, 10);
+   break;
+   case TYPE_flt:
+   t->val.fval = (flt) strtod(v, NULL);
+   break;
+   case TYPE_dbl:
+   t->val.dval = strtod(v, NULL);
+   break;
+   case TYPE_str:
+   t->val.sval = v;
+   break;
+   default:
+   return NULL;
+   }
+   return t;
+}
+
 static int
 insert_json_object(char **msg, JSON *js, BAT **bats, int nr, int elm, int id, 
int anr, sql_subtype *t)
 {
@@ -5745,28 +5771,30 @@ insert_json_object(char **msg, JSON *js,
case JSON_BOOL:
case JSON_NULL:
pos = -1;
+   ValPtr v = NULL;
+   if (jt->valuelen > 128-1)
+   return -8;
+   strncpy(buf, jt->value, jt->valuelen);
+   buf[jt->valuelen] = 0;
for(i = 0, n = t->type->d.fields->h; i < w && n && pos 
< 0; i++, n = n->next) {
sql_arg *a = n->data;
int alen = (int)strlen(a->name);
-   if (nlen == alen && strncmp(name, a->name, 
nlen) == 0)
+   if (nlen == alen && strncmp(name, a->name, 
nlen) == 0) {
pos = i;
+   ValRecord vr = (ValRecord) {.bat=false, 
.vtype=a->type.type->localtype};
+   v = jsonv2local(&vr, buf);
+   break;
+   }
}
-   char *v = buf;
-   if (pos < 0 || jt->valuelen > 128-1)
+   if (pos < 0 || v == NULL)
return -8;
-   strncpy(v, jt->value, jt->valuelen);
-   v[jt->valuelen] = 0;
-   /*
-* TODO check type of value
-* TODO insert value (not just strings)
-*/
-   if (elm > 0 && BUNappend(bats[pos], v, false) != 
GDK_SUCCEED) {
+   if (elm > 0 && BUNappend(bats[pos], VALget(v), false) 
!= GDK_SUCCEED) {
return -5;
}
}
}
 
-   if (elm > 0 && BUNappend(bats[w], &id, false) != GDK_SUCCEED)
+   if (t->multiset && elm > 0 && BUNappend(bats[w], &id, false) != 
GDK_SUCCEED)
elm = -3;
if (t->multiset == MS_ARRAY && elm > 0 && BUNappend(bats[w+1], &anr, 
false) != GDK_SUCCEED)
elm = -3;
@@ -5778,7 +5806,7 @@ insert_json_array(char **msg, JSON *js, 
 {
JSONterm *ja = js->elm+elm;
int tail = ja->tail;
-   if (ja->kind != JSON_ARRAY || !t->multiset) {
+   if (ja->kind != JSON_ARRAY) {
*msg = "missing array start";
return -1;
}
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - rename test

2025-02-07 Thread svetlin via checkin-list
Changeset: ce20980565e4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ce20980565e4
Added Files:
sql/test/nested/Tests/fileloader.test.in
Removed Files:
sql/test/nested/Tests/json.test.in
Branch: nested
Log Message:

rename test


diffs (36 lines):

diff --git a/sql/test/nested/Tests/fileloader.test.in 
b/sql/test/nested/Tests/fileloader.test.in
new file mode 100644
--- /dev/null
+++ b/sql/test/nested/Tests/fileloader.test.in
@@ -0,0 +1,13 @@
+statement ok
+create type event as (id int, type varchar)
+
+query TT
+select cast(t.json as event) from (select json from r'$TSTSRCDIR/events.json') 
t
+
+1
+"click"
+2
+"scroll"
+
+statement ok
+drop type event
diff --git a/sql/test/nested/Tests/json.test.in 
b/sql/test/nested/Tests/json.test.in
deleted file mode 100644
--- a/sql/test/nested/Tests/json.test.in
+++ /dev/null
@@ -1,13 +0,0 @@
-statement ok
-create type event as (id int, type varchar)
-
-query TT
-select cast(t.json as event) from (select json from r'$TSTSRCDIR/events.json') 
t
-
-49
-"click"
-50
-"scroll"
-
-statement ok
-drop type event
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - protect against virtual cols

2025-02-07 Thread Niels Nes via checkin-list
Changeset: 924377be0ef8 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/924377be0ef8
Modified Files:
sql/backends/monet5/rel_bin.c
sql/include/sql_relation.h
sql/server/rel_basetable.c
sql/server/rel_exp.c
Branch: nested
Log Message:

protect against virtual cols


diffs (71 lines):

diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -4926,11 +4926,11 @@ rel2bin_project(backend *be, sql_rel *re
return NULL;
for (en = rel->exps->h; en; en = en->next) {
sql_exp *exp = en->data;
-   /* we need to ouput composite properly, for insert statements
-   sql_subtype *st = exp_subtype(exp);
-   if (rel->l && st && st->type->composite)
+
+   if (exp->virt) {
+   /* we need to ouput composite properly, for insert 
statements */
continue;
-   */
+   }
int oldvtop = be->mb->vtop, oldstop = be->mb->stop;
stmt *s = exp_bin(be, exp, sub, NULL /*psub*/, NULL, NULL, 
NULL, NULL, 0, 0, 0);
 
diff --git a/sql/include/sql_relation.h b/sql/include/sql_relation.h
--- a/sql/include/sql_relation.h
+++ b/sql/include/sql_relation.h
@@ -33,7 +33,6 @@ typedef struct sql_alias {
int label;
struct sql_alias *parent;
const char *name;
-   //const char *rname;
 } sql_alias;
 
 typedef struct sql_var_name {
@@ -70,6 +69,7 @@ typedef struct expression {
 row:1, /* e_atom ->f is a list of values or a list of 
attributes aka a row/tuple */
 
 base:1,
+virt:1,
 ref:1, /* used to indicate an other expression may reference 
this one */
 used:1,/* used for quick dead code removal */
 symmetric:1; /* compare between symmetric */
diff --git a/sql/server/rel_basetable.c b/sql/server/rel_basetable.c
--- a/sql/server/rel_basetable.c
+++ b/sql/server/rel_basetable.c
@@ -383,6 +383,8 @@ bind_col_exp(mvc *sql, rel_base_t *ba, s
e->nid = -(ba->basenr + c->colnr);
e->alias.label = e->nid;
}
+   if (c->type.type->composite && !c->type.multiset)
+   e->virt = 1;
if (c->t->pkey && ((sql_kc*)c->t->pkey->k.columns->h->data)->c == c) {
p = e->p = prop_create(sql->sa, PROP_HASHCOL, e->p);
p->value.pval = c->t->pkey;
diff --git a/sql/server/rel_exp.c b/sql/server/rel_exp.c
--- a/sql/server/rel_exp.c
+++ b/sql/server/rel_exp.c
@@ -761,6 +761,8 @@ exp_propagate(allocator *sa, sql_exp *ne
set_unique(ne);
if (is_basecol(oe))
set_basecol(ne);
+   if (oe->virt)
+   ne->virt = 1;
ne->p = prop_copy(sa, oe->p);
return ne;
 }
@@ -790,6 +792,8 @@ exp_ref_by_label(allocator *sa, sql_exp 
set_unique(e);
if (is_intern(o))
set_intern(e);
+   if (o->virt)
+   e->virt = 1;
return exp_propagate(sa, e, o);
 }
 
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - Work on dumping complex types.

2025-02-07 Thread Sjoerd Mullender via checkin-list
Changeset: bd6de4362cd0 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/bd6de4362cd0
Modified Files:
clients/mapiclient/dump.c
Branch: nested
Log Message:

Work on dumping complex types.


diffs (truncated from 426 to 300 lines):

diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -491,6 +491,45 @@ bailout:
return false;
 }
 
+static bool
+has_multiset(Mapi mid)
+{
+   MapiHdl hdl;
+   bool ret;
+   static int answer = -1;
+
+   if (answer >= 0)
+   return answer;
+
+   if ((hdl = mapi_query(mid,
+ "select id from sys._columns"
+ " where table_id = 2076"
+ " and name = 'multiset'")) == 
NULL ||
+   mapi_error(mid))
+   goto bailout;
+   ret = mapi_get_row_count(hdl) == 1;
+   while ((mapi_fetch_row(hdl)) != 0) {
+   if (mapi_error(mid))
+   goto bailout;
+   }
+   if (mapi_error(mid))
+   goto bailout;
+   mapi_close_handle(hdl);
+   answer = ret;
+   return ret;
+
+bailout:
+   if (hdl) {
+   if (mapi_result_error(hdl))
+   mapi_explain_result(hdl, stderr);
+   else
+   mapi_explain_query(hdl, stderr);
+   mapi_close_handle(hdl);
+   } else
+   mapi_explain(mid, stderr);
+   return false;
+}
+
 static int
 dump_foreign_keys(Mapi mid, const char *schema, const char *tname, const char 
*tid, stream *sqlf)
 {
@@ -795,9 +834,12 @@ toUpper(const char *s)
size_t len = strlen(s);
 
if (len >= sizeof(toupperbuf))
-   return s;   /* too long: it's not *that* important */
-   for (i = 0; i < len; i++)
-   toupperbuf[i] = toupper((int)s[i]);
+   return NULL;/* too long */
+   for (i = 0; i < len; i++) {
+   if (s[i] & 0x80 || isupper(s[i]))
+   return NULL;/* not all ASCII lower case */
+   toupperbuf[i] = toupper(((unsigned char *) s)[i]);
+   }
toupperbuf[i] = '\0';
return toupperbuf;
 }
@@ -824,7 +866,7 @@ static const char *geomsubtypes[] = {
 };
 
 static int
-dump_type(Mapi mid, stream *sqlf, const char *c_type, const char 
*c_type_digits, const char *c_type_scale, bool hashge)
+dump_type(Mapi mid, stream *sqlf, const char *c_type, const char 
*c_type_digits, const char *c_type_scale, int c_multiset, bool hashge)
 {
int space = 0;
 
@@ -939,21 +981,29 @@ dump_type(Mapi mid, stream *sqlf, const 
} else {
mnstr_printf(sqlf, "GEOMETRY");
}
-   } else if (strcmp(c_type_digits, "0") == 0) {
-   space = mnstr_printf(sqlf, "%s", toUpper(c_type));
-   } else if (strcmp(c_type_scale, "0") == 0) {
-   space = mnstr_printf(sqlf, "%s(%s)",
-   toUpper(c_type), c_type_digits);
} else {
-   if (strcmp(c_type, "decimal") == 0) {
-   if (strcmp(c_type_digits, "39") == 0)
-   c_type_digits = "38";
-   else if (!hashge && strcmp(c_type_digits, "19") == 0)
-   c_type_digits = "18";
+   const char *s = toUpper(c_type);
+   if (s)
+   space = mnstr_printf(sqlf, "%s", s);
+   else
+   space = dquoted_print(sqlf, c_type, NULL);
+   if (strcmp(c_type_digits, "0") != 0) {
+   if (strcmp(c_type_scale, "0") == 0) {
+   space += mnstr_printf(sqlf, "(%s)", 
c_type_digits);
+   } else {
+   if (strcmp(c_type, "decimal") == 0) {
+   if (strcmp(c_type_digits, "39") == 0)
+   c_type_digits = "38";
+   else if (!hashge && 
strcmp(c_type_digits, "19") == 0)
+   c_type_digits = "18";
+   }
+   space += mnstr_printf(sqlf, "(%s,%s)",
+ 
c_type_digits, c_type_scale);
+   }
}
-   space = mnstr_printf(sqlf, "%s(%s,%s)",
-   toUpper(c_type), c_type_digits, c_type_scale);
}
+   if (c_multiset == 2)
+   space += mnstr_printf(sqlf, "[]");
return space;
 }
 
@@ -997,10 +1047,15 @@ dump_column_definition(Mapi mid, stream 
"c.type_digits, "   /* 2 */
"c.type_scale, "/* 3 

MonetDB: default - The realloc function does not necessarily ret...

2025-02-07 Thread Sjoerd Mullender via checkin-list
Changeset: 62ddf8c1f749 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/62ddf8c1f749
Modified Files:
clients/examples/C/testsfile.c
Branch: default
Log Message:

The realloc function does not necessarily return NULL when size is 0.


diffs (16 lines):

diff --git a/clients/examples/C/testsfile.c b/clients/examples/C/testsfile.c
--- a/clients/examples/C/testsfile.c
+++ b/clients/examples/C/testsfile.c
@@ -563,8 +563,11 @@ custom_allocator(void *state, void *old,
memset(old, '\0', cookie_size);
}
 
+   if (size == 0) {
+   free(old);
+   return NULL;
+   }
char *new_allocation = realloc(old, size > 0 ? size + prefix_size: 0);
-   assert(size > 0 || new_allocation == NULL);
 
if (new_allocation) {
// set magic cookie
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - merge with upstream

2025-02-07 Thread svetlin via checkin-list
Changeset: c05a8c21ff72 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/c05a8c21ff72
Branch: nested
Log Message:

merge with upstream


diffs (truncated from 497 to 300 lines):

diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -491,6 +491,45 @@ bailout:
return false;
 }
 
+static bool
+has_multiset(Mapi mid)
+{
+   MapiHdl hdl;
+   bool ret;
+   static int answer = -1;
+
+   if (answer >= 0)
+   return answer;
+
+   if ((hdl = mapi_query(mid,
+ "select id from sys._columns"
+ " where table_id = 2076"
+ " and name = 'multiset'")) == 
NULL ||
+   mapi_error(mid))
+   goto bailout;
+   ret = mapi_get_row_count(hdl) == 1;
+   while ((mapi_fetch_row(hdl)) != 0) {
+   if (mapi_error(mid))
+   goto bailout;
+   }
+   if (mapi_error(mid))
+   goto bailout;
+   mapi_close_handle(hdl);
+   answer = ret;
+   return ret;
+
+bailout:
+   if (hdl) {
+   if (mapi_result_error(hdl))
+   mapi_explain_result(hdl, stderr);
+   else
+   mapi_explain_query(hdl, stderr);
+   mapi_close_handle(hdl);
+   } else
+   mapi_explain(mid, stderr);
+   return false;
+}
+
 static int
 dump_foreign_keys(Mapi mid, const char *schema, const char *tname, const char 
*tid, stream *sqlf)
 {
@@ -795,9 +834,12 @@ toUpper(const char *s)
size_t len = strlen(s);
 
if (len >= sizeof(toupperbuf))
-   return s;   /* too long: it's not *that* important */
-   for (i = 0; i < len; i++)
-   toupperbuf[i] = toupper((int)s[i]);
+   return NULL;/* too long */
+   for (i = 0; i < len; i++) {
+   if (s[i] & 0x80 || isupper(s[i]))
+   return NULL;/* not all ASCII lower case */
+   toupperbuf[i] = toupper(((unsigned char *) s)[i]);
+   }
toupperbuf[i] = '\0';
return toupperbuf;
 }
@@ -824,7 +866,7 @@ static const char *geomsubtypes[] = {
 };
 
 static int
-dump_type(Mapi mid, stream *sqlf, const char *c_type, const char 
*c_type_digits, const char *c_type_scale, bool hashge)
+dump_type(Mapi mid, stream *sqlf, const char *c_type, const char 
*c_type_digits, const char *c_type_scale, int c_multiset, bool hashge)
 {
int space = 0;
 
@@ -939,21 +981,29 @@ dump_type(Mapi mid, stream *sqlf, const 
} else {
mnstr_printf(sqlf, "GEOMETRY");
}
-   } else if (strcmp(c_type_digits, "0") == 0) {
-   space = mnstr_printf(sqlf, "%s", toUpper(c_type));
-   } else if (strcmp(c_type_scale, "0") == 0) {
-   space = mnstr_printf(sqlf, "%s(%s)",
-   toUpper(c_type), c_type_digits);
} else {
-   if (strcmp(c_type, "decimal") == 0) {
-   if (strcmp(c_type_digits, "39") == 0)
-   c_type_digits = "38";
-   else if (!hashge && strcmp(c_type_digits, "19") == 0)
-   c_type_digits = "18";
+   const char *s = toUpper(c_type);
+   if (s)
+   space = mnstr_printf(sqlf, "%s", s);
+   else
+   space = dquoted_print(sqlf, c_type, NULL);
+   if (strcmp(c_type_digits, "0") != 0) {
+   if (strcmp(c_type_scale, "0") == 0) {
+   space += mnstr_printf(sqlf, "(%s)", 
c_type_digits);
+   } else {
+   if (strcmp(c_type, "decimal") == 0) {
+   if (strcmp(c_type_digits, "39") == 0)
+   c_type_digits = "38";
+   else if (!hashge && 
strcmp(c_type_digits, "19") == 0)
+   c_type_digits = "18";
+   }
+   space += mnstr_printf(sqlf, "(%s,%s)",
+ 
c_type_digits, c_type_scale);
+   }
}
-   space = mnstr_printf(sqlf, "%s(%s,%s)",
-   toUpper(c_type), c_type_digits, c_type_scale);
}
+   if (c_multiset == 2)
+   space += mnstr_printf(sqlf, "[]");
return space;
 }
 
@@ -997,10 +1047,15 @@ dump_column_definition(Mapi mid, stream 
"c.type_digits, "   /* 2 */
"c.type_scale, "/* 3 */
"c.\"null\", "  /*

MonetDB: nested - wip inserting nested json

2025-02-07 Thread svetlin via checkin-list
Changeset: f828e550 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/f828e550
Modified Files:
sql/backends/monet5/sql.c
Branch: nested
Log Message:

wip inserting nested json


diffs (136 lines):

diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -5708,8 +5708,8 @@ insert_json(JSON *js, BAT *bats, int nr,
 }
 #endif
 
-static int insert_json_object(char **msg, JSON *js, BAT **bats, int nr, int 
elm, int id, int anr, sql_subtype *t);
-static int insert_json_array(char **msg, JSON *js, BAT **bats, int nr, int 
elm, int id, int oanr, sql_subtype *t);
+static int insert_json_object(char **msg, JSON *js, BAT **bats, int 
bat_offset, int nr, int elm, int id, int anr, sql_subtype *t);
+static int insert_json_array(char **msg, JSON *js, BAT **bats, int bat_offset, 
int nr, int elm, int id, int oanr, sql_subtype *t);
 
 static ValPtr
 jsonv2local(const ValPtr t, char *v)
@@ -5738,7 +5738,7 @@ jsonv2local(const ValPtr t, char *v)
 }
 
 static int
-insert_json_object(char **msg, JSON *js, BAT **bats, int nr, int elm, int id, 
int anr, sql_subtype *t)
+insert_json_object(char **msg, JSON *js, BAT **bats, int bat_offset, int nr, 
int elm, int id, int anr, sql_subtype *t)
 {
char buf[128]; /* TODO use proper buffer */
node *n;
@@ -5750,16 +5750,38 @@ insert_json_object(char **msg, JSON *js,
const char *name = NULL;
int nlen = 0, pos = -1, w = list_length(t->type->d.fields), i = 0;
/* TODO check if full object is there */
-   for (elm++; elm >0 && elm <= jt->tail+1; elm++) {
+   for (elm++; elm > 0 && elm <= jt->tail+1; elm++) {
JSONterm *jt = js->elm+elm;
 
switch (jt->kind) {
case JSON_OBJECT:
-   elm = insert_json_object(msg, js, bats, nr, elm, id, 
anr, t);
+   if (name && nlen) {
+   // find subtype matching field
+   for(n = t->type->d.fields->h; n; n = n->next) {
+   sql_arg *a = n->data;
+   int alen = (int)strlen(a->name);
+   if (nlen == alen && strncmp(name, 
a->name, nlen) == 0) {
+   t = &a->type;
+   break;
+   }
+   }
+   }
+   elm = insert_json_object(msg, js, bats, bat_offset, nr, 
elm, id, anr, t);
break;
case JSON_ARRAY:
/* TODO get id for nested array from the a global 
struct */
-   elm = insert_json_array(msg, js, bats, nr, elm, id, 
anr, t);
+   if (name && nlen) {
+   // find subtype matching field
+   for(n = t->type->d.fields->h; n; n = n->next) {
+   sql_arg *a = n->data;
+   int alen = (int)strlen(a->name);
+   if (nlen == alen && strncmp(name, 
a->name, nlen) == 0) {
+   t = &a->type;
+   break;
+   }
+   }
+   }
+   elm = insert_json_array(msg, js, bats, bat_offset, nr, 
elm, id, anr, t);
break;
case JSON_ELEMENT: // field
name = jt->value;
@@ -5788,21 +5810,22 @@ insert_json_object(char **msg, JSON *js,
}
if (pos < 0 || v == NULL)
return -8;
-   if (elm > 0 && BUNappend(bats[pos], VALget(v), false) 
!= GDK_SUCCEED) {
+   if (elm > 0 && BUNappend(bats[bat_offset], VALget(v), 
false) != GDK_SUCCEED) {
return -5;
}
+   bat_offset ++;
}
}
 
-   if (t->multiset && elm > 0 && BUNappend(bats[w], &id, false) != 
GDK_SUCCEED)
+   if (t->multiset && elm > 0 && BUNappend(bats[w + bat_offset], &id, 
false) != GDK_SUCCEED)
elm = -3;
-   if (t->multiset == MS_ARRAY && elm > 0 && BUNappend(bats[w+1], &anr, 
false) != GDK_SUCCEED)
+   if (t->multiset == MS_ARRAY && elm > 0 && BUNappend(bats[w + 1 + 
bat_offset], &anr, false) != GDK_SUCCEED)
elm = -3;
return elm;
 }
 
 static int
-insert_json_array(char **msg, JSON *js, BAT **bats, int nr, int elm, int id, 
int oanr, sql_subtype *t)
+insert_json_array(char **msg, JSON *js, BAT **bats, int bat_offset, int nr, 
int elm, int id, int oanr, sql_subtype *t)
 {
JSONterm *ja = js->elm+