Search in sources :

Example 21 with RuntimeDataException

use of org.apache.asterix.common.exceptions.RuntimeDataException in project asterixdb by apache.

the class SemiStructuredRecordReader method hasNext.

@Override
public boolean hasNext() throws IOException {
    if (done) {
        return false;
    }
    record.reset();
    boolean hasStarted = false;
    boolean hasFinished = false;
    prevCharEscape = false;
    inString = false;
    depth = 0;
    do {
        // starting from where we left off the last time
        int startPosn = bufferPosn;
        if (bufferPosn >= bufferLength) {
            startPosn = bufferPosn = 0;
            bufferLength = reader.read(inputBuffer);
            if (bufferLength < 0) {
                close();
                // EOF
                return false;
            }
        }
        if (!hasStarted) {
            for (; bufferPosn < bufferLength; ++bufferPosn) {
                // search for record begin
                if (inputBuffer[bufferPosn] == recordStart) {
                    startPosn = bufferPosn;
                    hasStarted = true;
                    depth = 1;
                    // at next invocation proceed from following byte
                    ++bufferPosn;
                    break;
                } else if (inputBuffer[bufferPosn] != ExternalDataConstants.SPACE && inputBuffer[bufferPosn] != ExternalDataConstants.TAB && inputBuffer[bufferPosn] != ExternalDataConstants.LF && inputBuffer[bufferPosn] != ExternalDataConstants.CR) {
                    // corrupted file. clear the buffer and stop reading
                    reader.reset();
                    bufferPosn = bufferLength = 0;
                    throw new RuntimeDataException(ErrorCode.RECORD_READER_MALFORMED_INPUT_STREAM);
                }
            }
        }
        if (hasStarted) {
            for (; bufferPosn < bufferLength; ++bufferPosn) {
                // search for record begin
                if (inString) {
                    // we are in a string, we only care about the string end
                    if (inputBuffer[bufferPosn] == ExternalDataConstants.QUOTE && !prevCharEscape) {
                        inString = false;
                    }
                    if (prevCharEscape) {
                        prevCharEscape = false;
                    } else {
                        prevCharEscape = inputBuffer[bufferPosn] == ExternalDataConstants.ESCAPE;
                    }
                } else {
                    if (inputBuffer[bufferPosn] == ExternalDataConstants.QUOTE) {
                        inString = true;
                    } else if (inputBuffer[bufferPosn] == recordStart) {
                        depth += 1;
                    } else if (inputBuffer[bufferPosn] == recordEnd) {
                        depth -= 1;
                        if (depth == 0) {
                            hasFinished = true;
                            // at next invocation proceed from following byte
                            ++bufferPosn;
                            break;
                        }
                    }
                }
            }
        }
        int appendLength = bufferPosn - startPosn;
        if (appendLength > 0) {
            try {
                record.append(inputBuffer, startPosn, appendLength);
            } catch (IOException e) {
                reader.reset();
                bufferPosn = bufferLength = 0;
                throw new RuntimeDataException(ErrorCode.RECORD_READER_MALFORMED_INPUT_STREAM);
            }
        }
    } while (!hasFinished);
    record.endRecord();
    recordNumber++;
    return true;
}
Also used : IOException(java.io.IOException) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Example 22 with RuntimeDataException

use of org.apache.asterix.common.exceptions.RuntimeDataException in project asterixdb by apache.

the class SubstringDescriptor method createEvaluatorFactory.

@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
    return new IScalarEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
            return new IScalarEvaluator() {

                private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private final DataOutput out = resultStorage.getDataOutput();

                private IPointable argString = new VoidPointable();

                private IPointable argStart = new VoidPointable();

                private IPointable argLen = new VoidPointable();

                private final IScalarEvaluator evalString = args[0].createScalarEvaluator(ctx);

                private final IScalarEvaluator evalStart = args[1].createScalarEvaluator(ctx);

                private final IScalarEvaluator evalLen = args[2].createScalarEvaluator(ctx);

                private final GrowableArray array = new GrowableArray();

                private final UTF8StringBuilder builder = new UTF8StringBuilder();

                private final UTF8StringPointable string = new UTF8StringPointable();

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    evalString.evaluate(tuple, argString);
                    evalStart.evaluate(tuple, argStart);
                    evalLen.evaluate(tuple, argLen);
                    byte[] bytes = argStart.getByteArray();
                    int offset = argStart.getStartOffset();
                    int start = ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 0, bytes, offset) - 1;
                    bytes = argLen.getByteArray();
                    offset = argLen.getStartOffset();
                    int len = ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 1, bytes, offset);
                    bytes = argString.getByteArray();
                    offset = argString.getStartOffset();
                    int length = argString.getLength();
                    if (bytes[offset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                    }
                    string.set(bytes, offset + 1, length - 1);
                    array.reset();
                    try {
                        UTF8StringPointable.substr(string, start, len, builder, array);
                    } catch (StringIndexOutOfBoundsException e) {
                        throw new RuntimeDataException(ErrorCode.OUT_OF_BOUND, getIdentifier(), 1, start + len - 1);
                    } catch (IOException e) {
                        throw new HyracksDataException(e);
                    }
                    try {
                        out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                        out.write(array.getByteArray(), 0, array.getLength());
                    } catch (IOException e) {
                        throw new HyracksDataException(e);
                    }
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) UTF8StringPointable(org.apache.hyracks.data.std.primitive.UTF8StringPointable) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) GrowableArray(org.apache.hyracks.data.std.util.GrowableArray) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) UTF8StringBuilder(org.apache.hyracks.data.std.util.UTF8StringBuilder) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Example 23 with RuntimeDataException

use of org.apache.asterix.common.exceptions.RuntimeDataException in project asterixdb by apache.

the class Substring2Descriptor method createEvaluatorFactory.

@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
    return new IScalarEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
            return new IScalarEvaluator() {

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private DataOutput out = resultStorage.getDataOutput();

                private IPointable argString = new VoidPointable();

                private IPointable argStart = new VoidPointable();

                private IScalarEvaluator evalString = args[0].createScalarEvaluator(ctx);

                private IScalarEvaluator evalStart = args[1].createScalarEvaluator(ctx);

                private final GrowableArray array = new GrowableArray();

                private final UTF8StringBuilder builder = new UTF8StringBuilder();

                private final UTF8StringPointable string = new UTF8StringPointable();

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    evalString.evaluate(tuple, argString);
                    evalStart.evaluate(tuple, argStart);
                    byte[] bytes = argStart.getByteArray();
                    int offset = argStart.getStartOffset();
                    int start = ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 1, bytes, offset) - 1;
                    bytes = argString.getByteArray();
                    offset = argString.getStartOffset();
                    int len = argString.getLength();
                    if (bytes[offset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                    }
                    string.set(bytes, offset + 1, len - 1);
                    array.reset();
                    try {
                        UTF8StringPointable.substr(string, start, Integer.MAX_VALUE, builder, array);
                    } catch (StringIndexOutOfBoundsException e) {
                        throw new RuntimeDataException(ErrorCode.OUT_OF_BOUND, getIdentifier(), 1, start);
                    } catch (IOException e) {
                        throw new HyracksDataException(e);
                    }
                    try {
                        out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                        out.write(array.getByteArray(), 0, array.getLength());
                    } catch (IOException e) {
                        throw new HyracksDataException(e);
                    }
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) UTF8StringPointable(org.apache.hyracks.data.std.primitive.UTF8StringPointable) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) GrowableArray(org.apache.hyracks.data.std.util.GrowableArray) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) UTF8StringBuilder(org.apache.hyracks.data.std.util.UTF8StringBuilder) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Example 24 with RuntimeDataException

use of org.apache.asterix.common.exceptions.RuntimeDataException in project asterixdb by apache.

the class InjectFailureDescriptor method createEvaluatorFactory.

@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
    return new IScalarEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
            final IPointable argPtr = new VoidPointable();
            final IScalarEvaluator[] evals = new IScalarEvaluator[args.length];
            evals[0] = args[0].createScalarEvaluator(ctx);
            evals[1] = args[1].createScalarEvaluator(ctx);
            return new IScalarEvaluator() {

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    evals[1].evaluate(tuple, argPtr);
                    ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argPtr.getByteArray()[argPtr.getStartOffset()]);
                    if (typeTag == ATypeTag.BOOLEAN) {
                        boolean argResult = ABooleanSerializerDeserializer.getBoolean(argPtr.getByteArray(), argPtr.getStartOffset() + 1);
                        if (argResult) {
                            LOGGER.log(Level.SEVERE, ctx.getTaskAttemptId() + " injecting failure");
                            throw new RuntimeDataException(ErrorCode.INJECTED_FAILURE, getIdentifier());
                        }
                    }
                    // evaluate the real evaluator
                    evals[0].evaluate(tuple, argPtr);
                    result.set(argPtr.getByteArray(), argPtr.getStartOffset(), argPtr.getLength());
                }
            };
        }
    };
}
Also used : ATypeTag(org.apache.asterix.om.types.ATypeTag) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IPointable(org.apache.hyracks.data.std.api.IPointable) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Example 25 with RuntimeDataException

use of org.apache.asterix.common.exceptions.RuntimeDataException in project asterixdb by apache.

the class JavaFunctionHelper method setArgument.

public void setArgument(int index, IValueReference valueReference) throws IOException, AsterixException {
    IVisitablePointable pointable = null;
    IJObject jObject = null;
    IAType type = finfo.getParamList().get(index);
    switch(type.getTypeTag()) {
        case OBJECT:
            pointable = pointableAllocator.allocateRecordValue(type);
            pointable.set(valueReference);
            jObject = pointableVisitor.visit((ARecordVisitablePointable) pointable, getTypeInfo(index, type));
            break;
        case ARRAY:
        case MULTISET:
            pointable = pointableAllocator.allocateListValue(type);
            pointable.set(valueReference);
            jObject = pointableVisitor.visit((AListVisitablePointable) pointable, getTypeInfo(index, type));
            break;
        case ANY:
            throw new RuntimeDataException(ErrorCode.LIBRARY_JAVA_FUNCTION_HELPER_CANNOT_HANDLE_ARGU_TYPE, type.getTypeTag());
        default:
            pointable = pointableAllocator.allocateFieldValue(type);
            pointable.set(valueReference);
            jObject = pointableVisitor.visit((AFlatValuePointable) pointable, getTypeInfo(index, type));
            break;
    }
    arguments[index] = jObject;
}
Also used : AFlatValuePointable(org.apache.asterix.om.pointables.AFlatValuePointable) ARecordVisitablePointable(org.apache.asterix.om.pointables.ARecordVisitablePointable) AListVisitablePointable(org.apache.asterix.om.pointables.AListVisitablePointable) IVisitablePointable(org.apache.asterix.om.pointables.base.IVisitablePointable) IJObject(org.apache.asterix.external.api.IJObject) IAType(org.apache.asterix.om.types.IAType) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Aggregations

RuntimeDataException (org.apache.asterix.common.exceptions.RuntimeDataException)33 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)15 IOException (java.io.IOException)12 DataOutput (java.io.DataOutput)7 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)7 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)7 IPointable (org.apache.hyracks.data.std.api.IPointable)7 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)7 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)7 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)7 ATypeTag (org.apache.asterix.om.types.ATypeTag)6 IAType (org.apache.asterix.om.types.IAType)6 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)6 AsterixException (org.apache.asterix.common.exceptions.AsterixException)5 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)4 AUnionType (org.apache.asterix.om.types.AUnionType)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 RecordBuilder (org.apache.asterix.builders.RecordBuilder)2 IInputStreamFactory (org.apache.asterix.external.api.IInputStreamFactory)2