MCPcopy Create free account
hub / github.com/documentdb/documentdb / ParseAndGetValidatorSpec

Function ParseAndGetValidatorSpec

pg_documentdb/src/metadata/collection.c:1971–2009  ·  view source on GitHub ↗

* This function parses and checks the bson value for "validator" option * given in "create"/"collMod" command */

Source from the content-addressed store, hash-verified

1969 * given in "create"/"collMod" command
1970 */
1971const bson_value_t *
1972ParseAndGetValidatorSpec(bson_iter_t *iter, const char *validatorName, bool *hasValue)
1973{
1974 if (!EnableSchemaValidation)
1975 {
1976 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED),
1977 errmsg("validator not supported yet")));
1978 }
1979
1980 /* "validator" values of "null" and "undefined" are valid */
1981 if (BSON_ITER_HOLDS_UNDEFINED(iter) ||
1982 BSON_ITER_HOLDS_NULL(iter))
1983 {
1984 return NULL;
1985 }
1986
1987 EnsureTopLevelFieldType(validatorName, iter, BSON_TYPE_DOCUMENT);
1988
1989 /* Copy the bson value to make sure the validator is valid beyond the lifetime of iter */
1990 bson_value_t *validator = palloc(sizeof(bson_value_t));
1991 bson_value_copy(bson_iter_value(iter), validator);
1992
1993 /* Large and overly complex validation rules can impact database performance, especially during write operations. */
1994 if (validator->value.v_doc.data_len > (uint32_t) MaxSchemaValidatorSize)
1995 {
1996 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
1997 errmsg(
1998 "validator of size > %dKB is not supported. Contact Azure Support if you need to increase this limit.",
1999 MaxSchemaValidatorSize / 1024),
2000 errmsg(
2001 "validator of size > %dKB is not supported. Contact Azure Support if you need to increase this limit.",
2002 MaxSchemaValidatorSize / 1024)));
2003 }
2004
2005 ProcessJsonschemaInIter(iter);
2006
2007 *hasValue = true;
2008 return validator;
2009}
2010
2011
2012/*

Callers 2

ParseCreateSpecFunction · 0.85

Calls 2

EnsureTopLevelFieldTypeFunction · 0.85
ProcessJsonschemaInIterFunction · 0.85

Tested by

no test coverage detected