Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9497bee

Browse files
feodorNikita Glukhov
authored and
Nikita Glukhov
committed
Initial jsonpath support
Main TODO - indexed arrays [1,4, 6 to 18] - variables execution ( $varname ) - function support - ariphmetic support - correct error support It provides two debugging functions: _jsonpath_object and _jsonpath_exist Some examples are avaliable in src/test/regress/sql/sql_json.sql
1 parent 72da877 commit 9497bee

20 files changed

+2526
-3
lines changed

src/backend/Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl storage/lmgr/lw
139139
utils/errcodes.h: utils/generate-errcodes.pl utils/errcodes.txt
140140
$(MAKE) -C utils errcodes.h
141141

142+
utils/adt/jsonpath_gram.h: utils/adt/jsonpath_gram.y
143+
$(MAKE) -C utils/adt jsonpath_gram.h
144+
142145
# see explanation in parser/Makefile
143146
utils/fmgrprotos.h: utils/fmgroids.h ;
144147

@@ -169,7 +172,7 @@ submake-schemapg:
169172

170173
.PHONY: generated-headers
171174

172-
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
175+
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
173176

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

192+
$(top_builddir)/src/include/utils/jsonpath_gram.h: utils/adt/jsonpath_gram.h
193+
prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
194+
cd '$(dir $@)' && rm -f $(notdir $@) && \
195+
$(LN_S) "$$prereqdir/$(notdir $<)" .
196+
189197
$(top_builddir)/src/include/utils/errcodes.h: utils/errcodes.h
190198
prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
191199
cd '$(dir $@)' && rm -f $(notdir $@) && \
@@ -220,6 +228,7 @@ distprep:
220228
$(MAKE) -C replication repl_gram.c repl_scanner.c syncrep_gram.c syncrep_scanner.c
221229
$(MAKE) -C storage/lmgr lwlocknames.h
222230
$(MAKE) -C utils fmgrtab.c fmgroids.h fmgrprotos.h errcodes.h
231+
$(MAKE) -C utils/adt jsonpath_gram.c jsonpath_gram.h jsonpath_scan.c
223232
$(MAKE) -C utils/misc guc-file.c
224233
$(MAKE) -C utils/sort qsort_tuple.c
225234

@@ -308,6 +317,7 @@ endif
308317
clean:
309318
rm -f $(LOCALOBJS) postgres$(X) $(POSTGRES_IMP) \
310319
$(top_builddir)/src/include/parser/gram.h \
320+
$(top_builddir)/src/include/utils/jsonpath_gram.h \
311321
$(top_builddir)/src/include/catalog/schemapg.h \
312322
$(top_builddir)/src/include/storage/lwlocknames.h \
313323
$(top_builddir)/src/include/utils/fmgroids.h \
@@ -344,6 +354,7 @@ maintainer-clean: distclean
344354
utils/fmgrtab.c \
345355
utils/errcodes.h \
346356
utils/misc/guc-file.c \
357+
utils/adt/jsonpath_gram.h \
347358
utils/sort/qsort_tuple.c
348359

349360

src/backend/lib/stringinfo.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,24 @@ enlargeStringInfo(StringInfo str, int needed)
306306

307307
str->maxlen = newlen;
308308
}
309+
310+
/*
311+
* alignStringInfoInt - aling StringInfo to int by adding
312+
* zero padding bytes
313+
*/
314+
void
315+
alignStringInfoInt(StringInfo buf)
316+
{
317+
switch(INTALIGN(buf->len) - buf->len)
318+
{
319+
case 3:
320+
appendStringInfoCharMacro(buf, 0);
321+
case 2:
322+
appendStringInfoCharMacro(buf, 0);
323+
case 1:
324+
appendStringInfoCharMacro(buf, 0);
325+
default:
326+
break;
327+
}
328+
}
329+

src/backend/utils/adt/Makefile

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ OBJS = acl.o amutils.o arrayfuncs.o array_expanded.o array_selfuncs.o \
1616
float.o format_type.o formatting.o genfile.o \
1717
geo_ops.o geo_selfuncs.o geo_spgist.o inet_cidr_ntop.o inet_net_pton.o \
1818
int.o int8.o json.o jsonb.o jsonb_gin.o jsonb_op.o jsonb_util.o \
19-
jsonfuncs.o like.o lockfuncs.o mac.o mac8.o misc.o nabstime.o name.o \
19+
jsonfuncs.o jsonpath_gram.o jsonpath_scan.o jsonpath.o jsonpath_exec.o \
20+
like.o lockfuncs.o mac.o mac8.o misc.o nabstime.o name.o \
2021
network.o network_gist.o network_selfuncs.o network_spgist.o \
2122
numeric.o numutils.o oid.o oracle_compat.o \
2223
orderedsetaggs.o pg_locale.o pg_lsn.o pg_upgrade_support.o \
@@ -31,6 +32,26 @@ OBJS = acl.o amutils.o arrayfuncs.o array_expanded.o array_selfuncs.o \
3132
txid.o uuid.o varbit.o varchar.o varlena.o version.o \
3233
windowfuncs.o xid.o xml.o
3334

35+
# Latest flex causes warnings in this file.
36+
ifeq ($(GCC),yes)
37+
scan.o: CFLAGS += -Wno-error
38+
endif
39+
40+
jsonpath_gram.c: BISONFLAGS += -d
41+
42+
jsonpath_scan.c: FLEXFLAGS = -CF -p -p
43+
44+
jsonpath_gram.h: jsonpath_gram.c ;
45+
46+
# Force these dependencies to be known even without dependency info built:
47+
jsonpath_gram.o jsonpath_scan.o jsonpath_parser.o: jsonpath_gram.h
48+
49+
# jsonpath_gram.c, jsonpath_gram.h, and jsonpath_scan.c are in the distribution
50+
# tarball, so they are not cleaned here.
51+
clean distclean maintainer-clean:
52+
rm -f lex.backup
53+
54+
3455
like.o: like.c like_match.c
3556

3657
varlena.o: varlena.c levenshtein.c

src/backend/utils/adt/jsonb.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,3 +1897,24 @@ jsonb_object_agg_finalfn(PG_FUNCTION_ARGS)
18971897

18981898
PG_RETURN_POINTER(out);
18991899
}
1900+
1901+
JsonbValue *
1902+
JsonbExtractScalar(JsonbContainer *jbc, JsonbValue *res)
1903+
{
1904+
JsonbIterator *it = JsonbIteratorInit(jbc);
1905+
JsonbIteratorToken tok PG_USED_FOR_ASSERTS_ONLY;
1906+
JsonbValue tmp;
1907+
1908+
tok = JsonbIteratorNext(&it, &tmp, true);
1909+
Assert(tok == WJB_BEGIN_ARRAY);
1910+
Assert(tmp.val.array.nElems == 1 && tmp.val.array.rawScalar);
1911+
1912+
tok = JsonbIteratorNext(&it, res, true);
1913+
Assert (tok == WJB_ELEM);
1914+
Assert(IsAJsonbScalar(res));
1915+
1916+
tok = JsonbIteratorNext(&it, &tmp, true);
1917+
Assert (tok == WJB_END_ARRAY);
1918+
1919+
return res;
1920+
}

0 commit comments

Comments
 (0)