MCPcopy Create free account
hub / github.com/apache/cloudberry / PLyObject_FromJsonbContainer

Function PLyObject_FromJsonbContainer

contrib/jsonb_plpython/jsonb_plpython.c:140–261  ·  view source on GitHub ↗

* PLyObject_FromJsonbContainer * * Transform JsonbContainer to PyObject. */

Source from the content-addressed store, hash-verified

138 * Transform JsonbContainer to PyObject.
139 */
140static PyObject *
141PLyObject_FromJsonbContainer(JsonbContainer *jsonb)
142{
143 JsonbIteratorToken r;
144 JsonbValue v;
145 JsonbIterator *it;
146 PyObject *result;
147
148 it = JsonbIteratorInit(jsonb);
149 r = JsonbIteratorNext(&it, &v, true);
150
151 switch (r)
152 {
153 case WJB_BEGIN_ARRAY:
154 if (v.val.array.rawScalar)
155 {
156 JsonbValue tmp;
157
158 if ((r = JsonbIteratorNext(&it, &v, true)) != WJB_ELEM ||
159 (r = JsonbIteratorNext(&it, &tmp, true)) != WJB_END_ARRAY ||
160 (r = JsonbIteratorNext(&it, &tmp, true)) != WJB_DONE)
161 elog(ERROR, "unexpected jsonb token: %d", r);
162
163 result = PLyObject_FromJsonbValue(&v);
164 }
165 else
166 {
167 PyObject *volatile elem = NULL;
168
169 result = PyList_New(0);
170 if (!result)
171 return NULL;
172
173 PG_TRY();
174 {
175 while ((r = JsonbIteratorNext(&it, &v, true)) != WJB_DONE)
176 {
177 if (r != WJB_ELEM)
178 continue;
179
180 elem = PLyObject_FromJsonbValue(&v);
181
182 PyList_Append(result, elem);
183 Py_XDECREF(elem);
184 elem = NULL;
185 }
186 }
187 PG_CATCH();
188 {
189 Py_XDECREF(elem);
190 Py_XDECREF(result);
191 PG_RE_THROW();
192 }
193 PG_END_TRY();
194 }
195 break;
196
197 case WJB_BEGIN_OBJECT:

Callers 2

PLyObject_FromJsonbValueFunction · 0.85
jsonb_to_plpythonFunction · 0.85

Calls 4

JsonbIteratorInitFunction · 0.85
JsonbIteratorNextFunction · 0.85
PLyObject_FromJsonbValueFunction · 0.85
PLyString_FromJsonbValueFunction · 0.85

Tested by

no test coverage detected