Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit40ff744

Browse files
committed
new interface to JsQUery
1 parentb0094a7 commit40ff744

File tree

5 files changed

+514
-354
lines changed

5 files changed

+514
-354
lines changed

‎Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# contrib/jsquery/Makefile
22

33
MODULE_big = jsquery
4-
OBJS =jsquery_io.ojsquery_gram.ojsquery_op.o\
5-
jsquery_constr.ojsquery_extract.ojsonb_gin_ops.o
4+
OBJS =jsonb_gin_ops.ojsquery_constr.ojsquery_extract.o\
5+
jsquery_gram.o jsquery_io.ojsquery_op.ojsquery_support.o
66

77
EXTENSION = jsquery
88
DATA = jsquery--1.0.sql

‎jsquery.h

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ typedef struct JsQueryItem JsQueryItem;
5858

5959
structJsQueryItem {
6060
JsQueryItemTypetype;
61+
JsQueryItem*next;/* next in path */
6162

6263
union {
6364
struct {
@@ -71,7 +72,7 @@ struct JsQueryItem {
7172
boolboolean;
7273
struct {
7374
uint32len;
74-
char*val;/* could be not null-terminated */
75+
char*val;/* couldnotbe not null-terminated */
7576
}string;
7677

7778
struct {
@@ -80,9 +81,45 @@ struct JsQueryItem {
8081
}array;
8182
};
8283

83-
JsQueryItem*next;/* next in path */
8484
};
8585

86+
typedefstructJsQueryItemR {
87+
JsQueryItemTypetype;
88+
int32nextPos;
89+
char*base;
90+
91+
union {
92+
struct {
93+
char*data;
94+
intdatalen;/* filled only for string */
95+
}value;
96+
97+
struct {
98+
int32left;
99+
int32right;
100+
}args;
101+
int32arg;
102+
struct {
103+
intnelems;
104+
intcurrent;
105+
int32*arrayPtr;
106+
}array;
107+
};
108+
109+
110+
}JsQueryItemR;
111+
112+
externvoidjsqInit(JsQueryItemR*v,char*base,int32pos);
113+
externbooljsqGetNext(JsQueryItemR*v,JsQueryItemR*a);
114+
externvoidjsqGetArg(JsQueryItemR*v,JsQueryItemR*a);
115+
externvoidjsqGetLeftArg(JsQueryItemR*v,JsQueryItemR*a);
116+
externvoidjsqGetRightArg(JsQueryItemR*v,JsQueryItemR*a);
117+
externNumericjsqGetNumeric(JsQueryItemR*v);
118+
externbooljsqGetBool(JsQueryItemR*v);
119+
externchar*jsqGetString(JsQueryItemR*v,int32*len);
120+
externvoidjsqIterateInit(JsQueryItemR*v);
121+
externbooljsqIterateArray(JsQueryItemR*v,JsQueryItemR*e);
122+
86123
/*
87124
* support
88125
*/

‎jsquery_io.c

Lines changed: 51 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -213,92 +213,60 @@ printOperation(StringInfo buf, JsQueryItemType type)
213213
}
214214

215215
staticvoid
216-
printJsQueryItem(StringInfobuf,char*base,int32pos,boolinKey,boolprintBracketes)
216+
printJsQueryItem(StringInfobuf,JsQueryItemR*v,boolinKey,boolprintBracketes)
217217
{
218-
JsQueryItemTypetype;
219-
int32nextPos;
218+
JsQueryItemRelem;
219+
boolfirst= true;
220220

221221
check_stack_depth();
222222

223-
pos=readJsQueryHeader(base,pos,&type,&nextPos);
224-
225-
switch(type)
223+
switch(v->type)
226224
{
227225
casejqiNull:
228226
appendStringInfoString(buf,"null");
229227
break;
230228
casejqiKey:
229+
if (inKey)
230+
appendStringInfoChar(buf,'.');
231231
casejqiString:
232-
{
233-
int32len;
234-
235-
read_int32(len,base,pos);
236-
if (inKey&&type==jqiKey)
237-
appendStringInfoChar(buf,'.');
238-
escape_json(buf,base+pos);
239-
pos+=len+1;
240-
}
232+
escape_json(buf,jsqGetString(v,NULL));
241233
break;
242234
casejqiNumeric:
243-
{
244-
Numericn= (Numeric)(base+pos);
245-
246-
pos+=VARSIZE(n);
247-
248-
appendStringInfoString(buf,
249-
DatumGetCString(DirectFunctionCall1(numeric_out,
250-
PointerGetDatum(n))));
251-
}
252-
break;
235+
appendStringInfoString(buf,
236+
DatumGetCString(DirectFunctionCall1(numeric_out,
237+
PointerGetDatum(jsqGetNumeric(v)))));
238+
break;
253239
casejqiBool:
254-
{
255-
boolv;
256-
257-
read_byte(v,base,pos);
258-
259-
if (v)
260-
appendBinaryStringInfo(buf,"true",4);
261-
else
262-
appendBinaryStringInfo(buf,"false",5);
263-
}
240+
if (jsqGetBool(v))
241+
appendBinaryStringInfo(buf,"true",4);
242+
else
243+
appendBinaryStringInfo(buf,"false",5);
264244
break;
265245
casejqiArray:
266-
{
267-
int32i,nelems,*arrayPos;
268-
269-
read_int32(nelems,base,pos);
270-
arrayPos= (int32*)(base+pos);
271-
pos+=nelems*sizeof(*arrayPos);
272-
273-
if (printBracketes)
274-
appendStringInfoChar(buf,'[');
275-
276-
for(i=0;i<nelems;i++)
277-
{
278-
if (i!=0)
279-
appendBinaryStringInfo(buf,", ",2);
280-
281-
printJsQueryItem(buf,base,arrayPos[i], false, true);
282-
}
246+
if (printBracketes)
247+
appendStringInfoChar(buf,'[');
283248

284-
if (printBracketes)
285-
appendStringInfoChar(buf,']');
249+
while(jsqIterateArray(v,&elem))
250+
{
251+
if (first== false)
252+
appendBinaryStringInfo(buf,", ",2);
253+
else
254+
first= false;
255+
printJsQueryItem(buf,&elem, false, true);
286256
}
257+
258+
if (printBracketes)
259+
appendStringInfoChar(buf,']');
287260
break;
288261
casejqiAnd:
289262
casejqiOr:
290-
{
291-
int32left,right;
292-
293-
read_int32(left,base,pos);
294-
read_int32(right,base,pos);
295-
296-
appendStringInfoChar(buf,'(');
297-
printJsQueryItem(buf,base,left, false, true);
298-
printOperation(buf,type);
299-
printJsQueryItem(buf,base,right, false, true);
300-
appendStringInfoChar(buf,')');
301-
}
263+
appendStringInfoChar(buf,'(');
264+
jsqGetLeftArg(v,&elem);
265+
printJsQueryItem(buf,&elem, false, true);
266+
printOperation(buf,v->type);
267+
jsqGetRightArg(v,&elem);
268+
printJsQueryItem(buf,&elem, false, true);
269+
appendStringInfoChar(buf,')');
302270
break;
303271
casejqiEqual:
304272
casejqiLess:
@@ -308,36 +276,21 @@ printJsQueryItem(StringInfo buf, char *base, int32 pos, bool inKey, bool printBr
308276
casejqiContains:
309277
casejqiContained:
310278
casejqiOverlap:
311-
{
312-
int32arg;
313-
314-
read_int32(arg,base,pos);
315-
316-
printOperation(buf,type);
317-
printJsQueryItem(buf,base,arg, false, true);
318-
}
279+
printOperation(buf,v->type);
280+
jsqGetArg(v,&elem);
281+
printJsQueryItem(buf,&elem, false, true);
319282
break;
320283
casejqiIn:
321-
{
322-
int32arg;
323-
324-
read_int32(arg,base,pos);
325-
326-
appendBinaryStringInfo(buf," IN (",5);
327-
printJsQueryItem(buf,base,arg, false, false);
328-
appendStringInfoChar(buf,')');
329-
}
284+
appendBinaryStringInfo(buf," IN (",5);
285+
jsqGetArg(v,&elem);
286+
printJsQueryItem(buf,&elem, false, false);
287+
appendStringInfoChar(buf,')');
330288
break;
331289
casejqiNot:
332-
{
333-
int32arg;
334-
335-
read_int32(arg,base,pos);
336-
337-
appendBinaryStringInfo(buf,"!(",2);
338-
printJsQueryItem(buf,base,arg, false, true);
339-
appendStringInfoChar(buf,')');
340-
}
290+
appendBinaryStringInfo(buf,"!(",2);
291+
jsqGetArg(v,&elem);
292+
printJsQueryItem(buf,&elem, false, true);
293+
appendStringInfoChar(buf,')');
341294
break;
342295
casejqiAny:
343296
if (inKey)
@@ -360,11 +313,11 @@ printJsQueryItem(StringInfo buf, char *base, int32 pos, bool inKey, bool printBr
360313
appendStringInfoChar(buf,'%');
361314
break;
362315
default:
363-
elog(ERROR,"Unknown JsQueryItem type: %d",type);
316+
elog(ERROR,"Unknown JsQueryItem type: %d",v->type);
364317
}
365318

366-
if (nextPos>0)
367-
printJsQueryItem(buf,base,nextPos, true, true);
319+
if (jsqGetNext(v,&elem))
320+
printJsQueryItem(buf,&elem, true, true);
368321
}
369322

370323
PG_FUNCTION_INFO_V1(jsquery_out);
@@ -373,11 +326,13 @@ jsquery_out(PG_FUNCTION_ARGS)
373326
{
374327
JsQuery*in=PG_GETARG_JSQUERY(0);
375328
StringInfoDatabuf;
329+
JsQueryItemRv;
376330

377331
initStringInfo(&buf);
378332
enlargeStringInfo(&buf,VARSIZE(in)/* estimation */);
379333

380-
printJsQueryItem(&buf,VARDATA(in),0, false, true);
334+
jsqInit(&v,VARDATA(in),0);
335+
printJsQueryItem(&buf,&v, false, true);
381336

382337
PG_RETURN_CSTRING(buf.data);
383338
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp