MonetDB: newjson - get json type from sys schema

2025-01-29 Thread Niels Nes via checkin-list
Changeset: 8f03835dad79 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/8f03835dad79
Modified Files:
sql/backends/monet5/vaults/json/json.c
Branch: newjson
Log Message:

get json type from sys schema


diffs (20 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
@@ -160,13 +160,13 @@ json_relation(mvc *sql, sql_subfunc *f, 
// use file name as columnn name ?
char *cname = sa_strdup(sql->sa, "json");
list_append(names, cname);
-   sql_schema *jsons = mvc_bind_schema(sql, "json");
+   sql_schema *jsons = mvc_bind_schema(sql, "sys");
if (!jsons)
return NULL;
-   sql_type *tpe = schema_bind_type(sql, jsons, "json");
sql_subtype *st = SA_NEW(sql->sa, sql_subtype);
-   st->type = tpe;
st->digits = st->scale = 0;
+   st->multiset = 0;
+   st->type = schema_bind_type(sql, jsons, "json");
list_append(types, st);
sql_exp *ne = exp_column(sql->sa, a_create(sql->sa, tname), cname, st, 
CARD_MULTI, 1, 0, 0);
set_basecol(ne);
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: const_aggr_elim - Combine const_aggr_elim optimizers in...

2025-01-29 Thread Wolf Schulz via checkin-list
Changeset: 297226fc5337 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/297226fc5337
Modified Files:
sql/server/rel_optimize_proj.c
Branch: const_aggr_elim
Log Message:

Combine const_aggr_elim optimizers into one


diffs (141 lines):

diff --git a/sql/server/rel_optimize_proj.c b/sql/server/rel_optimize_proj.c
--- a/sql/server/rel_optimize_proj.c
+++ b/sql/server/rel_optimize_proj.c
@@ -2501,23 +2501,51 @@ rel_distinct_aggregate_on_unique_values(
return rel;
 }
 
-// Triggers On...
-// select 1 having true;
-// select 42 from foo group by ();
-// select n from foo group by rollup(n);
-
-// Does this also trigger?
-// plan SELECT avg(a) FROM baz GROUP BY pass HAVING pass = 1439;
-
-// Expiriment with ROLL UP!
-
 static inline sql_rel *
 rel_remove_const_aggr(visitor *v, sql_rel *rel)
 {
-   if (!rel) {
+   if(!rel) {
+   return rel;
+   }
+
+   list *exps = rel->exps;
+
+   if(rel->op != op_groupby || list_empty(exps)) {
return rel;
}
-   if (rel && is_groupby(rel->op) && list_length(rel->exps) >= 1 && 
!rel_is_ref(rel)) {
+
+   if(!list_empty(rel->r)) {
+   for(node *n = exps->h; n; n = n->next) {
+   sql_exp *e = n->data;
+
+   if(e->type == e_aggr &&
+  !((sql_subfunc *)e->f)->func->s &&
+  strcmp(((sql_subfunc *)e->f)->func->base.name, 
"count") != 0 && 
+  ((sql_subfunc *)e->f)->func->system == 1
+   ) {
+   list *se = e->l;
+
+   for(node *m = se->h; m; m = m->next) {
+   sql_exp *w = m->data;
+
+   if(w->type == e_atom && w->card == 
CARD_ATOM) {
+   
exp_setalias(w,e->alias.label,e->alias.rname,e->alias.name);
+
+   n->data = w;
+   v->changes++;
+   }
+   }
+   }
+   }
+   }
+
+   /* 
+* Below code replaces GROUP BY with PROJECT in some cases;
+* Triggers on... 
+* select 1 having true; select 42 from foo group by x; select n from 
foo group by rollup(n);
+   */
+
+   if (!rel_is_ref(rel)) {
int needed = 0;
for (node *n = rel->exps->h; n; n = n->next) {
sql_exp *exp = (sql_exp*) n->data;
@@ -2600,6 +2628,7 @@ rel_remove_const_aggr(visitor *v, sql_re
return nrel;
}
}
+
return rel;
 }
 
@@ -3037,64 +3066,17 @@ rel_project_select_exp(visitor *v, sql_r
return rel;
 }
 
-static inline sql_rel *
-rel_const_aggr_elimination(visitor *v, sql_rel *rel)
-{
-   sql_rel *g = rel->l;
-   
-   if(rel->op != op_project || !g)
-   {
-   return rel;
-   }
-
-   list *exps = g->exps;
-
-   if(g->op != op_groupby || list_empty(exps) || list_empty(g->r))
-   {
-   return rel;
-   }
-
-   for(node *n = exps->h; n; n = n->next)
-   {
-   sql_exp *e = n->data;
-
-   if(e->type == e_aggr &&
-  !((sql_subfunc *)e->f)->func->s &&
-  strcmp(((sql_subfunc *)e->f)->func->base.name, "count") != 0 
&& 
-  ((sql_subfunc *)e->f)->func->system == 1
- )
-   {
-   list *se = e->l;
-
-   for(node *m = se->h; m; m = m->next)
-   {
-   sql_exp *w = m->data;
-
-   if(w->type == e_atom && w->card == CARD_ATOM)
-   {
-   
exp_setalias(w,e->alias.label,e->alias.rname,e->alias.name);
-
-   n->data = w;
-   v->changes++;
-   }
-   }
-   }
-   }
-
-   return rel;
-}
-
 static sql_rel *
 rel_optimize_projections_(visitor *v, sql_rel *rel)
 {
rel = rel_project_cse(v, rel);
rel = rel_project_select_exp(v, rel);
-   rel = rel_const_aggr_elimination(v, rel);
 
if (!rel || !is_groupby(rel->op))
return rel;
 
rel = rel_remove_const_aggr(v, rel);
+
if (v->value_based_opt) {
rel = rel_simplify_sum(v, rel);
rel = rel_simplify_groupby_columns(v, rel);
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: newjson - merge nested

2025-01-29 Thread svetlin via checkin-list
Changeset: a44844d922ae for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a44844d922ae
Branch: newjson
Log Message:

merge nested


diffs (truncated from 1339 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
@@ -49147,7 +49147,12 @@ sql
 from_json
 pattern sql.from_json(X_0:json, X_1:ptr):bat[:any]...
 SQLfrom_json
-Reads json string into table of nested structures
+Reads json string into table of nested/multiset structures
+sql
+from_varchar
+pattern sql.from_varchar(X_0:str, X_1:ptr):bat[:any]...
+SQLfrom_varchar
+Reads string into table of nested/multiset structures
 sql
 getVariable
 pattern sql.getVariable(X_0:int, X_1:str, X_2:str):any_1
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
@@ -37602,7 +37602,12 @@ sql
 from_json
 pattern sql.from_json(X_0:json, X_1:ptr):bat[:any]...
 SQLfrom_json
-Reads json string into table of nested structures
+Reads json string into table of nested/multiset structures
+sql
+from_varchar
+pattern sql.from_varchar(X_0:str, X_1:ptr):bat[:any]...
+SQLfrom_varchar
+Reads string into table of nested/multiset structures
 sql
 getVariable
 pattern sql.getVariable(X_0:int, X_1:str, X_2:str):any_1
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
@@ -791,6 +791,8 @@ str COPYrejects(Client cntxt, MalBlkPtr 
 str COPYrejects_clear(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
 str GRPgroup1(bat *ngid, bat *next, bat *nhis, const bat *bid);
 str GRPsubgroup5(bat *ngid, bat *next, bat *nhis, const bat *bid, const bat 
*sid, const bat *gid, const bat *eid, const bat *hid);
+void JSONfree(JSON *jt);
+JSON *JSONparse(const char *j);
 int MAL_MAXCLIENTS;
 int MALcommentsOnly(MalBlkPtr mb);
 lng MALdebug;
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
@@ -1045,7 +1045,6 @@ mvc_renumber_bulk(Client cntxt, MalBlkPt
/* if oi is dense, use offset based renumbers */
if (!bo->tsorted || !BATtkey(bo) || (bcnt && (oi[0] + (int)(bcnt-1)) != 
oi[bcnt-1]) ) {
BAT *lo = NULL;
-   printf("not dense %d\n", oi[0]);
if (BATleftjoin(&lo, NULL, bo, i, NULL, NULL, false, cnt) != 
GDK_SUCCEED) {
BBPreclaim(i);
BBPreclaim(bo);
@@ -5866,6 +5865,109 @@ bailout:
throw(SQL, "SQLfrom_json", SQLSTATE(HY013) MAL_MALLOC_FAIL);
 }
 
+#define skipspace(s) while(*s && isspace(*s)) s++;
+
+static str
+ARRAYparser(char *s, BAT **bats, int nr, int elm, int id, int oanr, 
sql_subtype *t)
+{
+   (void)bats;
+   (void)nr;
+   if (!s && s[0] != '{')
+   throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) "missing { at 
start of array value");
+   s++;
+   skipspace(s);
+   /* insert id */
+   (void)id;
+   (void)oanr;
+   elm++;
+   int oelm = elm;
+   while (*s && s[0] != '}') {
+   elm = oelm;
+   /* insert values */
+   if (t->type->composite) {
+   if (*s && s[0] != '(')
+   throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) 
"missing ( at start of composite value");
+   /* handle composite */
+   for (node *n = t->type->d.fields->h; n; n = n->next) {
+   //sql_arg *f = n->data;
+   elm++;
+   }
+   if (*s && s[0] != ')')
+   throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) 
"missing ( at end of composite value");
+   } else {
+   /* handle literals */
+   elm++;
+   }
+   /* insert msid */
+   elm++;
+   if (t->multiset == MS_ARRAY) {
+   /* insert msnr */
+   elm++;
+   }
+
+   skipspace(s);
+   /* handle optinal ',' */
+   if (*s && s[0] != ',')
+   break;
+   s++;
+   skipspace(s);
+   }
+   if (!s || s[0] != '}')
+   throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) "missing } at end 
of array value");
+   return MAL_SUCCEED;
+}
+
+static str
+SQLfrom_varchar(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+   (void)cntxt;
+   str msg = NULL;
+   int mtype = getArgType(mb, pci, pci->retc);
+
+   if (mtype != TYPE_str)
+   throw(SQL, "SQLfrom_varchar", SQLSTATE(HY013) "Incorrect 
argument type");
+   str s = *(str*)getArgReference(stk, pci, pci->retc);
+   sql

MonetDB: odbc_loader - Add ChangeLog.odbc_loader entries

2025-01-29 Thread Joeri van Ruth via checkin-list
Changeset: 3b8d72b9d149 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/3b8d72b9d149
Added Files:
clients/mapilib/ChangeLog.odbc_loader
sql/ChangeLog.odbc_loader
Branch: odbc_loader
Log Message:

Add ChangeLog.odbc_loader entries

Is this the right file name?

Maybe not all these changes need a changelog entry..


diffs (40 lines):

diff --git a/clients/mapilib/ChangeLog.odbc_loader 
b/clients/mapilib/ChangeLog.odbc_loader
new file mode 100644
--- /dev/null
+++ b/clients/mapilib/ChangeLog.odbc_loader
@@ -0,0 +1,19 @@
+# ChangeLog file for mapilib
+# This file is updated with Maddlog
+
+* Wed Jan 29 2025 Joeri van Ruth 
+- msettings can now be allocated with a custom memory allocator using
+  msettings_create_with() and msettings_clone_with().  This is used in
+  the SQL module to allocate them using the arena allocator.
+- The msettings objects no longer keep track of 'ignored' settings.
+  Function msetting_set_ignored has been removed.
+- Function msetting_as_string() has been changed to never return a newly
+  allocated string.  To make this possible the user now has to pass in
+  a small scratch buffer that will be used if the setting is a number.
+  (booleans and strings can use existing strings).
+- Functions msettings_parse_url() and msettings_validate() have been
+  modified to return any error message instead of setting it through a
+  pointer parameter.
+- Function msettings_write_url() has been added to render an msettings
+  object as a URL string.
+
diff --git a/sql/ChangeLog.odbc_loader b/sql/ChangeLog.odbc_loader
new file mode 100644
--- /dev/null
+++ b/sql/ChangeLog.odbc_loader
@@ -0,0 +1,11 @@
+# ChangeLog file for sql
+# This file is updated with Maddlog
+
+* Wed Jan 29 2025 Joeri van Ruth 
+- REMOTE TABLES and REPLICA TABLES now fully support the monetdb://
+  and monetdbs:// URL's introduced in Aug2024.
+  Any mapi:monetdb:// URL's are normalized to the new style.
+- Add function sa_msettings_create() to allocate an msettings object
+  using the arena allocator.
+- Unused helper function mapiuri_database() has been removed from
+  rel_remote.h.
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: const_aggr_elim - Exclude sum from optimizer const_aggr...

2025-01-29 Thread Wolf Schulz via checkin-list
Changeset: 650e0badca9e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/650e0badca9e
Modified Files:
sql/server/rel_optimize_proj.c
Branch: const_aggr_elim
Log Message:

Exclude sum from optimizer const_aggr_elim


diffs (11 lines):

diff --git a/sql/server/rel_optimize_proj.c b/sql/server/rel_optimize_proj.c
--- a/sql/server/rel_optimize_proj.c
+++ b/sql/server/rel_optimize_proj.c
@@ -2521,6 +2521,7 @@ rel_remove_const_aggr(visitor *v, sql_re
if(e->type == e_aggr &&
   !((sql_subfunc *)e->f)->func->s &&
   strcmp(((sql_subfunc *)e->f)->func->base.name, 
"count") != 0 && 
+  strcmp(((sql_subfunc *)e->f)->func->base.name, 
"sum") != 0 && 
   ((sql_subfunc *)e->f)->func->system == 1
) {
list *se = e->l;
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - get json type from sys schema

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

get json type from sys schema


diffs (82 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
@@ -5866,6 +5866,54 @@ bailout:
 }
 
 static str
+ARRAYparser(char *s, BAT **bats, int nr, int elm, int id, int oanr, 
sql_subtype *t)
+{
+   (void)bats;
+   (void)nr;
+   if (!s && s[0] != '{')
+   throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) "missing { at 
start of array value");
+   s++;
+   skipspace(s);
+   /* insert id */
+   elm++;
+   int oelm = elm;
+   while (*s && s[0] != '}') {
+   elm = oelm;
+   /* insert values */
+   if (t->type->composite) {
+   if (*s && s[0] != '(')
+   throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) 
"missing ( at start of composite value");
+   /* handle composite */
+   for (node *n = t->type->d.fields->h; n; n = n->next) {
+   //sql_arg *f = n->data;
+   elm++;
+   }
+   if (*s && s[0] != ')')
+   throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) 
"missing ( at end of composite value");
+   } else {
+   /* handle literals */
+   elm++;
+   }
+   /* insert msid */
+   elm++;
+   if (t->multiset == MS_ARRAY) {
+   /* insert msnr */
+   elm++;
+   }
+
+   skipspace(s);
+   /* handle optinal ',' */
+   if (*s && s[0] != ',')
+   break;
+   s++;
+   skipspace(s);
+   }
+   if (!s && s[0] != '}')
+   throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) "missing } at end 
of array value");
+   return MAL_SUCCEED;
+}
+
+static str
 SQLfrom_varchar(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
(void)cntxt;
@@ -5886,15 +5934,19 @@ SQLfrom_varchar(Client cntxt, MalBlkPtr 
goto bailout;
}
 
-   JSON *js = JSONparse(s); /* TODO: this should parse { 1, 2,3 } and { 
(1,"string"), (2,"str2") } */
-   if (!js) /* TODO output parser error ?? */
+   /*
+   JSON *js = JSONparse(s);
+   if (!js)
goto bailout;
 
if (t->multiset)
(void)insert_json_array(&msg, js, bats, pci->retc, 0, 1, 1, t);
-   else
-   (void)insert_json_object(&msg, js, bats, pci->retc, 0, 1, 1, t);
JSONfree(js);
+   */
+
+   assert(t->multiset);
+   /* this should parse { 1, 2,3 } and { (1,"string"), (2,"str2") } */
+   msg = ARRAYparser(s, bats, pci->retc, 0, 1, 1, t);
if (msg)
goto bailout;
for(int i = 0; i < pci->retc && bats[i]; i++) {
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - initial parsing of array value string

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

initial parsing of array value string


diffs (30 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
@@ -5865,6 +5865,8 @@ bailout:
throw(SQL, "SQLfrom_json", SQLSTATE(HY013) MAL_MALLOC_FAIL);
 }
 
+#define skipspace(s) while(*s && isspace(*s)) s++;
+
 static str
 ARRAYparser(char *s, BAT **bats, int nr, int elm, int id, int oanr, 
sql_subtype *t)
 {
@@ -5875,6 +5877,8 @@ ARRAYparser(char *s, BAT **bats, int nr,
s++;
skipspace(s);
/* insert id */
+   (void)id;
+   (void)oanr;
elm++;
int oelm = elm;
while (*s && s[0] != '}') {
@@ -5908,7 +5912,7 @@ ARRAYparser(char *s, BAT **bats, int nr,
s++;
skipspace(s);
}
-   if (!s && s[0] != '}')
+   if (!s || s[0] != '}')
throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) "missing } at end 
of array value");
return MAL_SUCCEED;
 }
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: newjson - check return of read

2025-01-29 Thread svetlin via checkin-list
Changeset: 185155d4fcfd for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/185155d4fcfd
Modified Files:
sql/backends/monet5/vaults/json/json.c
Branch: newjson
Log Message:

check return of read


diffs (14 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
@@ -80,7 +80,9 @@ read_json_file(JSONFileHandle *jfh)
size_t length = jfh->size;
content = sa_zalloc(jfh->sa, length + 1);
if (content) {
-   read(jfh->fd, content, length);
+   ssize_t nbytes = read(jfh->fd, content, length);
+   if (nbytes < 0)
+   return NULL;
content[length + 1] = '\0';
}
}
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - disallow constraints on composite and/or multi...

2025-01-29 Thread Niels Nes via checkin-list
Changeset: 58aba4fccc13 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/58aba4fccc13
Modified Files:
sql/server/rel_schema.c
sql/test/pg_regress/Tests/arrays.test
Branch: nested
Log Message:

disallow constraints on composite and/or multisets for now

some more array operations work now,ie approve output


diffs (44 lines):

diff --git a/sql/server/rel_schema.c b/sql/server/rel_schema.c
--- a/sql/server/rel_schema.c
+++ b/sql/server/rel_schema.c
@@ -435,6 +435,10 @@ column_constraint_type(sql_query *query,
mvc *sql = query->sql;
int res = SQL_ERR;
 
+   if (cs && (cs->type.multiset || cs->type.type->composite)) {
+   (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT: 
constraints on multisets or composite types are not supported");
+   return res;
+   }
if (isDeclared && (s->token != SQL_NULL && s->token != SQL_NOT_NULL)) {
(void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT: 
constraints on declared tables are not supported");
return res;
diff --git a/sql/test/pg_regress/Tests/arrays.test 
b/sql/test/pg_regress/Tests/arrays.test
--- a/sql/test/pg_regress/Tests/arrays.test
+++ b/sql/test/pg_regress/Tests/arrays.test
@@ -91,7 +91,7 @@ SELECT a[1:3],
   d[1:1][2:2]
FROM arrtest
 
-statement error
+statement ok
 CREATE TEMP TABLE arrtest2 (i integer ARRAY[4], f double[], n numeric[], t 
text[], d timestamp[])
 
 statement error
@@ -168,7 +168,7 @@ SELECT t.f[1][3][1] AS "131", t.f[2][2][
   SELECT 
ARRAY[[[111,112],[121,122],[131,132]],[[211,212],[221,122],[231,232]]] AS f
 ) AS t
 
-statement error
+statement ok
 SELECT ARRAY[['hello'],['world']]
 
 statement error
@@ -360,7 +360,7 @@ select '{
 statement error
 DROP TABLE arrtest
 
-statement error
+statement ok
 DROP TABLE arrtest2
 
 statement ok
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - add comment

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

add comment


diffs (12 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
@@ -5886,7 +5886,7 @@ SQLfrom_varchar(Client cntxt, MalBlkPtr 
goto bailout;
}
 
-   JSON *js = JSONparse(s);
+   JSON *js = JSONparse(s); /* TODO: this should parse { 1, 2,3 } and { 
(1,"string"), (2,"str2") } */
if (!js) /* TODO output parser error ?? */
goto bailout;
 
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: newjson - lookup json type in schema

2025-01-29 Thread Niels Nes via checkin-list
Changeset: 2b981e18da67 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/2b981e18da67
Modified Files:
sql/backends/monet5/vaults/json/json.c
sql/test/nested/Tests/json.test
Branch: newjson
Log Message:

lookup json type in schema


diffs (32 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
@@ -160,9 +160,15 @@ json_relation(mvc *sql, sql_subfunc *f, 
// use file name as columnn name ?
char *cname = sa_strdup(sql->sa, "json");
list_append(names, cname);
-   sql_subtype *tpe = sql_bind_subtype(sql->sa, "json", 0, 0);
-   list_append(types, tpe);
-   sql_exp *ne = exp_column(sql->sa, a_create(sql->sa, tname), cname, tpe, 
CARD_MULTI, 1, 0, 0);
+   sql_schema *jsons = mvc_bind_schema(sql, "json");
+   if (!jsons)
+   return NULL;
+   sql_type *tpe = schema_bind_type(sql, jsons, "json");
+   sql_subtype *st = SA_NEW(sql->sa, sql_subtype);
+   st->type = tpe;
+   st->digits = st->scale = 0;
+   list_append(types, st);
+   sql_exp *ne = exp_column(sql->sa, a_create(sql->sa, tname), cname, st, 
CARD_MULTI, 1, 0, 0);
set_basecol(ne);
ne->alias.label = -(sql->nid++);
list_append(res_exps, ne);
diff --git a/sql/test/nested/Tests/json.test b/sql/test/nested/Tests/json.test
--- a/sql/test/nested/Tests/json.test
+++ b/sql/test/nested/Tests/json.test
@@ -2,5 +2,5 @@ statement ok
 create type event as (id int, type varchar)
 
 query T
-select cast(t.josn as event) from (select json from r'$TSTTRGDIR/events.json') 
t
+select cast(t.json as event) from (select json from r'$TSTTRGDIR/events.json') 
t
 
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - support parsing {1,2,3} array values

2025-01-29 Thread Niels Nes via checkin-list
Changeset: ab0a7788091a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ab0a7788091a
Modified Files:
sql/backends/monet5/sql.c
sql/backends/monet5/sql_result.c
sql/backends/monet5/sql_result.h
sql/server/sql_scan.c
Branch: nested
Log Message:

support parsing {1,2,3} array values


diffs (truncated from 324 to 300 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
@@ -5821,8 +5821,13 @@ insert_json_array(char **msg, JSON *js, 
 static str
 SQLfrom_json(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
-   (void)cntxt;
str msg = NULL;
+   mvc *m = NULL;
+
+   if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL)
+   return msg;
+   if ((msg = checkSQLContext(cntxt)) != NULL)
+   return msg;
int mtype = getArgType(mb, pci, pci->retc);
 
if (strcmp(BATatoms[mtype].name, "json") != 0)
@@ -5838,6 +5843,7 @@ SQLfrom_json(Client cntxt, MalBlkPtr mb,
if (!bats[i])
goto bailout;
}
+   (void)m;
 
JSON *js = JSONparse(json);
if (!js) /* TODO output parser error ?? */
@@ -5865,65 +5871,18 @@ bailout:
throw(SQL, "SQLfrom_json", SQLSTATE(HY013) MAL_MALLOC_FAIL);
 }
 
-#define skipspace(s) while(*s && isspace(*s)) s++;
-
-static str
-ARRAYparser(char *s, BAT **bats, int nr, int elm, int id, int oanr, 
sql_subtype *t)
-{
-   (void)bats;
-   (void)nr;
-   if (!s && s[0] != '{')
-   throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) "missing { at 
start of array value");
-   s++;
-   skipspace(s);
-   /* insert id */
-   (void)id;
-   (void)oanr;
-   elm++;
-   int oelm = elm;
-   while (*s && s[0] != '}') {
-   elm = oelm;
-   /* insert values */
-   if (t->type->composite) {
-   if (*s && s[0] != '(')
-   throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) 
"missing ( at start of composite value");
-   /* handle composite */
-   for (node *n = t->type->d.fields->h; n; n = n->next) {
-   //sql_arg *f = n->data;
-   elm++;
-   }
-   if (*s && s[0] != ')')
-   throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) 
"missing ( at end of composite value");
-   } else {
-   /* handle literals */
-   elm++;
-   }
-   /* insert msid */
-   elm++;
-   if (t->multiset == MS_ARRAY) {
-   /* insert msnr */
-   elm++;
-   }
-
-   skipspace(s);
-   /* handle optinal ',' */
-   if (*s && s[0] != ',')
-   break;
-   s++;
-   skipspace(s);
-   }
-   if (!s || s[0] != '}')
-   throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) "missing } at end 
of array value");
-   return MAL_SUCCEED;
-}
-
 static str
 SQLfrom_varchar(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
-   (void)cntxt;
str msg = NULL;
+   mvc *m = NULL;
+
+   if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL)
+   return msg;
+   if ((msg = checkSQLContext(cntxt)) != NULL)
+   return msg;
+
int mtype = getArgType(mb, pci, pci->retc);
-
if (mtype != TYPE_str)
throw(SQL, "SQLfrom_varchar", SQLSTATE(HY013) "Incorrect 
argument type");
str s = *(str*)getArgReference(stk, pci, pci->retc);
@@ -5937,20 +5896,7 @@ SQLfrom_varchar(Client cntxt, MalBlkPtr 
if (!bats[i])
goto bailout;
}
-
-   /*
-   JSON *js = JSONparse(s);
-   if (!js)
-   goto bailout;
-
-   if (t->multiset)
-   (void)insert_json_array(&msg, js, bats, pci->retc, 0, 1, 1, t);
-   JSONfree(js);
-   */
-
-   assert(t->multiset);
-   /* this should parse { 1, 2,3 } and { (1,"string"), (2,"str2") } */
-   msg = ARRAYparser(s, bats, pci->retc, 0, 1, 1, t);
+   msg = mvc_from_string(m, bats, pci->retc, s, t);
if (msg)
goto bailout;
for(int i = 0; i < pci->retc && bats[i]; i++) {
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
@@ -302,8 +302,7 @@ bat_max_length(hge, hge)
 
 #define DEC_FRSTR(X)   
\
do {
\
-   sql_column *col = c->extra;

MonetDB: nested - properly set output types of result

2025-01-29 Thread Niels Nes via checkin-list
Changeset: 3d2fc4e012ef for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/3d2fc4e012ef
Modified Files:
sql/backends/monet5/sql_statement.c
Branch: nested
Log Message:

properly set output types of result


diffs (99 lines):

diff --git a/sql/backends/monet5/sql_statement.c 
b/sql/backends/monet5/sql_statement.c
--- a/sql/backends/monet5/sql_statement.c
+++ b/sql/backends/monet5/sql_statement.c
@@ -3960,28 +3960,39 @@ composite_type_resultsize(sql_subtype *t
 }
 
 static int
-composite_type_result(backend *be, InstrPtr q, sql_subtype *t)
+composite_type_result(backend *be, InstrPtr q, sql_subtype *t, sql_subtype 
*tps)
 {
+   int i = 0;
if (t->multiset || t->type->composite) {
-   if (t->multiset) /* id col : rowid */
+   if (t->multiset) { /* id col : rowid */
q = pushReturn(be->mb, q, newTmpVariable(be->mb, 
newBatType(TYPE_int)));
+   tps[i++] = *sql_bind_localtype("int");
+   }
if (t->type->composite) {
for (node *n = t->type->d.fields->h; n; n = n->next) {
sql_arg *a = n->data;
-   if (composite_type_result(be, q, &a->type) != 0)
+   int r = 0;
+   if ((r = composite_type_result(be, q, &a->type, 
tps+i)) < 0)
return -1;
+   i += r;
}
} else {
q = pushReturn(be->mb, q, newTmpVariable(be->mb, 
newBatType(t->type->localtype)));
+   tps[i++] = *t;
}
-   if (t->multiset) /* msid */
+   if (t->multiset) { /* msid */
q = pushReturn(be->mb, q, newTmpVariable(be->mb, 
newBatType(TYPE_int)));
-   if (t->multiset == MS_ARRAY) /* msnr */
+   tps[i++] = *sql_bind_localtype("int");
+   }
+   if (t->multiset == MS_ARRAY) { /* msnr */
q = pushReturn(be->mb, q, newTmpVariable(be->mb, 
newBatType(TYPE_int)));
+   tps[i++] = *sql_bind_localtype("int");
+   }
} else {
q = pushReturn(be->mb, q, newTmpVariable(be->mb, 
newBatType(t->type->localtype)));
+   tps[i++] = *t;
}
-   return 0;
+   return i;
 }
 
 static stmt *
@@ -3989,13 +4000,14 @@ stmt_from_json(backend *be, stmt *v, stm
 {
(void)sel;
int nrcols = composite_type_resultsize(t);
+   sql_subtype *tps = SA_NEW_ARRAY(be->mvc->sa, sql_subtype, nrcols);
 
InstrPtr q = newStmtArgs(be->mb, "sql", "from_json", nrcols + 2);
if (q == NULL)
goto bailout;
 
q->retc = q->argc = 0;
-   if (composite_type_result(be, q, t) != 0) {
+   if (composite_type_result(be, q, t, tps) < 0) {
freeInstruction(q);
goto bailout;
}
@@ -4023,7 +4035,7 @@ stmt_from_json(backend *be, stmt *v, stm
/* for each result create stmt_result and return stmt list */
list *r = sa_list(be->mvc->sa);
for(int i = 0; i < nrcols; i++)
-   append(r, stmt_result(be, s, i));
+   append(r, stmt_blackbox_result(be, s->q, i, tps+i));
return stmt_list(be, r);
 bailout:
if (be->mvc->sa->eb.enabled)
@@ -4036,13 +4048,14 @@ stmt_from_varchar(backend *be, stmt *v, 
 {
(void)sel;
int nrcols = composite_type_resultsize(t);
+   sql_subtype *tps = SA_NEW_ARRAY(be->mvc->sa, sql_subtype, nrcols);
 
InstrPtr q = newStmtArgs(be->mb, "sql", "from_varchar", nrcols + 2);
if (q == NULL)
goto bailout;
 
q->retc = q->argc = 0;
-   if (composite_type_result(be, q, t) != 0) {
+   if (composite_type_result(be, q, t, tps) < 0) {
freeInstruction(q);
goto bailout;
}
@@ -4070,7 +4083,7 @@ stmt_from_varchar(backend *be, stmt *v, 
/* for each result create stmt_result and return stmt list */
list *r = sa_list(be->mvc->sa);
for(int i = 0; i < nrcols; i++)
-   append(r, stmt_result(be, s, i));
+   append(r, stmt_blackbox_result(be, s->q, i, tps+i));
return stmt_list(be, r);
 bailout:
if (be->mvc->sa->eb.enabled)
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: odbc_loader - Add odbc_loader framework. WIP

2025-01-29 Thread Martin van Dinther via checkin-list
Changeset: 9de4266bd701 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9de4266bd701
Added Files:
sql/backends/monet5/vaults/odbc/CMakeLists.txt
sql/backends/monet5/vaults/odbc/odbc_loader.c
Modified Files:
sql/backends/monet5/vaults/CMakeLists.txt
Branch: odbc_loader
Log Message:

Add odbc_loader framework. WIP


diffs (294 lines):

diff --git a/sql/backends/monet5/vaults/CMakeLists.txt 
b/sql/backends/monet5/vaults/CMakeLists.txt
--- a/sql/backends/monet5/vaults/CMakeLists.txt
+++ b/sql/backends/monet5/vaults/CMakeLists.txt
@@ -15,4 +15,5 @@ add_subdirectory(netcdf)
 add_subdirectory(shp)
 add_subdirectory(csv)
 add_subdirectory(monetdb)
+add_subdirectory(odbc)
 
diff --git a/sql/backends/monet5/vaults/odbc/CMakeLists.txt 
b/sql/backends/monet5/vaults/odbc/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/vaults/odbc/CMakeLists.txt
@@ -0,0 +1,60 @@
+#[[
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0.  If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# Copyright 2024, 2025 MonetDB Foundation;
+# Copyright August 2008 - 2023 MonetDB B.V.;
+# Copyright 1997 - July 2008 CWI.
+#]]
+
+if(ODBC_FOUND)
+  add_library(odbc_loader MODULE)
+
+  target_sources(odbc_loader
+PRIVATE
+odbc_loader.c)
+
+  target_include_directories(odbc_loader
+PRIVATE
+$<$:${ODBC_INCLUDE_DIRS}>
+$
+$
+$
+$
+$
+$
+$
+$
+$)
+
+  target_link_libraries(odbc_loader
+PRIVATE
+monetdb_config_header
+bat
+monetdb5
+sqlinclude)
+
+  set_target_properties(odbc_loader
+PROPERTIES
+OUTPUT_NAME
+_odbc_loader)
+
+  target_compile_definitions(odbc_loader
+PRIVATE
+LIBODBC)
+
+  install(TARGETS
+odbc_loader
+DESTINATION ${CMAKE_INSTALL_LIBDIR}/monetdb5-${MONETDB_VERSION}
+COMPONENT server)
+
+  if(WIN32)
+install(FILES
+  $
+  DESTINATION ${CMAKE_INSTALL_LIBDIR}/monetdb5-${MONETDB_VERSION}
+  OPTIONAL)
+  endif()
+endif()
diff --git a/sql/backends/monet5/vaults/odbc/odbc_loader.c 
b/sql/backends/monet5/vaults/odbc/odbc_loader.c
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/vaults/odbc/odbc_loader.c
@@ -0,0 +1,215 @@
+/*
+ * SPDX-License-Identifier: MPL-2.0
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 2024, 2025 MonetDB Foundation;
+ * Copyright August 2008 - 2023 MonetDB B.V.;
+ * Copyright 1997 - July 2008 CWI.
+ */
+
+#include "monetdb_config.h"
+#include "rel_proto_loader.h"
+#include "rel_exp.h"
+
+//#ifdef _MSC_VER
+//#include 
+//#endif
+//#include 
+//#include 
+//#include 
+
+/ Define the ODBC Version our ODBC application complies with /
+#define ODBCVER 0x0352 /* Important: this must be defined before 
include of sql.h and sqlext.h */
+#include 
+#include 
+
+typedef struct odbc_loader_t {
+   char *url;
+   SQLCHAR *query;
+   SQLHANDLE env;
+   SQLHANDLE dbc;
+   SQLHANDLE stmt;
+   SQLSMALLINT nr_cols;
+} odbc_loader_t;
+
+static void
+odbc_cleanup(SQLHANDLE env, SQLHANDLE dbc, SQLHANDLE stmt) {
+   if (stmt != SQL_NULL_HSTMT) {
+   SQLFreeStmt(stmt, SQL_CLOSE);
+   SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+   }
+   if (dbc != SQL_NULL_HDBC) {
+   SQLDisconnect(dbc);
+   SQLFreeHandle(SQL_HANDLE_DBC, dbc);
+   }
+   if (env != SQL_NULL_HENV) {
+   SQLFreeHandle(SQL_HANDLE_ENV, env);
+   }
+}
+
+/*
+ * returns an error string (static or via tmp sa_allocator allocated), NULL on 
success
+ *
+ * Extend the subfunc f with result columns, ie.
+   f->res = typelist;
+   f->coltypes = typelist;
+   f->colnames = nameslist; use tname if passed, for the relation name
+ * Fill the list res_exps, with one result expressions per resulting column.
+ */
+static str
+odbc_relation(mvc *sql, sql_subfunc *f, char *url, list *res_exps, char *aname)
+{
+   (void) res_exps;
+   (void) aname;
+// list *typelist = sa_list(sql->sa);
+// list *nameslist = sa_list(sql->sa);
+
+   // TODO validate the url, should/could start with 'odbc:', if so
+   // remove 'odbc:' prefix from url so we get an ODBC connection string
+
+   SQLCHAR * con_str = (SQLCHAR *) url;
+   // TODO validate the ODBC connection string, should start with 'DSN=' 
or 'DRIVER='
+
+   // TODO get the SQL query string. Not from the url but from an 
additional provided parameter
+   // for test we use a static query:
+   SQLCHAR * query = (SQLCHAR *) "SELECT * FROM INFORMATION_SCHEMA.TABLES";
+
+   SQLHANDLE env = SQL_NULL_HENV;
+   SQLHANDLE dbc = SQL_NULL_HDBC;
+   SQLHANDLE stmt = SQL_NULL_HSTMT;
+ 

MonetDB: newjson - add test

2025-01-29 Thread svetlin via checkin-list
Changeset: 27d702eac140 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/27d702eac140
Added Files:
sql/test/nested/Tests/events.json
sql/test/nested/Tests/json.test
Modified Files:
sql/test/nested/Tests/All
Branch: newjson
Log Message:

add test


diffs (26 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,1 +1,2 @@
 simple
+json
diff --git a/sql/test/nested/Tests/events.json 
b/sql/test/nested/Tests/events.json
new file mode 100644
--- /dev/null
+++ b/sql/test/nested/Tests/events.json
@@ -0,0 +1,4 @@
+[
+{"id": 1, "type": "click"},
+{"id": 2, "type": "scroll"}
+]
diff --git a/sql/test/nested/Tests/json.test b/sql/test/nested/Tests/json.test
new file mode 100644
--- /dev/null
+++ b/sql/test/nested/Tests/json.test
@@ -0,0 +1,6 @@
+statement ok
+create type event as (id int, type varchar)
+
+query T
+select cast(t.josn as event) from (select json from r'$TSTTRGDIR/events.json') 
t
+
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: newjson - glob.h not available on Windows

2025-01-29 Thread svetlin via checkin-list
Changeset: c1084716bfe5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/c1084716bfe5
Modified Files:
sql/backends/monet5/vaults/json/json.c
Branch: newjson
Log Message:

glob.h not available on Windows


diffs (12 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
@@ -28,7 +28,7 @@
 #include "mutils.h"
 
 #include 
-#include 
+// #include  // not available on Windows
 
 
 typedef struct JSONFileHandle {
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: newjson - merge nested

2025-01-29 Thread svetlin via checkin-list
Changeset: ed2657a48ba5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ed2657a48ba5
Branch: newjson
Log Message:

merge nested


diffs (truncated from 324 to 300 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
@@ -5821,8 +5821,13 @@ insert_json_array(char **msg, JSON *js, 
 static str
 SQLfrom_json(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
-   (void)cntxt;
str msg = NULL;
+   mvc *m = NULL;
+
+   if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL)
+   return msg;
+   if ((msg = checkSQLContext(cntxt)) != NULL)
+   return msg;
int mtype = getArgType(mb, pci, pci->retc);
 
if (strcmp(BATatoms[mtype].name, "json") != 0)
@@ -5838,6 +5843,7 @@ SQLfrom_json(Client cntxt, MalBlkPtr mb,
if (!bats[i])
goto bailout;
}
+   (void)m;
 
JSON *js = JSONparse(json);
if (!js) /* TODO output parser error ?? */
@@ -5865,65 +5871,18 @@ bailout:
throw(SQL, "SQLfrom_json", SQLSTATE(HY013) MAL_MALLOC_FAIL);
 }
 
-#define skipspace(s) while(*s && isspace(*s)) s++;
-
-static str
-ARRAYparser(char *s, BAT **bats, int nr, int elm, int id, int oanr, 
sql_subtype *t)
-{
-   (void)bats;
-   (void)nr;
-   if (!s && s[0] != '{')
-   throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) "missing { at 
start of array value");
-   s++;
-   skipspace(s);
-   /* insert id */
-   (void)id;
-   (void)oanr;
-   elm++;
-   int oelm = elm;
-   while (*s && s[0] != '}') {
-   elm = oelm;
-   /* insert values */
-   if (t->type->composite) {
-   if (*s && s[0] != '(')
-   throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) 
"missing ( at start of composite value");
-   /* handle composite */
-   for (node *n = t->type->d.fields->h; n; n = n->next) {
-   //sql_arg *f = n->data;
-   elm++;
-   }
-   if (*s && s[0] != ')')
-   throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) 
"missing ( at end of composite value");
-   } else {
-   /* handle literals */
-   elm++;
-   }
-   /* insert msid */
-   elm++;
-   if (t->multiset == MS_ARRAY) {
-   /* insert msnr */
-   elm++;
-   }
-
-   skipspace(s);
-   /* handle optinal ',' */
-   if (*s && s[0] != ',')
-   break;
-   s++;
-   skipspace(s);
-   }
-   if (!s || s[0] != '}')
-   throw(SQL, "SQLfrom_varchar", SQLSTATE(42000) "missing } at end 
of array value");
-   return MAL_SUCCEED;
-}
-
 static str
 SQLfrom_varchar(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
-   (void)cntxt;
str msg = NULL;
+   mvc *m = NULL;
+
+   if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL)
+   return msg;
+   if ((msg = checkSQLContext(cntxt)) != NULL)
+   return msg;
+
int mtype = getArgType(mb, pci, pci->retc);
-
if (mtype != TYPE_str)
throw(SQL, "SQLfrom_varchar", SQLSTATE(HY013) "Incorrect 
argument type");
str s = *(str*)getArgReference(stk, pci, pci->retc);
@@ -5937,20 +5896,7 @@ SQLfrom_varchar(Client cntxt, MalBlkPtr 
if (!bats[i])
goto bailout;
}
-
-   /*
-   JSON *js = JSONparse(s);
-   if (!js)
-   goto bailout;
-
-   if (t->multiset)
-   (void)insert_json_array(&msg, js, bats, pci->retc, 0, 1, 1, t);
-   JSONfree(js);
-   */
-
-   assert(t->multiset);
-   /* this should parse { 1, 2,3 } and { (1,"string"), (2,"str2") } */
-   msg = ARRAYparser(s, bats, pci->retc, 0, 1, 1, t);
+   msg = mvc_from_string(m, bats, pci->retc, s, t);
if (msg)
goto bailout;
for(int i = 0; i < pci->retc && bats[i]; i++) {
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
@@ -302,8 +302,7 @@ bat_max_length(hge, hge)
 
 #define DEC_FRSTR(X)   
\
do {
\
-   sql_column *col = c->extra; 
\
-   sql_subtype *t = &col->type;

MonetDB: newjson - add cast and includes

2025-01-29 Thread Niels Nes via checkin-list
Changeset: 3edbc730324c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/3edbc730324c
Modified Files:
sql/backends/monet5/vaults/json/json.c
Branch: newjson
Log Message:

add cast and includes


diffs (32 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
@@ -27,6 +27,10 @@
 #include "json.h"
 #include "mutils.h"
 
+#ifdef HAVE_FCNTL_H
+#include 
+#endif
+
 #include 
 // #include  // not available on Windows
 
@@ -44,7 +48,7 @@ json_open(const char *fname, allocator *
 {
if (!sa)
return NULL;
-   int fd = open(fname, O_RDONLY);
+   int fd = MT_open(fname, O_RDONLY);
if (fd < 0){
// TODO add relevant trace component
TRC_ERROR(SQL_EXECUTION, "Error opening file %s", fname);
@@ -77,7 +81,7 @@ read_json_file(JSONFileHandle *jfh)
 {
char *content = NULL;
if (jfh) {
-   size_t length = jfh->size;
+   unsigned int length = (unsigned int)jfh->size;
content = sa_zalloc(jfh->sa, length + 1);
if (content) {
ssize_t nbytes = read(jfh->fd, content, length);
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: nested - escape %

2025-01-29 Thread Niels Nes via checkin-list
Changeset: 8d39ef725918 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/8d39ef725918
Modified Files:
sql/backends/monet5/sql_statement.c
Branch: nested
Log Message:

escape %


diffs (12 lines):

diff --git a/sql/backends/monet5/sql_statement.c 
b/sql/backends/monet5/sql_statement.c
--- a/sql/backends/monet5/sql_statement.c
+++ b/sql/backends/monet5/sql_statement.c
@@ -3296,7 +3296,7 @@ dump_header(mvc *sql, MalBlkPtr mb, list
stmt *c = n->data;
sql_subtype *t = tail_type(c);
if (t->multiset) { /* properly handle subtable */
-   printf("%multiset\n");
+   printf("%%multiset\n");
}
sql_alias *tname = table_name(sql->sa, c);
const char *_empty = "";
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: newjson - merged with nested

2025-01-29 Thread Niels Nes via checkin-list
Changeset: e754ee514618 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/e754ee514618
Branch: newjson
Log Message:

merged with nested


diffs (12 lines):

diff --git a/sql/backends/monet5/sql_statement.c 
b/sql/backends/monet5/sql_statement.c
--- a/sql/backends/monet5/sql_statement.c
+++ b/sql/backends/monet5/sql_statement.c
@@ -3296,7 +3296,7 @@ dump_header(mvc *sql, MalBlkPtr mb, list
stmt *c = n->data;
sql_subtype *t = tail_type(c);
if (t->multiset) { /* properly handle subtable */
-   printf("%multiset\n");
+   printf("%%multiset\n");
}
sql_alias *tname = table_name(sql->sa, c);
const char *_empty = "";
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org