Files
documentdb/pg_documentdb/include/schema_validation/schema_validation.h
T
Jia Hu 07f6bec52f Merged PR 1523428: [schema validation] apply to stage $merge/$out
### Does this PR have any customer impact?

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)

### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)

### Are you introducing any new config? If yes, do you have tests with and without them being set?

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description

[schema validation] apply to stage $merge/$out

----
#### AI description  (iteration 1)
#### PR Classification
New feature

#### PR Summary
This pull request introduces schema validation for the `$merge` and `$out` stages in MongoDB aggregation pipelines.
- Added `schema_validation_merge.md` to document the design and implementation details.
- Created new SQL functions in `bson_merge_functions--1.24-0.sql` to handle schema validation during the `$merge` stage.
- Updated `bson_aggregation_output_pipeline.c` to integrate schema validation logic into the `$merge` and `$out` stages.
- Modified `toc.yml` to include the new schema validation documentation.
- Updated `pgmongo--1.23-0--1.24-0.sql` and `pg_helio_api--1.23-0--1.24-0.sql` to include the new SQL functions.
2025-03-18 21:57:32 -07:00

47 lines
1.7 KiB
C

/*-------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* src/schema_validation.h
*
* Common declarations for schema validation functions.
*
*-------------------------------------------------------------------------
*/
#ifndef SCHEMA_VALIDATION_H
#define SCHEMA_VALIDATION_H
#include "metadata/collection.h"
#include "operators/bson_expr_eval.h"
extern bool EnableSchemaValidation;
#define FAILED_VALIDATION_ERROR_MSG "Document failed validation"
#define FAILED_VALIDATION_PLAN_EXECUTOR_ERROR_MSG \
"PlanExecutor error during aggregation :: caused by :: Document failed validation"
ExprEvalState * PrepareForSchemaValidation(pgbson *schemaValidationInfo, MemoryContext
memoryContext);
void AssignSchemaValidationState(ExprEvalState *state, pgbson *schemaValidationInfo,
MemoryContext memoryContext);
void ValidateSchemaOnDocumentInsert(ExprEvalState *evalState, const
bson_value_t *document, const char *errMsg);
void ValidateSchemaOnDocumentUpdate(ValidationLevels validationLevelText,
ExprEvalState *evalState,
const pgbson *sourceDocument,
const pgbson *targetDocument,
const char *errMsg);
/* Inline function that determines whether to perform schema validation */
static inline bool
CheckSchemaValidationEnabled(MongoCollection *collection, bool bypassDocumentValidation)
{
return EnableSchemaValidation && collection->schemaValidator.validationLevel !=
ValidationLevel_Off && !bypassDocumentValidation &&
collection->schemaValidator.validator != NULL &&
collection->schemaValidator.validationAction == ValidationAction_Error;
}
#endif