use of com.google.api.expr.v1alpha1.Value in project java-firestore by googleapis.
the class QueryTest method withEqualityFilterForDocumentSnapshotCursor.
@Test
public void withEqualityFilterForDocumentSnapshotCursor() {
doAnswer(queryResponse()).when(firestoreMock).streamRequest(runQuery.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any());
query.whereEqualTo("foo", "bar").startAt(SINGLE_FIELD_SNAPSHOT).get();
Value documentBoundary = reference(DOCUMENT_NAME);
RunQueryRequest queryRequest = query(filter(Operator.EQUAL), order("__name__", StructuredQuery.Direction.ASCENDING), startAt(documentBoundary, true));
assertEquals(queryRequest, runQuery.getValue());
}
use of com.google.api.expr.v1alpha1.Value in project java-firestore by googleapis.
the class QueryTest method withInequalityFilterForDocumentSnapshotCursor.
@Test
public void withInequalityFilterForDocumentSnapshotCursor() {
doAnswer(queryResponse()).when(firestoreMock).streamRequest(runQuery.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any());
query.whereEqualTo("a", "b").whereGreaterThanOrEqualTo("foo", "bar").whereEqualTo("c", "d").startAt(SINGLE_FIELD_SNAPSHOT).get();
Value documentBoundary = reference(DOCUMENT_NAME);
RunQueryRequest queryRequest = query(filter(Operator.EQUAL, "a", "b"), filter(Operator.GREATER_THAN_OR_EQUAL), filter(Operator.EQUAL, "c", "d"), order("foo", Direction.ASCENDING), order("__name__", StructuredQuery.Direction.ASCENDING), startAt(true), startAt(documentBoundary, true));
assertEquals(queryRequest, runQuery.getValue());
}
use of com.google.api.expr.v1alpha1.Value in project java-firestore by googleapis.
the class QueryTest method withDocumentIdAndDocumentSnapshotCursor.
@Test
public void withDocumentIdAndDocumentSnapshotCursor() {
doAnswer(queryResponse()).when(firestoreMock).streamRequest(runQuery.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any());
query.orderBy(FieldPath.documentId()).startAt(SINGLE_FIELD_SNAPSHOT).get();
Value documentBoundary = reference(DOCUMENT_NAME);
RunQueryRequest queryRequest = query(order("__name__", StructuredQuery.Direction.ASCENDING), startAt(documentBoundary, true));
assertEquals(queryRequest, runQuery.getValue());
}
use of com.google.api.expr.v1alpha1.Value in project cel-java by projectnessie.
the class CELTest method CustomInterpreterDecorator.
@Test
void CustomInterpreterDecorator() {
AtomicReference<Interpretable> lastInstruction = new AtomicReference<>();
InterpretableDecorator optimizeArith = i -> {
lastInstruction.set(i);
// Only optimize the instruction if it is a call.
if (!(i instanceof InterpretableCall)) {
return i;
}
InterpretableCall call = (InterpretableCall) i;
// Only optimize the math functions when they have constant arguments.
switch(call.function()) {
case "_+_":
case "_-_":
case "_*_":
case "_/_":
// These are all binary operators so they should have to arguments
Interpretable[] args = call.args();
// an empty activation and the value returns as a constant.
if (!(args[0] instanceof InterpretableConst) || !(args[1] instanceof InterpretableConst)) {
return i;
}
Val val = call.eval(emptyActivation());
if (isError(val)) {
throw new RuntimeException(val.toString());
}
return newConstValue(call.id(), val);
default:
return i;
}
};
Env env = newEnv(declarations(Decls.newVar("foo", Decls.Int)));
AstIssuesTuple astIss = env.compile("foo == -1 + 2 * 3 / 3");
env.program(astIss.getAst(), evalOptions(OptPartialEval), customDecorator(optimizeArith));
assertThat(lastInstruction.get()).isInstanceOf(InterpretableCall.class);
InterpretableCall call = (InterpretableCall) lastInstruction.get();
Interpretable[] args = call.args();
Interpretable lhs = args[0];
assertThat(lhs).isInstanceOf(InterpretableAttribute.class);
InterpretableAttribute lastAttr = (InterpretableAttribute) lhs;
NamespacedAttribute absAttr = (NamespacedAttribute) lastAttr.attr();
String[] varNames = absAttr.candidateVariableNames();
assertThat(varNames).containsExactly("foo");
Interpretable rhs = args[1];
assertThat(rhs).isInstanceOf(InterpretableConst.class);
InterpretableConst lastConst = (InterpretableConst) rhs;
// This is the last number produced by the optimization.
assertThat(lastConst.value()).isSameAs(IntOne);
}
use of com.google.api.expr.v1alpha1.Value in project cel-java by projectnessie.
the class AstPruner method maybePruneConditional.
Expr maybePruneConditional(Expr node) {
if (!existsWithUnknownValue(node.getId())) {
return null;
}
Call call = node.getCallExpr();
Val condVal = value(call.getArgs(0).getId());
if (condVal == null || isUnknownOrError(condVal)) {
return null;
}
if (condVal == True) {
return call.getArgs(1);
}
return call.getArgs(2);
}
Aggregations