Package org.apache.vxquery.datamodel.accessors

Examples of org.apache.vxquery.datamodel.accessors.TaggedValuePointable


        final DynamicContext dCtx = (DynamicContext) ctx.getJobletContext().getGlobalJobData();
        final SequencePointable seqp1 = (SequencePointable) SequencePointable.FACTORY.createPointable();
        final SequencePointable seqp2 = (SequencePointable) SequencePointable.FACTORY.createPointable();
        final VoidPointable p1 = (VoidPointable) VoidPointable.FACTORY.createPointable();
        final VoidPointable p2 = (VoidPointable) VoidPointable.FACTORY.createPointable();
        final TaggedValuePointable tvpSeq1 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
        final TaggedValuePointable tvpSeq2 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
        final TaggedValuePointable tvpTransform1 = (TaggedValuePointable) TaggedValuePointable.FACTORY
                .createPointable();
        final TaggedValuePointable tvpTransform2 = (TaggedValuePointable) TaggedValuePointable.FACTORY
                .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)) {
View Full Code Here


            enb.addChild(tvp);
        } else {
            NodeTreePointable ntp = ppool.takeOne(NodeTreePointable.class);
            try {
                tvp.getValue(ntp);
                TaggedValuePointable innerTvp = ppool.takeOne(TaggedValuePointable.class);
                try {
                    ntp.getRootNode(innerTvp);
                    byte nTag = innerTvp.getTag();
                    switch (nTag) {
                        case ValueTag.ATTRIBUTE_NODE_TAG: {
                            throw new SystemException(ErrorCode.XQTY0024);
                        }
                        case ValueTag.ELEMENT_NODE_TAG: {
                            ElementNodePointable enp = ppool.takeOne(ElementNodePointable.class);
                            try {
                                innerTvp.getValue(enp);
                                copyElement(enb, db, ntp, enp);
                            } finally {
                                ppool.giveBack(enp);
                            }
                            break;
                        }
                        case ValueTag.COMMENT_NODE_TAG:
                        case ValueTag.PI_NODE_TAG:
                        case ValueTag.TEXT_NODE_TAG: {
                            enb.addChild(innerTvp);
                            break;
                        }
                        case ValueTag.DOCUMENT_NODE_TAG: {
                            DocumentNodePointable dnp = ppool.takeOne(DocumentNodePointable.class);
                            try {
                                innerTvp.getValue(dnp);
                                copyDocument(enb, db, ntp, dnp);
                            } finally {
                                ppool.giveBack(dnp);
                            }
                            break;
View Full Code Here

                    // 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.
                                            dOutInner.write(ValueTag.XS_STRING_TAG);
                                            dOutInner.write(0);
                                            dOutInner.write(0);
                                            break;
                                        }
                                        // Pass through if not empty sequence.
                                    default:
                                        throw new SystemException(ErrorCode.XPTY0004);
                                }

                                stringp.set(abvsInner.getByteArray(), abvsInner.getStartOffset() + 1,
                                        abvsInner.getLength() - 1);
                            } catch (IOException e) {
                                throw new SystemException(ErrorCode.SYSE0001, e);
                            }
                        } else {
                            tvp.getValue(stringp);
                        }

                        // If its an empty string do nothing.
                        if (stringp.getUTFLength() > 0) {
                            out.write(stringp.getByteArray(), stringp.getStartOffset() + 2, stringp.getUTFLength());
View Full Code Here

    /**
     * Get the local node id from a tagged value pointable when available.
     */
    public static int getLocalNodeId(TaggedValuePointable tvp1) {
        final TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
        final TypedPointables tp = new TypedPointables();
        int localNodeId = -1;
        if (tvp1.getTag() == ValueTag.NODE_TREE_TAG) {
            tvp1.getValue(tp.ntp);
            tp.ntp.getRootNode(tvp);
            switch (tvp.getTag()) {
                case ValueTag.ATTRIBUTE_NODE_TAG:
                    tvp.getValue(tp.anp);
                    localNodeId = tp.anp.getLocalNodeId(tp.ntp);
                    break;
                case ValueTag.COMMENT_NODE_TAG:
                case ValueTag.TEXT_NODE_TAG:
                    tvp.getValue(tp.tocnp);
                    localNodeId = tp.tocnp.getLocalNodeId(tp.ntp);
                    break;
                case ValueTag.DOCUMENT_NODE_TAG:
                    tvp.getValue(tp.dnp);
                    localNodeId = tp.dnp.getLocalNodeId(tp.ntp);
                    break;
                case ValueTag.ELEMENT_NODE_TAG:
                    tvp.getValue(tp.enp);
                    localNodeId = tp.enp.getLocalNodeId(tp.ntp);
                    break;
                case ValueTag.PI_NODE_TAG:
                    tvp.getValue(tp.pinp);
                    localNodeId = tp.pinp.getLocalNodeId(tp.ntp);
                    break;
                default:
                    localNodeId = -1;
                    break;
View Full Code Here

        parser.parseFile(file, in, abvs);
    }

    public static boolean transformThenCompareMinMaxTaggedValues(AbstractValueComparisonOperation aOp,
            TaggedValuePointable tvp1, TaggedValuePointable tvp2, DynamicContext dCtx) throws SystemException {
        TaggedValuePointable tvp1new = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
        TaggedValuePointable tvp2new = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();

        ArrayBackedValueStorage abvsArgument1 = new ArrayBackedValueStorage();
        DataOutput dOutArgument1 = abvsArgument1.getDataOutput();
        ArrayBackedValueStorage abvsArgument2 = new ArrayBackedValueStorage();
        DataOutput dOutArgument2 = abvsArgument2.getDataOutput();
        CastToDoubleOperation castToDouble = new CastToDoubleOperation();
        UTF8StringPointable stringp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
        UTF8StringPointable stringp2 = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();

        try {
            abvsArgument1.reset();
            if (tvp1.getTag() == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
                tvp1.getValue(stringp);
                castToDouble.convertUntypedAtomic(stringp, dOutArgument1);
                tvp1new.set(abvsArgument1.getByteArray(), abvsArgument1.getStartOffset(),
                        DoublePointable.TYPE_TRAITS.getFixedLength() + 1);
            } else if (isDerivedFromInteger(tvp1.getTag())) {
                getIntegerPointable(tvp1, dOutArgument1);
                tvp1new.set(abvsArgument1.getByteArray(), abvsArgument1.getStartOffset(),
                        LongPointable.TYPE_TRAITS.getFixedLength() + 1);
            } else {
                tvp1new = tvp1;
            }
            abvsArgument2.reset();
            if (tvp2.getTag() == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
                tvp2.getValue(stringp2);
                castToDouble.convertUntypedAtomic(stringp2, dOutArgument2);
                tvp2new.set(abvsArgument2.getByteArray(), abvsArgument2.getStartOffset(),
                        DoublePointable.TYPE_TRAITS.getFixedLength() + 1);
            } else if (isDerivedFromInteger(tvp2.getTag())) {
                getIntegerPointable(tvp2, dOutArgument2);
                tvp2new.set(abvsArgument2.getByteArray(), abvsArgument2.getStartOffset(),
                        LongPointable.TYPE_TRAITS.getFixedLength() + 1);
            } else {
                tvp2new = tvp2;
            }
View Full Code Here

        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();

        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                TaggedValuePointable tvp1 = args[0];
                TaggedValuePointable tvp2 = args[1];

                // Only accept strings or empty sequence as input.
                if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
                    tvp1.getValue(seqp);
                    if (seqp.getEntryCount() == 0) {
                        XDMConstants.setEmptySequence(result);
                        return;
                    } else {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                } else {
                    if (!FunctionHelper.isDerivedFromString(tvp1.getTag())) {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                    tvp1.getValue(stringp1);
                }
                if (tvp2.getTag() == ValueTag.SEQUENCE_TAG) {
                    tvp2.getValue(seqp);
                    if (seqp.getEntryCount() == 0) {
                        XDMConstants.setEmptySequence(result);
                        return;
                    } else {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                } else {
                    if (!FunctionHelper.isDerivedFromString(tvp2.getTag())) {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                    tvp2.getValue(stringp2);
                }

                // Third parameter is optional.
                if (args.length > 2) {
                    TaggedValuePointable tvp3 = args[2];
                    if (tvp3.getTag() != ValueTag.XS_STRING_TAG) {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                    tvp3.getValue(stringp3);
                }
                // TODO use the third value as collation

                integerResult[0] = ValueTag.XS_INTEGER_TAG;
                long compareTo = (stringp1.compareTo(stringp2) == 0 ? 0 : (stringp1.compareTo(stringp2) > 0 ? 1 : -1));
View Full Code Here

        }
    }

    public static void buildConcatenationRec(SequencePointable sp, PointablePool pp, DataOutput out,
            NodeTreePointable ntp) throws IOException {
        TaggedValuePointable tempTVP2 = pp.takeOne(TaggedValuePointable.class);
        int nItems = sp.getEntryCount();
        for (int i = 0; i < nItems; ++i) {
            sp.getEntry(i, tempTVP2);
            switch (tempTVP2.getTag()) {
                case ValueTag.TEXT_NODE_TAG: {
                    TextOrCommentNodePointable tcnp = pp.takeOne(TextOrCommentNodePointable.class);
                    VoidPointable vp = pp.takeOne(VoidPointable.class);
                    try {
                        tempTVP2.getValue(tcnp);
                        tcnp.getValue(ntp, vp);
                        out.write(vp.getByteArray(), vp.getStartOffset() + 2, vp.getLength() - 2);
                    } finally {
                        pp.giveBack(vp);
                        pp.giveBack(tcnp);
                    }
                    break;
                }
                case ValueTag.ELEMENT_NODE_TAG: {
                    ElementNodePointable enp = pp.takeOne(ElementNodePointable.class);
                    SequencePointable sp2 = pp.takeOne(SequencePointable.class);
                    try {
                        tempTVP2.getValue(enp);
                        if (enp.childrenChunkExists()) {
                            enp.getChildrenSequence(ntp, sp2);
                            buildConcatenationRec(sp2, pp, out, ntp);
                        }
                    } finally {
View Full Code Here

        final LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        final SubstringCharacterIterator charIterator = new SubstringCharacterIterator(new UTF8StringCharacterIterator(
                stringp));
        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
        final TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();

        return new AbstractCharacterIteratorCopyingEvaluator(args, charIterator) {
            @Override
            protected void preEvaluate(TaggedValuePointable[] args) throws SystemException {
                int startingLocation = 1;
                int length = Integer.MAX_VALUE;
                abvs.reset();
                charIterator.reset();

                // Only accept string, double, and optional double as input.
                TaggedValuePointable tvp1 = args[0];
                if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
                    tvp1.getValue(seqp);
                    if (seqp.getEntryCount() == 0) {
                        XDMConstants.setEmptyString(tvp);
                        tvp.getValue(stringp);
                    } else {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                } else {
                    if (!FunctionHelper.isDerivedFromString(tvp1.getTag())) {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                    tvp1.getValue(stringp);
                }

                // TODO Check specification to see if only double? If so change passing function.
                startingLocation = getIntParameter(args[1], doublep, longp);
View Full Code Here

        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                dCtx.getCurrentDateTime(ctxDatetimep);
                TaggedValuePointable tvp1 = args[0];
                if (tvp1.getTag() != ValueTag.XS_DATETIME_TAG) {
                    throw new SystemException(ErrorCode.FORG0006);
                }
                tvp1.getValue(datetimep);

                // Second argument is optional and will used the dynamic context if not supplied.
                long tz;
                if (args.length == 2) {
                    TaggedValuePointable tvp2 = args[1];
                    if (tvp2.getTag() == ValueTag.XS_DAY_TIME_DURATION_TAG) {
                        tvp2.getValue(longp);
                        if (Math.abs(longp.getLong()) > DateTime.CHRONON_OF_HOUR * 14) {
                            throw new SystemException(ErrorCode.FODT0003);
                        }
                        tz = longp.getLong() / DateTime.CHRONON_OF_MINUTE;
                    } else {
View Full Code Here

    @Override
    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
            throws AlgebricksException {
        final DynamicContext dCtx = (DynamicContext) ctx.getJobletContext().getGlobalJobData();
        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
        final TaggedValuePointable tvpNext = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
        final TaggedValuePointable tvpSum = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
        final TaggedValuePointable tvpCount = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        final DataOutput dOut = abvs.getDataOutput();
        final AddOperation aOp = new AddOperation();
        final DivideOperation aOpDivide = new DivideOperation();

        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                TaggedValuePointable tvp = args[0];
                if (tvp.getTag() == ValueTag.SEQUENCE_TAG) {
                    tvp.getValue(seqp);
                    int seqLen = seqp.getEntryCount();
                    if (seqLen == 0) {
                        XDMConstants.setEmptySequence(result);
                    } else {
                        // Add up the sequence.
View Full Code Here

TOP

Related Classes of org.apache.vxquery.datamodel.accessors.TaggedValuePointable

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.