Package com.foundationdb.server.types

Examples of com.foundationdb.server.types.TInstance


            @Override
            public TPreparedExpression getTPreparedExpression() {
                TPreparedExpression leftExpr = left.getTPreparedExpression();
                TPreparedExpression rightExpr = right.getTPreparedExpression();

                TInstance common = TypeResolver.commonInstance(
                        castResolver, leftExpr.resultType(), rightExpr.resultType());
                leftExpr = castTo(leftExpr, common, castResolver);
                rightExpr = castTo(rightExpr, common, castResolver);
                return new TComparisonExpression(leftExpr, comparison, rightExpr);
            }
View Full Code Here


        tableRowType = SchemaCache.globalSchema(ais()).tableRowType(tID);
        writeRows(row(tID, 2, 20),
                  row(tID, 4, 40));
        groupRows = runPlanTxn(groupScanCreator(tID));

        TInstance type = tableRowType.typeAt(1);
        newRowType = SchemaCache.globalSchema(ais()).newValuesType(type, type, type);
    }
View Full Code Here

    public Row row(RowType rowType, Object... fields) {
        if(fields.length < rowType.nFields()) {
            QueryContext context = new SimpleQueryContext(newStoreAdapter(rowType.schema()));
            List<TPreparedExpression> expressions = new ArrayList<>();
            for(int i = 0; i < fields.length; ++i) {
                TInstance type = rowType.typeAt(i);
                TPreptimeValue val = ValueSources.fromObject(fields[i], type);
                expressions.add(new TPreparedLiteral(type, val.value()));
            }
            for(int i = fields.length; i < rowType.nFields(); ++i) {
                Column col = getColumn(rowType, i);
View Full Code Here

                        return true;
                }
            }
            ValueSource expectedField = expected.value(expectedPosition);
            ValueSource actualField = actual.value(actualPosition);
            TInstance expectedType = expected.rowType().typeAt(expectedPosition);
            TInstance actualType = actual.rowType().typeAt(actualPosition);
            assertEquals("expected type", expectedType.typeClass(), actualType.typeClass());
            int c = TClass.compare(expectedType, expectedField, actualType, actualField);
            if (c != 0)
                return false;
        }
        return true;
View Full Code Here

        return TOverloadResult.custom(new TCustomOverloadResult()
        {
            @Override
            public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context)
            {
                TInstance source = inputs.get(0).type();
                return inputTypeString.instance(source.attribute(StringAttribute.MAX_LENGTH) + 2,
                        source.attribute(StringAttribute.CHARSET),
                        source.attribute(StringAttribute.COLLATION),
                        anyContaminatingNulls(inputs));
            }
        });
    }
View Full Code Here

              NO_PARSER,
              -1);
    }

    public TInstance instance(List<Column> columns) {
        TInstance instance = createInstanceNoArgs(false);
        instance.setMetaData(columns);
        return instance;
    }
View Full Code Here

        this.values = new Value[rowDef.getFieldCount()];
        this.executionContexts = new TExecutionContext[values.length];
        List<TInstance> inputs = Collections.singletonList(vstring.getType());
        for (int fi = 0; fi < fieldColumns.length; fi++) {
            int ci = fieldColumns[fi];
            TInstance output = columns.get(fi).getType();
            values[ci] = new Value(output);
            // TODO: Only needed until every place gets type from
            // ValueTarget, when there can just be one
            // TExecutionContext wrapping the QueryContext.
            executionContexts[ci] = new TExecutionContext(null,
                                                          inputs, output, queryContext,
                                                          ErrorHandlingMode.WARN,
                                                          ErrorHandlingMode.WARN,
                                                          ErrorHandlingMode.WARN);
        }
        for (int fi = 0; fi < constColumns.length; fi++) {
            int ci = constColumns[fi];
            Column column = defaultColumns.get(fi);
            TInstance output = column.getType();
            Value value = new Value(output);
            TExecutionContext te = new TExecutionContext(null,
                                                         inputs, output, queryContext,
                                                         ErrorHandlingMode.WARN,
                                                         ErrorHandlingMode.WARN,
                                                         ErrorHandlingMode.WARN);
            vstring.putString(column.getDefaultValue(), null);
            value.getType().typeClass().fromObject(te, vstring, value);
            values[ci] = value;
        }
        this.expressions = new TEvaluatableExpression[evalColumns.length];
        TypesRegistryService registry = null;
        if (evalColumns.length > 0) {
            registry = queryContext.getServiceManager().getServiceByClass(TypesRegistryService.class);
        }
        for (int fi = 0; fi < evalColumns.length; fi++) {
            int ci = evalColumns[fi];
            Column column = functionColumns.get(fi);
            TInstance columnType = column.getType();
            String functionName;
            List<TPreptimeValue> input;
            List<TPreparedExpression> arguments;
            if (column.getIdentityGenerator() != null) {
                Sequence sequence = column.getIdentityGenerator();
                TableName sequenceName = sequence.getSequenceName();
                functionName = "NEXTVAL";
                input = new ArrayList<>(2);
                input.add(ValueSources.fromObject(sequenceName.getSchemaName(), typesTranslator.typeForString(sequenceName.getSchemaName())));
                input.add(ValueSources.fromObject(sequenceName.getTableName(), typesTranslator.typeForString(sequenceName.getTableName())));
                arguments = new ArrayList<>(input.size());
                for (TPreptimeValue tpv : input) {
                    arguments.add(new TPreparedLiteral(tpv.type(), tpv.value()));
                }
            }
            else {
                functionName = column.getDefaultFunction();
                assert (functionName != null) : column;
                input = Collections.<TPreptimeValue>emptyList();
                arguments = Collections.<TPreparedExpression>emptyList();
            }
            TValidatedScalar overload = registry.getScalarsResolver().get(functionName, input).getOverload();
            TInstance functionType = overload.resultStrategy().fixed(column.getNullable());
            TPreparedExpression expr = new TPreparedFunction(overload, functionType, arguments);
            if (!functionType.equals(columnType)) {
                TCast tcast = registry.getCastsResolver().cast(functionType.typeClass(), columnType.typeClass());
                expr = new TCastExpression(expr, tcast, columnType);
            }
            TEvaluatableExpression eval = expr.build();
            eval.with(queryContext);
            expressions[fi] = eval;
View Full Code Here

            @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));
                    }
View Full Code Here

                                                                   final F[] formatters)
    {
        return new TParser() {
            @Override
            public void parse(TExecutionContext context, ValueSource in, ValueTarget out) {
                TInstance instance = context.outputType();
                int literalFormatId = instance.attribute(formatAttribute);
                F format = formatters[literalFormatId];
                String inString = in.getString();
                long months = format.parse(inString);
                out.putInt64(months);
            }
View Full Code Here

        private void aggregate(Row input) {
            for (int i=0; i < pAggrs.size(); ++i) {
                TAggregator aggregator = pAggrs.get(i);
                int inputIndex = i + inputsIndex;
                TInstance inputType = input.rowType().typeAt(inputIndex);
                ValueSource inputSource = input.value(inputIndex);
                aggregator.input(inputType, inputSource, pAggrTypes.get(i), pAggrsStates.get(i), options.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.