Package com.foundationdb.server.types

Examples of com.foundationdb.server.types.TPreptimeValue


                                 List<? extends TPreparedExpression> pExpressions,
                                 QueryContext queryContext) {
        Iterator<? extends ValueSource> newVals;
        ArgumentValidation.isEQ("rowType fields", rowType.nFields(), "expressions.size", pExpressions.size());
        for (TPreparedExpression expression : pExpressions) {
            TPreptimeValue tpv = expression.evaluateConstant(queryContext);
            if (tpv == null || tpv.value() == null)
                return new BindingExpressions(rowType, pExpressions);
        }
        newVals = new PExpressionEvaluator(pExpressions, queryContext);
        ImmutableRow holderRow = new ImmutableRow(rowType, newVals);
        return new Delegating(holderRow);
View Full Code Here


        }

        @Override
        public ValueSource next() {
            TPreparedExpression expression = expressions.next();
            TPreptimeValue ptv = expression.evaluateConstant(context);
            assert ptv != null && ptv.value() != null
                    : "not constant: " + expression + " with prepare-time value of " + ptv;
            return ptv.value();
        }
View Full Code Here

        return TOverloadResult.custom(new TCustomOverloadResult()
        {
            @Override
            public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context)
            {
                TPreptimeValue len = inputs.get(1);

                // if second argument is not available or is null
                if (len.value() == null || len.value().isNull())
                {
                    TPreptimeValue st = inputs.get(0);
                   
                    // if the string is also not available
                    // the return the precision of the string's type
                    if (st.value() == null || st.value().isNull())
                        return st.type().withNullable(false);
                    else // if the string is available, return its length
                        return stringType.instance((st.value().getString()).length(), anyContaminatingNulls(inputs));
                }
                else
                    return stringType.instance(len.value().getInt32(), anyContaminatingNulls(inputs));
            }
           
View Full Code Here

    }

    @Override
    public TInstance getTypeAt(int index) {
        ExpressionNode field = fields.get(index);
        TPreptimeValue tpv = field.getPreptimeValue();
        return tpv.type();
    }
View Full Code Here

    }

    @Override
    public String toString() {
        Object typeDescriptor;
        TPreptimeValue tpv = getPreptimeValue();
        if (tpv != null) {
            TInstance type = tpv.type();
            typeDescriptor = type == null ? "<unknown>" : type;
        }
        else {
            typeDescriptor = getSQLtype();
        }
View Full Code Here

                        seqNode.getSequenceName().getSchemaName() :
                            rulesContext.getDefaultSchemaName();
                // Extract the (potential) schema name as the first parameter
                TInstance schemaType = typesTranslator.typeForString(schema);
                params.add(new ConstantExpression(
                        new TPreptimeValue(new Value(schemaType, schema))));
                // Extract the schema name as the second parameter
                String sequence = seqNode.getSequenceName().getTableName();
                TInstance sequenceType = typesTranslator.typeForString(sequence);
                params.add(new ConstantExpression(
                        new TPreptimeValue(new Value(sequenceType, sequence))));
               
                return new FunctionExpression ("nextval", params,
                        sqlType, valueNode, type);
            }
            else if (valueNode instanceof CurrentSequenceNode) {
                CurrentSequenceNode seqNode = (CurrentSequenceNode)valueNode;
                List<ExpressionNode> params = new ArrayList<>(2);

                String schema = seqNode.getSequenceName().hasSchema() ?
                        seqNode.getSequenceName().getSchemaName() :
                            rulesContext.getDefaultSchemaName();
                // Extract the (potential) schema name as the first parameter
                TInstance schemaType = typesTranslator.typeForString(schema);
                params.add(new ConstantExpression(
                        new TPreptimeValue(new Value(schemaType, schema))));
                // Extract the schema name as the second parameter
                String sequence = seqNode.getSequenceName().getTableName();
                TInstance sequenceType = typesTranslator.typeForString(sequence);
                params.add(new ConstantExpression(
                        new TPreptimeValue(new Value(sequenceType, sequence))));
               
                return new FunctionExpression ("currval", params,
                        sqlType, valueNode, type);
            }
            else if (valueNode instanceof DefaultNode) {
View Full Code Here

                logger.warn("unrecognized ExpressionNode subclass: {}", n.getClass());

            n = folder.foldConstants(n);
            // Set nullability of TInstance if it hasn't been given explicitly
            // At the same time, update the node's DataTypeDescriptor to match its TInstance
            TPreptimeValue tpv = n.getPreptimeValue();
            if (tpv != null) {
                TInstance type = tpv.type();
                if ((n.getSQLtype() != null) &&
                    (n.getSQLtype().getCharacterAttributes() != null) &&
                    (n.getSQLtype().getCharacterAttributes().getCollationDerivation() ==
                        CharacterTypeAttributes.CollationDerivation.EXPLICIT)) {
                    // Apply result of explicit COLLATE, which will otherwise get lost.
                    // No way to mutate the existing instance, so replace entire tpv.
                    type = StringAttribute.copyWithCollation(type, n.getSQLtype().getCharacterAttributes());
                    tpv = new TPreptimeValue(type, tpv.value());
                    n.setPreptimeValue(tpv);
                }
                if (type != null) {
                    DataTypeDescriptor newDtd = type.dataTypeDescriptor();
                    n.setSQLtype(newDtd);
View Full Code Here

        }

        ExpressionNode handleCastExpression(CastExpression expression) {
            DataTypeDescriptor dtd = expression.getSQLtype();
            TInstance type = typesTranslator.typeForSQLType(dtd);
            expression.setPreptimeValue(new TPreptimeValue(type));
            if (expression.getOperand() instanceof ParameterExpression) {
                parametersSync.set(expression.getOperand(), type);
            }
            return finishCast(expression, folder, parametersSync);
        }
View Full Code Here

            final List<TPreptimeValue> operandValues = new ArrayList<>(operands.size());
            List<TInstance> operandInstances = new ArrayList<>(operands.size());
            boolean anyOperandsNullable = false;
            for (ExpressionNode operand : operands) {
                TPreptimeValue preptimeValue = operand.getPreptimeValue();
                operandValues.add(preptimeValue);
                operandInstances.add(preptimeValue.type());
                if (Boolean.TRUE.equals(preptimeValue.isNullable()))
                    anyOperandsNullable = true;
            }

            TOverloadResult overloadResultStrategy = overload.resultStrategy();
            TInstance resultInstance;
            TInstance castTo;

            TPreptimeContext context;
            if (createPreptimeContext) {
                context = new TPreptimeContext(operandInstances, queryContext);
                expression.setPreptimeContext(context);
            }
            else {
                context = null;
            }
            switch (overloadResultStrategy.category()) {
            case CUSTOM:
                TInstance castSource = overloadResultStrategy.customRuleCastSource(anyOperandsNullable);
                if (context == null)
                    context = new TPreptimeContext(operandInstances, queryContext);
                expression.setPreptimeContext(context);
                if (castSource == null) {
                    castTo = null;
                    resultInstance = overloadResultStrategy.customRule().resultInstance(operandValues, context);
                }
                else {
                    castTo = overloadResultStrategy.customRule().resultInstance(operandValues, context);
                    resultInstance = castSource;
                }
                break;
            case FIXED:
                resultInstance = overloadResultStrategy.fixed(anyOperandsNullable);
                castTo = null;
                break;
            case PICKING:
                resultInstance = resolutionResult.getPickedInstance();
                castTo = null;
                break;
            default:
                throw new AssertionError(overloadResultStrategy.category());
            }
            if (createPreptimeContext)
                context.setOutputType(resultInstance);

            expression.setPreptimeValue(new TPreptimeValue(resultInstance));

            ExpressionNode resultExpression;
            if (castTo == null) {
                resultExpression = expression;
            }
View Full Code Here

            TValidatedScalar overload = expression.getResolved();
            TPreptimeContext context = expression.getPreptimeContext();

            final List<TPreptimeValue> operandValues = new ArrayList<>(operands.size());
            for (ExpressionNode operand : operands) {
                TPreptimeValue preptimeValue = operand.getPreptimeValue();
                operandValues.add(preptimeValue);
            }
            overload.finishPreptimePhase(context);

            // Put the preptime value, possibly including nullness, into the expression. The constant folder
            // will use it.
            LazyList<TPreptimeValue> lazyInputs = new LazyListBase<TPreptimeValue>() {
                @Override
                public TPreptimeValue get(int i) {
                    return operandValues.get(i);
                }

                @Override
                public int size() {
                    return operandValues.size();
                }
            };

            TPreptimeValue constantTpv = overload.evaluateConstant(context, overload.filterInputs(lazyInputs));
            if (constantTpv != null) {
                TPreptimeValue oldTpv = expression.getPreptimeValue();
                assert oldTpv.type().equals(constantTpv.type())
                        : oldTpv.type() + " != " + constantTpv.type();
                expression.setPreptimeValue(constantTpv);
            }

            SparseArray<Object> values = context.getValues();
            if ((values != null) && !values.isEmpty())
View Full Code Here

TOP

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

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.