Package com.foundationdb.server.types

Examples of com.foundationdb.server.types.TInstance


    }

    public void copyParameters(QueryBindings source, QueryBindings target) {
        for (int i = 0; i < parameterArgs.length; i++) {
            if (parameterArgs[i] < 0) {
                TInstance type = null;
                if (constantArgs[i] == null)
                    type = this.getType(i);
                target.setValue(i, ValueSources.valuefromObject(constantArgs[i], type));
            }
            else {
View Full Code Here


            return context;
        }

        @Override
        protected ValueSource getValue(int index) {
            TInstance type = getType(index);
            TClass tclass = type.typeClass();
            ValueSource source;
            if (parameterArgs[index] < 0) {
                source = ValueSources.valuefromObject(constantArgs[index], type);
                if (source.getType().typeClass().equals(tclass))
                    return source; // Literal value matches.
View Full Code Here

                break;
            case ParameterMetaData.parameterModeInOut:
                direction = Parameter.Direction.INOUT;
                break;
            }
            TInstance type = typesTranslator.typeForSQLType(aliasInfo.getParameterTypes()[i],
                    schemaName, routineName, parameterName);
            builder.parameter(schemaName, routineName, parameterName,
                              direction, type);
        }
       
        if (aliasInfo.getReturnType() != null) {
            TInstance type = typesTranslator.typeForSQLType(aliasInfo.getReturnType(),
                    schemaName, routineName, "return value");
            builder.parameter(schemaName, routineName, null,
                              Parameter.Direction.RETURN, type);
        }
View Full Code Here

            @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;
                        return varbinary.instance(binaryLength, inputType.nullability());
                    }       
                });
            }

            @Override
View Full Code Here

        @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();

                   int arg0Precision = arg0.attribute(DecimalAttribute.PRECISION);
                   int arg0Scale = arg0.attribute(DecimalAttribute.SCALE);

                   int arg1Precision = arg1.attribute(DecimalAttribute.PRECISION);
                   int arg1Scale = arg1.attribute(DecimalAttribute.SCALE);
                   long resultPrecisionAndScale = precisionAndScale(arg0Precision, arg0Scale, arg1Precision, arg1Scale);
                   int resultPrecision = (int)(resultPrecisionAndScale >> 32);
                   int resultScale = (int)resultPrecisionAndScale;
                   return MNumeric.DECIMAL.instance(resultPrecision, resultScale, anyContaminatingNulls(inputs));
               }
View Full Code Here

            Object value = values.get(i);
            if (value instanceof byte[]) {
                appendRawSegment((byte[])value);
                continue;
            }
            TInstance type;
            if (i == firstSpatialColumn) {
                type = MNumeric.BIGINT.instance(true);
            }
            else {
                int offset = i;
                if (i > firstSpatialColumn) {
                    offset += index.dimensions() - 1;
                }
                Column column = index.getKeyColumns().get(firstColumn + offset).getColumn();
                type = column.getType();
                column.getCollator();
            }
            // For example, for DECIMAL, value will be a
            // String, pvalue will be a its VARCHAR, and pvalue2
            // will be a BigDecimalWrapper, which only
            // TBigDecimal.writeCollating knows how to unwrap into
            // a Key.
           
            TPreptimeValue pvalue = null;
            if (value == null)
                pvalue = ValueSources.fromObject(value, type);
            else
                pvalue = ValueSources.fromObject(value, (TInstance) null);
            TExecutionContext context = new TExecutionContext(null,
                                                              Collections.singletonList(pvalue.type()),
                    type,
                                                              null, null, null, null);
            Value pvalue2 = new Value(type);
            type.typeClass().fromObject(context, pvalue.value(), pvalue2);
            type.writeCollating(pvalue2, keyTarget);
        }
        return key;
    }
View Full Code Here

            firstSpatialColumn = index.firstSpatialArgument();
        }
        List<Object> result = new ArrayList<>(columnCount);

        for (int i = 0; i < columnCount; i++) {
            TInstance type;
            boolean useRawSegment;
            if (i == firstSpatialColumn) {
                type = MNumeric.BIGINT.instance(true);
                useRawSegment = false;
            }
            else {
                int offset = i;
                if (i > firstSpatialColumn) {
                    offset += index.dimensions() - 1;
                }
                Column column = index.getKeyColumns().get(firstColumn + offset).getColumn();
                type = column.getType();
                AkCollator collator = column.getCollator();
                useRawSegment = ((collator != null) && !collator.isRecoverable());
            }
            Object keyValue;
            if (useRawSegment) {
                keyValue = getRawSegment(key, i);
            }
            else {
                PersistitKeyValueSource keySource = new PersistitKeyValueSource(type);
                keySource.attach(key, i, type);
                if (convertToType(type)) {
                    keyValue = ValueSources.toObject(keySource);
                }
                else if (keySource.isNull()) {
                    keyValue = null;
                }
                else {
                    StringBuilder str = new StringBuilder();
                    type.format(keySource, AkibanAppender.of(str));
                    keyValue = str.toString();
                }
                if (willUseBinaryTag(keyValue)) {
                    // Otherwise it would be ambiguous when reading.
                    keyValue = getRawSegment(key, i);
View Full Code Here

        Iterator<Column> colIt = inputColumns.iterator();
        TableRowType targetRowType = schema().tableRowType(table);
        TPreparedExpression[] row = new TPreparedExpression[targetRowType.nFields()];
        for (int i = 0; i < inputColumns.size(); i++) {
            Column column = colIt.next();
            TInstance type = column.getType();
            int pos = column.getPosition();
            row[pos] = insertExprs.get(i);
            if(!type.equals(row[pos].resultType())) {
                TCast tcast = registryService().getCastsResolver().cast(row[pos].resultType().typeClass(),
                                                                        type.typeClass());
                row[pos] = new TCastExpression(row[pos], tcast, type);
            }
        }
        // Fill in column defaults
        for(int i = 0, len = targetRowType.nFields(); i < len; ++i) {
View Full Code Here

        this.isMutable = isMutable;
        this.rowType = rowType;
        int nfields = rowType.nFields();
        values = new ArrayList<>(nfields);
        for (int i = 0; i < nfields; ++i) {
            TInstance type = rowType.typeAt(i);
            values.add(new Value(type));
        }
    }
View Full Code Here

        int i = 0;
        while(initialValues.hasNext()) {
            if (i >= values.size())
                throw new IllegalArgumentException("too many initial values: reached limit of " + values.size());
            ValueSource nextValue = initialValues.next();
            TInstance nextValueType = nextValue.getType();
            TInstance expectedTInst = rowType.typeAt(i);
            if (TInstance.tClass(nextValueType) != TInstance.tClass(expectedTInst))
                throw new IllegalArgumentException(
                        "value at index " + i + " expected type " + expectedTInst
                                + ", but UnderlyingType was " + nextValueType + ": " + nextValue);
            ValueTargets.copyFrom(nextValue, values.get(i++));
View Full Code Here

TOP

Related Classes of com.foundationdb.server.types.TInstance

Copyright © 2018 www.massapicom. 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.