Search in sources :

Example 56 with Type

use of com.google.api.expr.v1alpha1.Type in project java-spanner by googleapis.

the class SpannerClientTest method executeStreamingSqlExceptionTest.

@Test
public void executeStreamingSqlExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockSpanner.addException(exception);
    ExecuteSqlRequest request = ExecuteSqlRequest.newBuilder().setSession(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).setTransaction(TransactionSelector.newBuilder().build()).setSql("sql114126").setParams(Struct.newBuilder().build()).putAllParamTypes(new HashMap<String, Type>()).setResumeToken(ByteString.EMPTY).setPartitionToken(ByteString.EMPTY).setSeqno(109325920).setQueryOptions(ExecuteSqlRequest.QueryOptions.newBuilder().build()).setRequestOptions(RequestOptions.newBuilder().build()).build();
    MockStreamObserver<PartialResultSet> responseObserver = new MockStreamObserver<>();
    ServerStreamingCallable<ExecuteSqlRequest, PartialResultSet> callable = client.executeStreamingSqlCallable();
    callable.serverStreamingCall(request, responseObserver);
    try {
        List<PartialResultSet> actualResponses = responseObserver.future().get();
        Assert.fail("No exception thrown");
    } catch (ExecutionException e) {
        Assert.assertTrue(e.getCause() instanceof InvalidArgumentException);
        InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
        Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
    }
}
Also used : Type(com.google.spanner.v1.Type) ExecuteSqlRequest(com.google.spanner.v1.ExecuteSqlRequest) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) MockStreamObserver(com.google.api.gax.grpc.testing.MockStreamObserver) ExecutionException(java.util.concurrent.ExecutionException) PartialResultSet(com.google.spanner.v1.PartialResultSet) Test(org.junit.Test)

Example 57 with Type

use of com.google.api.expr.v1alpha1.Type in project java-spanner by googleapis.

the class SpannerClientTest method partitionQueryTest.

@Test
public void partitionQueryTest() throws Exception {
    PartitionResponse expectedResponse = PartitionResponse.newBuilder().addAllPartitions(new ArrayList<Partition>()).setTransaction(Transaction.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    PartitionQueryRequest request = PartitionQueryRequest.newBuilder().setSession(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).setTransaction(TransactionSelector.newBuilder().build()).setSql("sql114126").setParams(Struct.newBuilder().build()).putAllParamTypes(new HashMap<String, Type>()).setPartitionOptions(PartitionOptions.newBuilder().build()).build();
    PartitionResponse actualResponse = client.partitionQuery(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    PartitionQueryRequest actualRequest = ((PartitionQueryRequest) actualRequests.get(0));
    Assert.assertEquals(request.getSession(), actualRequest.getSession());
    Assert.assertEquals(request.getTransaction(), actualRequest.getTransaction());
    Assert.assertEquals(request.getSql(), actualRequest.getSql());
    Assert.assertEquals(request.getParams(), actualRequest.getParams());
    Assert.assertEquals(request.getParamTypesMap(), actualRequest.getParamTypesMap());
    Assert.assertEquals(request.getPartitionOptions(), actualRequest.getPartitionOptions());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : PartitionResponse(com.google.spanner.v1.PartitionResponse) Partition(com.google.spanner.v1.Partition) Type(com.google.spanner.v1.Type) AbstractMessage(com.google.protobuf.AbstractMessage) PartitionQueryRequest(com.google.spanner.v1.PartitionQueryRequest) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 58 with Type

use of com.google.api.expr.v1alpha1.Type in project cel-java by projectnessie.

the class ConformanceServerTest method expectEvalTrue.

/**
 * expectEvalTrue parses, checks, and evaluates the CEL expression in source and checks that the
 * result is the boolean value 'true'.
 */
void expectEvalTrue(String source) {
    FullPipelineResult fp = fullPipeline(source);
    long rootID = fp.parseResponse.getParsedExpr().getExpr().getId();
    Type topType = fp.checkResponse.getCheckedExpr().getTypeMapMap().get(rootID);
    assertThat(topType).extracting(Type::getTypeKindCase).isEqualTo(Type.TypeKindCase.PRIMITIVE);
    assertThat(topType).extracting(Type::getPrimitive).isEqualTo(Type.PrimitiveType.BOOL);
    ExprValue er = fp.evalResponse.getResult();
    assertThat(er).extracting(ExprValue::getKindCase).isEqualTo(ExprValue.KindCase.VALUE);
    Value ev = er.getValue();
    assertThat(ev).extracting(Value::getKindCase).isEqualTo(Value.KindCase.BOOL_VALUE);
    assertThat(ev).extracting(Value::getBoolValue).isEqualTo(true);
}
Also used : PrimitiveType(com.google.api.expr.v1alpha1.Type.PrimitiveType) Type(com.google.api.expr.v1alpha1.Type) ExprValue(com.google.api.expr.v1alpha1.ExprValue) Value(com.google.api.expr.v1alpha1.Value) ExprValue(com.google.api.expr.v1alpha1.ExprValue)

Example 59 with Type

use of com.google.api.expr.v1alpha1.Type in project cel-java by projectnessie.

the class ConformanceServerTest method Check.

/**
 * TestCheck tests the Check method.
 */
@Test
void Check() {
    // If TestParse() passes, it validates a good chunk
    // of the server mechanisms for data conversion, so we
    // won't be as fussy here..
    CheckRequest req = CheckRequest.newBuilder().setParsedExpr(parsed).build();
    CheckResponse res = stub.check(req);
    assertThat(res.isInitialized()).isTrue();
    assertThat(res.getCheckedExpr().isInitialized()).isTrue();
    Type tp = res.getCheckedExpr().getTypeMapMap().get(1L);
    assertThat(tp).isNotNull();
    assertThat(tp.getTypeKindCase()).isSameAs(TypeKindCase.PRIMITIVE);
    assertThat(tp.getPrimitive()).isSameAs(PrimitiveType.INT64);
}
Also used : PrimitiveType(com.google.api.expr.v1alpha1.Type.PrimitiveType) Type(com.google.api.expr.v1alpha1.Type) CheckResponse(com.google.api.expr.v1alpha1.CheckResponse) CheckRequest(com.google.api.expr.v1alpha1.CheckRequest) Test(org.junit.jupiter.api.Test)

Example 60 with Type

use of com.google.api.expr.v1alpha1.Type in project cel-java by projectnessie.

the class ConformanceServerTest method FullUp.

/**
 * TestFullUp tests Parse, Check, and Eval back-to-back.
 */
@Test
void FullUp() {
    ParseRequest preq = ParseRequest.newBuilder().setCelSource("x + y").build();
    ParseResponse pres = stub.parse(preq);
    assertThat(pres.isInitialized()).isTrue();
    ParsedExpr parsedExpr = pres.getParsedExpr();
    assertThat(parsedExpr.isInitialized()).isTrue();
    CheckRequest creq = CheckRequest.newBuilder().setParsedExpr(parsedExpr).addTypeEnv(Decls.newVar("x", Decls.Int)).addTypeEnv(Decls.newVar("y", Decls.Int)).build();
    CheckResponse cres = stub.check(creq);
    assertThat(cres.isInitialized()).isTrue();
    CheckedExpr checkedExpr = cres.getCheckedExpr();
    assertThat(checkedExpr.isInitialized()).isTrue();
    Type tp = checkedExpr.getTypeMapMap().get(1L);
    assertThat(tp).isNotNull();
    assertThat(tp.getTypeKindCase()).isSameAs(TypeKindCase.PRIMITIVE);
    assertThat(tp.getPrimitive()).isSameAs(PrimitiveType.INT64);
    EvalRequest ereq = EvalRequest.newBuilder().setCheckedExpr(checkedExpr).putBindings("x", exprValueInt64(1)).putBindings("y", exprValueInt64(2)).build();
    EvalResponse eres = stub.eval(ereq);
    assertThat(eres.isInitialized()).isTrue();
    assertThat(eres.getResult().isInitialized()).isTrue();
    assertThat(eres.getResult().getKindCase()).isSameAs(KindCase.VALUE);
    assertThat(eres.getResult().getValue().getKindCase()).isSameAs(Value.KindCase.INT64_VALUE);
    assertThat(eres.getResult().getValue().getInt64Value()).isEqualTo(3L);
}
Also used : EvalRequest(com.google.api.expr.v1alpha1.EvalRequest) PrimitiveType(com.google.api.expr.v1alpha1.Type.PrimitiveType) Type(com.google.api.expr.v1alpha1.Type) ParseRequest(com.google.api.expr.v1alpha1.ParseRequest) CheckedExpr(com.google.api.expr.v1alpha1.CheckedExpr) ParsedExpr(com.google.api.expr.v1alpha1.ParsedExpr) CheckResponse(com.google.api.expr.v1alpha1.CheckResponse) CheckRequest(com.google.api.expr.v1alpha1.CheckRequest) ParseResponse(com.google.api.expr.v1alpha1.ParseResponse) EvalResponse(com.google.api.expr.v1alpha1.EvalResponse) Test(org.junit.jupiter.api.Test)

Aggregations

Type (com.google.api.expr.v1alpha1.Type)30 Test (org.junit.Test)16 MapType (com.google.api.expr.v1alpha1.Type.MapType)15 Type (edu.stanford.CVC4.Type)14 Type (com.google.spanner.v1.Type)12 Test (org.junit.jupiter.api.Test)12 CheckedExpr (com.google.api.expr.v1alpha1.CheckedExpr)11 ByteString (com.google.protobuf.ByteString)11 ArrayType (edu.stanford.CVC4.ArrayType)11 BitVectorType (edu.stanford.CVC4.BitVectorType)11 Expr (edu.stanford.CVC4.Expr)11 ArrayList (java.util.ArrayList)11 Type (org.apache.xbean.asm9.Type)10 Expr (com.google.api.expr.v1alpha1.Expr)9 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)9 FieldType (org.projectnessie.cel.common.types.ref.FieldType)8 ListValue (com.google.protobuf.ListValue)7 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)7 CheckerEnv.dynElementType (org.projectnessie.cel.checker.CheckerEnv.dynElementType)7 CheckerEnv.getObjectWellKnownType (org.projectnessie.cel.checker.CheckerEnv.getObjectWellKnownType)7