Package org.apache.vxquery.runtime.functions.cast

Examples of org.apache.vxquery.runtime.functions.cast.CastToStringOperation


    @Override
    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
            throws AlgebricksException {
        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        final DataOutput dOut = abvs.getDataOutput();
        final CastToStringOperation castToString = new CastToStringOperation();
        final FunctionHelper.TypedPointables tp = new FunctionHelper.TypedPointables();

        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                TaggedValuePointable tvp1 = args[0];
                try {
                    abvs.reset();
                    switch (tvp1.getTag()) {
                        case ValueTag.XS_ANY_URI_TAG:
                            tvp1.getValue(tp.utf8sp);
                            castToString.convertAnyURI(tp.utf8sp, dOut);
                            break;
                        case ValueTag.XS_STRING_TAG:
                        case ValueTag.XS_NORMALIZED_STRING_TAG:
                        case ValueTag.XS_TOKEN_TAG:
                        case ValueTag.XS_LANGUAGE_TAG:
                        case ValueTag.XS_NMTOKEN_TAG:
                        case ValueTag.XS_NAME_TAG:
                        case ValueTag.XS_NCNAME_TAG:
                        case ValueTag.XS_ID_TAG:
                        case ValueTag.XS_IDREF_TAG:
                        case ValueTag.XS_ENTITY_TAG:
                            tvp1.getValue(tp.utf8sp);
                            castToString.convertString(tp.utf8sp, dOut);
                            break;
                        case ValueTag.XS_UNTYPED_ATOMIC_TAG:
                            tvp1.getValue(tp.utf8sp);
                            castToString.convertUntypedAtomic(tp.utf8sp, dOut);
                            break;
                        case ValueTag.XS_BASE64_BINARY_TAG:
                            tvp1.getValue(tp.binaryp);
                            castToString.convertBase64Binary(tp.binaryp, dOut);
                            break;
                        case ValueTag.XS_HEX_BINARY_TAG:
                            tvp1.getValue(tp.binaryp);
                            castToString.convertHexBinary(tp.binaryp, dOut);
                            break;
                        case ValueTag.XS_BOOLEAN_TAG:
                            tvp1.getValue(tp.boolp);
                            castToString.convertBoolean(tp.boolp, dOut);
                            break;
                        case ValueTag.XS_DATETIME_TAG:
                            tvp1.getValue(tp.datetimep);
                            castToString.convertDatetime(tp.datetimep, dOut);
                            break;
                        case ValueTag.XS_DAY_TIME_DURATION_TAG:
                            tvp1.getValue(tp.longp);
                            castToString.convertDTDuration(tp.longp, dOut);
                            break;
                        case ValueTag.XS_INTEGER_TAG:
                        case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
                        case ValueTag.XS_NEGATIVE_INTEGER_TAG:
                        case ValueTag.XS_LONG_TAG:
                        case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
                        case ValueTag.XS_UNSIGNED_LONG_TAG:
                        case ValueTag.XS_POSITIVE_INTEGER_TAG:
                        case ValueTag.XS_UNSIGNED_INT_TAG:
                            tvp1.getValue(tp.longp);
                            castToString.convertInteger(tp.longp, dOut);
                            break;
                        case ValueTag.XS_DURATION_TAG:
                            tvp1.getValue(tp.durationp);
                            castToString.convertDuration(tp.durationp, dOut);
                            break;
                        case ValueTag.XS_DATE_TAG:
                            tvp1.getValue(tp.datep);
                            castToString.convertDate(tp.datep, dOut);
                            break;
                        case ValueTag.XS_G_DAY_TAG:
                            tvp1.getValue(tp.datep);
                            castToString.convertGDay(tp.datep, dOut);
                            break;
                        case ValueTag.XS_G_MONTH_DAY_TAG:
                            tvp1.getValue(tp.datep);
                            castToString.convertGMonthDay(tp.datep, dOut);
                            break;
                        case ValueTag.XS_G_MONTH_TAG:
                            tvp1.getValue(tp.datep);
                            castToString.convertGMonth(tp.datep, dOut);
                            break;
                        case ValueTag.XS_G_YEAR_MONTH_TAG:
                            tvp1.getValue(tp.datep);
                            castToString.convertGYearMonth(tp.datep, dOut);
                            break;
                        case ValueTag.XS_G_YEAR_TAG:
                            tvp1.getValue(tp.datep);
                            castToString.convertGYear(tp.datep, dOut);
                            break;
                        case ValueTag.XS_QNAME_TAG:
                            tvp1.getValue(tp.qnamep);
                            castToString.convertQName(tp.qnamep, dOut);
                            break;
                        case ValueTag.XS_TIME_TAG:
                            tvp1.getValue(tp.timep);
                            castToString.convertTime(tp.timep, dOut);
                            break;
                        case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
                            tvp1.getValue(tp.intp);
                            castToString.convertYMDuration(tp.intp, dOut);
                            break;
                        case ValueTag.XS_INT_TAG:
                        case ValueTag.XS_UNSIGNED_SHORT_TAG:
                            tvp1.getValue(tp.intp);
                            castToString.convertInt(tp.intp, dOut);
                            break;
                        case ValueTag.XS_DECIMAL_TAG:
                            tvp1.getValue(tp.decp);
                            castToString.convertDecimal(tp.decp, dOut);
                            break;
                        case ValueTag.XS_DOUBLE_TAG:
                            tvp1.getValue(tp.doublep);
                            castToString.convertDouble(tp.doublep, dOut);
                            break;
                        case ValueTag.XS_FLOAT_TAG:
                            tvp1.getValue(tp.floatp);
                            castToString.convertFloat(tp.floatp, dOut);
                            break;
                        case ValueTag.XS_SHORT_TAG:
                        case ValueTag.XS_UNSIGNED_BYTE_TAG:
                            tvp1.getValue(tp.shortp);
                            castToString.convertShort(tp.shortp, dOut);
                            break;
                        case ValueTag.XS_BYTE_TAG:
                            tvp1.getValue(tp.bytep);
                            castToString.convertByte(tp.bytep, dOut);
                            break;
                        case ValueTag.SEQUENCE_TAG:
                            tvp1.getValue(tp.seqp);
                            if (tp.seqp.getEntryCount() == 0) {
                                XDMConstants.setEmptyString(result);
View Full Code Here


            throws AlgebricksException {
        return new AbstractTypeScalarEvaluator(args, ctx) {
            final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
            final DataOutput dOut = abvs.getDataOutput();
            final FunctionHelper.TypedPointables tp = new FunctionHelper.TypedPointables();
            AbstractCastToOperation aOp = new CastToStringOperation();
            int castToTag = 0;

            @Override
            protected void evaluate(TaggedValuePointable tvp, IPointable result) throws SystemException {
                abvs.reset();
                int tid = tvp.getTag();
                if (castToTag == -1 || castToTag == 0) {
                    // The promote type is not supported. No change.
                    result.set(tvp);
                    return;
                } else if (castToTag > 0) {
                    try {
                        switch (tid) {
                            case ValueTag.XS_ANY_URI_TAG:
                                tvp.getValue(tp.utf8sp);
                                aOp.convertAnyURI(tp.utf8sp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_BYTE_TAG:
                                tvp.getValue(tp.bytep);
                                aOp.convertByte(tp.bytep, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_DECIMAL_TAG:
                                tvp.getValue(tp.decp);
                                aOp.convertDecimal(tp.decp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_DOUBLE_TAG:
                                tvp.getValue(tp.doublep);
                                aOp.convertDouble(tp.doublep, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_FLOAT_TAG:
                                tvp.getValue(tp.floatp);
                                aOp.convertFloat(tp.floatp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_INT_TAG:
                                tvp.getValue(tp.intp);
                                aOp.convertInt(tp.intp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_INTEGER_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertInteger(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_LONG_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertLong(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_NEGATIVE_INTEGER_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertNegativeInteger(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertNonNegativeInteger(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertNonPositiveInteger(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_POSITIVE_INTEGER_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertPositiveInteger(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_SHORT_TAG:
                                tvp.getValue(tp.shortp);
                                aOp.convertShort(tp.shortp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_STRING_TAG:
                                tvp.getValue(tp.utf8sp);
                                aOp.convertString(tp.utf8sp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_UNSIGNED_BYTE_TAG:
                                tvp.getValue(tp.shortp);
                                aOp.convertUnsignedByte(tp.shortp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_UNSIGNED_INT_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertUnsignedInt(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_UNSIGNED_LONG_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertUnsignedLong(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_UNSIGNED_SHORT_TAG:
                                tvp.getValue(tp.intp);
                                aOp.convertUnsignedShort(tp.intp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            default:
                                // Promote type does not require us to change the value.
                                result.set(tvp);
                                break;
                        }
                    } catch (SystemException se) {
                        throw se;
                    } catch (Exception e) {
                        throw new SystemException(ErrorCode.SYSE0001, e);
                    }
                }
            }

            @Override
            protected void setSequenceType(SequenceType sType) {
                if (sType.getItemType() == BuiltinTypeRegistry.XS_DOUBLE) {
                    castToTag = ValueTag.XS_DOUBLE_TAG;
                    aOp = new CastToDoubleOperation();
                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_FLOAT) {
                    castToTag = ValueTag.XS_FLOAT_TAG;
                    aOp = new CastToFloatOperation();
                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_STRING) {
                    castToTag = ValueTag.XS_STRING_TAG;
                    aOp = new CastToStringOperation();
                } else {
                    castToTag = -1;
                }
            }
        };
View Full Code Here

            throws AlgebricksException {
        final UTF8StringPointable stringp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
        final DataOutput dOutInner = abvsInner.getDataOutput();
        final CastToStringOperation castToString = new CastToStringOperation();
        final FunctionHelper.TypedPointables tp = new FunctionHelper.TypedPointables();

        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                abvs.reset();

                try {
                    // Byte Format: Type (1 byte) + String Byte Length (2 bytes) + String.
                    DataOutput out = abvs.getDataOutput();
                    out.write(ValueTag.XS_STRING_TAG);

                    // Default values for the length and update later
                    out.write(0xFF);
                    out.write(0xFF);

                    for (int i = 0; i < args.length; i++) {
                        TaggedValuePointable tvp = args[i];

                        // TODO Update function to support cast to a string from any atomic value.
                        if (!FunctionHelper.isDerivedFromString(tvp.getTag())) {

                            try {
                                abvsInner.reset();
                                switch (tvp.getTag()) {
                                    case ValueTag.XS_ANY_URI_TAG:
                                        tvp.getValue(tp.utf8sp);
                                        castToString.convertAnyURI(tp.utf8sp, dOutInner);
                                        break;
                                    case ValueTag.XS_UNTYPED_ATOMIC_TAG:
                                        tvp.getValue(tp.utf8sp);
                                        castToString.convertUntypedAtomic(tp.utf8sp, dOutInner);
                                        break;
                                    case ValueTag.XS_BASE64_BINARY_TAG:
                                        tvp.getValue(tp.binaryp);
                                        castToString.convertBase64Binary(tp.binaryp, dOutInner);
                                        break;
                                    case ValueTag.XS_HEX_BINARY_TAG:
                                        tvp.getValue(tp.binaryp);
                                        castToString.convertHexBinary(tp.binaryp, dOutInner);
                                        break;
                                    case ValueTag.XS_BOOLEAN_TAG:
                                        tvp.getValue(tp.boolp);
                                        castToString.convertBoolean(tp.boolp, dOutInner);
                                        break;
                                    case ValueTag.XS_DATETIME_TAG:
                                        tvp.getValue(tp.datetimep);
                                        castToString.convertDatetime(tp.datetimep, dOutInner);
                                        break;
                                    case ValueTag.XS_DAY_TIME_DURATION_TAG:
                                        tvp.getValue(tp.longp);
                                        castToString.convertDTDuration(tp.longp, dOutInner);
                                        break;
                                    case ValueTag.XS_INTEGER_TAG:
                                    case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
                                    case ValueTag.XS_NEGATIVE_INTEGER_TAG:
                                    case ValueTag.XS_LONG_TAG:
                                    case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
                                    case ValueTag.XS_UNSIGNED_LONG_TAG:
                                    case ValueTag.XS_POSITIVE_INTEGER_TAG:
                                    case ValueTag.XS_UNSIGNED_INT_TAG:
                                        tvp.getValue(tp.longp);
                                        castToString.convertInteger(tp.longp, dOutInner);
                                        break;
                                    case ValueTag.XS_DURATION_TAG:
                                        tvp.getValue(tp.durationp);
                                        castToString.convertDuration(tp.durationp, dOutInner);
                                        break;
                                    case ValueTag.XS_DATE_TAG:
                                        tvp.getValue(tp.datep);
                                        castToString.convertDate(tp.datep, dOutInner);
                                        break;
                                    case ValueTag.XS_G_DAY_TAG:
                                        tvp.getValue(tp.datep);
                                        castToString.convertGDay(tp.datep, dOutInner);
                                        break;
                                    case ValueTag.XS_G_MONTH_DAY_TAG:
                                        tvp.getValue(tp.datep);
                                        castToString.convertGMonthDay(tp.datep, dOutInner);
                                        break;
                                    case ValueTag.XS_G_MONTH_TAG:
                                        tvp.getValue(tp.datep);
                                        castToString.convertGMonth(tp.datep, dOutInner);
                                        break;
                                    case ValueTag.XS_G_YEAR_MONTH_TAG:
                                        tvp.getValue(tp.datep);
                                        castToString.convertGYearMonth(tp.datep, dOutInner);
                                        break;
                                    case ValueTag.XS_G_YEAR_TAG:
                                        tvp.getValue(tp.datep);
                                        castToString.convertGYear(tp.datep, dOutInner);
                                        break;
                                    case ValueTag.XS_QNAME_TAG:
                                        tvp.getValue(tp.qnamep);
                                        castToString.convertQName(tp.qnamep, dOutInner);
                                        break;
                                    case ValueTag.XS_TIME_TAG:
                                        tvp.getValue(tp.timep);
                                        castToString.convertTime(tp.timep, dOutInner);
                                        break;
                                    case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
                                        tvp.getValue(tp.intp);
                                        castToString.convertYMDuration(tp.intp, dOutInner);
                                        break;
                                    case ValueTag.XS_INT_TAG:
                                    case ValueTag.XS_UNSIGNED_SHORT_TAG:
                                        tvp.getValue(tp.intp);
                                        castToString.convertInt(tp.intp, dOutInner);
                                        break;
                                    case ValueTag.XS_DECIMAL_TAG:
                                        tvp.getValue(tp.decp);
                                        castToString.convertDecimal(tp.decp, dOutInner);
                                        break;
                                    case ValueTag.XS_DOUBLE_TAG:
                                        tvp.getValue(tp.doublep);
                                        castToString.convertDouble(tp.doublep, dOutInner);
                                        break;
                                    case ValueTag.XS_FLOAT_TAG:
                                        tvp.getValue(tp.floatp);
                                        castToString.convertFloat(tp.floatp, dOutInner);
                                        break;
                                    case ValueTag.XS_SHORT_TAG:
                                    case ValueTag.XS_UNSIGNED_BYTE_TAG:
                                        tvp.getValue(tp.shortp);
                                        castToString.convertShort(tp.shortp, dOutInner);
                                        break;
                                    case ValueTag.XS_BYTE_TAG:
                                        tvp.getValue(tp.bytep);
                                        castToString.convertByte(tp.bytep, dOutInner);
                                        break;
                                    case ValueTag.SEQUENCE_TAG:
                                        tvp.getValue(tp.seqp);
                                        if (tp.seqp.getEntryCount() == 0) {
                                            // Byte Format: Type (1 byte) + String Length (2 bytes) + String.
View Full Code Here

                .createPointable();
        final TaggedValuePointable tvpCompare1 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
        final TaggedValuePointable tvpCompare2 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();

        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            AbstractCastToOperation aCastToOp = new CastToStringOperation();

            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                boolean booleanResult = false;
                TaggedValuePointable tvpArg1 = args[0];
                TaggedValuePointable tvpArg2 = args[1];
                try {
                    if (tvpArg1.getTag() == ValueTag.SEQUENCE_TAG) {
                        tvpArg1.getValue(seqp1);
                        int seqLen = seqp1.getEntryCount();
                        for (int j = 0; j < seqLen; ++j) {
                            seqp1.getEntry(j, p1);
                            tvpSeq1.set(p1.getByteArray(), p1.getStartOffset(), p1.getLength());
                            if (evaluateTaggedValueArgument2(aOp, tvpSeq1, tvpArg2, dCtx)) {
                                booleanResult = true;
                                break;
                            }
                        }
                    } else {
                        booleanResult = evaluateTaggedValueArgument2(aOp, tvpArg1, tvpArg2, dCtx);
                    }

                    byte[] byteResult = new byte[2];
                    byteResult[0] = ValueTag.XS_BOOLEAN_TAG;
                    byteResult[1] = (byte) (booleanResult ? 1 : 0);
                    result.set(byteResult, 0, 2);
                } catch (SystemException se) {
                    throw se;
                } catch (Exception e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
            }

            /**
             * Check the second argument for a sequence and loop if required.
             *
             * @param aOp
             * @param tvpArg1
             * @param tvpArg2
             * @param dCtx
             * @return
             * @throws SystemException
             */
            protected boolean evaluateTaggedValueArgument2(AbstractValueComparisonOperation aOp,
                    TaggedValuePointable tvpArg1, TaggedValuePointable tvpArg2, DynamicContext dCtx)
                    throws SystemException {
                try {
                    if (tvpArg2.getTag() == ValueTag.SEQUENCE_TAG) {
                        tvpArg2.getValue(seqp2);
                        int seqLen = seqp2.getEntryCount();
                        for (int j = 0; j < seqLen; ++j) {
                            seqp2.getEntry(j, p2);
                            tvpSeq2.set(p2.getByteArray(), p2.getStartOffset(), p2.getLength());
                            if (transformThenCompareTaggedValues(aOp, tvpArg1, tvpSeq2, dCtx)) {
                                return true;
                            }
                        }
                    } else {
                        return transformThenCompareTaggedValues(aOp, tvpArg1, tvpArg2, dCtx);
                    }
                } catch (SystemException se) {
                    throw se;
                } catch (Exception e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
                return false;
            }

            /**
             * Transform the values into values supported for general comparison.
             *
             * @param aOp
             * @param tvpArg1
             * @param tvpArg2
             * @param dCtx
             * @return
             * @throws SystemException
             */
            protected boolean transformThenCompareTaggedValues(AbstractValueComparisonOperation aOp,
                    TaggedValuePointable tvpArg1, TaggedValuePointable tvpArg2, DynamicContext dCtx)
                    throws SystemException {
                boolean tagTransformed1 = false, tagTransformed2 = false;
                abvsInner1.reset();
                abvsInner2.reset();
                tvpTransform1.set(tvpArg1);
                tvpTransform2.set(tvpArg2);
                int tid1 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform1.getTag());
                int tid2 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform2.getTag());

                // Converted tags
                try {
                    // Converts node tree's into untyped atomic values that can then be compared as atomic items.
                    if (tid1 == ValueTag.NODE_TREE_TAG && tid2 == ValueTag.NODE_TREE_TAG) {
                        ah.atomize(tvpArg1, ppool, tvpTransform1);
                        ah.atomize(tvpArg2, ppool, tvpTransform2);
                        tid1 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform1.getTag());
                        tid2 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform2.getTag());
                    } else if (tid1 == ValueTag.NODE_TREE_TAG) {
                        ah.atomize(tvpArg1, ppool, tvpTransform1);
                        tid1 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform1.getTag());
                    } else if (tid2 == ValueTag.NODE_TREE_TAG) {
                        ah.atomize(tvpArg2, ppool, tvpTransform2);
                        tid2 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform2.getTag());
                    }

                    // Set up value comparison tagged value pointables.
                    if (tid1 == ValueTag.XS_UNTYPED_ATOMIC_TAG && tid2 == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
                        // Only need to change tag since the storage is the same for untyped atomic and string.
                        tvpCompare1.getByteArray()[0] = ValueTag.XS_STRING_TAG;
                        tvpCompare2.getByteArray()[0] = ValueTag.XS_STRING_TAG;
                    } else if (tid1 == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
                        tid1 = tid2;
                        getCastToOperator(tid2);
                        tvpTransform1.getValue(tp1.utf8sp);
                        aCastToOp.convertUntypedAtomic(tp1.utf8sp, dOutInner1);
                        tvpCompare1.set(abvsInner1.getByteArray(), abvsInner1.getStartOffset(), abvsInner1.getLength());
                        tagTransformed1 = true;
                    } else if (tid2 == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
                        tid2 = tid1;
                        getCastToOperator(tid1);
                        tvpTransform2.getValue(tp2.utf8sp);
                        aCastToOp.convertUntypedAtomic(tp2.utf8sp, dOutInner2);
                        tvpCompare2.set(abvsInner2.getByteArray(), abvsInner2.getStartOffset(), abvsInner2.getLength());
                        tagTransformed2 = true;
                    }
                    // Copy over the values not changed and upgrade numeric values to double.
                    if (!tagTransformed1) {
                        tvpCompare1.set(tvpTransform1);
                        if (FunctionHelper.isDerivedFromDouble(tvpCompare1.getTag())) {
                            FunctionHelper.getDoublePointable(tvpTransform1, dOutInner1);
                            tvpCompare1.set(abvsInner1.getByteArray(), abvsInner1.getStartOffset(),
                                    DoublePointable.TYPE_TRAITS.getFixedLength() + 1);
                            tagTransformed1 = true;
                        }
                    }
                    if (!tagTransformed2) {
                        tvpCompare2.set(tvpTransform2);
                        if (FunctionHelper.isDerivedFromDouble(tvpCompare2.getTag())) {
                            FunctionHelper.getDoublePointable(tvpTransform2, dOutInner2);
                            tvpCompare2.set(abvsInner2.getByteArray(), abvsInner2.getStartOffset(),
                                    DoublePointable.TYPE_TRAITS.getFixedLength() + 1);
                            tagTransformed2 = true;
                        }
                    }
                } catch (SystemException se) {
                    throw se;
                } catch (Exception e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
                return FunctionHelper.compareTaggedValues(aOp, tvpCompare1, tvpCompare2, dCtx);
            }

            private void getCastToOperator(int tid) {
                switch (tid) {
                    case ValueTag.XS_ANY_URI_TAG:
                        aCastToOp = new CastToAnyURIOperation();
                        break;
                    case ValueTag.XS_BASE64_BINARY_TAG:
                        aCastToOp = new CastToBase64BinaryOperation();
                        break;
                    case ValueTag.XS_BOOLEAN_TAG:
                        aCastToOp = new CastToBooleanOperation();
                        break;
                    case ValueTag.XS_DATE_TAG:
                        aCastToOp = new CastToDateOperation();
                        break;
                    case ValueTag.XS_DATETIME_TAG:
                        aCastToOp = new CastToDateTimeOperation();
                        break;
                    case ValueTag.XS_DAY_TIME_DURATION_TAG:
                        aCastToOp = new CastToDTDurationOperation();
                        break;
                    case ValueTag.XS_DURATION_TAG:
                        aCastToOp = new CastToDurationOperation();
                        break;
                    case ValueTag.XS_HEX_BINARY_TAG:
                        aCastToOp = new CastToHexBinaryOperation();
                        break;
                    case ValueTag.XS_G_DAY_TAG:
                        aCastToOp = new CastToGDayOperation();
                        break;
                    case ValueTag.XS_G_MONTH_DAY_TAG:
                        aCastToOp = new CastToGMonthDayOperation();
                        break;
                    case ValueTag.XS_G_MONTH_TAG:
                        aCastToOp = new CastToGMonthOperation();
                        break;
                    case ValueTag.XS_G_YEAR_MONTH_TAG:
                        aCastToOp = new CastToGYearMonthOperation();
                        break;
                    case ValueTag.XS_G_YEAR_TAG:
                        aCastToOp = new CastToGYearOperation();
                        break;
                    case ValueTag.XS_QNAME_TAG:
                        aCastToOp = new CastToQNameOperation();
                        break;
                    case ValueTag.XS_STRING_TAG:
                        aCastToOp = new CastToStringOperation();
                        break;
                    case ValueTag.XS_TIME_TAG:
                        aCastToOp = new CastToTimeOperation();
                        break;
                    case ValueTag.XS_UNTYPED_ATOMIC_TAG:
View Full Code Here

            throws AlgebricksException {
        return new AbstractTypeScalarEvaluator(args, ctx) {
            final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
            final DataOutput dOut = abvs.getDataOutput();
            final FunctionHelper.TypedPointables tp = new FunctionHelper.TypedPointables();
            AbstractCastToOperation aOp = new CastToStringOperation();
            int castToTag = 0;

            @Override
            protected void evaluate(TaggedValuePointable tvp, IPointable result) throws SystemException {
                abvs.reset();
                int tid = tvp.getTag();
                if (castToTag == -1 || castToTag == 0) {
                    // The promote type is not supported. No change.
                    result.set(tvp);
                    return;
                } else if (castToTag > 0) {
                    try {
                        switch (tid) {
                            case ValueTag.XS_ANY_URI_TAG:
                                tvp.getValue(tp.utf8sp);
                                aOp.convertAnyURI(tp.utf8sp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            case ValueTag.XS_BYTE_TAG:
                                tvp.getValue(tp.bytep);
                                aOp.convertByte(tp.bytep, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            case ValueTag.XS_DECIMAL_TAG:
                                tvp.getValue(tp.decp);
                                aOp.convertDecimal(tp.decp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            case ValueTag.XS_DOUBLE_TAG:
                                tvp.getValue(tp.doublep);
                                aOp.convertDouble(tp.doublep, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            case ValueTag.XS_FLOAT_TAG:
                                tvp.getValue(tp.floatp);
                                aOp.convertFloat(tp.floatp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            case ValueTag.XS_INT_TAG:
                                tvp.getValue(tp.intp);
                                aOp.convertInt(tp.intp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            case ValueTag.XS_INTEGER_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertInteger(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            case ValueTag.XS_LONG_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertLong(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            case ValueTag.XS_NEGATIVE_INTEGER_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertNegativeInteger(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertNonNegativeInteger(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertNonPositiveInteger(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            case ValueTag.XS_POSITIVE_INTEGER_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertPositiveInteger(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            case ValueTag.XS_SHORT_TAG:
                                tvp.getValue(tp.shortp);
                                aOp.convertShort(tp.shortp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            case ValueTag.XS_STRING_TAG:
                                tvp.getValue(tp.utf8sp);
                                aOp.convertString(tp.utf8sp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            case ValueTag.XS_UNSIGNED_BYTE_TAG:
                                tvp.getValue(tp.shortp);
                                aOp.convertUnsignedByte(tp.shortp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            case ValueTag.XS_UNSIGNED_INT_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertUnsignedInt(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            case ValueTag.XS_UNSIGNED_LONG_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertUnsignedLong(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            case ValueTag.XS_UNSIGNED_SHORT_TAG:
                                tvp.getValue(tp.intp);
                                aOp.convertUnsignedShort(tp.intp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                return;

                            default:
                                // Promote type does not require us to change the value.
                                result.set(tvp);
                                return;
                        }
                    } catch (SystemException se) {
                        throw se;
                    } catch (Exception e) {
                        throw new SystemException(ErrorCode.SYSE0001, e);
                    }
                }
            }

            @Override
            protected void setSequenceType(SequenceType sType) {
                if (sType.getItemType() == BuiltinTypeRegistry.XS_DOUBLE) {
                    castToTag = ValueTag.XS_DOUBLE_TAG;
                    aOp = new CastToDoubleOperation();
                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_FLOAT) {
                    castToTag = ValueTag.XS_FLOAT_TAG;
                    aOp = new CastToFloatOperation();
                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_STRING) {
                    castToTag = ValueTag.XS_STRING_TAG;
                    aOp = new CastToStringOperation();
                } else {
                    castToTag = -1;
                }
            }
        };
View Full Code Here

        final VoidPointable p2 = (VoidPointable) VoidPointable.FACTORY.createPointable();
        final TaggedValuePointable tvpSeq1 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
        final TaggedValuePointable tvpSeq2 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();

        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            AbstractCastToOperation aCastToOp = new CastToStringOperation();

            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                boolean booleanResult = false;
                TaggedValuePointable tvpArg1 = args[0];
                TaggedValuePointable tvpArg2 = args[1];
                try {
                    if (tvpArg1.getTag() == ValueTag.SEQUENCE_TAG) {
                        tvpArg1.getValue(seqp1);
                        int seqLen = seqp1.getEntryCount();
                        for (int j = 0; j < seqLen; ++j) {
                            seqp1.getEntry(j, p1);
                            tvpSeq1.set(p1.getByteArray(), p1.getStartOffset(), p1.getLength());
                            if (evaluateTaggedValueArgument2(aOp, tvpSeq1, tvpArg2, dCtx)) {
                                booleanResult = true;
                                break;
                            }
                        }
                    } else {
                        booleanResult = evaluateTaggedValueArgument2(aOp, tvpArg1, tvpArg2, dCtx);
                    }

                    byte[] byteResult = new byte[2];
                    byteResult[0] = ValueTag.XS_BOOLEAN_TAG;
                    byteResult[1] = (byte) (booleanResult ? 1 : 0);
                    result.set(byteResult, 0, 2);
                } catch (SystemException se) {
                    throw se;
                } catch (Exception e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
            }

            /**
             * Check the second argument for a sequence and loop if required.
             *
             * @param aOp
             * @param tvpArg1
             * @param tvpArg2
             * @param dCtx
             * @return
             * @throws SystemException
             */
            protected boolean evaluateTaggedValueArgument2(AbstractValueComparisonOperation aOp,
                    TaggedValuePointable tvpArg1, TaggedValuePointable tvpArg2, DynamicContext dCtx)
                    throws SystemException {
                try {
                    if (tvpArg2.getTag() == ValueTag.SEQUENCE_TAG) {
                        tvpArg2.getValue(seqp2);
                        int seqLen = seqp2.getEntryCount();
                        for (int j = 0; j < seqLen; ++j) {
                            seqp2.getEntry(j, p2);
                            tvpSeq2.set(p2.getByteArray(), p2.getStartOffset(), p2.getLength());
                            if (transformThenCompareTaggedValues(aOp, tvpArg1, tvpSeq2, dCtx)) {
                                return true;
                            }
                        }
                    } else {
                        return transformThenCompareTaggedValues(aOp, tvpArg1, tvpArg2, dCtx);
                    }
                } catch (SystemException se) {
                    throw se;
                } catch (Exception e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
                return false;
            }

            /**
             * Transform the values into values supported for general comparison.
             *
             * @param aOp
             * @param tvpArg1
             * @param tvpArg2
             * @param dCtx
             * @return
             * @throws SystemException
             */
            protected boolean transformThenCompareTaggedValues(AbstractValueComparisonOperation aOp,
                    TaggedValuePointable tvpArg1, TaggedValuePointable tvpArg2, DynamicContext dCtx)
                    throws SystemException {
                boolean tagTransformed1 = false, tagTransformed2 = false;
                int tid1 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpArg1.getTag());
                int tid2 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpArg2.getTag());
                abvsInner1.reset();
                abvsInner2.reset();
                // Converted tags
                TaggedValuePointable tvp1 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
                TaggedValuePointable tvp2 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
                try {
                    // Set up value comparison tagged value pointables.
                    if (tid1 == ValueTag.XS_UNTYPED_ATOMIC_TAG && tid2 == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
                        // Only need to change tag since the storage is the same for untyped atomic and string.
                        tvp1.getByteArray()[0] = ValueTag.XS_STRING_TAG;
                        tvp2.getByteArray()[0] = ValueTag.XS_STRING_TAG;
                    } else if (tid1 == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
                        tid1 = tid2;
                        getCastToOperator(tid2);
                        tvpArg1.getValue(tp1.utf8sp);
                        aCastToOp.convertUntypedAtomic(tp1.utf8sp, dOutInner1);
                        tvp1.set(abvsInner1.getByteArray(), abvsInner1.getStartOffset(), abvsInner1.getLength());
                        tagTransformed1 = true;
                    } else if (tid2 == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
                        tid2 = tid1;
                        getCastToOperator(tid1);
                        tvpArg2.getValue(tp2.utf8sp);
                        aCastToOp.convertUntypedAtomic(tp2.utf8sp, dOutInner2);
                        tvp2.set(abvsInner2.getByteArray(), abvsInner2.getStartOffset(), abvsInner2.getLength());
                        tagTransformed2 = true;
                    }
                    // Copy over the values not changed and upgrade numeric values to double.
                    if (!tagTransformed1) {
                        tvp1 = tvpArg1;
                        if (FunctionHelper.isDerivedFromDouble(tvp1.getTag())) {
                            FunctionHelper.getDoublePointable(tvpArg1, dOutInner1);
                            tvp1.set(abvsInner1.getByteArray(), abvsInner1.getStartOffset(),
                                    DoublePointable.TYPE_TRAITS.getFixedLength() + 1);
                            tagTransformed1 = true;
                        }
                    }
                    if (!tagTransformed2) {
                        tvp2 = tvpArg2;
                        if (FunctionHelper.isDerivedFromDouble(tvp2.getTag())) {
                            FunctionHelper.getDoublePointable(tvpArg2, dOutInner2);
                            tvp2.set(abvsInner2.getByteArray(), abvsInner2.getStartOffset(),
                                    DoublePointable.TYPE_TRAITS.getFixedLength() + 1);
                            tagTransformed2 = true;
                        }
                    }
                } catch (SystemException se) {
                    throw se;
                } catch (Exception e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
                return FunctionHelper.compareTaggedValues(aOp, tvp1, tvp2, dCtx);
            }

            private void getCastToOperator(int tid) {
                switch (tid) {
                    case ValueTag.XS_ANY_URI_TAG:
                        aCastToOp = new CastToAnyURIOperation();
                        break;
                    case ValueTag.XS_BASE64_BINARY_TAG:
                        aCastToOp = new CastToBase64BinaryOperation();
                        break;
                    case ValueTag.XS_BOOLEAN_TAG:
                        aCastToOp = new CastToBooleanOperation();
                        break;
                    case ValueTag.XS_DATE_TAG:
                        aCastToOp = new CastToDateOperation();
                        break;
                    case ValueTag.XS_DATETIME_TAG:
                        aCastToOp = new CastToDateTimeOperation();
                        break;
                    case ValueTag.XS_DAY_TIME_DURATION_TAG:
                        aCastToOp = new CastToDTDurationOperation();
                        break;
                    case ValueTag.XS_DURATION_TAG:
                        aCastToOp = new CastToDurationOperation();
                        break;
                    case ValueTag.XS_HEX_BINARY_TAG:
                        aCastToOp = new CastToHexBinaryOperation();
                        break;
                    case ValueTag.XS_G_DAY_TAG:
                        aCastToOp = new CastToGDayOperation();
                        break;
                    case ValueTag.XS_G_MONTH_DAY_TAG:
                        aCastToOp = new CastToGMonthDayOperation();
                        break;
                    case ValueTag.XS_G_MONTH_TAG:
                        aCastToOp = new CastToGMonthOperation();
                        break;
                    case ValueTag.XS_G_YEAR_MONTH_TAG:
                        aCastToOp = new CastToGYearMonthOperation();
                        break;
                    case ValueTag.XS_G_YEAR_TAG:
                        aCastToOp = new CastToGYearOperation();
                        break;
                    case ValueTag.XS_QNAME_TAG:
                        aCastToOp = new CastToQNameOperation();
                        break;
                    case ValueTag.XS_STRING_TAG:
                        aCastToOp = new CastToStringOperation();
                        break;
                    case ValueTag.XS_TIME_TAG:
                        aCastToOp = new CastToTimeOperation();
                        break;
                    case ValueTag.XS_UNTYPED_ATOMIC_TAG:
View Full Code Here

            throws AlgebricksException {
        final UTF8StringPointable stringp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
        final DataOutput dOutInner = abvsInner.getDataOutput();
        final CastToStringOperation castToString = new CastToStringOperation();
        final TypedPointables tp = new TypedPointables();

        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                abvs.reset();

                try {
                    // Byte Format: Type (1 byte) + String Byte Length (2 bytes) + String.
                    DataOutput out = abvs.getDataOutput();
                    out.write(ValueTag.XS_STRING_TAG);

                    // Default values for the length and update later
                    out.write(0xFF);
                    out.write(0xFF);

                    for (int i = 0; i < args.length; i++) {
                        TaggedValuePointable tvp = args[i];

                        // TODO Update function to support cast to a string from any atomic value.
                        if (!FunctionHelper.isDerivedFromString(tvp.getTag())) {

                            try {
                                abvsInner.reset();
                                switch (tvp.getTag()) {
                                    case ValueTag.XS_ANY_URI_TAG:
                                        tvp.getValue(tp.utf8sp);
                                        castToString.convertAnyURI(tp.utf8sp, dOutInner);
                                        break;
                                    case ValueTag.XS_UNTYPED_ATOMIC_TAG:
                                        tvp.getValue(tp.utf8sp);
                                        castToString.convertUntypedAtomic(tp.utf8sp, dOutInner);
                                        break;
                                    case ValueTag.XS_BASE64_BINARY_TAG:
                                        tvp.getValue(tp.binaryp);
                                        castToString.convertBase64Binary(tp.binaryp, dOutInner);
                                        break;
                                    case ValueTag.XS_HEX_BINARY_TAG:
                                        tvp.getValue(tp.binaryp);
                                        castToString.convertHexBinary(tp.binaryp, dOutInner);
                                        break;
                                    case ValueTag.XS_BOOLEAN_TAG:
                                        tvp.getValue(tp.boolp);
                                        castToString.convertBoolean(tp.boolp, dOutInner);
                                        break;
                                    case ValueTag.XS_DATETIME_TAG:
                                        tvp.getValue(tp.datetimep);
                                        castToString.convertDatetime(tp.datetimep, dOutInner);
                                        break;
                                    case ValueTag.XS_DAY_TIME_DURATION_TAG:
                                        tvp.getValue(tp.longp);
                                        castToString.convertDTDuration(tp.longp, dOutInner);
                                        break;
                                    case ValueTag.XS_INTEGER_TAG:
                                    case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
                                    case ValueTag.XS_NEGATIVE_INTEGER_TAG:
                                    case ValueTag.XS_LONG_TAG:
                                    case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
                                    case ValueTag.XS_UNSIGNED_LONG_TAG:
                                    case ValueTag.XS_POSITIVE_INTEGER_TAG:
                                    case ValueTag.XS_UNSIGNED_INT_TAG:
                                        tvp.getValue(tp.longp);
                                        castToString.convertInteger(tp.longp, dOutInner);
                                        break;
                                    case ValueTag.XS_DURATION_TAG:
                                        tvp.getValue(tp.durationp);
                                        castToString.convertDuration(tp.durationp, dOutInner);
                                        break;
                                    case ValueTag.XS_DATE_TAG:
                                        tvp.getValue(tp.datep);
                                        castToString.convertDate(tp.datep, dOutInner);
                                        break;
                                    case ValueTag.XS_G_DAY_TAG:
                                        tvp.getValue(tp.datep);
                                        castToString.convertGDay(tp.datep, dOutInner);
                                        break;
                                    case ValueTag.XS_G_MONTH_DAY_TAG:
                                        tvp.getValue(tp.datep);
                                        castToString.convertGMonthDay(tp.datep, dOutInner);
                                        break;
                                    case ValueTag.XS_G_MONTH_TAG:
                                        tvp.getValue(tp.datep);
                                        castToString.convertGMonth(tp.datep, dOutInner);
                                        break;
                                    case ValueTag.XS_G_YEAR_MONTH_TAG:
                                        tvp.getValue(tp.datep);
                                        castToString.convertGYearMonth(tp.datep, dOutInner);
                                        break;
                                    case ValueTag.XS_G_YEAR_TAG:
                                        tvp.getValue(tp.datep);
                                        castToString.convertGYear(tp.datep, dOutInner);
                                        break;
                                    case ValueTag.XS_QNAME_TAG:
                                        tvp.getValue(tp.qnamep);
                                        castToString.convertQName(tp.qnamep, dOutInner);
                                        break;
                                    case ValueTag.XS_TIME_TAG:
                                        tvp.getValue(tp.timep);
                                        castToString.convertTime(tp.timep, dOutInner);
                                        break;
                                    case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
                                        tvp.getValue(tp.intp);
                                        castToString.convertYMDuration(tp.intp, dOutInner);
                                        break;
                                    case ValueTag.XS_INT_TAG:
                                    case ValueTag.XS_UNSIGNED_SHORT_TAG:
                                        tvp.getValue(tp.intp);
                                        castToString.convertInt(tp.intp, dOutInner);
                                        break;
                                    case ValueTag.XS_DECIMAL_TAG:
                                        tvp.getValue(tp.decp);
                                        castToString.convertDecimal(tp.decp, dOutInner);
                                        break;
                                    case ValueTag.XS_DOUBLE_TAG:
                                        tvp.getValue(tp.doublep);
                                        castToString.convertDouble(tp.doublep, dOutInner);
                                        break;
                                    case ValueTag.XS_FLOAT_TAG:
                                        tvp.getValue(tp.floatp);
                                        castToString.convertFloat(tp.floatp, dOutInner);
                                        break;
                                    case ValueTag.XS_SHORT_TAG:
                                    case ValueTag.XS_UNSIGNED_BYTE_TAG:
                                        tvp.getValue(tp.shortp);
                                        castToString.convertShort(tp.shortp, dOutInner);
                                        break;
                                    case ValueTag.XS_BYTE_TAG:
                                        tvp.getValue(tp.bytep);
                                        castToString.convertByte(tp.bytep, dOutInner);
                                        break;
                                    case ValueTag.SEQUENCE_TAG:
                                        tvp.getValue(tp.seqp);
                                        if (tp.seqp.getEntryCount() == 0) {
                                            // Byte Format: Type (1 byte) + String Length (2 bytes) + String.
View Full Code Here

    @Override
    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
            throws AlgebricksException {
        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        final DataOutput dOut = abvs.getDataOutput();
        final CastToStringOperation castToString = new CastToStringOperation();
        final TypedPointables tp = new TypedPointables();

        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                TaggedValuePointable tvp1 = args[0];
                try {
                    abvs.reset();
                    switch (tvp1.getTag()) {
                        case ValueTag.XS_ANY_URI_TAG:
                            tvp1.getValue(tp.utf8sp);
                            castToString.convertAnyURI(tp.utf8sp, dOut);
                            break;
                        case ValueTag.XS_STRING_TAG:
                        case ValueTag.XS_NORMALIZED_STRING_TAG:
                        case ValueTag.XS_TOKEN_TAG:
                        case ValueTag.XS_LANGUAGE_TAG:
                        case ValueTag.XS_NMTOKEN_TAG:
                        case ValueTag.XS_NAME_TAG:
                        case ValueTag.XS_NCNAME_TAG:
                        case ValueTag.XS_ID_TAG:
                        case ValueTag.XS_IDREF_TAG:
                        case ValueTag.XS_ENTITY_TAG:
                            tvp1.getValue(tp.utf8sp);
                            castToString.convertString(tp.utf8sp, dOut);
                            break;
                        case ValueTag.XS_UNTYPED_ATOMIC_TAG:
                            tvp1.getValue(tp.utf8sp);
                            castToString.convertUntypedAtomic(tp.utf8sp, dOut);
                            break;
                        case ValueTag.XS_BASE64_BINARY_TAG:
                            tvp1.getValue(tp.binaryp);
                            castToString.convertBase64Binary(tp.binaryp, dOut);
                            break;
                        case ValueTag.XS_HEX_BINARY_TAG:
                            tvp1.getValue(tp.binaryp);
                            castToString.convertHexBinary(tp.binaryp, dOut);
                            break;
                        case ValueTag.XS_BOOLEAN_TAG:
                            tvp1.getValue(tp.boolp);
                            castToString.convertBoolean(tp.boolp, dOut);
                            break;
                        case ValueTag.XS_DATETIME_TAG:
                            tvp1.getValue(tp.datetimep);
                            castToString.convertDatetime(tp.datetimep, dOut);
                            break;
                        case ValueTag.XS_DAY_TIME_DURATION_TAG:
                            tvp1.getValue(tp.longp);
                            castToString.convertDTDuration(tp.longp, dOut);
                            break;
                        case ValueTag.XS_INTEGER_TAG:
                        case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
                        case ValueTag.XS_NEGATIVE_INTEGER_TAG:
                        case ValueTag.XS_LONG_TAG:
                        case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
                        case ValueTag.XS_UNSIGNED_LONG_TAG:
                        case ValueTag.XS_POSITIVE_INTEGER_TAG:
                        case ValueTag.XS_UNSIGNED_INT_TAG:
                            tvp1.getValue(tp.longp);
                            castToString.convertInteger(tp.longp, dOut);
                            break;
                        case ValueTag.XS_DURATION_TAG:
                            tvp1.getValue(tp.durationp);
                            castToString.convertDuration(tp.durationp, dOut);
                            break;
                        case ValueTag.XS_DATE_TAG:
                            tvp1.getValue(tp.datep);
                            castToString.convertDate(tp.datep, dOut);
                            break;
                        case ValueTag.XS_G_DAY_TAG:
                            tvp1.getValue(tp.datep);
                            castToString.convertGDay(tp.datep, dOut);
                            break;
                        case ValueTag.XS_G_MONTH_DAY_TAG:
                            tvp1.getValue(tp.datep);
                            castToString.convertGMonthDay(tp.datep, dOut);
                            break;
                        case ValueTag.XS_G_MONTH_TAG:
                            tvp1.getValue(tp.datep);
                            castToString.convertGMonth(tp.datep, dOut);
                            break;
                        case ValueTag.XS_G_YEAR_MONTH_TAG:
                            tvp1.getValue(tp.datep);
                            castToString.convertGYearMonth(tp.datep, dOut);
                            break;
                        case ValueTag.XS_G_YEAR_TAG:
                            tvp1.getValue(tp.datep);
                            castToString.convertGYear(tp.datep, dOut);
                            break;
                        case ValueTag.XS_QNAME_TAG:
                            tvp1.getValue(tp.qnamep);
                            castToString.convertQName(tp.qnamep, dOut);
                            break;
                        case ValueTag.XS_TIME_TAG:
                            tvp1.getValue(tp.timep);
                            castToString.convertTime(tp.timep, dOut);
                            break;
                        case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
                            tvp1.getValue(tp.intp);
                            castToString.convertYMDuration(tp.intp, dOut);
                            break;
                        case ValueTag.XS_INT_TAG:
                        case ValueTag.XS_UNSIGNED_SHORT_TAG:
                            tvp1.getValue(tp.intp);
                            castToString.convertInt(tp.intp, dOut);
                            break;
                        case ValueTag.XS_DECIMAL_TAG:
                            tvp1.getValue(tp.decp);
                            castToString.convertDecimal(tp.decp, dOut);
                            break;
                        case ValueTag.XS_DOUBLE_TAG:
                            tvp1.getValue(tp.doublep);
                            castToString.convertDouble(tp.doublep, dOut);
                            break;
                        case ValueTag.XS_FLOAT_TAG:
                            tvp1.getValue(tp.floatp);
                            castToString.convertFloat(tp.floatp, dOut);
                            break;
                        case ValueTag.XS_SHORT_TAG:
                        case ValueTag.XS_UNSIGNED_BYTE_TAG:
                            tvp1.getValue(tp.shortp);
                            castToString.convertShort(tp.shortp, dOut);
                            break;
                        case ValueTag.XS_BYTE_TAG:
                            tvp1.getValue(tp.bytep);
                            castToString.convertByte(tp.bytep, dOut);
                            break;
                        case ValueTag.SEQUENCE_TAG:
                            tvp1.getValue(tp.seqp);
                            if (tp.seqp.getEntryCount() == 0) {
                                XDMConstants.setEmptyString(result);
View Full Code Here

                .createPointable();
        final TaggedValuePointable tvpCompare1 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
        final TaggedValuePointable tvpCompare2 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();

        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            AbstractCastToOperation aCastToOp = new CastToStringOperation();

            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                boolean booleanResult = false;
                TaggedValuePointable tvpArg1 = args[0];
                TaggedValuePointable tvpArg2 = args[1];
                try {
                    if (tvpArg1.getTag() == ValueTag.SEQUENCE_TAG) {
                        tvpArg1.getValue(seqp1);
                        int seqLen = seqp1.getEntryCount();
                        for (int j = 0; j < seqLen; ++j) {
                            seqp1.getEntry(j, p1);
                            tvpSeq1.set(p1.getByteArray(), p1.getStartOffset(), p1.getLength());
                            if (evaluateTaggedValueArgument2(aOp, tvpSeq1, tvpArg2, dCtx)) {
                                booleanResult = true;
                                break;
                            }
                        }
                    } else {
                        booleanResult = evaluateTaggedValueArgument2(aOp, tvpArg1, tvpArg2, dCtx);
                    }

                    byte[] byteResult = new byte[2];
                    byteResult[0] = ValueTag.XS_BOOLEAN_TAG;
                    byteResult[1] = (byte) (booleanResult ? 1 : 0);
                    result.set(byteResult, 0, 2);
                } catch (SystemException se) {
                    throw se;
                } catch (Exception e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
            }

            /**
             * Check the second argument for a sequence and loop if required.
             *
             * @param aOp
             * @param tvpArg1
             * @param tvpArg2
             * @param dCtx
             * @return
             * @throws SystemException
             */
            protected boolean evaluateTaggedValueArgument2(AbstractValueComparisonOperation aOp,
                    TaggedValuePointable tvpArg1, TaggedValuePointable tvpArg2, DynamicContext dCtx)
                    throws SystemException {
                try {
                    if (tvpArg2.getTag() == ValueTag.SEQUENCE_TAG) {
                        tvpArg2.getValue(seqp2);
                        int seqLen = seqp2.getEntryCount();
                        for (int j = 0; j < seqLen; ++j) {
                            seqp2.getEntry(j, p2);
                            tvpSeq2.set(p2.getByteArray(), p2.getStartOffset(), p2.getLength());
                            if (transformThenCompareTaggedValues(aOp, tvpArg1, tvpSeq2, dCtx)) {
                                return true;
                            }
                        }
                    } else {
                        return transformThenCompareTaggedValues(aOp, tvpArg1, tvpArg2, dCtx);
                    }
                } catch (SystemException se) {
                    throw se;
                } catch (Exception e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
                return false;
            }

            /**
             * Transform the values into values supported for general comparison.
             *
             * @param aOp
             * @param tvpArg1
             * @param tvpArg2
             * @param dCtx
             * @return
             * @throws SystemException
             */
            protected boolean transformThenCompareTaggedValues(AbstractValueComparisonOperation aOp,
                    TaggedValuePointable tvpArg1, TaggedValuePointable tvpArg2, DynamicContext dCtx)
                    throws SystemException {
                boolean tagTransformed1 = false, tagTransformed2 = false;
                abvsInner1.reset();
                abvsInner2.reset();
                tvpTransform1.set(tvpArg1);
                tvpTransform2.set(tvpArg2);
                int tid1 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform1.getTag());
                int tid2 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform2.getTag());

                // Converted tags
                try {
                    // Converts node tree's into untyped atomic values that can then be compared as atomic items.
                    if (tid1 == ValueTag.NODE_TREE_TAG && tid2 == ValueTag.NODE_TREE_TAG) {
                        ah.atomize(tvpArg1, ppool, tvpTransform1);
                        ah.atomize(tvpArg2, ppool, tvpTransform2);
                        tid1 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform1.getTag());
                        tid2 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform2.getTag());
                    } else if (tid1 == ValueTag.NODE_TREE_TAG) {
                        ah.atomize(tvpArg1, ppool, tvpTransform1);
                        tid1 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform1.getTag());
                    } else if (tid2 == ValueTag.NODE_TREE_TAG) {
                        ah.atomize(tvpArg2, ppool, tvpTransform2);
                        tid2 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform2.getTag());
                    }

                    // Set up value comparison tagged value pointables.
                    if (tid1 == ValueTag.XS_UNTYPED_ATOMIC_TAG && tid2 == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
                        // Only need to change tag since the storage is the same for untyped atomic and string.
                        tvpCompare1.getByteArray()[0] = ValueTag.XS_STRING_TAG;
                        tvpCompare2.getByteArray()[0] = ValueTag.XS_STRING_TAG;
                    } else if (tid1 == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
                        tid1 = tid2;
                        getCastToOperator(tid2);
                        tvpTransform1.getValue(tp1.utf8sp);
                        aCastToOp.convertUntypedAtomic(tp1.utf8sp, dOutInner1);
                        tvpCompare1.set(abvsInner1.getByteArray(), abvsInner1.getStartOffset(), abvsInner1.getLength());
                        tagTransformed1 = true;
                    } else if (tid2 == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
                        tid2 = tid1;
                        getCastToOperator(tid1);
                        tvpTransform2.getValue(tp2.utf8sp);
                        aCastToOp.convertUntypedAtomic(tp2.utf8sp, dOutInner2);
                        tvpCompare2.set(abvsInner2.getByteArray(), abvsInner2.getStartOffset(), abvsInner2.getLength());
                        tagTransformed2 = true;
                    }
                    // Copy over the values not changed and upgrade numeric values to double.
                    if (!tagTransformed1) {
                        tvpCompare1.set(tvpTransform1);
                        if (FunctionHelper.isDerivedFromDouble(tvpCompare1.getTag())) {
                            FunctionHelper.getDoublePointable(tvpTransform1, dOutInner1, tp1);
                            tvpCompare1.set(abvsInner1.getByteArray(), abvsInner1.getStartOffset(),
                                    DoublePointable.TYPE_TRAITS.getFixedLength() + 1);
                            tagTransformed1 = true;
                        }
                    }
                    if (!tagTransformed2) {
                        tvpCompare2.set(tvpTransform2);
                        if (FunctionHelper.isDerivedFromDouble(tvpCompare2.getTag())) {
                            FunctionHelper.getDoublePointable(tvpTransform2, dOutInner2, tp2);
                            tvpCompare2.set(abvsInner2.getByteArray(), abvsInner2.getStartOffset(),
                                    DoublePointable.TYPE_TRAITS.getFixedLength() + 1);
                            tagTransformed2 = true;
                        }
                    }
                } catch (SystemException se) {
                    throw se;
                } catch (Exception e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
                return FunctionHelper.compareTaggedValues(aOp, tvpCompare1, tvpCompare2, dCtx, tp1, tp2);
            }

            private void getCastToOperator(int tid) {
                switch (tid) {
                    case ValueTag.XS_ANY_URI_TAG:
                        aCastToOp = new CastToAnyURIOperation();
                        break;
                    case ValueTag.XS_BASE64_BINARY_TAG:
                        aCastToOp = new CastToBase64BinaryOperation();
                        break;
                    case ValueTag.XS_BOOLEAN_TAG:
                        aCastToOp = new CastToBooleanOperation();
                        break;
                    case ValueTag.XS_DATE_TAG:
                        aCastToOp = new CastToDateOperation();
                        break;
                    case ValueTag.XS_DATETIME_TAG:
                        aCastToOp = new CastToDateTimeOperation();
                        break;
                    case ValueTag.XS_DAY_TIME_DURATION_TAG:
                        aCastToOp = new CastToDTDurationOperation();
                        break;
                    case ValueTag.XS_DURATION_TAG:
                        aCastToOp = new CastToDurationOperation();
                        break;
                    case ValueTag.XS_HEX_BINARY_TAG:
                        aCastToOp = new CastToHexBinaryOperation();
                        break;
                    case ValueTag.XS_G_DAY_TAG:
                        aCastToOp = new CastToGDayOperation();
                        break;
                    case ValueTag.XS_G_MONTH_DAY_TAG:
                        aCastToOp = new CastToGMonthDayOperation();
                        break;
                    case ValueTag.XS_G_MONTH_TAG:
                        aCastToOp = new CastToGMonthOperation();
                        break;
                    case ValueTag.XS_G_YEAR_MONTH_TAG:
                        aCastToOp = new CastToGYearMonthOperation();
                        break;
                    case ValueTag.XS_G_YEAR_TAG:
                        aCastToOp = new CastToGYearOperation();
                        break;
                    case ValueTag.XS_QNAME_TAG:
                        aCastToOp = new CastToQNameOperation();
                        break;
                    case ValueTag.XS_STRING_TAG:
                        aCastToOp = new CastToStringOperation();
                        break;
                    case ValueTag.XS_TIME_TAG:
                        aCastToOp = new CastToTimeOperation();
                        break;
                    case ValueTag.XS_UNTYPED_ATOMIC_TAG:
View Full Code Here

            throws AlgebricksException {
        return new AbstractTypeScalarEvaluator(args, ctx) {
            final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
            final DataOutput dOut = abvs.getDataOutput();
            final TypedPointables tp = new TypedPointables();
            AbstractCastToOperation aOp = new CastToStringOperation();
            int castToTag = 0;

            @Override
            protected void evaluate(TaggedValuePointable tvp, IPointable result) throws SystemException {
                abvs.reset();
                int tid = tvp.getTag();
                if (castToTag == -1 || castToTag == 0) {
                    // The promote type is not supported. No change.
                    result.set(tvp);
                    return;
                } else if (castToTag > 0) {
                    try {
                        switch (tid) {
                            case ValueTag.XS_ANY_URI_TAG:
                                tvp.getValue(tp.utf8sp);
                                aOp.convertAnyURI(tp.utf8sp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_BYTE_TAG:
                                tvp.getValue(tp.bytep);
                                aOp.convertByte(tp.bytep, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_DECIMAL_TAG:
                                tvp.getValue(tp.decp);
                                aOp.convertDecimal(tp.decp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_DOUBLE_TAG:
                                tvp.getValue(tp.doublep);
                                aOp.convertDouble(tp.doublep, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_FLOAT_TAG:
                                tvp.getValue(tp.floatp);
                                aOp.convertFloat(tp.floatp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_INT_TAG:
                                tvp.getValue(tp.intp);
                                aOp.convertInt(tp.intp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_INTEGER_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertInteger(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_LONG_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertLong(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_NEGATIVE_INTEGER_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertNegativeInteger(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertNonNegativeInteger(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertNonPositiveInteger(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_POSITIVE_INTEGER_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertPositiveInteger(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_SHORT_TAG:
                                tvp.getValue(tp.shortp);
                                aOp.convertShort(tp.shortp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_STRING_TAG:
                                tvp.getValue(tp.utf8sp);
                                aOp.convertString(tp.utf8sp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_UNSIGNED_BYTE_TAG:
                                tvp.getValue(tp.shortp);
                                aOp.convertUnsignedByte(tp.shortp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_UNSIGNED_INT_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertUnsignedInt(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_UNSIGNED_LONG_TAG:
                                tvp.getValue(tp.longp);
                                aOp.convertUnsignedLong(tp.longp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            case ValueTag.XS_UNSIGNED_SHORT_TAG:
                                tvp.getValue(tp.intp);
                                aOp.convertUnsignedShort(tp.intp, dOut);
                                result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                                break;

                            default:
                                // Promote type does not require us to change the value.
                                result.set(tvp);
                                break;
                        }
                    } catch (SystemException se) {
                        throw se;
                    } catch (Exception e) {
                        throw new SystemException(ErrorCode.SYSE0001, e);
                    }
                }
            }

            @Override
            protected void setSequenceType(SequenceType sType) {
                if (sType.getItemType() == BuiltinTypeRegistry.XS_DOUBLE) {
                    castToTag = ValueTag.XS_DOUBLE_TAG;
                    aOp = new CastToDoubleOperation();
                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_FLOAT) {
                    castToTag = ValueTag.XS_FLOAT_TAG;
                    aOp = new CastToFloatOperation();
                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_STRING) {
                    castToTag = ValueTag.XS_STRING_TAG;
                    aOp = new CastToStringOperation();
                } else {
                    castToTag = -1;
                }
            }
        };
View Full Code Here

TOP

Related Classes of org.apache.vxquery.runtime.functions.cast.CastToStringOperation

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.