Search in sources :

Example 1 with Type

use of com.google.api.expr.v1alpha1.Type in project tomee by apache.

the class CmrField method createSignature.

private static String createSignature(final Type type, final Type... genericTypes) {
    final StringBuilder builder = new StringBuilder();
    builder.append("L").append(type.getInternalName());
    if (genericTypes.length > 0) {
        builder.append("<");
        for (final Type genericType : genericTypes) {
            builder.append(genericType.getDescriptor());
        }
        builder.append(">");
    }
    builder.append(";");
    return builder.toString();
}
Also used : Type(org.apache.xbean.asm9.Type)

Example 2 with Type

use of com.google.api.expr.v1alpha1.Type in project tomee by apache.

the class DependencyVisitor method addMethodDesc.

private void addMethodDesc(final String desc) {
    addType(Type.getReturnType(desc));
    final Type[] types = Type.getArgumentTypes(desc);
    for (Type type : types) {
        addType(type);
    }
}
Also used : Type(org.apache.xbean.asm9.Type)

Example 3 with Type

use of com.google.api.expr.v1alpha1.Type in project tomee by apache.

the class DynamicSubclass method visitConstructor.

private static MethodVisitor visitConstructor(final ClassWriter cw, final String proxyClassFileName, final String classFileName, final Constructor<?> constructor) {
    final String descriptor = Type.getConstructorDescriptor(constructor);
    final String[] exceptions = new String[constructor.getExceptionTypes().length];
    for (int i = 0; i < exceptions.length; i++) {
        exceptions[i] = Type.getInternalName(constructor.getExceptionTypes()[i]);
    }
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", descriptor, null, exceptions);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    int index = 1;
    for (final Type type : Type.getArgumentTypes(descriptor)) {
        mv.visitVarInsn(type.getOpcode(ILOAD), index);
        index += size(type);
    }
    mv.visitMethodInsn(INVOKESPECIAL, classFileName, "<init>", descriptor, false);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(PUTFIELD, proxyClassFileName, "this$handler", "Ljava/lang/reflect/InvocationHandler;");
    mv.visitInsn(RETURN);
    mv.visitMaxs(2, 1);
    return mv;
}
Also used : Type(org.apache.xbean.asm9.Type) MethodVisitor(org.apache.xbean.asm9.MethodVisitor)

Example 4 with Type

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

the class MockSpannerServiceImpl method buildStatement.

@SuppressWarnings("unchecked")
private Statement buildStatement(String sql, Map<String, Type> paramTypes, com.google.protobuf.Struct params) {
    Statement.Builder builder = Statement.newBuilder(sql);
    // Set all untyped null values first.
    for (Entry<String, com.google.protobuf.Value> entry : params.getFieldsMap().entrySet()) {
        if (entry.getValue().hasNullValue() && !paramTypes.containsKey(entry.getKey())) {
            builder.bind(entry.getKey()).to((Value) null);
        }
    }
    for (Entry<String, Type> entry : paramTypes.entrySet()) {
        final String fieldName = entry.getKey();
        final Type fieldType = entry.getValue();
        final Type elementType = fieldType.getArrayElementType();
        com.google.protobuf.Value value = params.getFieldsOrThrow(fieldName);
        if (value.getKindCase() == KindCase.NULL_VALUE) {
            switch(fieldType.getCode()) {
                case ARRAY:
                    switch(elementType.getCode()) {
                        case BOOL:
                            builder.bind(fieldName).toBoolArray((Iterable<Boolean>) null);
                            break;
                        case BYTES:
                            builder.bind(fieldName).toBytesArray(null);
                            break;
                        case DATE:
                            builder.bind(fieldName).toDateArray(null);
                            break;
                        case FLOAT64:
                            builder.bind(fieldName).toFloat64Array((Iterable<Double>) null);
                            break;
                        case INT64:
                            builder.bind(fieldName).toInt64Array((Iterable<Long>) null);
                            break;
                        case STRING:
                            builder.bind(fieldName).toStringArray(null);
                            break;
                        case NUMERIC:
                            if (elementType.getTypeAnnotation() == TypeAnnotationCode.PG_NUMERIC) {
                                builder.bind(fieldName).toPgNumericArray(null);
                            } else {
                                builder.bind(fieldName).toNumericArray(null);
                            }
                            break;
                        case TIMESTAMP:
                            builder.bind(fieldName).toTimestampArray(null);
                            break;
                        case JSON:
                            builder.bind(fieldName).toJsonArray(null);
                            break;
                        case STRUCT:
                        case TYPE_CODE_UNSPECIFIED:
                        case UNRECOGNIZED:
                        default:
                            throw new IllegalArgumentException("Unknown or invalid array parameter type: " + elementType.getCode());
                    }
                    break;
                case BOOL:
                    builder.bind(fieldName).to((Boolean) null);
                    break;
                case BYTES:
                    builder.bind(fieldName).to((ByteArray) null);
                    break;
                case DATE:
                    builder.bind(fieldName).to((Date) null);
                    break;
                case FLOAT64:
                    builder.bind(fieldName).to((Double) null);
                    break;
                case INT64:
                    builder.bind(fieldName).to((Long) null);
                    break;
                case STRING:
                    builder.bind(fieldName).to((String) null);
                    break;
                case NUMERIC:
                    if (fieldType.getTypeAnnotation() == TypeAnnotationCode.PG_NUMERIC) {
                        builder.bind(fieldName).to(Value.pgNumeric(null));
                    } else {
                        builder.bind(fieldName).to((BigDecimal) null);
                    }
                    break;
                case STRUCT:
                    builder.bind(fieldName).to((Struct) null);
                    break;
                case TIMESTAMP:
                    builder.bind(fieldName).to((com.google.cloud.Timestamp) null);
                    break;
                case JSON:
                    builder.bind(fieldName).to(Value.json(null));
                    break;
                case TYPE_CODE_UNSPECIFIED:
                case UNRECOGNIZED:
                default:
                    throw new IllegalArgumentException("Unknown parameter type: " + fieldType.getCode());
            }
        } else {
            switch(fieldType.getCode()) {
                case ARRAY:
                    switch(elementType.getCode()) {
                        case BOOL:
                            builder.bind(fieldName).toBoolArray((Iterable<Boolean>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.bool(), value.getListValue()));
                            break;
                        case BYTES:
                            builder.bind(fieldName).toBytesArray((Iterable<ByteArray>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.bytes(), value.getListValue()));
                            break;
                        case DATE:
                            builder.bind(fieldName).toDateArray((Iterable<Date>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.date(), value.getListValue()));
                            break;
                        case FLOAT64:
                            builder.bind(fieldName).toFloat64Array((Iterable<Double>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.float64(), value.getListValue()));
                            break;
                        case INT64:
                            builder.bind(fieldName).toInt64Array((Iterable<Long>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.int64(), value.getListValue()));
                            break;
                        case STRING:
                            builder.bind(fieldName).toStringArray((Iterable<String>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.string(), value.getListValue()));
                            break;
                        case NUMERIC:
                            if (elementType.getTypeAnnotation() == TypeAnnotationCode.PG_NUMERIC) {
                                builder.bind(fieldName).toPgNumericArray((Iterable<String>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.pgNumeric(), value.getListValue()));
                            } else {
                                builder.bind(fieldName).toNumericArray((Iterable<BigDecimal>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.numeric(), value.getListValue()));
                            }
                            break;
                        case TIMESTAMP:
                            builder.bind(fieldName).toTimestampArray((Iterable<com.google.cloud.Timestamp>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.timestamp(), value.getListValue()));
                            break;
                        case JSON:
                            builder.bind(fieldName).toJsonArray((Iterable<String>) GrpcStruct.decodeArrayValue(com.google.cloud.spanner.Type.json(), value.getListValue()));
                            break;
                        case STRUCT:
                        case TYPE_CODE_UNSPECIFIED:
                        case UNRECOGNIZED:
                        default:
                            throw new IllegalArgumentException("Unknown or invalid array parameter type: " + elementType.getCode());
                    }
                    break;
                case BOOL:
                    builder.bind(fieldName).to(value.getBoolValue());
                    break;
                case BYTES:
                    builder.bind(fieldName).to(ByteArray.fromBase64(value.getStringValue()));
                    break;
                case DATE:
                    builder.bind(fieldName).to(Date.parseDate(value.getStringValue()));
                    break;
                case FLOAT64:
                    builder.bind(fieldName).to(value.getNumberValue());
                    break;
                case INT64:
                    builder.bind(fieldName).to(Long.valueOf(value.getStringValue()));
                    break;
                case STRING:
                    builder.bind(fieldName).to(value.getStringValue());
                    break;
                case NUMERIC:
                    if (fieldType.getTypeAnnotation() == TypeAnnotationCode.PG_NUMERIC) {
                        builder.bind(fieldName).to(Value.pgNumeric(value.getStringValue()));
                    } else {
                        builder.bind(fieldName).to(new BigDecimal(value.getStringValue()));
                    }
                    break;
                case STRUCT:
                    throw new IllegalArgumentException("Struct parameters not (yet) supported");
                case TIMESTAMP:
                    builder.bind(fieldName).to(com.google.cloud.Timestamp.parseTimestamp(value.getStringValue()));
                    break;
                case JSON:
                    builder.bind(fieldName).to(Value.json(value.getStringValue()));
                    break;
                case TYPE_CODE_UNSPECIFIED:
                case UNRECOGNIZED:
                default:
                    throw new IllegalArgumentException("Unknown parameter type: " + fieldType.getCode());
            }
        }
    }
    return builder.build();
}
Also used : ByteString(com.google.protobuf.ByteString) Timestamp(com.google.protobuf.Timestamp) Date(com.google.cloud.Date) BigDecimal(java.math.BigDecimal) StructType(com.google.spanner.v1.StructType) Type(com.google.spanner.v1.Type) ListValue(com.google.protobuf.ListValue) AtomicLong(java.util.concurrent.atomic.AtomicLong) ByteArray(com.google.cloud.ByteArray) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 5 with Type

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

the class SpannerClientTest method executeStreamingSqlTest.

@Test
public void executeStreamingSqlTest() throws Exception {
    PartialResultSet expectedResponse = PartialResultSet.newBuilder().setMetadata(ResultSetMetadata.newBuilder().build()).addAllValues(new ArrayList<Value>()).setChunkedValue(true).setResumeToken(ByteString.EMPTY).setStats(ResultSetStats.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    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);
    List<PartialResultSet> actualResponses = responseObserver.future().get();
    Assert.assertEquals(1, actualResponses.size());
    Assert.assertEquals(expectedResponse, actualResponses.get(0));
}
Also used : Type(com.google.spanner.v1.Type) ExecuteSqlRequest(com.google.spanner.v1.ExecuteSqlRequest) ListValue(com.google.protobuf.ListValue) Value(com.google.protobuf.Value) ByteString(com.google.protobuf.ByteString) MockStreamObserver(com.google.api.gax.grpc.testing.MockStreamObserver) PartialResultSet(com.google.spanner.v1.PartialResultSet) Test(org.junit.Test)

Aggregations

Type (com.google.api.expr.v1alpha1.Type)30 MapType (com.google.api.expr.v1alpha1.Type.MapType)15 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 ArrayList (java.util.ArrayList)10 Type (org.apache.xbean.asm9.Type)10 Expr (com.google.api.expr.v1alpha1.Expr)9 Test (org.junit.Test)9 ListValue (com.google.protobuf.ListValue)8 FieldType (org.projectnessie.cel.common.types.ref.FieldType)8 Val (org.projectnessie.cel.common.types.ref.Val)8 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 CheckerEnv.isObjectWellKnownType (org.projectnessie.cel.checker.CheckerEnv.isObjectWellKnownType)7 ParsedExpr (com.google.api.expr.v1alpha1.ParsedExpr)6 Value (com.google.protobuf.Value)6 Types.formatCheckedType (org.projectnessie.cel.checker.Types.formatCheckedType)6