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

72

73

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

137

138#define JENTRY_OFFLENMASK 0x0FFFFFFF

139#define JENTRY_TYPEMASK 0x70000000

140#define JENTRY_HAS_OFF 0x80000000

141

142

143#define JENTRY_ISSTRING 0x00000000

144#define JENTRY_ISNUMERIC 0x10000000

145#define JENTRY_ISBOOL_FALSE 0x20000000

146#define JENTRY_ISBOOL_TRUE 0x30000000

147#define JENTRY_ISNULL 0x40000000

148#define JENTRY_ISCONTAINER 0x50000000

149

150

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

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

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

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

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

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

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

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

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

160

161

162#define JBE_ADVANCE_OFFSET(offset, je) \

163 do { \

164 JEntry je_ = (je); \

165 if (JBE_HAS_OFF(je_)) \

166 (offset) = JBE_OFFLENFLD(je_); \

167 else \

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

169 } while(0)

170

171

172

173

174

175

176

177

178#define JB_OFFSET_STRIDE 32

179

180

181

182

183

184

185

186

187

188

189

191{

192 uint32 header;

193

195

196

198

199

200#define JB_CMASK 0x0FFFFFFF

201#define JB_FSCALAR 0x10000000

202#define JB_FOBJECT 0x20000000

203#define JB_FARRAY 0x40000000

204

205

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

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

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

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

210

211

212typedef struct

213{

214 int32 vl_len_;

217

218

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

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

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

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

223

224

226{

227

232

235

237

238

239

240

241

242

243

245};

246

247

248

249

250

251

252

254{

256

257 union

258 {

261 struct

262 {

264 char *val;

265 } string;

266

267 struct

268 {

271 bool rawScalar;

272 } array;

273

274 struct

275 {

276 int nPairs;

278 } object;

279

280 struct

281 {

284 } binary;

285

286 struct

287 {

291 int tz;

292

295};

296

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

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

299 (jsonbval)->type == jbvDatetime)

300

301

302

303

304

305

306

307

308

309

310

312{

315 uint32 order;

316};

317

318

320{

327

328

329

330

331

332typedef enum

333{

340

342{

343

345 uint32 nElems;

346

347 bool isScalar;

349

351

352

354

355

357

358

359

360

361

362

364

365

367

370

371

372

373static inline Jsonb *

375{

377}

378

379static inline Jsonb *

381{

383}

384

385static inline Datum

387{

389}

390

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

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

393#define PG_RETURN_JSONB_P(x) PG_RETURN_POINTER(x)

394

395

403 const char *keyVal, int keyLen,

411 bool skipNested);

419

420

422 int estimated_len);

424 int estimated_len);

428

432 bool *isnull, bool as_text);

435 const Oid *types, bool absent_on_null,

436 bool unique_keys);

438 const Oid *types, bool absent_on_null);

439

440#endif

#define FLEXIBLE_ARRAY_MEMBER

#define PG_DETOAST_DATUM_COPY(datum)

#define PG_DETOAST_DATUM(datum)

static Jsonb * DatumGetJsonbPCopy(Datum d)

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)

struct JsonbParseState JsonbParseState

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

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

int compareJsonbContainers(JsonbContainer *a, JsonbContainer *b)

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

uint32 getJsonbLength(const JsonbContainer *jc, int index)

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

JsonbValue * pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq, JsonbValue *jbval)

JsonbIterator * JsonbIteratorInit(JsonbContainer *container)

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)

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]

struct JsonbIterator * parent

JsonbContainer * container

struct JsonbParseState * next

struct JsonbValue::@141::@144 object

struct JsonbValue::@141::@143 array

struct JsonbValue::@141::@145 binary

struct JsonbValue::@141::@146 datetime

struct JsonbValue::@141::@142 string