use of com.google.api.expr.v1alpha1.Constant in project cel-java by projectnessie.
the class Env method residualAst.
/**
* ResidualAst takes an Ast and its EvalDetails to produce a new Ast which only contains the
* attribute references which are unknown.
*
* <p>Residual expressions are beneficial in a few scenarios:
*
* <ul>
* <li>Optimizing constant expression evaluations away.
* <li>Indexing and pruning expressions based on known input arguments.
* <li>Surfacing additional requirements that are needed in order to complete an evaluation.
* <li>Sharing the evaluation of an expression across multiple machines/nodes.
* </ul>
*
* <p>For example, if an expression targets a 'resource' and 'request' attribute and the possible
* values for the resource are known, a PartialActivation could mark the 'request' as an unknown
* interpreter.AttributePattern and the resulting ResidualAst would be reduced to only the parts
* of the expression that reference the 'request'.
*
* <p>Note, the expression ids within the residual AST generated through this method have no
* correlation to the expression ids of the original AST.
*
* <p>See the PartialVars helper for how to construct a PartialActivation.
*
* <p>TODO: Consider adding an option to generate a Program.Residual to avoid round-tripping to an
* Ast format and then Program again.
*/
public Ast residualAst(Ast a, EvalDetails details) {
Expr pruned = pruneAst(a.getExpr(), details.getState());
String expr = astToString(parsedExprToAst(ParsedExpr.newBuilder().setExpr(pruned).build()));
AstIssuesTuple parsedIss = parse(expr);
if (parsedIss.hasIssues()) {
throw parsedIss.getIssues().err();
}
if (!a.isChecked()) {
return parsedIss.ast;
}
AstIssuesTuple checkedIss = check(parsedIss.ast);
if (checkedIss.hasIssues()) {
throw checkedIss.getIssues().err();
}
return checkedIss.ast;
}
use of com.google.api.expr.v1alpha1.Constant in project cel-java by projectnessie.
the class ProviderTest method typeRegistryNewValue_OneofFields.
@Test
void typeRegistryNewValue_OneofFields() {
TypeRegistry reg = newRegistry(CheckedExpr.getDefaultInstance(), ParsedExpr.getDefaultInstance());
Val exp = reg.newValue("google.api.expr.v1alpha1.CheckedExpr", mapOf("expr", reg.newValue("google.api.expr.v1alpha1.Expr", mapOf("const_expr", reg.newValue("google.api.expr.v1alpha1.Constant", mapOf("string_value", stringOf("oneof")))))));
assertThat(exp).matches(v -> !Err.isError(v));
CheckedExpr ce = exp.convertToNative(CheckedExpr.class);
assertThat(ce).extracting(CheckedExpr::getExpr).extracting(Expr::getConstExpr).extracting(Constant::getStringValue).isEqualTo("oneof");
}
Aggregations