Examples of TClass


Examples of com.foundationdb.server.types.TClass

        else if (left == null)
            return right;
        else if (right == null)
            return left;

        TClass leftTClass = left.typeClass();
        TClass rightTClass = right.typeClass();
        if (leftTClass == rightTClass)
            return leftTClass.pickInstance(left, right);
        TClass commonClass = resolver.commonTClass(leftTClass, rightTClass);
        if (commonClass == null)
            throw error("couldn't determine a type for CASE expression");
        if (commonClass == leftTClass)
            return left;
        if (commonClass == rightTClass)
            return right;
        return commonClass.instance(left.nullability() || right.nullability());
    }
View Full Code Here

Examples of com.foundationdb.server.types.TClass

                    // This logic also handles the case where both are null, which is not a valid argument
                    // to resolver.commonTClass.
                    if (Objects.equal(instances[field], botInstance))
                        continue;
                   
                    TClass topClass = tclass(instances[field]);
                    TClass botClass = tclass(botInstance);
                    TClass commonTClass = registry.getCastsResolver().commonTClass(topClass, botClass);
                    if (commonTClass == null) {
                        throw new AkibanInternalException("no common type found found between row " + (rownum-1)
                        + " and " + rownum + " at field " + field);
                    }
                    // The two rows have different TClasses at this index, so we'll need at least one of them to
                    // be casted. Also the common class will be the widest comparable.
                    needCasts.set(field);
                    widened.set(field);

                    boolean eitherIsNullable;
                    if (botInstance == null)
                        eitherIsNullable = true;
                    else
                        eitherIsNullable = botInstance.nullability();
                    if ( (!eitherIsNullable) && (instances[field] != null)) {
                        // bottom is not nullable, and there is a top. See if it's nullable
                        eitherIsNullable = instances[field].nullability();
                    }
                   
                    // need to set a new instances[field]. Rules:
                    // - if topClass and botClass are the same as common, use picking algorithm
                    // - else, if one of them == commonTClass, use topInstance or botInstance (whichever is == common)
                    // - else, use commonTClass.instance()
                    boolean topIsCommon = (topClass == commonTClass);
                    boolean botIsCommon = (botClass == commonTClass);
                    if (topIsCommon && botIsCommon) {
                        // TODO: The special case here for TClass VARCHAR with mismatched charsets
                        // is a limitation of the TClass#pickInstance, as there is no current way
                        // to create a common TInstance for TString with difference charsets.
                        if (commonTClass instanceof TString &&
                            botInstance.attribute(StringAttribute.CHARSET) != instances[field].attribute(StringAttribute.CHARSET)) {
                            ;
                        }
                        else {   
                            instances[field] = topClass.pickInstance(instances[field], botInstance);
                        }
                    }
                    else if (botIsCommon) {
                        instances[field] = botInstance;
                    }
                    else if (!topIsCommon) { // this of this as "else if (topIsBottom) { <noop> } else { ..."
                        instances[field] = commonTClass.instance(eitherIsNullable);
                    }

                    // See if the top instance is not nullable but should be
                    if (instances[field] != null) {
                        instances[field] = instances[field].withNullable(eitherIsNullable);
                    }
                }
            }

            // See if we need any casts
            if (!needCasts.isEmpty()) {
                for (int field = 0; field < nfields; field++) {
                    if (widened.get(field)) {
                        // A parameter should get a really wide VARCHAR so that it
                        // won't be truncated because of other non-parameters.
                        // Also make sure it's VARBINARY, as BINARY means pad, which
                        // we don't want here.
                        TClass tclass = TInstance.tClass(instances[field]);
                        if (tclass instanceof TString) {
                            if (((TString)tclass).getFixedLength() < 0) {
                                instances[field] =
                                    typesTranslator.typeClassForString()
                                      .instance(Integer.MAX_VALUE,
View Full Code Here

Examples of com.foundationdb.server.types.TClass

        private TKeyComparisonPreparation(TPreparedExpression left, Comparison op, TPreparedExpression right,
                                          TKeyComparable comparable)
        {
            super(left, op, right);
            this.comparison = comparable.getComparison();
            TClass leftIn = tClass(left);
            TClass rightIn = tClass(right);
            TClass leftCmp = comparable.getLeftTClass();
            TClass rightCmp = comparable.getRightTClass();
            if (leftIn == leftCmp && rightIn == rightCmp) {
                reverseComparison = false;
            }
            else if (rightIn == leftCmp && leftIn == rightCmp) {
                reverseComparison = true;
View Full Code Here

Examples of com.foundationdb.server.types.TClass

            : new TableIndexStatistics(rowType, tableRowCounts);
    }

    int fieldWidth(Column column)
    {
        TClass tclass = column.getType().typeClass();
        if (tclass.hasFixedSerializationSize()) {
            if (tclass instanceof MNumeric) {
                return 8;       // TODO: For compatibility with existing tests.
            }
            return tclass.fixedSerializationSize();
        }
        if (tclass instanceof TString) {
            int length = ((TString)tclass).getFixedLength();
            if (length < 0) {
                return (int)(column.getAverageStorageSize() * PLAUSIBLE_AVERAGE_VAR_USAGE);
 
View Full Code Here

Examples of com.foundationdb.server.types.TClass

    }

    private AkCollator collator(ComparisonCondition cond, TPreparedExpression left, TPreparedExpression right) {
        TInstance leftInstance = left.resultType();
        TInstance rightInstance = right.resultType();
        TClass tClass = leftInstance.typeClass();
        assert tClass.compatibleForCompare(rightInstance.typeClass())
                : tClass + " != " + rightInstance.typeClass();
        if (tClass.underlyingType() != UnderlyingType.STRING)
            return null;
        CharacterTypeAttributes leftAttributes = StringAttribute.characterTypeAttributes(leftInstance);
        CharacterTypeAttributes rightAttributes = StringAttribute.characterTypeAttributes(rightInstance);
        return TString.mergeAkCollators(leftAttributes, rightAttributes);
    }
View Full Code Here

Examples of com.foundationdb.server.types.TClass

    {
        for (int d = 0; d < dimensions; d++) {
            rowDataSource.bind(fieldDefs[d], rowData);

            RowDataValueSource rowDataValueSource = (RowDataValueSource)rowDataSource;
            TClass tclass = tinstances[d].typeClass();
            if (tclass == MNumeric.DECIMAL) {
                BigDecimalWrapper wrapper = TBigDecimal.getWrapper(rowDataValueSource, tinstances[d]);
                coords[d] = wrapper.asBigDecimal().doubleValue();
            }
            else if (tclass == MNumeric.BIGINT) {
View Full Code Here

Examples of com.foundationdb.server.types.TClass

        Map<TClass, TCast> castsFrom = strongCastsBySource.get(tClass);
        return castsFrom.keySet();
    }

    public boolean isStrong(TCast cast) {
        TClass source = cast.sourceClass();
        TClass target = cast.targetClass();
        return stronglyCastableFrom(source).contains(target);
    }
View Full Code Here

Examples of com.foundationdb.server.types.TClass

    static Map<TClass, Map<TClass, TCast>> createStrongCastsMap(Map<TClass, Map<TClass, TCast>> castsBySource,
                                                                final Set<TCastIdentifier> strongCasts) {
        Map<TClass,Map<TClass,TCast>> result = new HashMap<>();
        for (Map.Entry<TClass, Map<TClass,TCast>> origEntry : castsBySource.entrySet()) {
            final TClass source = origEntry.getKey();
            Map<TClass, TCast> filteredView = Maps.filterKeys(origEntry.getValue(), new Predicate<TClass>() {
                @Override
                public boolean apply(TClass target) {
                    return (source == target) || strongCasts.contains(new TCastIdentifier(source, target));
                }
View Full Code Here

Examples of com.foundationdb.server.types.TClass

     * from A to VARCHAR and from VARCHAR to B. This essentially uses VARCHAR as a base type. Not pretty, but effective.
     * Uses the instance variable #castsBySource for its input and output; it must be initialized with at least
     * the self-casts and declared casts.
     */
    private void deriveCastsFromVarchar() {
        final TClass COMMON = MString.VARCHAR;
        Set<TClass> tClasses = castsBySource.keySet();
        for (Map.Entry<TClass, Map<TClass, TCast>> entry : castsBySource.entrySet()) {
            TClass source = entry.getKey();
            Map<TClass, TCast> castsByTarget = entry.getValue();
            for (TClass target : tClasses) {
                if (target == source || castsByTarget.containsKey(target))
                    continue;
                TCast sourceToVarchar = cast(source, COMMON);
View Full Code Here

Examples of com.foundationdb.server.types.TClass

        }
    }

    private static TCast deriveCast(Map<TClass,Map<TClass,TCast>> castsBySource,
                                    List<? extends TClass> path, int targetIndex) {
        TClass source = path.get(0);
        TClass target = path.get(targetIndex);
        TCast alreadyThere = cast(castsBySource, source,  target);
        if (alreadyThere != null)
            return alreadyThere;
        int intermediateIndex = targetIndex - 1;
        TClass intermediateClass = path.get(intermediateIndex);
        TCast second = cast(castsBySource, intermediateClass, target);
        if (second == null)
            throw new AkibanInternalException("no explicit cast between " + intermediateClass + " and " + target
                    + " while creating cast path: " + path);
        TCast first = deriveCast(castsBySource, path, intermediateIndex);
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.