Changeset: 2cdba8f80381 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/2cdba8f80381 Added Files: monetdb5/modules/atoms/pg_jsonpath/postgres_defines_internal.h Modified Files: monetdb5/modules/atoms/json.c monetdb5/modules/atoms/pg_jsonpath/CMakeLists.txt monetdb5/modules/atoms/pg_jsonpath/jsonpath.c monetdb5/modules/atoms/pg_jsonpath/jsonpath.h monetdb5/modules/atoms/pg_jsonpath/jsonpath_gram.y monetdb5/modules/atoms/pg_jsonpath/jsonpath_internal.h monetdb5/modules/atoms/pg_jsonpath/jsonpath_scan.l monetdb5/modules/atoms/pg_jsonpath/postgres_defines.h Branch: json-extend Log Message:
jsonpath_gram is compiles diffs (truncated from 603 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 @@ -1636,6 +1636,8 @@ JSONfilterArrayDefault_hge(json *ret, co } #endif +#include "jsonpath.h" + static str JSONfilter(json *ret, const json *js, const char *const *expr) { @@ -1644,6 +1646,14 @@ JSONfilter(json *ret, const json *js, co throw(MAL, "json.filter", SQLSTATE(HY013) MAL_MALLOC_FAIL); return MAL_SUCCEED; } + + struct Node* escontext = init_escontext(); + if (!escontext) + throw(MAL, "json.filter", SQLSTATE(HY013) MAL_MALLOC_FAIL); + + JsonPathParseResult* result = parsejsonpath(*expr, strlen(*expr), escontext); + (void) result; + return JSONfilterInternal(ret, js, expr, 0); } diff --git a/monetdb5/modules/atoms/pg_jsonpath/CMakeLists.txt b/monetdb5/modules/atoms/pg_jsonpath/CMakeLists.txt --- a/monetdb5/modules/atoms/pg_jsonpath/CMakeLists.txt +++ b/monetdb5/modules/atoms/pg_jsonpath/CMakeLists.txt @@ -14,36 +14,49 @@ add_library(pg_jsonpath OBJECT) FLEX_TARGET(jsonpath_scanner jsonpath_scan.l - ${CMAKE_CURRENT_BINARY_DIR}/jsonpath_scan.tab.c - DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/jsonpath_scan.tab.h) + ${CMAKE_CURRENT_BINARY_DIR}/jsonpath_scan.c + DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/jsonpath_scan.h) BISON_TARGET(jsonpath_parser jsonpath_gram.y - ${CMAKE_CURRENT_BINARY_DIR}/jsonpath_parser.tab.c + ${CMAKE_CURRENT_BINARY_DIR}/jsonpath_gram.c COMPILE_FLAGS "-d -p json -Wno-conflicts-sr -Wno-conflicts-rr" - DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/jsonpath_parser.tab.h) + DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/jsonpath_gram.h) target_sources(pg_jsonpath PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/jsonpath.c - ${CMAKE_CURRENT_SOURCE_DIR}/jsonpath_internal.h + # ${CMAKE_CURRENT_SOURCE_DIR}/jsonpath.c + jsonpath_internal.h postgres_defines.h + postgres_defines_internal.h ${FLEX_jsonpath_scanner_OUTPUT_HEADER} - ${FLEX_jsonpath_scanner_OUTPUT_SOURCE} + ${FLEX_jsonpath_scanner_OUTPUTS} ${BISON_jsonpath_parser_OUTPUT_HEADER} ${BISON_jsonpath_parser_OUTPUT_SOURCE} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/jsonpath.h ) - target_link_libraries(pg_jsonpath +target_link_libraries(pg_jsonpath PRIVATE monetdb_config_header bat sqlinclude sqlcommon) - target_include_directories(pg_jsonpath +target_include_directories(pg_jsonpath PRIVATE $<TARGET_PROPERTY:sqlcommon,INTERFACE_INCLUDE_DIRECTORIES> + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:${INCLUDEDIR}/monetdb>) + + +target_compile_definitions(pg_jsonpath + PRIVATE + LIBMONETDB5) + +set_target_properties(pg_jsonpath + PROPERTIES + POSITION_INDEPENDENT_CODE ON) 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 @@ -1216,7 +1216,6 @@ jspGetBool(JsonPathItem *v) return (bool) *v->content.value.data; } -/* Numeric jspGetNumeric(JsonPathItem *v) { @@ -1224,7 +1223,6 @@ jspGetNumeric(JsonPathItem *v) return (Numeric) v->content.value.data; } -*/ char * jspGetString(JsonPathItem *v, int32 *len) @@ -1280,6 +1278,7 @@ static enum JsonPathDatatypeStatus jspIs * Function to check whether jsonpath expression is mutable to be used in the * planner function contain_mutable_functions(). */ +/* bool jspIsMutable(JsonPath *path, List *varnames, List *varexprs) { @@ -1297,7 +1296,7 @@ jspIsMutable(JsonPath *path, List *varna return cxt.mutable; } - +*/ /* * Recursive walker for jspIsMutable() */ 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 @@ -197,12 +197,12 @@ extern bool jspGetNext(JsonPathItem *v, extern void jspGetArg(JsonPathItem *v, JsonPathItem *a); extern void jspGetLeftArg(JsonPathItem *v, JsonPathItem *a); extern void jspGetRightArg(JsonPathItem *v, JsonPathItem *a); -// extern Numeric jspGetNumeric(JsonPathItem *v); +extern Numeric jspGetNumeric(JsonPathItem *v); extern bool jspGetBool(JsonPathItem *v); extern char *jspGetString(JsonPathItem *v, int32 *len); extern bool jspGetArraySubscript(JsonPathItem *v, JsonPathItem *from, JsonPathItem *to, int i); -extern bool jspIsMutable(JsonPath *path, List *varnames, List *varexprs); +// extern bool jspIsMutable(JsonPath *path, List *varnames, List *varexprs); extern const char *jspOperationName(JsonPathItemType type); @@ -257,7 +257,7 @@ struct JsonPathParseItem } like_regex; /* scalars */ - // Numeric numeric; + Numeric numeric; bool boolean; struct { @@ -273,12 +273,14 @@ typedef struct JsonPathParseResult bool lax; } JsonPathParseResult; +extern struct Node * init_escontext(); + extern JsonPathParseResult *parsejsonpath(const char *str, int len, struct Node *escontext); - +/* extern bool jspConvertRegexFlags(uint32 xflags, int *result, struct Node *escontext); - +*/ /* * Struct for details about external variables passed into jsonpath executor */ diff --git a/monetdb5/modules/atoms/pg_jsonpath/jsonpath_gram.y b/monetdb5/modules/atoms/pg_jsonpath/jsonpath_gram.y --- a/monetdb5/modules/atoms/pg_jsonpath/jsonpath_gram.y +++ b/monetdb5/modules/atoms/pg_jsonpath/jsonpath_gram.y @@ -15,6 +15,8 @@ */ +#include "jsonpath_internal.h" + static JsonPathParseItem *makeItemType(JsonPathItemType type); static JsonPathParseItem *makeItemString(JsonPathString *s); static JsonPathParseItem *makeItemVariable(JsonPathString *s); @@ -29,19 +31,21 @@ static JsonPathParseItem *makeItemUnary( static JsonPathParseItem *makeItemList(List *list); static JsonPathParseItem *makeIndexArray(List *list); static JsonPathParseItem *makeAny(int first, int last); +/* static bool makeItemLikeRegex(JsonPathParseItem *expr, JsonPathString *pattern, JsonPathString *flags, JsonPathParseItem ** result, struct Node *escontext); +*/ /* * Bison doesn't allocate anything that needs to live across parser calls, * so we can easily have it use palloc instead of malloc. This prevents * memory leaks if we error out during parsing. */ -#define YYMALLOC palloc -#define YYFREE pfree +#define YYMALLOC malloc +#define YYFREE free %} @@ -162,6 +166,7 @@ predicate: { $$ = makeItemUnary(jpiIsUnknown, $2); } | expr STARTS_P WITH_P starts_with_initial { $$ = makeItemBinary(jpiStartsWith, $1, $4); } +/* | expr LIKE_REGEX_P STRING_P { JsonPathParseItem *jppitem; @@ -176,6 +181,7 @@ predicate: YYABORT; $$ = jppitem; } +*/ ; starts_with_initial: @@ -428,6 +434,7 @@ makeItemKey(JsonPathString *s) static JsonPathParseItem * makeItemNumeric(JsonPathString *s) { + (void) s; // TODO JsonPathParseItem *v; v = makeItemType(jpiNumeric); @@ -543,12 +550,13 @@ makeAny(int first, int last) { JsonPathParseItem *v = makeItemType(jpiAny); - v->value.anybounds.first = (first >= 0) ? first : PG_UINT32_MAX; - v->value.anybounds.last = (last >= 0) ? last : PG_UINT32_MAX; + v->value.anybounds.first = (first >= 0) ? (uint32) first : PG_UINT32_MAX; + v->value.anybounds.last = (last >= 0) ? (uint32) last : PG_UINT32_MAX; return v; } +/* static bool makeItemLikeRegex(JsonPathParseItem *expr, JsonPathString *pattern, JsonPathString *flags, JsonPathParseItem ** result, @@ -561,8 +569,9 @@ makeItemLikeRegex(JsonPathParseItem *exp v->value.like_regex.expr = expr; v->value.like_regex.pattern = pattern->val; v->value.like_regex.patternlen = pattern->len; - +*/ /* Parse the flags string, convert to bitmask. Duplicate flags are OK. */ +/* v->value.like_regex.flags = 0; for (i = 0; flags && i < flags->len; i++) { @@ -592,12 +601,14 @@ makeItemLikeRegex(JsonPathParseItem *exp break; } } - +*/ /* Convert flags to what pg_regcomp needs */ +/* if ( !jspConvertRegexFlags(v->value.like_regex.flags, &cflags, escontext)) return false; - +*/ /* check regex validity */ +/* { regex_t re_tmp; pg_wchar *wpattern; @@ -627,21 +638,26 @@ makeItemLikeRegex(JsonPathParseItem *exp return true; } - +*/ /* * Convert from XQuery regex flags to those recognized by our regex library. */ +/* bool jspConvertRegexFlags(uint32 xflags, int *result, struct Node *escontext) { +*/ /* By default, XQuery is very nearly the same as Spencer's AREs */ +/* int cflags = REG_ADVANCED; - +*/ /* Ignore-case means the same thing, too, modulo locale issues */ +/* if (xflags & JSP_REGEX_ICASE) cflags |= REG_ICASE; - +*/ /* Per XQuery spec, if 'q' is specified then 'm', 's', 'x' are ignored */ +/* _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org