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;
}
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);
}
};
}
};
}
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);
}
};
}
};
}
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());
}
};
}
};
}
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;
}
Aggregations