26#include "utils/fmgrprotos.h"
79 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
80 errdetail(
"Initial element must be an array."));
87 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
95 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
96 errdetail(
"Value of \"%s\" must be an array of attribute numbers.",
104 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
105 errdetail(
"Attribute lists can only contain attribute numbers."));
112 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
113 errdetail(
"Value of \"%s\" must be an integer.",
121 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
122 errdetail(
"Value of \"%s\" must be an integer.",
128 "object start of \"%s\" found in unexpected parse state: %d.",
129 "pg_dependencies", (
int)
parse->state);
152 "object end of \"%s\" found in unexpected parse state: %d.",
153 "pg_dependencies", (
int)
parse->state);
155 if (!
parse->found_attributes)
159 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
160 errdetail(
"Item must contain \"%s\" key.",
165 if (!
parse->found_dependency)
169 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
170 errdetail(
"Item must contain \"%s\" key.",
175 if (!
parse->found_degree)
179 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
180 errdetail(
"Item must contain \"%s\" key.",
194 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
195 errdetail(
"The \"%s\" key must contain an array of at least %d and no more than %d elements.",
206 dep->nattributes = natts + 1;
208 dep->attributes[natts] =
parse->dependency;
215 for (
int i = 0;
i < natts;
i++)
218 if (
dep->attributes[
i] ==
parse->dependency)
222 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
223 errdetail(
"Item \"%s\" with value %d has been found in the \"%s\" list.",
238 parse->dependency = 0;
240 parse->found_attributes =
false;
241 parse->found_dependency =
false;
242 parse->found_degree =
false;
259 switch (
parse->state)
270 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
271 errdetail(
"Array has been found at an unexpected location."));
288 switch (
parse->state)
299 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
300 errdetail(
"The \"%s\" key must be a non-empty array.",
313 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
314 errdetail(
"Item array cannot be empty."));
324 "array end of \"%s\" found in unexpected parse state: %d.",
325 "pg_dependencies", (
int)
parse->state);
346 if (
parse->found_attributes)
350 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
351 errdetail(
"Multiple \"%s\" keys are not allowed.",
356 parse->found_attributes =
true;
363 if (
parse->found_dependency)
367 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
368 errdetail(
"Multiple \"%s\" keys are not allowed.",
373 parse->found_dependency =
true;
380 if (
parse->found_degree)
384 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
385 errdetail(
"Multiple \"%s\" keys are not allowed.",
390 parse->found_degree =
true;
397 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
398 errdetail(
"Only allowed keys are \"%s\", \"%s\", and \"%s\".",
416 switch (
parse->state)
424 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
425 errdetail(
"Attribute number array cannot be null."));
434 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
435 errdetail(
"Item list elements cannot be null."));
440 "array element start of \"%s\" found in unexpected parse state: %d.",
441 "pg_dependencies", (
int)
parse->state);
466 return ((
cur > prev) || (
cur < 0));
484 switch (
parse->state)
489 if (escontext.error_occurred)
493 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
506 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
507 errdetail(
"Invalid \"%s\" element has been found: %d.",
520 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
521 errdetail(
"Invalid \"%s\" element has been found: %d cannot follow %d.",
534 if (escontext.error_occurred)
538 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
551 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
552 errdetail(
"Key \"%s\" has an incorrect value: %d.",
564 if (escontext.error_occurred)
568 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
579 errmsg(
"malformed pg_dependencies: \"%s\"",
parse->str),
580 errdetail(
"Unexpected scalar has been found."));
596 if (
a->nattributes !=
b->nattributes)
599 for (
i = 0;
i <
a->nattributes;
i++)
601 if (
a->attributes[
i] !=
b->attributes[
i])
654 switch (
parse->state)
665 "pg_dependencies parsing claims success with an empty item list.");
672 errmsg(
"malformed pg_dependencies: \"%s\"",
str),
680 errmsg(
"malformed pg_dependencies: \"%s\"",
str),
681 errdetail(
"Unexpected end state has been found: %d.",
parse->state));
691 for (
int i = 0;
i < ndeps;
i++)
705 for (
int j = 0;
j <
i;
j++)
715 errmsg(
"malformed pg_dependencies: \"%s\"",
str),
716 errdetail(
"Duplicated \"%s\" array has been found: [%s] for key \"%s\" and value %d.",
802 errmsg(
"malformed pg_dependencies: \"%s\"",
str),
803 errdetail(
"Input data must be valid JSON."));
822 for (
int i = 0;
i < dependencies->
ndeps;
i++)
830 elog(
ERROR,
"invalid zero-length nattributes array in MVDependencies");
857 errmsg(
"cannot accept a value of type %s",
"pg_dependencies")));
Datum byteasend(PG_FUNCTION_ARGS)
#define Assert(condition)
MVDependencies * statext_dependencies_deserialize(bytea *data)
bytea * statext_dependencies_serialize(MVDependencies *dependencies)
int errcode(int sqlerrcode)
#define errsave(context,...)
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define ereport(elevel,...)
float8 float8in_internal(char *num, char **endptr_p, const char *type_name, const char *orig_string, struct Node *escontext)
#define PG_GETARG_BYTEA_PP(n)
#define PG_RETURN_BYTEA_P(x)
#define PG_RETURN_CSTRING(x)
#define PG_GETARG_CSTRING(n)
JsonParseErrorType pg_parse_json(JsonLexContext *lex, const JsonSemAction *sem)
JsonLexContext * makeJsonLexContextCstringLen(JsonLexContext *lex, const char *json, size_t len, int encoding, bool need_escapes)
void freeJsonLexContext(JsonLexContext *lex)
List * lappend(List *list, void *datum)
List * lappend_int(List *list, int datum)
void list_free(List *list)
void list_free_deep(List *list)
void pfree(void *pointer)
void * palloc0(Size size)
#define SOFT_ERROR_OCCURRED(escontext)
int16 pg_strtoint16_safe(const char *s, Node *escontext)
static JsonParseErrorType dependencies_array_end(void *state)
static JsonParseErrorType dependencies_array_start(void *state)
Datum pg_dependencies_in(PG_FUNCTION_ARGS)
static JsonParseErrorType dependencies_array_element_start(void *state, bool isnull)
DependenciesSemanticState
@ DEPS_EXPECT_ATTNUM_LIST
static JsonParseErrorType dependencies_object_end(void *state)
static bytea * build_mvdependencies(DependenciesParseState *parse, char *str)
static bool valid_subsequent_attnum(const AttrNumber prev, const AttrNumber cur)
static char * dep_attnum_list(const MVDependency *item)
Datum pg_dependencies_out(PG_FUNCTION_ARGS)
static AttrNumber dep_attnum_dependency(const MVDependency *item)
static JsonParseErrorType dependencies_scalar(void *state, char *token, JsonTokenType tokentype)
Datum pg_dependencies_send(PG_FUNCTION_ARGS)
static JsonParseErrorType dependencies_object_field_start(void *state, char *fname, bool isnull)
Datum pg_dependencies_recv(PG_FUNCTION_ARGS)
static bool dep_attributes_eq(const MVDependency *a, const MVDependency *b)
static JsonParseErrorType dependencies_object_start(void *state)
static int list_length(const List *l)
static void * list_nth(const List *list, int n)
static int list_nth_int(const List *list, int n)
#define STATS_MAX_DIMENSIONS
#define STATS_DEPS_TYPE_BASIC
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
DependenciesSemanticState state
MVDependency * deps[FLEXIBLE_ARRAY_MEMBER]
AttrNumber attributes[FLEXIBLE_ARRAY_MEMBER]