Examples of TCustomOverloadResult


Examples of com.foundationdb.server.types.TCustomOverloadResult

    }

    @Override
    public TOverloadResult resultType() {
        // actual return type is exactly the same as input type
        return TOverloadResult.custom(new TCustomOverloadResult()
        {
            @Override
            public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context)
            {
                TInstance source = inputs.get(0).type();
View Full Code Here

Examples of com.foundationdb.server.types.TCustomOverloadResult

    }

    @Override
    public TOverloadResult resultType()
    {
        return TOverloadResult.custom(new TCustomOverloadResult()
        {
            @Override
            public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context)
            {
                TPreptimeValue on = inputs.get(1);
View Full Code Here

Examples of com.foundationdb.server.types.TCustomOverloadResult

                return HEX_NAME;
            }

            @Override
            public TOverloadResult resultType() {
                return TOverloadResult.custom(new TCustomOverloadResult() {
                    @Override
                    public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context) {
                        TInstance type = inputs.get(0).type();
                        int maxLen = type.attribute(StringAttribute.MAX_LENGTH);
                        Charset charset = getCharset(type);
                        long maxBytes = (long)Math.ceil(maxLen * charset.newEncoder().maxBytesPerChar());
                        long maxHexLength = maxBytes * 2;
                        return stringType.instance(Ints.saturatedCast(maxHexLength), anyContaminatingNulls(inputs));
                    }
                });
            }

        };

        TScalar hex_bigint = new TScalarBase()
        {
            @Override
            protected void buildInputSets(TInputSetBuilder builder) {
                builder.covers(longType, 0);
            }

            @Override
            protected void doEvaluate(TExecutionContext context,
                                      LazyList<? extends ValueSource> inputs,
                                      ValueTarget output) {
                long value = inputs.get(0).getInt64();
                output.putString(Long.toHexString(value).toUpperCase(), null);
            }

            @Override
            public String displayName() {
                return HEX_NAME;
            }

            @Override
            public TOverloadResult resultType() {
                return TOverloadResult.custom(new TCustomOverloadResult() {
                    @Override
                    public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context) {
                        // 16 = BIGINT size * 2
                        return stringType.instance(16, anyContaminatingNulls(inputs));
                    }
                });
            }
        };

        TScalar hex_binary = new TScalarBase()
        {
            @Override
            protected void buildInputSets(TInputSetBuilder builder) {
                builder.covers(binaryType, 0);
            }

            @Override
            protected void doEvaluate(TExecutionContext context,
                                      LazyList<? extends ValueSource> inputs,
                                      ValueTarget output) {
                byte[] bytes = inputs.get(0).getBytes();
                output.putString(Strings.hex(bytes), null);
            }

            @Override
            public String displayName() {
                return HEX_NAME;
            }

            @Override
            public TOverloadResult resultType() {
                return TOverloadResult.custom(new TCustomOverloadResult() {
                    @Override
                    public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context) {
                        int length = inputs.get(0).type().attribute(TBinary.Attrs.LENGTH);
                        return stringType.instance(Ints.saturatedCast(length * 2), anyContaminatingNulls(inputs));
                    }
View Full Code Here

Examples of com.foundationdb.server.types.TCustomOverloadResult

    }

    @Override
    public TOverloadResult resultType()
    {
        return TOverloadResult.custom(new TCustomOverloadResult()
        {
            @Override
            public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context)
            {
                TPreptimeValue formatArg = inputs.get(1);
View Full Code Here

Examples of com.foundationdb.server.types.TCustomOverloadResult

                builder.covers(varbinary, 0);
            }

            @Override
            public TOverloadResult resultType() {
                return TOverloadResult.custom(new TCustomOverloadResult() {
                    @Override
                    public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context) {
                        TInstance inputType = inputs.get(0).type();
                        int binaryLength = inputType.attribute(TBinary.Attrs.LENGTH);
                        int base64Length = (binaryLength * 4 + 2) / 3; // round up for ='s
                        return varchar.instance(base64Length, inputType.nullability());
                    }       
                });
            }

            @Override
            protected void doEvaluate(TExecutionContext context,
                                      LazyList<? extends ValueSource> inputs,
                                      ValueTarget output) {
                byte[] binary = inputs.get(0).getBytes();
                output.putString(Strings.toBase64(binary), null);
            }
        };

        TScalar string_to_base64 = new TScalarBase()
        {
            @Override
            public String displayName() {
                return "TO_BASE64";
            }

            @Override
            protected void buildInputSets(TInputSetBuilder builder) {
                builder.covers(varchar, 0);
            }

            @Override
            public TOverloadResult resultType() {
                return TOverloadResult.custom(new TCustomOverloadResult() {
                    @Override
                    public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context) {
                        TInstance inputType = inputs.get(0).type();
                        int stringLength = inputType.attribute(StringAttribute.MAX_LENGTH);
                        int encodedLength = (int)Math.ceil(stringLength * Charset.forName(StringFactory.Charset.of(inputType.attribute(StringAttribute.CHARSET))).newEncoder().maxBytesPerChar());
                        int base64Length = (encodedLength * 4 + 2) / 3; // round up for ='s
                        return varchar.instance(base64Length, inputType.nullability());
                    }       
                });
            }

            @Override
            protected void doEvaluate(TExecutionContext context,
                                      LazyList<? extends ValueSource> inputs,
                                      ValueTarget output) {
                String charset = StringFactory.Charset.of(context.inputTypeAt(0).attribute(StringAttribute.CHARSET));
                String string = inputs.get(0).getString();
                try {
                    byte[] binary = string.getBytes(charset);
                    output.putString(Strings.toBase64(binary), null);
                }
                catch (UnsupportedEncodingException ex)
                {
                    context.warnClient(new InvalidParameterValueException("Unknown CHARSET: " + charset));
                    output.putNull();
                }
            }
        };

        TScalar from_base64 = new TScalarBase()
        {
            @Override
            public String displayName() {
                return "FROM_BASE64";
            }

            @Override
            protected void buildInputSets(TInputSetBuilder builder) {
                builder.covers(varchar, 0);
            }

            @Override
            public TOverloadResult resultType() {
                return TOverloadResult.custom(new TCustomOverloadResult() {
                    @Override
                    public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context) {
                        TInstance inputType = inputs.get(0).type();
                        int stringLength = inputType.attribute(StringAttribute.MAX_LENGTH);
                        int binaryLength = stringLength / 4 * 3;
 
View Full Code Here

Examples of com.foundationdb.server.types.TCustomOverloadResult

        return new String[] { "concatenate", "concat" };
    }

    @Override
    public TOverloadResult resultType() {
        return TOverloadResult.custom(new TCustomOverloadResult() {
            @Override
            public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context) {
                int length = 0;
                for (TPreptimeValue ptv : inputs) {
                    length += ptv.type().attribute(StringAttribute.MAX_LENGTH);
View Full Code Here

Examples of com.foundationdb.server.types.TCustomOverloadResult

   // TODO this should extend some base class that MArithmetic also extends, rather than extending MArithmetic
   // but ignoring its TInstance field
    private abstract static class DecimalArithmetic extends MArithmetic {
        @Override
        public TOverloadResult resultType() {
           return TOverloadResult.custom(new TCustomOverloadResult() {
               @Override
               public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context) {
                   TInstance arg0 = inputs.get(0).type();
                   TInstance arg1 = inputs.get(1).type();
View Full Code Here

Examples of com.foundationdb.server.types.TCustomOverloadResult

        }

        @Override
        public TOverloadResult resultType()
        {
            return TOverloadResult.custom(new TCustomOverloadResult()
            {
                @Override
                public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context)
                {
                    return inputs.get(pos0).type();
View Full Code Here

Examples of com.foundationdb.server.types.TCustomOverloadResult

        return "REPEAT";
    }

    @Override
    public TOverloadResult resultType() {
        return TOverloadResult.custom(new TCustomOverloadResult()
        {
            @Override
            public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context)
            {
                ValueSource string = inputs.get(0).value();
View Full Code Here

Examples of com.foundationdb.server.types.TCustomOverloadResult

        output.putDouble(result);
    }

    @Override
    public TOverloadResult resultType() {
        return TOverloadResult.custom(new TCustomOverloadResult() {
            @Override
            public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context) {
                ValueSource incomingScale = signatureStrategy.getScaleOperand(inputs);
                int resultScale = (incomingScale == null)
                        ? inputs.get(0).type().attribute(DoubleAttribute.SCALE)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.