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

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


    }

    @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 {
                    abvs.reset();
                    sb.reset(abvs);
                    for (int i = 0; i < args.length; ++i) {
                        TaggedValuePointable tvp = args[i];
                        if (tvp.getTag() == ValueTag.SEQUENCE_TAG) {
                            tvp.getValue(seq);
View Full Code Here


    }

    @Override
    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
            throws AlgebricksException {
        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        final UTF8StringPointable stringp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
        final TaggedValuePointable nodep = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
        final ByteBufferInputStream bbis = new ByteBufferInputStream();
        final DataInputStream di = new DataInputStream(bbis);
        final SequenceBuilder sb = new SequenceBuilder();
        final ArrayBackedValueStorage abvsFileNode = new ArrayBackedValueStorage();
        final InputSource in = new InputSource();

        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                TaggedValuePointable tvp = args[0];
                // TODO add support empty sequence and no argument.
                if (tvp.getTag() != ValueTag.XS_STRING_TAG) {
                    throw new SystemException(ErrorCode.FORG0006);
                }
                tvp.getValue(stringp);
                try {
                    // Get the list of files.
                    bbis.setByteBuffer(ByteBuffer.wrap(Arrays.copyOfRange(stringp.getByteArray(),
                            stringp.getStartOffset(), stringp.getLength() + stringp.getStartOffset())), 0);
                    String collectionName = di.readUTF();
                    File collectionDirectory = new File(collectionName);
                    File[] list = collectionDirectory.listFiles();

                    abvs.reset();
                    sb.reset(abvs);
                    for (int i = 0; i < list.length; ++i) {
                        // Add the document node to the sequence.
                        abvsFileNode.reset();
                        FunctionHelper.readInDocFromString(list[i].getPath(), in, abvsFileNode);
                        nodep.set(abvsFileNode.getByteArray(), abvsFileNode.getStartOffset(), abvsFileNode.getLength());
                        sb.addItem(nodep);
                    }
                    sb.finish();
                    result.set(abvs);
                } catch (IOException e) {
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

    private final ArrayBackedValueStorage currentDateTime;

    public DynamicContextImpl(StaticContext sCtx) {
        this.sCtx = sCtx;
        currentDateTime = new ArrayBackedValueStorage();
        variables = new HashMap<QName, ArrayBackedValueStorage>();
    }
View Full Code Here

        value.set(currentDateTime);
    }

    @Override
    public void bindVariable(QName var, IValueReference value) {
        ArrayBackedValueStorage abvs = variables.get(var);
        if (abvs == null) {
            abvs = new ArrayBackedValueStorage();
            variables.put(var, abvs);
        }
        abvs.assign(value);
    }
View Full Code Here

        abvs.assign(value);
    }

    @Override
    public void lookupVariable(QName var, IPointable value) {
        ArrayBackedValueStorage abvs = variables.get(var);
        if (abvs == null) {
            value.set(null, -1, -1);
        } else {
            value.set(abvs);
        }
View Full Code Here

        Map<QName, ArrayBackedValueStorage> vMap = dCtx.getVariableMap();
        int nVars = vMap.size();
        QName[] variableNames = new QName[nVars];
        int[] valueOffsets = new int[nVars];
        ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        int i = 0;
        for (Map.Entry<QName, ArrayBackedValueStorage> e : vMap.entrySet()) {
            variableNames[i] = e.getKey();
            abvs.append(e.getValue());
            valueOffsets[i] = abvs.getLength();
            ++i;
        }

        return new DynamicContextImplFactory(scFactory, currentDateTime, variableNames, valueOffsets,
                Arrays.copyOfRange(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength()));
    }
View Full Code Here

    private int nodeIdCounter;

    private boolean pendingText;

    public SAXContentHandler(boolean attachTypes, ITreeNodeIdProvider nodeIdProvider) {
        docABVS = new ArrayBackedValueStorage();
        this.createNodeIds = nodeIdProvider != null;
        this.attachTypes = attachTypes;
        this.nodeIdProvider = nodeIdProvider;
        this.tempABVS = new ArrayBackedValueStorage();
        docb = new DocumentNodeBuilder();
        tnb = new TextNodeBuilder();
        cnb = new CommentNodeBuilder();
        pinb = new PINodeBuilder();
        anb = new AttributeNodeBuilder();
View Full Code Here

    @Override
    protected AbstractTaggedValueArgumentScalarEvaluator createEvaluator(IHyracksTaskContext ctx,
            IScalarEvaluator[] args) throws AlgebricksException {
        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
            final DataOutput dOut = abvs.getDataOutput();
            final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
            final DataOutput dOutInner = abvsInner.getDataOutput();
            final TypedPointables tp = new TypedPointables();
            final LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
            final CastToDecimalOperation castToDecimal = new CastToDecimalOperation();

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

                long precision = 0;
                if (args.length > 1) {
                    TaggedValuePointable tvp2 = args[1];
                    if (tvp2.getTag() != ValueTag.XS_INTEGER_TAG) {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                    tvp2.getValue(longp);
                    precision = longp.getLong();
                }

                // Check special cases.
                try {
                    switch (tid) {
                        case ValueTag.XS_FLOAT_TAG:
                            tvp1.getValue(tp.floatp);
                            if (tp.floatp.getFloat() == 0 || Float.isNaN(tp.floatp.getFloat())
                                    || Float.isInfinite(tp.floatp.getFloat())) {
                                result.set(tvp1.getByteArray(), tvp1.getStartOffset(),
                                        FloatPointable.TYPE_TRAITS.getFixedLength() + 1);
                                return;
                            }
                            break;

                        case ValueTag.XS_DOUBLE_TAG:
                            tvp1.getValue(tp.doublep);
                            if (tp.doublep.getDouble() == 0 || Double.isNaN(tp.doublep.getDouble())
                                    || Double.isInfinite(tp.doublep.getDouble())) {
                                result.set(tvp1.getByteArray(), tvp1.getStartOffset(),
                                        DoublePointable.TYPE_TRAITS.getFixedLength() + 1);
                                return;
                            }
                            break;

                    }
                } catch (Exception e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }

                // Prepare input.
                try {
                    getDecimalPointable(tp, tvp1);
                } catch (IOException e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }

                // Perform rounding on decimal value.
                // TODO round half to the nearest even number.
                long decimalPlace = tp.decp.getDecimalPlace();
                if ((precision - decimalPlace) < 0) {
                    long decimalValue = tp.decp.getDecimalValue();
                    decimalValue = (long) (decimalValue / Math.pow(10, -(precision - decimalPlace)));
                    tp.decp.setDecimal(decimalValue, (byte) precision);
                }

                // Return result.
                try {
                    switch (tvp1.getTag()) {
                        case ValueTag.XS_DECIMAL_TAG:
                            dOut.write(ValueTag.XS_DECIMAL_TAG);
                            dOut.write(tp.decp.getByteArray(), tp.decp.getStartOffset(),
                                    XSDecimalPointable.TYPE_TRAITS.getFixedLength());
                            result.set(abvs.getByteArray(), abvs.getStartOffset(),
                                    XSDecimalPointable.TYPE_TRAITS.getFixedLength() + 1);
                            return;

                        case ValueTag.XS_INTEGER_TAG:
                        case ValueTag.XS_LONG_TAG:
                        case ValueTag.XS_NEGATIVE_INTEGER_TAG:
                        case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
                        case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
                        case ValueTag.XS_POSITIVE_INTEGER_TAG:
                        case ValueTag.XS_UNSIGNED_INT_TAG:
                        case ValueTag.XS_UNSIGNED_LONG_TAG:
                            dOut.write(tvp1.getTag());
                            dOut.writeLong(tp.decp.longValue());
                            result.set(abvs.getByteArray(), abvs.getStartOffset(),
                                    LongPointable.TYPE_TRAITS.getFixedLength() + 1);
                            return;

                        case ValueTag.XS_INT_TAG:
                        case ValueTag.XS_UNSIGNED_SHORT_TAG:
                            dOut.write(tvp1.getTag());
                            dOut.writeInt(tp.decp.intValue());
                            result.set(abvs.getByteArray(), abvs.getStartOffset(),
                                    IntegerPointable.TYPE_TRAITS.getFixedLength() + 1);
                            return;

                        case ValueTag.XS_SHORT_TAG:
                        case ValueTag.XS_UNSIGNED_BYTE_TAG:
                            dOut.write(tvp1.getTag());
                            dOut.writeShort(tp.decp.shortValue());
                            result.set(abvs.getByteArray(), abvs.getStartOffset(),
                                    ShortPointable.TYPE_TRAITS.getFixedLength() + 1);
                            return;

                        case ValueTag.XS_BYTE_TAG:
                            dOut.write(tvp1.getTag());
                            dOut.writeByte(tp.decp.byteValue());
                            result.set(abvs.getByteArray(), abvs.getStartOffset(),
                                    BytePointable.TYPE_TRAITS.getFixedLength() + 1);
                            return;

                        case ValueTag.XS_FLOAT_TAG:
                            dOut.write(ValueTag.XS_FLOAT_TAG);
                            dOut.writeFloat(tp.decp.floatValue());
                            result.set(abvs.getByteArray(), abvs.getStartOffset(),
                                    FloatPointable.TYPE_TRAITS.getFixedLength() + 1);
                            return;

                        case ValueTag.XS_DOUBLE_TAG:
                            dOut.write(ValueTag.XS_DOUBLE_TAG);
                            dOut.writeDouble(tp.decp.doubleValue());
                            result.set(abvs.getByteArray(), abvs.getStartOffset(),
                                    DoublePointable.TYPE_TRAITS.getFixedLength() + 1);
                            return;
                    }
                } catch (Exception e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
            }

            private void getDecimalPointable(TypedPointables tp, TaggedValuePointable tvp) throws SystemException,
                    IOException {
                abvsInner.reset();
                long value;
                switch (tvp.getTag()) {
                    case ValueTag.XS_DECIMAL_TAG:
                        tvp.getValue(tp.decp);
                        return;

                    case ValueTag.XS_FLOAT_TAG:
                        tvp.getValue(tp.floatp);
                        castToDecimal.convertFloat(tp.floatp, dOutInner);
                        tp.decp.set(abvsInner.getByteArray(), abvsInner.getStartOffset() + 1,
                                XSDecimalPointable.TYPE_TRAITS.getFixedLength());
                        return;

                    case ValueTag.XS_DOUBLE_TAG:
                        tvp.getValue(tp.doublep);
                        castToDecimal.convertDouble(tp.doublep, dOutInner);
                        tp.decp.set(abvsInner.getByteArray(), abvsInner.getStartOffset() + 1,
                                XSDecimalPointable.TYPE_TRAITS.getFixedLength());
                        return;

                    case ValueTag.XS_INTEGER_TAG:
                    case ValueTag.XS_LONG_TAG:
                    case ValueTag.XS_NEGATIVE_INTEGER_TAG:
                    case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
                    case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
                    case ValueTag.XS_POSITIVE_INTEGER_TAG:
                    case ValueTag.XS_UNSIGNED_INT_TAG:
                    case ValueTag.XS_UNSIGNED_LONG_TAG:
                        tvp.getValue(tp.longp);
                        value = tp.longp.longValue();
                        break;

                    case ValueTag.XS_INT_TAG:
                    case ValueTag.XS_UNSIGNED_SHORT_TAG:
                        tvp.getValue(tp.intp);
                        value = tp.intp.longValue();
                        break;

                    case ValueTag.XS_SHORT_TAG:
                    case ValueTag.XS_UNSIGNED_BYTE_TAG:
                        tvp.getValue(tp.shortp);
                        value = tp.shortp.longValue();
                        break;

                    case ValueTag.XS_BYTE_TAG:
                        tvp.getValue(tp.bytep);
                        value = tp.bytep.longValue();
                        break;

                    default:
                        throw new SystemException(ErrorCode.XPTY0004);
                }
                dOutInner.write(ValueTag.XS_DECIMAL_TAG);
                tp.decp.set(abvsInner.getByteArray(), abvsInner.getStartOffset() + 1,
                        XSDecimalPointable.TYPE_TRAITS.getFixedLength());
                tp.decp.setDecimal(value, (byte) 0);
            }

            private int getBaseTypeForArithmetics(int tid) throws SystemException {
View Full Code Here

    @Override
    protected AbstractTaggedValueArgumentScalarEvaluator createEvaluator(IHyracksTaskContext ctx,
            IScalarEvaluator[] args) throws AlgebricksException {
        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
            final AbstractNumericOperation aOp = createNumericOperation();
            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.SEQUENCE_TAG:
                            tvp.getValue(tp.seqp);
                            if (tp.seqp.getEntryCount() == 0) {
                                XDMConstants.setEmptySequence(result);
                                return;
                            }

                        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

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.