Search in sources :

Example 16 with DataOutput

use of java.io.DataOutput in project asterixdb by apache.

the class LongParserFactory method createValueParser.

@Override
public IValueParser createValueParser() {
    return new IValueParser() {

        @Override
        public void parse(char[] buffer, int start, int length, DataOutput out) throws HyracksDataException {
            long n = 0;
            int sign = 1;
            int i = 0;
            boolean pre = true;
            for (; pre && i < length; ++i) {
                char ch = buffer[i + start];
                switch(ch) {
                    case ' ':
                    case '\t':
                    case '\n':
                    case '\r':
                    case '\f':
                        break;
                    case '-':
                        sign = -1;
                        pre = false;
                        break;
                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                    case '9':
                        pre = false;
                        n = n * 10 + (ch - '0');
                        break;
                    default:
                        String errorString = new String(buffer, i + start, length - i);
                        throw new HyracksDataException("Long Parser - a digit is expected. But, encountered this character: " + ch + " in the incoming input: " + errorString);
                }
            }
            boolean post = false;
            for (; !post && i < length; ++i) {
                char ch = buffer[i + start];
                switch(ch) {
                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                    case '9':
                        n = n * 10 + (ch - '0');
                        break;
                    default:
                        String errorString = new String(buffer, i + start, length - i);
                        throw new HyracksDataException("Long Parser - a digit is expected. But, encountered this character: " + ch + " in the incoming input: " + errorString);
                }
            }
            for (; i < length; ++i) {
                char ch = buffer[i + start];
                switch(ch) {
                    case ' ':
                    case '\t':
                    case '\n':
                    case '\r':
                    case '\f':
                        break;
                    default:
                        String errorString = new String(buffer, i + start, length - i);
                        throw new HyracksDataException("Long Parser - a whitespace, tab, new line, or form-feed expected. " + "But, encountered this character: " + ch + " in the incoming input: " + errorString);
                }
            }
            try {
                out.writeLong(n * sign);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
        }
    };
}
Also used : DataOutput(java.io.DataOutput) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 17 with DataOutput

use of java.io.DataOutput in project asterixdb by apache.

the class TupleUtils method createTuple.

@SuppressWarnings("unchecked")
public static void createTuple(ArrayTupleBuilder tupleBuilder, ArrayTupleReference tuple, ISerializerDeserializer[] fieldSerdes, boolean filtered, final Object... fields) throws HyracksDataException {
    DataOutput dos = tupleBuilder.getDataOutput();
    tupleBuilder.reset();
    int numFields = Math.min(tupleBuilder.getFieldEndOffsets().length, fields.length);
    for (int i = 0; i < numFields; i++) {
        fieldSerdes[i].serialize(fields[i], dos);
        tupleBuilder.addFieldEndOffset();
    }
    if (filtered) {
        fieldSerdes[0].serialize(fields[0], dos);
        tupleBuilder.addFieldEndOffset();
    }
    tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
}
Also used : DataOutput(java.io.DataOutput)

Example 18 with DataOutput

use of java.io.DataOutput in project asterixdb by apache.

the class TupleUtils method createIntegerTuple.

public static void createIntegerTuple(ArrayTupleBuilder tupleBuilder, ArrayTupleReference tuple, boolean filtered, final int... fields) throws HyracksDataException {
    DataOutput dos = tupleBuilder.getDataOutput();
    tupleBuilder.reset();
    for (final int i : fields) {
        IntegerSerializerDeserializer.INSTANCE.serialize(i, dos);
        tupleBuilder.addFieldEndOffset();
    }
    if (filtered) {
        IntegerSerializerDeserializer.INSTANCE.serialize(fields[0], dos);
        tupleBuilder.addFieldEndOffset();
    }
    tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
}
Also used : DataOutput(java.io.DataOutput)

Example 19 with DataOutput

use of java.io.DataOutput in project asterixdb by apache.

the class LSMRTreeWithAntiMatterTuplesSecondaryIndexSearchOperatorTest method shouldWriteFilterValueIfAppendFilterIsTrue.

@Test
public void shouldWriteFilterValueIfAppendFilterIsTrue() throws Exception {
    JobSpecification spec = new JobSpecification();
    // build tuple
    ArrayTupleBuilder tb = new ArrayTupleBuilder(secondaryKeyFieldCount);
    DataOutput dos = tb.getDataOutput();
    tb.reset();
    DoubleSerializerDeserializer.INSTANCE.serialize(61.2894, dos);
    tb.addFieldEndOffset();
    DoubleSerializerDeserializer.INSTANCE.serialize(-149.624, dos);
    tb.addFieldEndOffset();
    DoubleSerializerDeserializer.INSTANCE.serialize(61.8894, dos);
    tb.addFieldEndOffset();
    DoubleSerializerDeserializer.INSTANCE.serialize(-149.024, dos);
    tb.addFieldEndOffset();
    ISerializerDeserializer[] keyRecDescSers = { DoubleSerializerDeserializer.INSTANCE, DoubleSerializerDeserializer.INSTANCE, DoubleSerializerDeserializer.INSTANCE, DoubleSerializerDeserializer.INSTANCE };
    RecordDescriptor keyRecDesc = new RecordDescriptor(keyRecDescSers);
    ConstantTupleSourceOperatorDescriptor keyProviderOp = new ConstantTupleSourceOperatorDescriptor(spec, keyRecDesc, tb.getFieldEndOffsets(), tb.getByteArray(), tb.getSize());
    PartitionConstraintHelper.addAbsoluteLocationConstraint(spec, keyProviderOp, NC1_ID);
    int[] keyFields = { 0, 1, 2, 3 };
    RTreeSearchOperatorDescriptor secondarySearchOp = new RTreeSearchOperatorDescriptor(spec, secondaryWithFilterRecDesc, keyFields, true, true, secondaryHelperFactory, false, false, null, NoOpOperationCallbackFactory.INSTANCE, null, null, false);
    PartitionConstraintHelper.addAbsoluteLocationConstraint(spec, secondarySearchOp, NC1_ID);
    IFileSplitProvider outSplits = new ConstantFileSplitProvider(new FileSplit[] { createFile(nc1) });
    IOperatorDescriptor printer = new PlainFileWriterOperatorDescriptor(spec, outSplits, ",");
    PartitionConstraintHelper.addAbsoluteLocationConstraint(spec, printer, NC1_ID);
    spec.connect(new OneToOneConnectorDescriptor(spec), keyProviderOp, 0, secondarySearchOp, 0);
    spec.connect(new OneToOneConnectorDescriptor(spec), secondarySearchOp, 0, printer, 0);
    spec.addRoot(printer);
    runTest(spec);
}
Also used : DataOutput(java.io.DataOutput) RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) IFileSplitProvider(org.apache.hyracks.dataflow.std.file.IFileSplitProvider) ConstantFileSplitProvider(org.apache.hyracks.dataflow.std.file.ConstantFileSplitProvider) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) OneToOneConnectorDescriptor(org.apache.hyracks.dataflow.std.connectors.OneToOneConnectorDescriptor) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) ConstantTupleSourceOperatorDescriptor(org.apache.hyracks.dataflow.std.misc.ConstantTupleSourceOperatorDescriptor) IOperatorDescriptor(org.apache.hyracks.api.dataflow.IOperatorDescriptor) PlainFileWriterOperatorDescriptor(org.apache.hyracks.dataflow.std.file.PlainFileWriterOperatorDescriptor) RTreeSearchOperatorDescriptor(org.apache.hyracks.storage.am.rtree.dataflow.RTreeSearchOperatorDescriptor) JobSpecification(org.apache.hyracks.api.job.JobSpecification) RTreeSecondaryIndexSearchOperatorTest(org.apache.hyracks.tests.am.rtree.RTreeSecondaryIndexSearchOperatorTest) Test(org.junit.Test)

Example 20 with DataOutput

use of java.io.DataOutput in project asterixdb by apache.

the class AbstractRTreeOperatorTest method loadSecondaryIndex.

protected void loadSecondaryIndex() throws Exception {
    JobSpecification spec = new JobSpecification();
    // build dummy tuple containing nothing
    ArrayTupleBuilder tb = new ArrayTupleBuilder(primaryKeyFieldCount * 2);
    DataOutput dos = tb.getDataOutput();
    tb.reset();
    new UTF8StringSerializerDeserializer().serialize("0", dos);
    tb.addFieldEndOffset();
    ISerializerDeserializer[] keyRecDescSers = { new UTF8StringSerializerDeserializer(), new UTF8StringSerializerDeserializer() };
    RecordDescriptor keyRecDesc = new RecordDescriptor(keyRecDescSers);
    ConstantTupleSourceOperatorDescriptor keyProviderOp = new ConstantTupleSourceOperatorDescriptor(spec, keyRecDesc, tb.getFieldEndOffsets(), tb.getByteArray(), tb.getSize());
    PartitionConstraintHelper.addAbsoluteLocationConstraint(spec, keyProviderOp, NC1_ID);
    // - infinity
    int[] lowKeyFields = null;
    // + infinity
    int[] highKeyFields = null;
    // scan primary index
    BTreeSearchOperatorDescriptor primarySearchOp = new BTreeSearchOperatorDescriptor(spec, primaryRecDesc, lowKeyFields, highKeyFields, true, true, primaryHelperFactory, false, false, null, NoOpOperationCallbackFactory.INSTANCE, null, null, false);
    PartitionConstraintHelper.addAbsoluteLocationConstraint(spec, primarySearchOp, NC1_ID);
    // load secondary index
    int[] fieldPermutation = { 6, 7, 8, 9, 0 };
    TreeIndexBulkLoadOperatorDescriptor secondaryBulkLoad = new TreeIndexBulkLoadOperatorDescriptor(spec, secondaryRecDesc, fieldPermutation, 0.7f, false, 1000L, true, secondaryHelperFactory);
    PartitionConstraintHelper.addAbsoluteLocationConstraint(spec, secondaryBulkLoad, NC1_ID);
    NullSinkOperatorDescriptor nsOpDesc = new NullSinkOperatorDescriptor(spec);
    PartitionConstraintHelper.addAbsoluteLocationConstraint(spec, nsOpDesc, NC1_ID);
    spec.connect(new OneToOneConnectorDescriptor(spec), keyProviderOp, 0, primarySearchOp, 0);
    spec.connect(new OneToOneConnectorDescriptor(spec), primarySearchOp, 0, secondaryBulkLoad, 0);
    spec.connect(new OneToOneConnectorDescriptor(spec), secondaryBulkLoad, 0, nsOpDesc, 0);
    spec.addRoot(nsOpDesc);
    runTest(spec);
}
Also used : NullSinkOperatorDescriptor(org.apache.hyracks.dataflow.std.misc.NullSinkOperatorDescriptor) DataOutput(java.io.DataOutput) RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) BTreeSearchOperatorDescriptor(org.apache.hyracks.storage.am.btree.dataflow.BTreeSearchOperatorDescriptor) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) OneToOneConnectorDescriptor(org.apache.hyracks.dataflow.std.connectors.OneToOneConnectorDescriptor) UTF8StringSerializerDeserializer(org.apache.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) ConstantTupleSourceOperatorDescriptor(org.apache.hyracks.dataflow.std.misc.ConstantTupleSourceOperatorDescriptor) JobSpecification(org.apache.hyracks.api.job.JobSpecification) TreeIndexBulkLoadOperatorDescriptor(org.apache.hyracks.storage.am.common.dataflow.TreeIndexBulkLoadOperatorDescriptor)

Aggregations

DataOutput (java.io.DataOutput)268 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)140 IPointable (org.apache.hyracks.data.std.api.IPointable)135 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)134 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)133 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)129 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)126 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)125 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)124 IOException (java.io.IOException)117 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)116 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)96 DataOutputStream (java.io.DataOutputStream)56 InvalidDataFormatException (org.apache.asterix.runtime.exceptions.InvalidDataFormatException)48 Test (org.junit.Test)43 ByteArrayOutputStream (java.io.ByteArrayOutputStream)42 UTF8StringPointable (org.apache.hyracks.data.std.primitive.UTF8StringPointable)35 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)33 DataInputStream (java.io.DataInputStream)30 ByteArrayInputStream (java.io.ByteArrayInputStream)29