Changeset: 9efa1bb87631 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/9efa1bb87631 Modified Files: monetdb5/modules/atoms/json.c monetdb5/modules/atoms/pg_jsonpath/jsonpath.h monetdb5/modules/atoms/pg_jsonpath/jsonpath_exec.c Branch: json-extend Log Message:
fix interface JsonPathQuery and use it diffs (82 lines): diff --git a/monetdb5/modules/atoms/json.c b/monetdb5/modules/atoms/json.c --- a/monetdb5/modules/atoms/json.c +++ b/monetdb5/modules/atoms/json.c @@ -1663,8 +1663,13 @@ JSONfilter(json *ret, const json *js, co yyjson_val *root = yyjson_doc_get_root(doc); bool empty; bool error; + List* vars = NULL; const char *column_name = NULL; - yyjson_val *res = JsonPathValue((Datum) root, path, &empty, &error, NULL, column_name); // TODO pass the result as yyjson document + // TODO pass the result as yyjson document + yyjson_val *res = JsonPathQuery((Datum) root, path, JSW_UNCONDITIONAL, &empty, &error, vars, column_name); + if (!res) + throw(MAL, "json.unfold", SQLSTATE(HY013) "JsonPathQuery error"); + char* tmp_res = yyjson_val_write(res, 0, NULL); // TODO use different allocation or doc write *ret = GDKstrdup(tmp_res); free(tmp_res); diff --git a/monetdb5/modules/atoms/pg_jsonpath/jsonpath.h b/monetdb5/modules/atoms/pg_jsonpath/jsonpath.h --- a/monetdb5/modules/atoms/pg_jsonpath/jsonpath.h +++ b/monetdb5/modules/atoms/pg_jsonpath/jsonpath.h @@ -198,7 +198,7 @@ typedef struct JsonPathVariable /* SQL/JSON query functions */ extern bool JsonPathExists(Datum jb, JsonPath *jp, bool *error, List *vars); -extern Datum JsonPathQuery(Datum jb, JsonPath *jp, JsonWrapper wrapper, +extern JsonbValue *JsonPathQuery(Datum jb, JsonPath *jp, JsonWrapper wrapper, bool *empty, bool *error, List *vars, const char *column_name); extern JsonbValue *JsonPathValue(Datum jb, JsonPath *jp, bool *empty, diff --git a/monetdb5/modules/atoms/pg_jsonpath/jsonpath_exec.c b/monetdb5/modules/atoms/pg_jsonpath/jsonpath_exec.c --- a/monetdb5/modules/atoms/pg_jsonpath/jsonpath_exec.c +++ b/monetdb5/modules/atoms/pg_jsonpath/jsonpath_exec.c @@ -2371,7 +2371,7 @@ JsonPathExists(Datum jb, JsonPath *jp, b * Returns NULL instead of throwing errors if 'error' is not NULL, setting * *error to true. *empty is set to true if no match is found. */ -Datum +JsonbValue * JsonPathQuery(Datum jb, JsonPath *jp, JsonWrapper wrapper, bool *empty, bool *error, List *vars, const char *column_name) @@ -2390,7 +2390,7 @@ JsonPathQuery(Datum jb, JsonPath *jp, Js { *error = true; *empty = false; - return (Datum) 0; + return NULL; } /* @@ -2428,7 +2428,7 @@ JsonPathQuery(Datum jb, JsonPath *jp, Js } if (wrap) - return (Datum) wrapItemsInArray(&found); // TODO track the yyjson_doc + return wrapItemsInArray(&found); // TODO track the yyjson_doc /* No wrapping means only one item is expected. */ if (count > 1) @@ -2436,7 +2436,7 @@ JsonPathQuery(Datum jb, JsonPath *jp, Js if (error) { *error = true; - return (Datum) 0; + return NULL; } if (column_name) @@ -2453,10 +2453,10 @@ JsonPathQuery(Datum jb, JsonPath *jp, Js } if (singleton) - return (Datum) singleton; // TODO track the yyjson_doc + return singleton; // TODO track the yyjson_doc *empty = true; - return (Datum) NULL; + return NULL; } /* _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org