Changeset: 5125f7ae04bf for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/5125f7ae04bf
Modified Files:
        monetdb5/modules/atoms/json.c
        monetdb5/modules/atoms/pg_jsonpath/jsonpath.c
        monetdb5/modules/atoms/pg_jsonpath/jsonpath.h
        monetdb5/modules/atoms/pg_jsonpath/jsonpath_exec.c
        monetdb5/modules/atoms/pg_jsonpath/jsonpath_scan.l
        monetdb5/modules/atoms/pg_jsonpath/postgres_defines.h
        monetdb5/modules/atoms/pg_jsonpath/postgres_defines_internal.h
        monetdb5/modules/atoms/pg_jsonpath/yyjson.c
        monetdb5/modules/atoms/pg_jsonpath/yyjson.h
Branch: json-extend
Log Message:

It lives... (yyjson/postgres mix compiles in our json module)


diffs (truncated from 5749 to 300 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
@@ -13,6 +13,11 @@
 /*
  * (c) 2013 Martin Kersten
  */
+#ifdef free
+#undef free
+#endif
+#include "yyjson.h"
+
 #include "monetdb_config.h"
 #include "gdk.h"
 #include "mal.h"
@@ -1636,6 +1641,7 @@ JSONfilterArrayDefault_hge(json *ret, co
 }
 #endif
 
+
 #include "jsonpath.h"
 
 static str
@@ -1651,10 +1657,19 @@ JSONfilter(json *ret, const json *js, co
        if (!escontext)
                throw(MAL, "json.filter", SQLSTATE(HY013) MAL_MALLOC_FAIL);
 
-       JsonPathParseResult* result = parsejsonpath(*expr, strlen(*expr), 
escontext);
-       (void) result;
+       JsonPathParseResult* path = parsejsonpath(*expr, strlen(*expr), 
escontext);
 
-       return JSONfilterInternal(ret, js, expr, 0);
+       yyjson_doc *doc = yyjson_read(*js, strlen(*js), 0);
+       yyjson_val *root = yyjson_doc_get_root(doc);
+       bool empty;
+       bool error;
+       const char *column_name = NULL;
+       yyjson_val *res = JsonPathValue((Datum) root, path, &empty, &error, 
NULL, column_name); // TODO pass the result as yyjson document
+       char* tmp_res = yyjson_val_write(res, 0, NULL); // TODO use different 
allocation or doc write
+       *ret = GDKstrdup(tmp_res);
+       free(tmp_res);
+       return MAL_SUCCEED;
+       // return JSONfilterInternal(ret, js, expr, 0);
 }
 
 // glue all values together with an optional separator
diff --git a/monetdb5/modules/atoms/pg_jsonpath/jsonpath.c 
b/monetdb5/modules/atoms/pg_jsonpath/jsonpath.c
--- a/monetdb5/modules/atoms/pg_jsonpath/jsonpath.c
+++ b/monetdb5/modules/atoms/pg_jsonpath/jsonpath.c
@@ -62,784 +62,7 @@
  */
 
 #include "jsonpath.h"
-
-
-static Datum jsonPathFromCstring(char *in, int len, struct Node *escontext);
-static char *jsonPathToCstring(StringInfo out, JsonPath *in,
-                                                          int estimated_len);
-static bool flattenJsonPathParseItem(StringInfo buf, int *result,
-                                                                        struct 
Node *escontext,
-                                                                        
JsonPathParseItem *item,
-                                                                        int 
nestingLevel, bool insideArraySubscript);
-static void alignStringInfoInt(StringInfo buf);
-static int32 reserveSpaceForItemPointer(StringInfo buf);
-static void printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
-                                                         bool printBracketes);
-static int     operationPriority(JsonPathItemType op);
-
-
-/**************************** INPUT/OUTPUT ********************************/
-
-/*
- * jsonpath type input function
- */
-/*
-Datum
-jsonpath_in(PG_FUNCTION_ARGS)
-{
-       char       *in = PG_GETARG_CSTRING(0);
-       int                     len = strlen(in);
-
-       return jsonPathFromCstring(in, len, fcinfo->context);
-}
-*/
-
-/*
- * jsonpath type recv function
- *
- * The type is sent as text in binary mode, so this is almost the same
- * as the input function, but it's prefixed with a version number so we
- * can change the binary format sent in future if necessary. For now,
- * only version 1 is supported.
- */
-/*
-Datum
-jsonpath_recv(PG_FUNCTION_ARGS)
-{
-       StringInfo      buf = (StringInfo) PG_GETARG_POINTER(0);
-       int                     version = pq_getmsgint(buf, 1);
-       char       *str;
-       int                     nbytes;
-
-       if (version == JSONPATH_VERSION)
-               str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
-       else
-               elog(ERROR, "unsupported jsonpath version number: %d", version);
-
-       return jsonPathFromCstring(str, nbytes, NULL);
-}
-*/
-
-/*
- * jsonpath type output function
- */
-/*
-Datum
-jsonpath_out(PG_FUNCTION_ARGS)
-{
-       JsonPath   *in = PG_GETARG_JSONPATH_P(0);
-
-       PG_RETURN_CSTRING(jsonPathToCstring(NULL, in, VARSIZE(in)));
-}
-*/
-
-/*
- * jsonpath type send function
- *
- * Just send jsonpath as a version number, then a string of text
- */
-/*
-Datum
-jsonpath_send(PG_FUNCTION_ARGS)
-{
-       JsonPath   *in = PG_GETARG_JSONPATH_P(0);
-       StringInfoData buf;
-       StringInfoData jtext;
-       int                     version = JSONPATH_VERSION;
-
-       initStringInfo(&jtext);
-       (void) jsonPathToCstring(&jtext, in, VARSIZE(in));
-
-       pq_begintypsend(&buf);
-       pq_sendint8(&buf, version);
-       pq_sendtext(&buf, jtext.data, jtext.len);
-       pfree(jtext.data);
-
-       PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
-}
-*/
-
-/*
- * Converts C-string to a jsonpath value.
- *
- * Uses jsonpath parser to turn string into an AST, then
- * flattenJsonPathParseItem() does second pass turning AST into binary
- * representation of jsonpath.
- */
-/*
-static Datum
-jsonPathFromCstring(char *in, int len, struct Node *escontext)
-{
-       JsonPathParseResult *jsonpath = parsejsonpath(in, len, escontext);
-       JsonPath   *res;
-       StringInfoData buf;
-
-       if (SOFT_ERROR_OCCURRED(escontext))
-               return (Datum) 0;
-
-       if (!jsonpath)
-               return TODO_ERROR;
-               ereturn(escontext, (Datum) 0,
-                               (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
-                                errmsg("invalid input syntax for type %s: 
\"%s\"", "jsonpath",
-                                               in)));
-
-       initStringInfo(&buf);
-       enlargeStringInfo(&buf, 4 * len );
-
-       appendStringInfoSpaces(&buf, JSONPATH_HDRSZ);
-
-       if (!flattenJsonPathParseItem(&buf, NULL, escontext,
-                                                                 
jsonpath->expr, 0, false))
-               return (Datum) 0;
-
-       res = (JsonPath *) buf.data;
-       SET_VARSIZE(res, buf.len);
-       res->header = JSONPATH_VERSION;
-       if (jsonpath->lax)
-               res->header |= JSONPATH_LAX;
-
-       PG_RETURN_JSONPATH_P(res);
-}
-*/
-
-/*
- * Converts jsonpath value to a C-string.
- *
- * If 'out' argument is non-null, the resulting C-string is stored inside the
- * StringBuffer.  The resulting string is always returned.
- */
-/*
-static char *
-jsonPathToCstring(StringInfo out, JsonPath *in, int estimated_len)
-{
-       StringInfoData buf;
-       JsonPathItem v;
-
-       if (!out)
-       {
-               out = &buf;
-               initStringInfo(out);
-       }
-       enlargeStringInfo(out, estimated_len);
-
-       if (!(in->header & JSONPATH_LAX))
-               appendStringInfoString(out, "strict ");
-
-       jspInit(&v, in);
-       printJsonPathItem(out, &v, false, true);
-
-       return out->data;
-}
-*/
-
-/*
- * Recursive function converting given jsonpath parse item and all its
- * children into a binary representation.
- */
-static bool
-flattenJsonPathParseItem(StringInfo buf, int *result, struct Node *escontext,
-                                                JsonPathParseItem *item, int 
nestingLevel,
-                                                bool insideArraySubscript)
-{
-       /* position from beginning of jsonpath data */
-       int32           pos = buf->len - JSONPATH_HDRSZ;
-       int32           chld;
-       int32           next;
-       int                     argNestingLevel = 0;
-
-       check_stack_depth();
-       CHECK_FOR_INTERRUPTS();
-
-       appendStringInfoChar(buf, (char) (item->type));
-
-       /*
-        * We align buffer to int32 because a series of int32 values often goes
-        * after the header, and we want to read them directly by dereferencing
-        * int32 pointer (see jspInitByBuffer()).
-        */
-       alignStringInfoInt(buf);
-
-       /*
-        * Reserve space for next item pointer.  Actual value will be recorded
-        * later, after next and children items processing.
-        */
-       next = reserveSpaceForItemPointer(buf);
-
-       switch (item->type)
-       {
-               case jpiString:
-               case jpiVariable:
-               case jpiKey:
-                       appendBinaryStringInfo(buf, &item->value.string.len,
-                                                                  
sizeof(item->value.string.len));
-                       appendBinaryStringInfo(buf, item->value.string.val,
-                                                                  
item->value.string.len);
-                       appendStringInfoChar(buf, '\0');
-                       break;
-               case jpiNumeric:
-                       appendBinaryStringInfo(buf, item->value.numeric,
-                                                                  
VARSIZE(item->value.numeric));
-                       break;
-               case jpiBool:
-                       appendBinaryStringInfo(buf, &item->value.boolean,
-                                                                  
sizeof(item->value.boolean));
-                       break;
-               case jpiAnd:
-               case jpiOr:
-               case jpiEqual:
-               case jpiNotEqual:
-               case jpiLess:
-               case jpiGreater:
-               case jpiLessOrEqual:
-               case jpiGreaterOrEqual:
-               case jpiAdd:
-               case jpiSub:
-               case jpiMul:
-               case jpiDiv:
-               case jpiMod:
-               case jpiStartsWith:
-               case jpiDecimal:
-                       {
-                               /*
-                                * First, reserve place for left/right arg's 
positions, then
-                                * record both args and sets actual position in 
reserved
-                                * places.
-                                */
-                               int32           left = 
reserveSpaceForItemPointer(buf);
-                               int32           right = 
reserveSpaceForItemPointer(buf);
-
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to