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

Function evaluateExpr

src/bin/pgbench/pgbench.c:2654–2693  ·  view source on GitHub ↗

* Recursive evaluation of an expression in a pgbench script * using the current state of variables. * Returns whether the evaluation was ok, * the value itself is returned through the retval pointer. */

Source from the content-addressed store, hash-verified

2652 * the value itself is returned through the retval pointer.
2653 */
2654static bool
2655evaluateExpr(CState *st, PgBenchExpr *expr, PgBenchValue *retval)
2656{
2657 switch (expr->etype)
2658 {
2659 case ENODE_CONSTANT:
2660 {
2661 *retval = expr->u.constant;
2662 return true;
2663 }
2664
2665 case ENODE_VARIABLE:
2666 {
2667 Variable *var;
2668
2669 if ((var = lookupVariable(st, expr->u.variable.varname)) == NULL)
2670 {
2671 pg_log_error("undefined variable \"%s\"", expr->u.variable.varname);
2672 return false;
2673 }
2674
2675 if (!makeVariableValue(var))
2676 return false;
2677
2678 *retval = var->value;
2679 return true;
2680 }
2681
2682 case ENODE_FUNCTION:
2683 return evalFunc(st,
2684 expr->u.function.function,
2685 expr->u.function.args,
2686 retval);
2687
2688 default:
2689 /* internal error which should never occur */
2690 pg_log_fatal("unexpected enode type in evaluation: %d", expr->etype);
2691 exit(1);
2692 }
2693}
2694
2695/*
2696 * Convert command name to meta-command enum identifier

Callers 3

evalLazyFuncFunction · 0.85
evalStandardFuncFunction · 0.85
executeMetaCommandFunction · 0.85

Calls 3

lookupVariableFunction · 0.85
makeVariableValueFunction · 0.85
evalFuncFunction · 0.85

Tested by

no test coverage detected