static void yaml_ofstart(void *state, char *fname, bool isnull) { word_table *p; pgspParserContext *ctx = (pgspParserContext *)state; char *s; p = search_word_table(propfields, fname, ctx->mode); if (!p) { ereport(DEBUG1, (errmsg("Short JSON parser encoutered unknown field name: \"%s\".", fname), errdetail_log("INPUT: \"%s\"", ctx->org_string))); } s = (p ? p->longname : fname); if (!bms_is_member(ctx->level, ctx->first)) { appendStringInfoString(ctx->dest, "\n"); appendStringInfoSpaces(ctx->dest, ctx->level * INDENT_STEP); } else ctx->first = bms_del_member(ctx->first, ctx->level); ctx->valconverter = NULL; ctx->fname = s; ctx->valconverter = (p ? p->converter : NULL); }
static void json_aestart(void *state, bool isnull) { pgspParserContext *ctx = (pgspParserContext *)state; if (ctx->remove) return; if (IS_INDENTED_ARRAY(ctx->current_list) && ctx->wlist_level == 1) { if (!bms_is_member(ctx->level, ctx->first)) appendStringInfoChar(ctx->dest, ','); if (ctx->mode == PGSP_JSON_INFLATE) { appendStringInfoChar(ctx->dest, '\n'); appendStringInfoSpaces(ctx->dest, (ctx->level) * INDENT_STEP); } } else { if (!bms_is_member(ctx->level, ctx->first)) { appendStringInfoChar(ctx->dest, ','); if (ctx->mode == PGSP_JSON_INFLATE && !ctx->last_elem_is_object) appendStringInfoChar(ctx->dest, ' '); } } ctx->first = bms_del_member(ctx->first, ctx->level); }
static void yaml_objend(void *state) { pgspParserContext *ctx = (pgspParserContext *)state; ctx->level--; ctx->last_elem_is_object = true; ctx->first = bms_del_member(ctx->first, ctx->level); }
static void yaml_aestart(void *state, bool isnull) { pgspParserContext *ctx = (pgspParserContext *)state; appendStringInfoString(ctx->dest, "\n"); bms_del_member(ctx->first, ctx->level); appendStringInfoSpaces(ctx->dest, ctx->level * INDENT_STEP); appendStringInfoString(ctx->dest, "- "); }
static void xml_objend(void *state) { pgspParserContext *ctx = (pgspParserContext *)state; appendStringInfoChar(ctx->dest, '\n'); appendStringInfoSpaces(ctx->dest, ctx->level * INDENT_STEP); ctx->level--; ctx->first = bms_del_member(ctx->first, ctx->level); ctx->last_elem_is_object = true; }
static void json_ofstart(void *state, char *fname, bool isnull) { word_table *p; pgspParserContext *ctx = (pgspParserContext *)state; char *fn; ctx->remove = false; p = search_word_table(propfields, fname, ctx->mode); if (!p) { ereport(DEBUG1, (errmsg("JSON parser encoutered unknown field name: \"%s\".", fname), errdetail_log("INPUT: \"%s\"", ctx->org_string))); } ctx->remove = (ctx->mode == PGSP_JSON_NORMALIZE && (!p || !p->normalize_use)); if (ctx->remove) return; if (!bms_is_member(ctx->level, ctx->first)) { appendStringInfoChar(ctx->dest, ','); if (ctx->mode == PGSP_JSON_INFLATE) appendStringInfoChar(ctx->dest, '\n'); } else ctx->first = bms_del_member(ctx->first, ctx->level); if (ctx->mode == PGSP_JSON_INFLATE) appendStringInfoSpaces(ctx->dest, ctx->level * INDENT_STEP); if (!p || !p->longname) fn = fname; else if (ctx->mode == PGSP_JSON_INFLATE) fn = p->longname; else fn = p->shortname; escape_json(ctx->dest, fn); ctx->fname = fn; ctx->valconverter = (p ? p->converter : NULL); appendStringInfoChar(ctx->dest, ':'); if (ctx->mode == PGSP_JSON_INFLATE) appendStringInfoChar(ctx->dest, ' '); }
static void json_aestart(void *state, bool isnull) { pgspParserContext *ctx = (pgspParserContext *)state; if (ctx->remove) return; if (!bms_is_member(ctx->level, ctx->first)) { appendStringInfoChar(ctx->dest, ','); if (ctx->mode == PGSP_JSON_INFLATE && !ctx->last_elem_is_object) appendStringInfoChar(ctx->dest, ' '); } else ctx->first = bms_del_member(ctx->first, ctx->level); }
static void json_objend(void *state) { pgspParserContext *ctx = (pgspParserContext *)state; if (ctx->mode == PGSP_JSON_INFLATE) { if (!bms_is_member(ctx->level, ctx->first)) appendStringInfoChar(ctx->dest, '\n'); appendStringInfoSpaces(ctx->dest, (ctx->level - 1) * INDENT_STEP); } appendStringInfoChar(ctx->dest, '}'); ctx->level--; ctx->last_elem_is_object = true; ctx->first = bms_del_member(ctx->first, ctx->level); ctx->fname = NULL; }
/* * fixup_whole_row_references * * When user reference a whole of row, it is equivalent to reference to * all the user columns (not system columns). So, we need to fix up the * given bitmapset, if it contains a whole of the row reference. */ static Bitmapset * fixup_whole_row_references(Oid relOid, Bitmapset *columns) { Bitmapset *result; HeapTuple tuple; AttrNumber natts; AttrNumber attno; int index; /* if no whole of row references, do not anything */ index = InvalidAttrNumber - FirstLowInvalidHeapAttributeNumber; if (!bms_is_member(index, columns)) return columns; /* obtain number of attributes */ tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relOid)); if (!HeapTupleIsValid(tuple)) elog(ERROR, "cache lookup failed for relation %u", relOid); natts = ((Form_pg_class) GETSTRUCT(tuple))->relnatts; ReleaseSysCache(tuple); /* fix up the given columns */ result = bms_copy(columns); result = bms_del_member(result, index); for (attno = 1; attno <= natts; attno++) { tuple = SearchSysCache2(ATTNUM, ObjectIdGetDatum(relOid), Int16GetDatum(attno)); if (!HeapTupleIsValid(tuple)) continue; if (((Form_pg_attribute) GETSTRUCT(tuple))->attisdropped) continue; index = attno - FirstLowInvalidHeapAttributeNumber; result = bms_add_member(result, index); ReleaseSysCache(tuple); } return result; }
static void xml_ofstart(void *state, char *fname, bool isnull) { word_table *p; pgspParserContext *ctx = (pgspParserContext *)state; char *s; p = search_word_table(propfields, fname, ctx->mode); if (!p) { ereport(DEBUG1, (errmsg("Short JSON parser encoutered unknown field name: \"%s\".", fname), errdetail_log("INPUT: \"%s\"", ctx->org_string))); } s = (p ? p->longname : fname); /* * save current process context * There's no problem if P_Plan appears recursively. */ if (p && (p->tag == P_Plan || p->tag == P_Triggers)) ctx->processing = p->tag; appendStringInfoChar(ctx->dest, '\n'); appendStringInfoSpaces(ctx->dest, (ctx->level + 1) * INDENT_STEP); ctx->valconverter = NULL; appendStringInfoChar(ctx->dest, '<'); appendStringInfoString(ctx->dest, escape_xml(hyphenate_words(ctx, s))); appendStringInfoChar(ctx->dest, '>'); ctx->valconverter = (p ? p->converter : NULL); /* * If the object field name is Plan or Triggers, the value should be an * array and the items are tagged by other than "Item". "Item"s appear * only in Output field. */ if (p && (p->tag == P_Plans || p->tag == P_Triggers)) ctx->not_item = bms_add_member(ctx->not_item, ctx->level + 1); else ctx->not_item = bms_del_member(ctx->not_item, ctx->level + 1); }
static void json_ofstart(void *state, char *fname, bool isnull) { word_table *p; pgspParserContext *ctx = (pgspParserContext *)state; char *fn; ctx->remove = false; p = search_word_table(propfields, fname, ctx->mode); if (!p) { ereport(DEBUG1, (errmsg("JSON parser encoutered unknown field name: \"%s\".", fname), errdetail_log("INPUT: \"%s\"", ctx->org_string))); } ctx->remove = (ctx->mode == PGSP_JSON_NORMALIZE && (!p || !p->normalize_use)); if (ctx->remove) return; if (!bms_is_member(ctx->level, ctx->first)) { appendStringInfoChar(ctx->dest, ','); if (ctx->mode == PGSP_JSON_INFLATE) appendStringInfoChar(ctx->dest, '\n'); } else ctx->first = bms_del_member(ctx->first, ctx->level); if (ctx->mode == PGSP_JSON_INFLATE) appendStringInfoSpaces(ctx->dest, ctx->level * INDENT_STEP); /* * We intentionally let some property names not have a short name. Use long * name for the cases. */ if (!p || !p->longname) fn = fname; else if (ctx->mode == PGSP_JSON_INFLATE || !(p->shortname && p->shortname[0])) fn = p->longname; else fn = p->shortname; escape_json(ctx->dest, fn); ctx->fname = fn; ctx->valconverter = (p ? p->converter : NULL); appendStringInfoChar(ctx->dest, ':'); if (ctx->mode == PGSP_JSON_INFLATE) appendStringInfoChar(ctx->dest, ' '); if (p && IS_INDENTED_ARRAY(p->tag)) { ctx->current_list = p->tag; ctx->list_fname = fname; ctx->wlist_level = 0; } }