Skip to content

All array element accessors require non-array items to be wrapped #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 74 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
3ceda3b
Add SQL/JSON SQLSTATE errcodes
Feb 16, 2017
b7bf33f
Initial jsonpath support
feodor Feb 22, 2017
d3cd3af
add array indexes to jsonpath
feodor Feb 22, 2017
9b78542
Add passing params to jsonpath
feodor Feb 22, 2017
9bc56ec
Fix jsonpath grammar: add support for $[*]
Feb 25, 2017
1aad789
Add jsonb-typed variables support to jsonpath
Feb 25, 2017
d86181e
fix list of special characters in jsonpath
feodor Feb 27, 2017
b574c58
implement **{} path opt in jsonpath
feodor Feb 27, 2017
47ef89a
Fix jsonpath grammar: add multiple filters support, expressions, comp…
Feb 27, 2017
c2c38d4
Use == instead of =
feodor Feb 27, 2017
07f0f51
Add jsonpath IS UNKNOWN predicate
Feb 27, 2017
a3e88ef
implement jsonpath EXISTS clause
feodor Feb 27, 2017
d0d8198
Fix jsonpath ternary logic
Feb 27, 2017
4cbe9d6
Introduce struct JsonPathExecContext
Feb 27, 2017
983be66
Add jsonpath binary arithmetic expression evaluation
Feb 28, 2017
573da88
improve tests
feodor Feb 28, 2017
f5ae4e5
fix support () in jsonpath expression
feodor Feb 28, 2017
9e05e3f
correct work of unnary plus/minus
feodor Feb 28, 2017
70a8776
Fix unary arithmetic jsonpath expressions
Feb 28, 2017
cdf207b
make beauty
feodor Feb 28, 2017
37a7122
add header for jsonpath type
feodor Feb 28, 2017
1120c2a
completely remove anon union in jsonpath
feodor Feb 28, 2017
c927339
make beauty
feodor Feb 28, 2017
38edfd6
Add STRICT/LAX jsonpath mode
Feb 28, 2017
b2f398c
Add jsonpath item methods
Mar 6, 2017
2a225eb
Use JsonContainerXxx() macros instead of raw jsonb flags
Mar 6, 2017
811284e
Allow jsonpath scalars to be a part of path
Mar 7, 2017
dee12a9
Implement jsonpath unary operations output
Mar 7, 2017
6799ba5
Add jsonpath array index expressions
Mar 7, 2017
68fe2aa
Add jsonpath last subscript
Mar 7, 2017
928c0f7
Add jsonpath STARTS WITH predicate
Mar 9, 2017
69b54ed
Add jsonpath LIKE_REGEX predicate
Sep 6, 2017
f53d202
Add TZH and TZM timezone format fields for to_timestamp()
Mar 10, 2017
75deccf
Add jbvDatetime JsonbValue type
Mar 10, 2017
b7aa7ee
Add .datetime() jsonpath item method
Mar 10, 2017
abd1289
Allow jsonpath parenthized expressions to be a base part of a path
Mar 22, 2017
2ba7d47
Allow jsonpath $ everywhere
Mar 27, 2017
529b3cc
Refactor jsonpath items appending to the resulting list
Mar 27, 2017
06c0870
Introduce JsonValueList for jsonpath
Mar 30, 2017
7bd4357
Mark some jsonpath functions as inline
Mar 31, 2017
f4c1667
Add jsonpath JsonbInitBinary()
Mar 31, 2017
24b5707
Add jsonpath JsonbWrapInBinary()
Mar 31, 2017
aa33c9c
Add jsonpath support for JsonbValue objects and arrays
Mar 31, 2017
008d948
Extract recursiveExecuteUnwrapArray()
Mar 31, 2017
62dc266
Add boolean jsonpath expressions
Mar 31, 2017
aa01256
Add _jsonpath_predicate()
Mar 31, 2017
0d86152
Add jsonpath operators @*, @?, @~
May 11, 2017
f294c37
Remove _ prefix in jsonpath function names
Oct 2, 2017
23f74ae
Add jsonpath @? support to GIN json_ops and jsonb_path_ops
May 23, 2017
392bad7
Add jsonpath support for json type
Aug 16, 2017
f16754b
Add jsonpath datetime() extension: UNIX epoch time to timestamptz
Mar 22, 2017
118b562
Add jsonpath .map() item method
Apr 4, 2017
952b2be
Add jsonpath sequences
Apr 5, 2017
ef9b60a
Add jsonpath array constructors
Apr 6, 2017
4dc4b35
Add jsonpath object constructors
Apr 6, 2017
a28f313
Add jsonpath .reduce() and .fold() item methods
Apr 10, 2017
6efb195
Add jsonpath .min() and .max() item methods
May 3, 2017
63113dc
Add jsonpath object subscripting
May 11, 2017
e623880
Add json tests for jsonpath extensions
Aug 16, 2017
ec36501
Add SQL/JSON parsing
Feb 10, 2017
db0fe79
Add JSON_OBJECT() transformation
Feb 11, 2017
ff85a1c
Add JSON_ARRAY() transformation
Feb 13, 2017
8b57ebb
Add JSON_OBJECTAGG() and JSON_ARRAYAGG() transformation
Feb 13, 2017
65d63bc
Add JSON_ARRAY(subquery) transformation
Feb 13, 2017
a0d144d
Add IS JSON predicate transformation
Feb 15, 2017
6308c1e
Add JSON_VALUE, JSON_EXISTS, JSON_QUERY
Feb 15, 2017
4b2f674
Add JSON_OBJECT() transformation
Feb 11, 2017
e282236
Optimize and fix JSON item coercion to target type in JSON_VALUE
May 5, 2017
32be627
Add JSON_OBJECT() transformation
Feb 11, 2017
a4cba96
Add JSON_QUERY support for row, array and domain types
May 11, 2017
3687882
Add json support for JSON_EXISTS, JSON_VALUE, JSON_QUERY
Aug 16, 2017
c4d4c8f
Add JSON_TABLE
Jul 24, 2017
15b0e2c
Add json support for JSON_TABLE
Aug 16, 2017
8d6f1b0
All array element accessors require non-array items to be wrapped
Nov 5, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions contrib/pg_stat_statements/pg_stat_statements.c
Original file line number Diff line number Diff line change
Expand Up @@ -2805,6 +2805,17 @@ JumbleExpr(pgssJumbleState *jstate, Node *node)
JumbleExpr(jstate, (Node *) conf->exclRelTlist);
}
break;
case T_JsonExpr:
{
JsonExpr *jexpr = (JsonExpr *) node;

APP_JUMB(jexpr->op);
JumbleExpr(jstate, jexpr->raw_expr);
JumbleExpr(jstate, (Node *) jexpr->passing.values);
JumbleExpr(jstate, jexpr->on_empty.default_expr);
JumbleExpr(jstate, jexpr->on_error.default_expr);
}
break;
case T_List:
foreach(temp, (List *) node)
{
Expand Down Expand Up @@ -2876,9 +2887,11 @@ JumbleExpr(pgssJumbleState *jstate, Node *node)
{
TableFunc *tablefunc = (TableFunc *) node;

APP_JUMB(tablefunc->functype);
JumbleExpr(jstate, tablefunc->docexpr);
JumbleExpr(jstate, tablefunc->rowexpr);
JumbleExpr(jstate, (Node *) tablefunc->colexprs);
JumbleExpr(jstate, (Node *) tablefunc->colvalexprs);
}
break;
case T_TableSampleClause:
Expand Down
13 changes: 12 additions & 1 deletion src/backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl storage/lmgr/lw
utils/errcodes.h: utils/generate-errcodes.pl utils/errcodes.txt
$(MAKE) -C utils errcodes.h

utils/adt/jsonpath_gram.h: utils/adt/jsonpath_gram.y
$(MAKE) -C utils/adt jsonpath_gram.h

# see explanation in parser/Makefile
utils/fmgrprotos.h: utils/fmgroids.h ;

Expand Down Expand Up @@ -169,7 +172,7 @@ submake-schemapg:

.PHONY: generated-headers

generated-headers: $(top_builddir)/src/include/parser/gram.h $(top_builddir)/src/include/catalog/schemapg.h $(top_builddir)/src/include/storage/lwlocknames.h $(top_builddir)/src/include/utils/errcodes.h $(top_builddir)/src/include/utils/fmgroids.h $(top_builddir)/src/include/utils/fmgrprotos.h $(top_builddir)/src/include/utils/probes.h
generated-headers: $(top_builddir)/src/include/parser/gram.h $(top_builddir)/src/include/catalog/schemapg.h $(top_builddir)/src/include/storage/lwlocknames.h $(top_builddir)/src/include/utils/errcodes.h $(top_builddir)/src/include/utils/fmgroids.h $(top_builddir)/src/include/utils/fmgrprotos.h $(top_builddir)/src/include/utils/probes.h $(top_builddir)/src/include/utils/jsonpath_gram.h

$(top_builddir)/src/include/parser/gram.h: parser/gram.h
prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
Expand All @@ -186,6 +189,11 @@ $(top_builddir)/src/include/storage/lwlocknames.h: storage/lmgr/lwlocknames.h
cd '$(dir $@)' && rm -f $(notdir $@) && \
$(LN_S) "$$prereqdir/$(notdir $<)" .

$(top_builddir)/src/include/utils/jsonpath_gram.h: utils/adt/jsonpath_gram.h
prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
cd '$(dir $@)' && rm -f $(notdir $@) && \
$(LN_S) "$$prereqdir/$(notdir $<)" .

$(top_builddir)/src/include/utils/errcodes.h: utils/errcodes.h
prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
cd '$(dir $@)' && rm -f $(notdir $@) && \
Expand Down Expand Up @@ -220,6 +228,7 @@ distprep:
$(MAKE) -C replication repl_gram.c repl_scanner.c syncrep_gram.c syncrep_scanner.c
$(MAKE) -C storage/lmgr lwlocknames.h
$(MAKE) -C utils fmgrtab.c fmgroids.h fmgrprotos.h errcodes.h
$(MAKE) -C utils/adt jsonpath_gram.c jsonpath_gram.h jsonpath_scan.c
$(MAKE) -C utils/misc guc-file.c
$(MAKE) -C utils/sort qsort_tuple.c

Expand Down Expand Up @@ -308,6 +317,7 @@ endif
clean:
rm -f $(LOCALOBJS) postgres$(X) $(POSTGRES_IMP) \
$(top_builddir)/src/include/parser/gram.h \
$(top_builddir)/src/include/utils/jsonpath_gram.h \
$(top_builddir)/src/include/catalog/schemapg.h \
$(top_builddir)/src/include/storage/lwlocknames.h \
$(top_builddir)/src/include/utils/fmgroids.h \
Expand Down Expand Up @@ -344,6 +354,7 @@ maintainer-clean: distclean
utils/fmgrtab.c \
utils/errcodes.h \
utils/misc/guc-file.c \
utils/adt/jsonpath_gram.h \
utils/sort/qsort_tuple.c


Expand Down
4 changes: 3 additions & 1 deletion src/backend/commands/explain.c
Original file line number Diff line number Diff line change
Expand Up @@ -2752,7 +2752,9 @@ ExplainTargetRel(Plan *plan, Index rti, ExplainState *es)
break;
case T_TableFuncScan:
Assert(rte->rtekind == RTE_TABLEFUNC);
objectname = "xmltable";
objectname = rte->tablefunc ?
rte->tablefunc->functype == TFT_XMLTABLE ?
"xmltable" : "json_table" : NULL;
objecttag = "Table Function Name";
break;
case T_ValuesScan:
Expand Down
74 changes: 74 additions & 0 deletions src/backend/executor/execExpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "optimizer/planner.h"
#include "pgstat.h"
#include "utils/builtins.h"
#include "utils/jsonpath.h"
#include "utils/lsyscache.h"
#include "utils/typcache.h"

Expand Down Expand Up @@ -2033,6 +2034,79 @@ ExecInitExprRec(Expr *node, PlanState *parent, ExprState *state,
break;
}

case T_JsonExpr:
{
JsonExpr *jexpr = castNode(JsonExpr, node);
ListCell *argexprlc;
ListCell *argnamelc;

scratch.opcode = EEOP_JSONEXPR;
scratch.d.jsonexpr.jsexpr = jexpr;

scratch.d.jsonexpr.raw_expr =
palloc(sizeof(*scratch.d.jsonexpr.raw_expr));

ExecInitExprRec((Expr *) jexpr->raw_expr, parent, state,
&scratch.d.jsonexpr.raw_expr->value,
&scratch.d.jsonexpr.raw_expr->isnull);

scratch.d.jsonexpr.formatted_expr =
ExecInitExpr((Expr *) jexpr->formatted_expr, parent);

scratch.d.jsonexpr.result_expr =
ExecInitExpr((Expr *) jexpr->result_expr, parent);

scratch.d.jsonexpr.default_on_empty =
ExecInitExpr((Expr *) jexpr->on_empty.default_expr, parent);

scratch.d.jsonexpr.default_on_error =
ExecInitExpr((Expr *) jexpr->on_error.default_expr, parent);

if (jexpr->coerce_via_io || jexpr->omit_quotes)
{
Oid typinput;

/* lookup the result type's input function */
getTypeInputInfo(jexpr->returning.typid, &typinput,
&scratch.d.jsonexpr.input.typioparam);
fmgr_info(typinput, &scratch.d.jsonexpr.input.func);
}

scratch.d.jsonexpr.args = NIL;

forboth(argexprlc, jexpr->passing.values,
argnamelc, jexpr->passing.names)
{
Expr *argexpr = (Expr *) lfirst(argexprlc);
Value *argname = (Value *) lfirst(argnamelc);
JsonPathVariableEvalContext *var = palloc(sizeof(*var));

var->var.varName = cstring_to_text(argname->val.str);
var->var.typid = exprType((Node *) argexpr);
var->var.typmod = exprTypmod((Node *) argexpr);
var->var.cb = EvalJsonPathVar;
var->var.cb_arg = var;
var->estate = ExecInitExpr(argexpr, parent);
var->econtext = NULL;
var->mcxt = NULL;
var->evaluated = false;
var->value = (Datum) 0;
var->isnull = true;

scratch.d.jsonexpr.args =
lappend(scratch.d.jsonexpr.args, var);
}

scratch.d.jsonexpr.cache = NULL;

memset(&scratch.d.jsonexpr.scalar, 0,
sizeof(scratch.d.jsonexpr.scalar));

ExprEvalPushStep(state, &scratch);
}
break;


default:
elog(ERROR, "unrecognized node type: %d",
(int) nodeTag(node));
Expand Down
Loading