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

Function ValidateQueryDocuments

pg_documentdb/src/commands/delete.c:1812–1860  ·  view source on GitHub ↗

* ValidateQueryDocuments validates query document of each deletion specified * by given BatchDeletionSpec and returns a list of write errors. * * Stops after the first failure if the deletion mode is ordered. * * This is useful for performing query document validations when we certainly * know that the delete operation would become a noop due to non-existent * collection. * * Otherwise, i

Source from the content-addressed store, hash-verified

1810 * in the run-time to implicitly perform necessary validations.
1811 */
1812static List *
1813ValidateQueryDocuments(BatchDeletionSpec *batchSpec)
1814{
1815 /* declared volatile because of the longjmp in PG_CATCH */
1816 List *volatile writeErrorList = NIL;
1817
1818 /*
1819 * Weirdly, compiler complains that writeErrorIdx might be clobbered by
1820 * longjmp in PG_CATCH, so declare writeErrorIdx as volatile as well.
1821 */
1822 for (volatile int writeErrorIdx = 0;
1823 writeErrorIdx < list_length(batchSpec->deletionsProcessed);
1824 writeErrorIdx++)
1825 {
1826 DeletionSpec *deletionSpec = list_nth(batchSpec->deletionsProcessed,
1827 writeErrorIdx);
1828
1829 /* declared volatile because of the longjmp in PG_CATCH */
1830 volatile bool isSuccess = false;
1831
1832 MemoryContext oldContext = CurrentMemoryContext;
1833 PG_TRY();
1834 {
1835 ValidateQueryDocumentValue(deletionSpec->deleteOneParams.query);
1836 isSuccess = true;
1837 }
1838 PG_CATCH();
1839 {
1840 MemoryContextSwitchTo(oldContext);
1841 ErrorData *errorData = CopyErrorDataAndFlush();
1842
1843 writeErrorList = lappend(writeErrorList, GetWriteErrorFromErrorData(errorData,
1844 writeErrorIdx));
1845 isSuccess = false;
1846 }
1847 PG_END_TRY();
1848
1849 if (!isSuccess && batchSpec->isOrdered)
1850 {
1851 /*
1852 * Stop validating query documents after a failure if using
1853 * ordered:true.
1854 */
1855 break;
1856 }
1857 }
1858
1859 return writeErrorList;
1860}
1861
1862
1863/*

Callers 1

command_deleteFunction · 0.85

Calls 3

CopyErrorDataAndFlushFunction · 0.85

Tested by

no test coverage detected