Search in sources :

Example 1 with Type

use of com.acgist.snail.pojo.bean.M3u8.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 2 with Type

use of com.acgist.snail.pojo.bean.M3u8.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)

Example 3 with Type

use of com.acgist.snail.pojo.bean.M3u8.Type in project openwebbeans by apache.

the class NormalScopeProxyFactory method delegateNonInterceptedMethods.

@Override
protected void delegateNonInterceptedMethods(ClassLoader classLoader, ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, Method[] noninterceptedMethods) throws ProxyGenerationException {
    for (Method delegatedMethod : noninterceptedMethods) {
        if (isIgnoredMethod(delegatedMethod)) {
            return;
        }
        String methodDescriptor = Type.getMethodDescriptor(delegatedMethod);
        // X TODO handle generic exception types?
        Class[] exceptionTypes = delegatedMethod.getExceptionTypes();
        String[] exceptionTypeNames = new String[exceptionTypes.length];
        for (int i = 0; i < exceptionTypes.length; i++) {
            exceptionTypeNames[i] = Type.getType(exceptionTypes[i]).getInternalName();
        }
        int targetModifiers = delegatedMethod.getModifiers() & (Modifier.PROTECTED | Modifier.PUBLIC | MODIFIER_VARARGS);
        MethodVisitor mv = cw.visitMethod(targetModifiers, delegatedMethod.getName(), methodDescriptor, null, exceptionTypeNames);
        // fill method body
        mv.visitCode();
        // load the contextual instance Provider
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, proxyClassFileName, FIELD_INSTANCE_PROVIDER, Type.getDescriptor(Provider.class));
        // invoke the get() method on the Provider
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Provider.class), "get", "()Ljava/lang/Object;", true);
        // and convert the Object to the target class type
        mv.visitTypeInsn(Opcodes.CHECKCAST, Type.getInternalName(classToProxy));
        // now calculate the parameters
        int offset = 1;
        for (Class<?> aClass : delegatedMethod.getParameterTypes()) {
            Type type = Type.getType(aClass);
            mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), offset);
            offset += type.getSize();
        }
        // and finally invoke the target method on the provided Contextual Instance
        Type declaringClass = Type.getType(delegatedMethod.getDeclaringClass());
        boolean interfaceMethod = Modifier.isInterface(delegatedMethod.getDeclaringClass().getModifiers());
        mv.visitMethodInsn(interfaceMethod ? Opcodes.INVOKEINTERFACE : Opcodes.INVOKEVIRTUAL, declaringClass.getInternalName(), delegatedMethod.getName(), methodDescriptor, interfaceMethod);
        generateReturn(mv, delegatedMethod);
        mv.visitMaxs(-1, -1);
        mv.visitEnd();
    }
}
Also used : Type(org.apache.xbean.asm9.Type) Method(java.lang.reflect.Method) MethodVisitor(org.apache.xbean.asm9.MethodVisitor) Provider(javax.inject.Provider)

Example 4 with Type

use of com.acgist.snail.pojo.bean.M3u8.Type in project osate2 by osate.

the class TypedElementImpl method setType.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setType(Type newType) {
    Type oldType = type;
    type = newType;
    if (eNotificationRequired()) {
        eNotify(new ENotificationImpl(this, Notification.SET, Aadl2Package.TYPED_ELEMENT__TYPE, oldType, type));
    }
}
Also used : Type(org.osate.aadl2.Type) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 5 with Type

use of com.acgist.snail.pojo.bean.M3u8.Type in project cel-java by projectnessie.

the class CELTest method GlobalVars.

@Test
void GlobalVars() {
    Type mapStrDyn = Decls.newMapType(Decls.String, Decls.Dyn);
    Env e = newEnv(declarations(Decls.newVar("attrs", mapStrDyn), Decls.newVar("default", Decls.Dyn), Decls.newFunction("get", Decls.newInstanceOverload("get_map", asList(mapStrDyn, Decls.String, Decls.Dyn), Decls.Dyn))));
    AstIssuesTuple astIss = e.compile("attrs.get(\"first\", attrs.get(\"second\", default))");
    // Create the program.
    ProgramOption funcs = functions(Overload.function("get", args -> {
        if (args.length != 3) {
            return newErr("invalid arguments to 'get'");
        }
        if (!(args[0] instanceof Mapper)) {
            return newErr("invalid operand of type '%s' to obj.get(key, def)", args[0].type());
        }
        Mapper attrs = (Mapper) args[0];
        if (!(args[1] instanceof StringT)) {
            return newErr("invalid key of type '%s' to obj.get(key, def)", args[1].type());
        }
        StringT key = (StringT) args[1];
        Val defVal = args[2];
        if (attrs.contains(key) == True) {
            return attrs.get(key);
        }
        return defVal;
    }));
    // Global variables can be configured as a ProgramOption and optionally overridden on Eval.
    Program prg = e.program(astIss.getAst(), funcs, globals(mapOf("default", "third")));
    // t.Run("global_default", func(t *testing.T) {
    Object vars = mapOf("attrs", mapOf());
    EvalResult out = prg.eval(vars);
    assertThat(out.getVal().equal(stringOf("third"))).isSameAs(True);
    // })
    // t.Run("attrs_alt", func(t *testing.T) {
    vars = mapOf("attrs", mapOf("second", "yep"));
    out = prg.eval(vars);
    assertThat(out.getVal().equal(stringOf("yep"))).isSameAs(True);
    // })
    // t.Run("local_default", func(t *testing.T) {
    vars = mapOf("attrs", mapOf(), "default", "fourth");
    out = prg.eval(vars);
    assertThat(out.getVal().equal(stringOf("fourth"))).isSameAs(True);
// })
}
Also used : BoolT(org.projectnessie.cel.common.types.BoolT) Interpretable(org.projectnessie.cel.interpreter.Interpretable) Macro(org.projectnessie.cel.parser.Macro) Call(com.google.api.expr.v1alpha1.Expr.Call) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PartialActivation(org.projectnessie.cel.interpreter.Activation.PartialActivation) EnvOption.container(org.projectnessie.cel.EnvOption.container) Macro.newReceiverMacro(org.projectnessie.cel.parser.Macro.newReceiverMacro) Activation.emptyActivation(org.projectnessie.cel.interpreter.Activation.emptyActivation) Disabled(org.junit.jupiter.api.Disabled) InterpretableDecorator(org.projectnessie.cel.interpreter.InterpretableDecorator) Collections.singletonList(java.util.Collections.singletonList) True(org.projectnessie.cel.common.types.BoolT.True) Err.isError(org.projectnessie.cel.common.types.Err.isError) Container(org.projectnessie.cel.common.types.traits.Container) Arrays.asList(java.util.Arrays.asList) CEL.estimateCost(org.projectnessie.cel.CEL.estimateCost) OptPartialEval(org.projectnessie.cel.EvalOption.OptPartialEval) ProtoTypeRegistry.newEmptyRegistry(org.projectnessie.cel.common.types.pb.ProtoTypeRegistry.newEmptyRegistry) ParsedExpr(com.google.api.expr.v1alpha1.ParsedExpr) EnvOption.customTypeProvider(org.projectnessie.cel.EnvOption.customTypeProvider) Val(org.projectnessie.cel.common.types.ref.Val) TypeRegistry(org.projectnessie.cel.common.types.ref.TypeRegistry) InterpretableAttribute(org.projectnessie.cel.interpreter.Interpretable.InterpretableAttribute) Collections.emptyList(java.util.Collections.emptyList) Expr(com.google.api.expr.v1alpha1.Expr) Ident(com.google.api.expr.v1alpha1.Expr.Ident) InterpretableCall(org.projectnessie.cel.interpreter.Interpretable.InterpretableCall) OptExhaustiveEval(org.projectnessie.cel.EvalOption.OptExhaustiveEval) OptTrackState(org.projectnessie.cel.EvalOption.OptTrackState) StringT.stringOf(org.projectnessie.cel.common.types.StringT.stringOf) Decls(org.projectnessie.cel.checker.Decls) CEL.attributePattern(org.projectnessie.cel.CEL.attributePattern) Executors(java.util.concurrent.Executors) Test(org.junit.jupiter.api.Test) ProgramOption.functions(org.projectnessie.cel.ProgramOption.functions) DefaultTypeAdapter(org.projectnessie.cel.common.types.pb.DefaultTypeAdapter) Overload(org.projectnessie.cel.interpreter.functions.Overload) EvalResult(org.projectnessie.cel.Program.EvalResult) Err.newErr(org.projectnessie.cel.common.types.Err.newErr) IntOne(org.projectnessie.cel.common.types.IntT.IntOne) IntStream(java.util.stream.IntStream) Overloads(org.projectnessie.cel.common.types.Overloads) Env.newEnv(org.projectnessie.cel.Env.newEnv) StdLib(org.projectnessie.cel.Library.StdLib) IntT(org.projectnessie.cel.common.types.IntT) Trait(org.projectnessie.cel.common.types.traits.Trait) EnvOption.declarations(org.projectnessie.cel.EnvOption.declarations) CompletableFuture(java.util.concurrent.CompletableFuture) Err.valOrErr(org.projectnessie.cel.common.types.Err.valOrErr) CEL.partialVars(org.projectnessie.cel.CEL.partialVars) AtomicReference(java.util.concurrent.atomic.AtomicReference) EnvOption.customTypeAdapter(org.projectnessie.cel.EnvOption.customTypeAdapter) AstIssuesTuple(org.projectnessie.cel.Env.AstIssuesTuple) Mapper(org.projectnessie.cel.common.types.traits.Mapper) ProgramOption.evalOptions(org.projectnessie.cel.ProgramOption.evalOptions) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Type(com.google.api.expr.v1alpha1.Type) CEL.astToCheckedExpr(org.projectnessie.cel.CEL.astToCheckedExpr) CEL.noVars(org.projectnessie.cel.CEL.noVars) ExecutorService(java.util.concurrent.ExecutorService) Collections.emptyMap(java.util.Collections.emptyMap) CEL.astToString(org.projectnessie.cel.CEL.astToString) ProgramOption.globals(org.projectnessie.cel.ProgramOption.globals) Operator(org.projectnessie.cel.common.operators.Operator) NamespacedAttribute(org.projectnessie.cel.interpreter.AttributeFactory.NamespacedAttribute) UnknownT(org.projectnessie.cel.common.types.UnknownT) Cost(org.projectnessie.cel.interpreter.Coster.Cost) EnvOption.types(org.projectnessie.cel.EnvOption.types) ProgramOption.customDecorator(org.projectnessie.cel.ProgramOption.customDecorator) EnvOption.macros(org.projectnessie.cel.EnvOption.macros) Interpretable.newConstValue(org.projectnessie.cel.interpreter.Interpretable.newConstValue) CheckedExpr(com.google.api.expr.v1alpha1.CheckedExpr) CEL.parsedExprToAst(org.projectnessie.cel.CEL.parsedExprToAst) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) InterpretableConst(org.projectnessie.cel.interpreter.Interpretable.InterpretableConst) CEL.astToParsedExpr(org.projectnessie.cel.CEL.astToParsedExpr) CEL.checkedExprToAst(org.projectnessie.cel.CEL.checkedExprToAst) EvalState(org.projectnessie.cel.interpreter.EvalState) Util.mapOf(org.projectnessie.cel.Util.mapOf) StringT(org.projectnessie.cel.common.types.StringT) EnvOption.homogeneousAggregateLiterals(org.projectnessie.cel.EnvOption.homogeneousAggregateLiterals) Env.newCustomEnv(org.projectnessie.cel.Env.newCustomEnv) EnvOption.abbrevs(org.projectnessie.cel.EnvOption.abbrevs) Val(org.projectnessie.cel.common.types.ref.Val) Mapper(org.projectnessie.cel.common.types.traits.Mapper) Type(com.google.api.expr.v1alpha1.Type) EvalResult(org.projectnessie.cel.Program.EvalResult) Env.newEnv(org.projectnessie.cel.Env.newEnv) Env.newCustomEnv(org.projectnessie.cel.Env.newCustomEnv) AstIssuesTuple(org.projectnessie.cel.Env.AstIssuesTuple) StringT(org.projectnessie.cel.common.types.StringT) Test(org.junit.jupiter.api.Test)

Aggregations

Type (com.google.api.expr.v1alpha1.Type)30 Test (org.junit.Test)16 Type (edu.stanford.CVC4.Type)14 Type (com.google.spanner.v1.Type)12 ArrayType (edu.stanford.CVC4.ArrayType)11 BitVectorType (edu.stanford.CVC4.BitVectorType)11 Expr (edu.stanford.CVC4.Expr)11 MapType (com.google.api.expr.v1alpha1.Type.MapType)10 Type (org.apache.xbean.asm9.Type)10 ByteString (com.google.protobuf.ByteString)9 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)9 ArrayList (java.util.ArrayList)9 CheckedExpr (com.google.api.expr.v1alpha1.CheckedExpr)8 FieldType (org.projectnessie.cel.common.types.ref.FieldType)8 FormulaType (org.sosy_lab.java_smt.api.FormulaType)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 CheckerEnv.isObjectWellKnownType (org.projectnessie.cel.checker.CheckerEnv.isObjectWellKnownType)7