Search in sources :

Example 81 with DataOutput

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

the class TreeIndexTestUtils method createTupleFromCheckTuple.

@SuppressWarnings("unchecked")
public static void createTupleFromCheckTuple(CheckTuple checkTuple, ArrayTupleBuilder tupleBuilder, ArrayTupleReference tuple, ISerializerDeserializer[] fieldSerdes, boolean filtered) throws HyracksDataException {
    int fieldCount = tupleBuilder.getFieldEndOffsets().length;
    DataOutput dos = tupleBuilder.getDataOutput();
    tupleBuilder.reset();
    for (int i = 0; i < (filtered ? fieldCount - 1 : fieldCount); i++) {
        fieldSerdes[i].serialize(checkTuple.getField(i), dos);
        tupleBuilder.addFieldEndOffset();
    }
    if (filtered) {
        fieldSerdes[0].serialize(checkTuple.getField(0), dos);
        tupleBuilder.addFieldEndOffset();
    }
    tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
}
Also used : DataOutput(java.io.DataOutput)

Example 82 with DataOutput

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

the class HiveRecordParser method parse.

@Override
public void parse(IRawRecord<? extends Writable> record, DataOutput out) throws HyracksDataException {
    try {
        Writable hiveRawRecord = record.get();
        Object hiveObject = hiveSerde.deserialize(hiveRawRecord);
        int n = recordType.getFieldNames().length;
        List<Object> attributesValues = oi.getStructFieldsDataAsList(hiveObject);
        recBuilder.reset(recordType);
        recBuilder.init();
        for (int i = 0; i < n; i++) {
            final Object value = attributesValues.get(i);
            final ObjectInspector foi = fieldRefs.get(i).getFieldObjectInspector();
            fieldValueBuffer.reset();
            final DataOutput dataOutput = fieldValueBuffer.getDataOutput();
            dataOutput.writeByte(fieldTypeTags[i]);
            //get field type
            parseItem(fieldTypes[i], value, foi, dataOutput, false);
            recBuilder.addField(i, fieldValueBuffer);
        }
        recBuilder.write(out, true);
    } catch (Exception e) {
        throw new HyracksDataException(e);
    }
}
Also used : DataOutput(java.io.DataOutput) ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) IntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector) BooleanObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector) ShortObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.ShortObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) LongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) FloatObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.FloatObjectInspector) StringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector) ByteObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.ByteObjectInspector) DoubleObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector) TimestampObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector) Writable(org.apache.hadoop.io.Writable) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 83 with DataOutput

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

the class ADMDataParser method parseConstructor.

private void parseConstructor(ATypeTag typeTag, IAType objectType, DataOutput out) throws IOException {
    ATypeTag targetTypeTag = getTargetTypeTag(typeTag, objectType);
    if (targetTypeTag != null) {
        DataOutput dataOutput = out;
        if (targetTypeTag != typeTag) {
            castBuffer.reset();
            dataOutput = castBuffer.getDataOutput();
        }
        int token = admLexer.next();
        if (token == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
            token = admLexer.next();
            if (token == AdmLexer.TOKEN_STRING_LITERAL) {
                String unquoted = admLexer.getLastTokenImage().substring(1, admLexer.getLastTokenImage().length() - 1);
                if (!parseValue(unquoted, typeTag, dataOutput)) {
                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_CONSTRUCTOR_MISSING_DESERIALIZER, AdmLexer.tokenKindToString(token));
                }
                token = admLexer.next();
                if (token == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
                    if (targetTypeTag != typeTag) {
                        ITypeConvertComputer promoteComputer = ATypeHierarchy.getTypePromoteComputer(typeTag, targetTypeTag);
                        // the availability of a target type
                        assert promoteComputer != null;
                        // do the promotion; note that the type tag field should be skipped
                        promoteComputer.convertType(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1, castBuffer.getLength() - 1, out);
                    }
                    return;
                }
            }
        }
    }
    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_TYPE_MISMATCH, objectType.getTypeName() + " got " + typeTag);
}
Also used : ITypeConvertComputer(org.apache.asterix.om.types.hierachy.ITypeConvertComputer) DataOutput(java.io.DataOutput) ATypeTag(org.apache.asterix.om.types.ATypeTag)

Example 84 with DataOutput

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

the class ExternalRTreeSearchOperatorNodePushable method open.

// We override this method to specify the searched version of the index
@Override
public void open() throws HyracksDataException {
    writer.open();
    accessor = new FrameTupleAccessor(inputRecDesc);
    indexHelper.open();
    index = indexHelper.getIndexInstance();
    if (retainMissing) {
        int fieldCount = getFieldCount();
        nonMatchTupleBuild = new ArrayTupleBuilder(fieldCount);
        DataOutput out = nonMatchTupleBuild.getDataOutput();
        for (int i = 0; i < fieldCount; i++) {
            try {
                nonMatchWriter.writeMissing(out);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
            nonMatchTupleBuild.addFieldEndOffset();
        }
    } else {
        nonMatchTupleBuild = null;
    }
    ExternalRTree rTreeIndex = (ExternalRTree) index;
    try {
        searchPred = createSearchPredicate();
        tb = new ArrayTupleBuilder(recordDesc.getFieldCount());
        dos = tb.getDataOutput();
        appender = new FrameTupleAppender(new VSizeFrame(ctx));
        ISearchOperationCallback searchCallback = searchCallbackFactory.createSearchOperationCallback(indexHelper.getResource().getId(), ctx, null);
        // The next line is the reason we override this method...
        // The right thing to do would be to change the signature of createAccessor
        indexAccessor = rTreeIndex.createAccessor(searchCallback, version);
        cursor = createCursor();
        if (retainInput) {
            frameTuple = new FrameTupleReference();
        }
    } catch (Exception e) {
        throw new HyracksDataException(e);
    }
}
Also used : DataOutput(java.io.DataOutput) FrameTupleAppender(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender) FrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) IOException(java.io.IOException) ExternalRTree(org.apache.hyracks.storage.am.lsm.rtree.impls.ExternalRTree) ISearchOperationCallback(org.apache.hyracks.storage.common.ISearchOperationCallback) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IOException(java.io.IOException) FrameTupleAccessor(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor)

Example 85 with DataOutput

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

the class ADMDataParser method parseAndCastNumeric.

private void parseAndCastNumeric(ATypeTag typeTag, IAType objectType, DataOutput out) throws IOException {
    ATypeTag targetTypeTag = getTargetTypeTag(typeTag, objectType);
    DataOutput dataOutput = out;
    if (targetTypeTag != typeTag) {
        castBuffer.reset();
        dataOutput = castBuffer.getDataOutput();
    }
    if ((targetTypeTag == null) || !parseValue(admLexer.getLastTokenImage(), typeTag, dataOutput)) {
        throw new ParseException(mismatchErrorMessage + objectType.getTypeName() + mismatchErrorMessage2 + typeTag);
    }
    // target type
    if (targetTypeTag != typeTag) {
        if (ATypeHierarchy.canPromote(typeTag, targetTypeTag)) {
            // can promote typeTag to targetTypeTag
            ITypeConvertComputer promoteComputer = ATypeHierarchy.getTypePromoteComputer(typeTag, targetTypeTag);
            if (promoteComputer == null) {
                throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_CAST_ERROR, typeTag, targetTypeTag);
            }
            // do the promotion; note that the type tag field should be skipped
            promoteComputer.convertType(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1, castBuffer.getLength() - 1, out);
        } else if (ATypeHierarchy.canDemote(typeTag, targetTypeTag)) {
            // can demote source type to the target type
            ITypeConvertComputer demoteComputer = ATypeHierarchy.getTypeDemoteComputer(typeTag, targetTypeTag, true);
            if (demoteComputer == null) {
                throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_CAST_ERROR, typeTag, targetTypeTag);
            }
            // do the demotion; note that the type tag field should be skipped
            demoteComputer.convertType(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1, castBuffer.getLength() - 1, out);
        }
    }
}
Also used : ITypeConvertComputer(org.apache.asterix.om.types.hierachy.ITypeConvertComputer) DataOutput(java.io.DataOutput) ATypeTag(org.apache.asterix.om.types.ATypeTag)

Aggregations

DataOutput (java.io.DataOutput)295 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 IOException (java.io.IOException)127 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 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)116 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)96 DataOutputStream (java.io.DataOutputStream)79 ByteArrayOutputStream (java.io.ByteArrayOutputStream)60 Test (org.junit.Test)56 InvalidDataFormatException (org.apache.asterix.runtime.exceptions.InvalidDataFormatException)48 DataInputStream (java.io.DataInputStream)40 ByteArrayInputStream (java.io.ByteArrayInputStream)39 UTF8StringPointable (org.apache.hyracks.data.std.primitive.UTF8StringPointable)35 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)33