PostgreSQL Source Code: src/include/utils/jsonb.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12#ifndef __JSONB_H__

13#define __JSONB_H__

14

18

19

20typedef enum

21{

31

32

33#define JsonbContainsStrategyNumber 7

34#define JsonbExistsStrategyNumber 9

35#define JsonbExistsAnyStrategyNumber 10

36#define JsonbExistsAllStrategyNumber 11

37#define JsonbJsonpathExistsStrategyNumber 15

38#define JsonbJsonpathPredicateStrategyNumber 16

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62#define JGINFLAG_KEY 0x01

63#define JGINFLAG_NULL 0x02

64#define JGINFLAG_BOOL 0x03

65#define JGINFLAG_NUM 0x04

66#define JGINFLAG_STR 0x05

67#define JGINFLAG_HASHED 0x10

68#define JGIN_MAXLENGTH 125

69

70

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

139

140#define JENTRY_OFFLENMASK 0x0FFFFFFF

141#define JENTRY_TYPEMASK 0x70000000

142#define JENTRY_HAS_OFF 0x80000000

143

144

145#define JENTRY_ISSTRING 0x00000000

146#define JENTRY_ISNUMERIC 0x10000000

147#define JENTRY_ISBOOL_FALSE 0x20000000

148#define JENTRY_ISBOOL_TRUE 0x30000000

149#define JENTRY_ISNULL 0x40000000

150#define JENTRY_ISCONTAINER 0x50000000

151

152

153#define JBE_OFFLENFLD(je_) ((je_) & JENTRY_OFFLENMASK)

154#define JBE_HAS_OFF(je_) (((je_) & JENTRY_HAS_OFF) != 0)

155#define JBE_ISSTRING(je_) (((je_) & JENTRY_TYPEMASK) == JENTRY_ISSTRING)

156#define JBE_ISNUMERIC(je_) (((je_) & JENTRY_TYPEMASK) == JENTRY_ISNUMERIC)

157#define JBE_ISCONTAINER(je_) (((je_) & JENTRY_TYPEMASK) == JENTRY_ISCONTAINER)

158#define JBE_ISNULL(je_) (((je_) & JENTRY_TYPEMASK) == JENTRY_ISNULL)

159#define JBE_ISBOOL_TRUE(je_) (((je_) & JENTRY_TYPEMASK) == JENTRY_ISBOOL_TRUE)

160#define JBE_ISBOOL_FALSE(je_) (((je_) & JENTRY_TYPEMASK) == JENTRY_ISBOOL_FALSE)

161#define JBE_ISBOOL(je_) (JBE_ISBOOL_TRUE(je_) || JBE_ISBOOL_FALSE(je_))

162

163

164#define JBE_ADVANCE_OFFSET(offset, je) \

165 do { \

166 JEntry je_ = (je); \

167 if (JBE_HAS_OFF(je_)) \

168 (offset) = JBE_OFFLENFLD(je_); \

169 else \

170 (offset) += JBE_OFFLENFLD(je_); \

171 } while(0)

172

173

174

175

176

177

178

179

180#define JB_OFFSET_STRIDE 32

181

182

183

184

185

186

187

188

189

190

191

193{

194 uint32 header;

195

197

198

200

201

202#define JB_CMASK 0x0FFFFFFF

203#define JB_FSCALAR 0x10000000

204#define JB_FOBJECT 0x20000000

205#define JB_FARRAY 0x40000000

206

207

208#define JsonContainerSize(jc) ((jc)->header & JB_CMASK)

209#define JsonContainerIsScalar(jc) (((jc)->header & JB_FSCALAR) != 0)

210#define JsonContainerIsObject(jc) (((jc)->header & JB_FOBJECT) != 0)

211#define JsonContainerIsArray(jc) (((jc)->header & JB_FARRAY) != 0)

212

213

214typedef struct

215{

216 int32 vl_len_;

219

220

221#define JB_ROOT_COUNT(jbp_) (*(uint32 *) VARDATA(jbp_) & JB_CMASK)

222#define JB_ROOT_IS_SCALAR(jbp_) ((*(uint32 *) VARDATA(jbp_) & JB_FSCALAR) != 0)

223#define JB_ROOT_IS_OBJECT(jbp_) ((*(uint32 *) VARDATA(jbp_) & JB_FOBJECT) != 0)

224#define JB_ROOT_IS_ARRAY(jbp_) ((*(uint32 *) VARDATA(jbp_) & JB_FARRAY) != 0)

225

226

228{

229

234

237

239

240

241

242

243

244

245

247};

248

249

250

251

252

253

254

256{

258

259 union

260 {

263 struct

264 {

266 char *val;

267 } string;

268

269 struct

270 {

273 bool rawScalar;

274 } array;

275

276 struct

277 {

278 int nPairs;

280 } object;

281

282 struct

283 {

286 } binary;

287

288 struct

289 {

293 int tz;

294

297};

298

299#define IsAJsonbScalar(jsonbval) (((jsonbval)->type >= jbvNull && \

300 (jsonbval)->type <= jbvBool) || \

301 (jsonbval)->type == jbvDatetime)

302

303

304

305

306

307

308

309

310

311

312

314{

317 uint32 order;

318};

319

320

321

322

323

324

325

326

327

328

329

330

332{

335 struct Node *escontext;

336

340

341

342

343

344

345

347{

349 Size size;

353};

354

355

356

357

358

359typedef enum

360{

367

369{

370

372 uint32 nElems;

373

374 bool isScalar;

376

378

379

381

382

384

385

386

387

388

389

391

392

394

397

398

399

400static inline Jsonb *

402{

404}

405

406static inline Jsonb *

408{

410}

411

412static inline Datum

414{

416}

417

418#define PG_GETARG_JSONB_P(x) DatumGetJsonbP(PG_GETARG_DATUM(x))

419#define PG_GETARG_JSONB_P_COPY(x) DatumGetJsonbPCopy(PG_GETARG_DATUM(x))

420#define PG_RETURN_JSONB_P(x) PG_RETURN_POINTER(x)

421

422

430 const char *keyVal, int keyLen,

438 bool skipNested);

446

447

449 int estimated_len);

451 int estimated_len);

455

459 bool *isnull, bool as_text);

462 const Oid *types, bool absent_on_null,

463 bool unique_keys);

465 const Oid *types, bool absent_on_null);

466

467#endif

#define FLEXIBLE_ARRAY_MEMBER

#define PG_DETOAST_DATUM_COPY(datum)

#define PG_DETOAST_DATUM(datum)

static Jsonb * DatumGetJsonbPCopy(Datum d)

void pushJsonbValue(JsonbInState *pstate, JsonbIteratorToken seq, JsonbValue *jbval)

char * JsonbUnquote(Jsonb *jb)

Datum jsonb_build_array_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null)

static Datum JsonbPGetDatum(const Jsonb *p)

JsonbValue * getKeyJsonValueFromContainer(JsonbContainer *container, const char *keyVal, int keyLen, JsonbValue *res)

Datum jsonb_set_element(Jsonb *jb, const Datum *path, int path_len, JsonbValue *newval)

int compareJsonbContainers(JsonbContainer *a, JsonbContainer *b)

uint32 getJsonbLength(const JsonbContainer *jc, int index)

char * JsonbToCString(StringInfo out, JsonbContainer *in, int estimated_len)

JsonbIterator * JsonbIteratorInit(JsonbContainer *container)

Datum jsonb_get_element(Jsonb *jb, const Datum *path, int npath, bool *isnull, bool as_text)

const char * JsonbTypeName(JsonbValue *val)

static Jsonb * DatumGetJsonbP(Datum d)

void JsonbHashScalarValue(const JsonbValue *scalarVal, uint32 *hash)

Datum jsonb_build_object_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null, bool unique_keys)

void JsonbToJsonbValue(Jsonb *jsonb, JsonbValue *val)

struct JsonbInState JsonbInState

JsonbValue * findJsonbValueFromContainer(JsonbContainer *container, uint32 flags, JsonbValue *key)

JsonbIteratorToken JsonbIteratorNext(JsonbIterator **it, JsonbValue *val, bool skipNested)

struct JsonbIterator JsonbIterator

uint32 getJsonbOffset(const JsonbContainer *jc, int index)

bool JsonbExtractScalar(JsonbContainer *jbc, JsonbValue *res)

void JsonbHashScalarValueExtended(const JsonbValue *scalarVal, uint64 *hash, uint64 seed)

JsonbValue * getIthJsonbValueFromContainer(JsonbContainer *container, uint32 i)

Jsonb * JsonbValueToJsonb(JsonbValue *val)

char * JsonbToCStringIndent(StringInfo out, JsonbContainer *in, int estimated_len)

bool JsonbDeepContains(JsonbIterator **val, JsonbIterator **mContained)

bool to_jsonb_is_immutable(Oid typoid)

struct JsonbContainer JsonbContainer

static Datum PointerGetDatum(const void *X)

static unsigned hash(unsigned *uv, int n)

JEntry children[FLEXIBLE_ARRAY_MEMBER]

JsonbParseState * parseState

struct JsonbIterator * parent

JsonbContainer * container

struct JsonbValue::@160::@164 binary

struct JsonbValue::@160::@165 datetime

struct JsonbValue::@160::@161 string

struct JsonbValue::@160::@162 array

struct JsonbValue::@160::@163 object