Package edu.uci.ics.hyracks.data.std.util

Examples of edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage


        super(args);
    }

    @Override
    protected IAggregateEvaluator createEvaluator(IScalarEvaluator[] args) throws AlgebricksException {
        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        final GrowableIntArray slots = new GrowableIntArray();
        final ArrayBackedValueStorage dataArea = new ArrayBackedValueStorage();
        final SequencePointable seq = new SequencePointable();
        final VoidPointable p = (VoidPointable) VoidPointable.FACTORY.createPointable();
        return new AbstractTaggedValueArgumentAggregateEvaluator(args) {
            @Override
            public void init() throws AlgebricksException {
                abvs.reset();
                slots.clear();
                dataArea.reset();
            }

            @Override
            public void finish(IPointable result) throws AlgebricksException {
                if (slots.getSize() != 1) {
                    try {
                        assembleResult(abvs, slots, dataArea);
                    } catch (SystemException e) {
                        throw new AlgebricksException(e);
                    }
                    result.set(abvs);
                } else {
                    result.set(dataArea);
                }
            }

            @Override
            protected void step(TaggedValuePointable[] args) throws SystemException {
                TaggedValuePointable tvp = args[0];
                if (tvp.getTag() == ValueTag.SEQUENCE_TAG) {
                    tvp.getValue(seq);
                    int seqLen = seq.getEntryCount();
                    for (int j = 0; j < seqLen; ++j) {
                        seq.getEntry(j, p);
                        addItem(p);
                    }
                } else {
                    addItem(tvp);
                }
            }

            private void assembleResult(ArrayBackedValueStorage abvs, GrowableIntArray slots,
                    ArrayBackedValueStorage dataArea) throws SystemException {
                try {
                    DataOutput out = abvs.getDataOutput();
                    out.write(ValueTag.SEQUENCE_TAG);
                    int size = slots.getSize();
                    out.writeInt(size);
                    if (size > 0) {
                        int[] slotArray = slots.getArray();
                        for (int i = 0; i < size; ++i) {
                            out.writeInt(slotArray[i]);
                        }
                        out.write(dataArea.getByteArray(), dataArea.getStartOffset(), dataArea.getLength());
                    }
                } catch (IOException e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
            }

            private void addItem(final IPointable p) throws SystemException {
                try {
                    dataArea.getDataOutput().write(p.getByteArray(), p.getStartOffset(), p.getLength());
                    slots.append(dataArea.getLength());
                } catch (IOException e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
            }
        };
View Full Code Here


    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
            throws AlgebricksException {
        final TaggedValuePointable tvp = new TaggedValuePointable();
        final UTF8StringPointable stringp1 = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
        final UTF8StringPointable stringp2 = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        final SequencePointable seq = new SequencePointable();

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

                TaggedValuePointable tvp1 = args[0];
                TaggedValuePointable tvp2 = args[1];

                // Only accept a sequence of strings and a string.
                if (!FunctionHelper.isDerivedFromString(tvp2.getTag())) {
                    throw new SystemException(ErrorCode.FORG0006);
                }
                if (FunctionHelper.isDerivedFromString(tvp1.getTag())) {
                    try {
                        // Return first parameter as a string.
                        DataOutput out = abvs.getDataOutput();
                        tvp1.getValue(stringp1);
                        out.write(ValueTag.XS_STRING_TAG);
                        out.write(stringp1.getByteArray(), stringp1.getStartOffset(), stringp1.getLength());
                        result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                    } catch (IOException e) {
                        throw new SystemException(ErrorCode.SYSE0001, e);
                    }
                    return;
                } else if (tvp1.getTag() != ValueTag.SEQUENCE_TAG) {
                    throw new SystemException(ErrorCode.FORG0006);
                }

                // Operate on a sequence.
                tvp1.getValue(seq);
                tvp2.getValue(stringp2);

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

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

                    int seqLen = seq.getEntryCount();
                    if (seqLen != 0) {
                        for (int j = 0; j < seqLen; ++j) {
                            // Add separator if more than one value.
                            if (j > 0) {
                                out.write(stringp2.getByteArray(), stringp2.getStartOffset() + 2,
                                        stringp2.getUTFLength());
                            }
                            // Get string from sequence.
                            seq.getEntry(j, tvp);
                            if (!FunctionHelper.isDerivedFromString(tvp.getTag())) {
                                throw new SystemException(ErrorCode.FORG0006);
                            }
                            tvp.getValue(stringp1);
                            out.write(stringp1.getByteArray(), stringp1.getStartOffset() + 2, stringp1.getUTFLength());
                        }

                        // Update the full length string in the byte array.
                        abvs.getByteArray()[1] = (byte) (((abvs.getLength() - 3) >>> 8) & 0xFF);
                        abvs.getByteArray()[2] = (byte) (((abvs.getLength() - 3) >>> 0) & 0xFF);
                    }

                    result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                } catch (IOException e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
            }
        };
View Full Code Here

    }

    @Override
    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
            throws AlgebricksException {
        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        final SequenceBuilder sb = new SequenceBuilder();
        final SequencePointable seq = new SequencePointable();
        final VoidPointable p = (VoidPointable) VoidPointable.FACTORY.createPointable();
        final LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                try {
                    TaggedValuePointable tvp2 = args[1];
                    if (tvp2.getTag() != ValueTag.XS_INTEGER_TAG) {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                    tvp2.getValue(longp);

                    abvs.reset();
                    sb.reset(abvs);
                    TaggedValuePointable tvp1 = args[0];
                    if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
                        tvp1.getValue(seq);
                        int seqLen = seq.getEntryCount();
View Full Code Here

    @Override
    protected AbstractTaggedValueArgumentScalarEvaluator createEvaluator(IHyracksTaskContext ctx,
            IScalarEvaluator[] args) throws AlgebricksException {
        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            final AbstractNumericUnaryOperation aOp = createNumericUnaryOperation();
            final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
            final DataOutput dOut = abvs.getDataOutput();
            final ArrayBackedValueStorage abvsInteger = new ArrayBackedValueStorage();
            final DataOutput dOutInteger = abvsInteger.getDataOutput();
            final TypedPointables tp = new TypedPointables();

            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                TaggedValuePointable tvp = args[0];
                int tid = getBaseTypeForArithmetics(tvp.getTag());
                abvs.reset();

                try {
                    switch (tid) {
                        case ValueTag.XS_DECIMAL_TAG:
                            tvp.getValue(tp.decp);
                            aOp.operateDecimal(tp.decp, dOut);
                            result.set(abvs);
                            return;

                        case ValueTag.XS_INTEGER_TAG:
                            LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
                            switch (tvp.getTag()) {
                                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_INT_TAG:
                                case ValueTag.XS_UNSIGNED_INT_TAG:
                                case ValueTag.XS_SHORT_TAG:
                                case ValueTag.XS_UNSIGNED_SHORT_TAG:
                                case ValueTag.XS_BYTE_TAG:
                                case ValueTag.XS_UNSIGNED_BYTE_TAG:
                                    abvsInteger.reset();
                                    getIntegerPointable(tp, tvp, dOutInteger);
                                    longp.set(abvsInteger.getByteArray(), abvsInteger.getStartOffset() + 1,
                                            LongPointable.TYPE_TRAITS.getFixedLength());
                            }
                            aOp.operateInteger(longp, dOut);
                            result.set(abvs);
                            return;
View Full Code Here

    }

    @Override
    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
            throws AlgebricksException {
        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        final InputSource in = new InputSource();
        final UTF8StringPointable stringp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
        final ByteBufferInputStream bbis = new ByteBufferInputStream();
        final DataInputStream di = new DataInputStream(bbis);
View Full Code Here

    }

    @Override
    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
            throws AlgebricksException {
        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        final SequenceBuilder sb = new SequenceBuilder();
        final SequencePointable seq = new SequencePointable();
        final SequencePointable seq2 = new SequencePointable();
        final VoidPointable p = (VoidPointable) VoidPointable.FACTORY.createPointable();
        final LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                try {
                    TaggedValuePointable tvp2 = args[1];
                    if (tvp2.getTag() != ValueTag.XS_INTEGER_TAG) {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                    tvp2.getValue(longp);

                    abvs.reset();
                    sb.reset(abvs);
                    TaggedValuePointable tvp1 = args[0];
                    TaggedValuePointable tvp3 = args[2];
                    if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
                        tvp1.getValue(seq);
View Full Code Here

    @Override
    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
            throws AlgebricksException {
        final AbstractArithmeticOperation aOp = createArithmeticOperation();
        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        final DataOutput dOut = abvs.getDataOutput();
        final ArrayBackedValueStorage abvsArgument1 = new ArrayBackedValueStorage();
        final DataOutput dOutArgument1 = abvsArgument1.getDataOutput();
        final ArrayBackedValueStorage abvsArgument2 = new ArrayBackedValueStorage();
        final DataOutput dOutArgument2 = abvsArgument2.getDataOutput();
        final FunctionHelper.TypedPointables tp1 = new FunctionHelper.TypedPointables();
        final FunctionHelper.TypedPointables tp2 = new FunctionHelper.TypedPointables();
        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
        final DynamicContext dCtx = (DynamicContext) ctx.getJobletContext().getGlobalJobData();
        final CastToDoubleOperation castToDouble = new CastToDoubleOperation();

        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                TaggedValuePointable tvp1 = args[0];
                TaggedValuePointable tvp2 = args[1];
                if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
                    tvp1.getValue(seqp);
                    if (seqp.getEntryCount() == 0) {
                        result.set(tvp1);
                        return;
                    }
                    throw new SystemException(ErrorCode.XPTY0004);
                }
                if (tvp2.getTag() == ValueTag.SEQUENCE_TAG) {
                    tvp2.getValue(seqp);
                    if (seqp.getEntryCount() == 0) {
                        result.set(tvp2);
                        return;
                    }
                    throw new SystemException(ErrorCode.XPTY0004);
                }
                abvs.reset();
                try {
                    int tid1 = FunctionHelper.getBaseTypeForArithmetics(tvp1.getTag());
                    int tid2 = FunctionHelper.getBaseTypeForArithmetics(tvp2.getTag());
                    LongPointable longp1 = (LongPointable) LongPointable.FACTORY.createPointable();
                    DoublePointable doublep1 = (DoublePointable) DoublePointable.FACTORY.createPointable();
                    switch (tvp1.getTag()) {
                        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_INT_TAG:
                        case ValueTag.XS_UNSIGNED_INT_TAG:
                        case ValueTag.XS_SHORT_TAG:
                        case ValueTag.XS_UNSIGNED_SHORT_TAG:
                        case ValueTag.XS_BYTE_TAG:
                        case ValueTag.XS_UNSIGNED_BYTE_TAG:
                            abvsArgument1.reset();
                            FunctionHelper.getIntegerPointable(tvp1, dOutArgument1);
                            longp1.set(abvsArgument1.getByteArray(), abvsArgument1.getStartOffset() + 1,
                                    LongPointable.TYPE_TRAITS.getFixedLength());
                            break;
                        case ValueTag.XS_DOUBLE_TAG:
                            tvp1.getValue(doublep1);
                            break;
                        case ValueTag.XS_UNTYPED_ATOMIC_TAG:
                            tid1 = ValueTag.XS_DOUBLE_TAG;
                            tvp1.getValue(tp1.utf8sp);
                            abvsArgument1.reset();
                            castToDouble.convertUntypedAtomic(tp1.utf8sp, dOutArgument1);
                            doublep1.set(abvsArgument1.getByteArray(), abvsArgument1.getStartOffset() + 1,
                                    DoublePointable.TYPE_TRAITS.getFixedLength());
                            break;
                    }
                    LongPointable longp2 = (LongPointable) LongPointable.FACTORY.createPointable();
                    DoublePointable doublep2 = (DoublePointable) DoublePointable.FACTORY.createPointable();
                    switch (tvp2.getTag()) {
                        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_INT_TAG:
                        case ValueTag.XS_UNSIGNED_INT_TAG:
                        case ValueTag.XS_SHORT_TAG:
                        case ValueTag.XS_UNSIGNED_SHORT_TAG:
                        case ValueTag.XS_BYTE_TAG:
                        case ValueTag.XS_UNSIGNED_BYTE_TAG:
                            abvsArgument2.reset();
                            FunctionHelper.getIntegerPointable(tvp2, dOutArgument2);
                            longp2.set(abvsArgument2.getByteArray(), abvsArgument2.getStartOffset() + 1,
                                    LongPointable.TYPE_TRAITS.getFixedLength());
                            break;
                        case ValueTag.XS_DOUBLE_TAG:
                            tvp2.getValue(doublep2);
                            break;
                        case ValueTag.XS_UNTYPED_ATOMIC_TAG:
                            tid2 = ValueTag.XS_DOUBLE_TAG;
                            tvp2.getValue(tp2.utf8sp);
                            abvsArgument2.reset();
                            castToDouble.convertUntypedAtomic(tp2.utf8sp, dOutArgument2);
                            doublep2.set(abvsArgument2.getByteArray(), abvsArgument2.getStartOffset() + 1,
                                    DoublePointable.TYPE_TRAITS.getFixedLength());
                            break;
                    }
                    switch (tid1) {
                        case ValueTag.XS_DECIMAL_TAG:
View Full Code Here

    }

    @Override
    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
            throws AlgebricksException {
        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        final SequenceBuilder sb = new SequenceBuilder();
        final SequencePointable seq = new SequencePointable();
        final VoidPointable p = (VoidPointable) VoidPointable.FACTORY.createPointable();
        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                try {
                    TaggedValuePointable tvp = args[0];
                    if (tvp.getTag() == ValueTag.SEQUENCE_TAG) {
                        abvs.reset();
                        sb.reset(abvs);
                        tvp.getValue(seq);
                        int seqLen = seq.getEntryCount();
                        for (int j = 0; j < seqLen; ++j) {
                            seq.getEntry(seqLen - j - 1, p);
View Full Code Here

    @Override
    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
            throws AlgebricksException {
        final AbstractValueComparisonOperation aOp = createValueComparisonOperation();
        final ArrayBackedValueStorage abvsInner1 = new ArrayBackedValueStorage();
        final DataOutput dOutInner1 = abvsInner1.getDataOutput();
        final ArrayBackedValueStorage abvsInner2 = new ArrayBackedValueStorage();
        final DataOutput dOutInner2 = abvsInner2.getDataOutput();

        final FunctionHelper.TypedPointables tp1 = new FunctionHelper.TypedPointables();
        final FunctionHelper.TypedPointables tp2 = new FunctionHelper.TypedPointables();
        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();

        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) {
View Full Code Here

    @Override
    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
            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);
View Full Code Here

TOP

Related Classes of edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage

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.