MCPcopy Create free account
hub / github.com/apache/cloudberry / CheckForAssertViolations

Function CheckForAssertViolations

src/backend/executor/nodeAssertOp.c:27–64  ·  view source on GitHub ↗

* Check for assert violations and error out, if any. */

Source from the content-addressed store, hash-verified

25 * Check for assert violations and error out, if any.
26 */
27static void
28CheckForAssertViolations(AssertOpState* node, TupleTableSlot* slot)
29{
30 AssertOp* plannode = (AssertOp*) node->ps.plan;
31 ExprContext* econtext = node->ps.ps_ExprContext;
32 ResetExprContext(econtext);
33 /* Arrange for econtext's scan tuple to be the tuple under test */
34 econtext->ecxt_outertuple = slot;
35 /*
36 * Run in short-lived per-tuple context while computing expressions.
37 */
38 MemoryContext oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
39 StringInfoData errorString;
40 initStringInfo(&errorString);
41
42 ExprState *clause = node->ps.qual;
43 bool isNull = false;
44 Datum expr_value = ExecEvalExpr(clause, econtext, &isNull);
45
46 if (!isNull && !DatumGetBool(expr_value))
47 {
48 Value *valErrorMessage = (Value*) list_nth(plannode->errmessage, 0);
49
50 Assert(NULL != valErrorMessage && IsA(valErrorMessage, String) &&
51 0 < strlen(strVal(valErrorMessage)));
52
53 appendStringInfo(&errorString, "%s\n", strVal(valErrorMessage));
54
55 ereport(ERROR,
56 (errcode(plannode->errcode),
57 errmsg("one or more assertions failed"),
58 errdetail("%s", errorString.data)));
59 }
60
61 pfree(errorString.data);
62 MemoryContextSwitchTo(oldContext);
63 ResetExprContext(econtext);
64}
65
66/*
67 * Evaluate Constraints (in node->ps.qual) and project output TupleTableSlot.

Callers 1

ExecAssertOpFunction · 0.85

Calls 10

MemoryContextSwitchToFunction · 0.85
initStringInfoFunction · 0.85
ExecEvalExprFunction · 0.85
DatumGetBoolFunction · 0.85
list_nthFunction · 0.85
appendStringInfoFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
errdetailFunction · 0.50
pfreeFunction · 0.50

Tested by

no test coverage detected