use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.
the class DatasetUtil method createDummyKeyProviderOp.
/**
* Creates a dummy key provider operator for the primary index scan.
*
* @param spec,
* the job specification.
* @param dataset,
* the dataset to scan.
* @param metadataProvider,
* the metadata provider.
* @return a dummy key provider operator.
* @throws AlgebricksException
*/
public static IOperatorDescriptor createDummyKeyProviderOp(JobSpecification spec, Dataset dataset, MetadataProvider metadataProvider) throws AlgebricksException {
Pair<IFileSplitProvider, AlgebricksPartitionConstraint> primarySplitsAndConstraint = metadataProvider.getSplitProviderAndConstraints(dataset);
AlgebricksPartitionConstraint primaryPartitionConstraint = primarySplitsAndConstraint.second;
// Build dummy tuple containing one field with a dummy value inside.
ArrayTupleBuilder tb = new ArrayTupleBuilder(1);
DataOutput dos = tb.getDataOutput();
tb.reset();
try {
// Serialize dummy value into a field.
IntegerSerializerDeserializer.INSTANCE.serialize(0, dos);
} catch (HyracksDataException e) {
throw new AsterixException(e);
}
// Add dummy field.
tb.addFieldEndOffset();
ISerializerDeserializer[] keyRecDescSers = { IntegerSerializerDeserializer.INSTANCE };
RecordDescriptor keyRecDesc = new RecordDescriptor(keyRecDescSers);
ConstantTupleSourceOperatorDescriptor keyProviderOp = new ConstantTupleSourceOperatorDescriptor(spec, keyRecDesc, tb.getFieldEndOffsets(), tb.getByteArray(), tb.getSize());
AlgebricksPartitionConstraintHelper.setPartitionConstraintInJobSpec(spec, keyProviderOp, primaryPartitionConstraint);
return keyProviderOp;
}
use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.
the class AbstractSubBinaryEvaluator method evaluate.
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
for (int i = 0; i < pointables.length; ++i) {
evaluators[i].evaluate(tuple, pointables[i]);
}
try {
ATypeTag argTag0 = ATypeTag.VALUE_TYPE_MAPPING[pointables[0].getByteArray()[pointables[0].getStartOffset()]];
ATypeTag argTag1 = ATypeTag.VALUE_TYPE_MAPPING[pointables[1].getByteArray()[pointables[1].getStartOffset()]];
checkTypeMachingThrowsIfNot(functionName, EXPECTED_INPUT_TAGS, argTag0, argTag1);
byteArrayPointable.set(pointables[0].getByteArray(), pointables[0].getStartOffset() + 1, pointables[0].getLength() - 1);
byte[] startBytes = pointables[1].getByteArray();
int offset = pointables[1].getStartOffset();
int subStart;
// strange SQL index convention
subStart = ATypeHierarchy.getIntegerValue(BuiltinFunctions.SUBBINARY_FROM.getName(), 1, startBytes, offset) - 1;
int totalLength = byteArrayPointable.getContentLength();
int subLength = getSubLength(tuple);
if (subStart < 0) {
subStart = 0;
}
if (subStart >= totalLength || subLength < 0) {
subLength = 0;
} else if (// for the IntMax case
subLength > totalLength || subStart + subLength > totalLength) {
subLength = totalLength - subStart;
}
dataOutput.write(ATypeTag.BINARY.serialize());
int metaLength = VarLenIntEncoderDecoder.encode(subLength, metaBuffer, 0);
dataOutput.write(metaBuffer, 0, metaLength);
dataOutput.write(byteArrayPointable.getByteArray(), byteArrayPointable.getContentStartOffset() + subStart, subLength);
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.
the class BinaryConcatDescriptor 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 AbstractBinaryScalarEvaluator(ctx, args) {
private final ListAccessor listAccessor = new ListAccessor();
private final byte[] metaBuffer = new byte[5];
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ANull> nullSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ANULL);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<AMissing> missingSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AMISSING);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
evaluators[0].evaluate(tuple, pointables[0]);
byte[] data = pointables[0].getByteArray();
int offset = pointables[0].getStartOffset();
byte typeTag = data[offset];
if (typeTag != ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG && typeTag != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, typeTag, ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG, ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG);
}
try {
listAccessor.reset(data, offset);
int concatLength = 0;
for (int i = 0; i < listAccessor.size(); i++) {
int itemOffset = listAccessor.getItemOffset(i);
ATypeTag itemType = listAccessor.getItemType(itemOffset);
if (itemType != ATypeTag.BINARY) {
if (serializeUnknownIfAnyUnknown(itemType)) {
result.set(resultStorage);
return;
}
throw new UnsupportedItemTypeException(getIdentifier(), itemType.serialize());
}
concatLength += ByteArrayPointable.getContentLength(data, itemOffset);
}
dataOutput.writeByte(ATypeTag.SERIALIZED_BINARY_TYPE_TAG);
int metaLen = VarLenIntEncoderDecoder.encode(concatLength, metaBuffer, 0);
dataOutput.write(metaBuffer, 0, metaLen);
for (int i = 0; i < listAccessor.size(); i++) {
int itemOffset = listAccessor.getItemOffset(i);
int length = ByteArrayPointable.getContentLength(data, itemOffset);
dataOutput.write(data, itemOffset + ByteArrayPointable.getNumberBytesToStoreMeta(length), length);
}
} catch (IOException e) {
throw new HyracksDataException(e);
} catch (AsterixException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
private boolean serializeUnknownIfAnyUnknown(ATypeTag... tags) throws HyracksDataException {
for (ATypeTag typeTag : tags) {
if (typeTag == ATypeTag.NULL) {
nullSerde.serialize(ANull.NULL, dataOutput);
return true;
}
if (typeTag == ATypeTag.MISSING) {
missingSerde.serialize(AMissing.MISSING, dataOutput);
return true;
}
}
return false;
}
};
}
};
}
use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.
the class StringSplitDescriptor 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() {
// Argument evaluators.
private final IScalarEvaluator stringEval = args[0].createScalarEvaluator(ctx);
private final IScalarEvaluator patternEval = args[1].createScalarEvaluator(ctx);
// Argument pointers.
private final IPointable argString = new VoidPointable();
private final IPointable argPattern = new VoidPointable();
private final UTF8StringPointable argStrPtr = new UTF8StringPointable();
private final UTF8StringPointable argPatternPtr = new UTF8StringPointable();
// For an output string item.
private final ArrayBackedValueStorage itemStorge = new ArrayBackedValueStorage();
private final DataOutput itemOut = itemStorge.getDataOutput();
private final byte[] tempLengthArray = new byte[5];
// For the output list of strings.
private final AOrderedListType intListType = new AOrderedListType(BuiltinType.ASTRING, null);
private final OrderedListBuilder listBuilder = new OrderedListBuilder();
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
try {
resultStorage.reset();
// Calls argument evaluators.
stringEval.evaluate(tuple, argString);
patternEval.evaluate(tuple, argPattern);
// Gets the bytes of the source string.
byte[] srcString = argString.getByteArray();
int srcOffset = argString.getStartOffset();
int srcLen = argString.getLength();
// Type check for the first argument.
if (srcString[srcOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, srcString[srcOffset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
// Gets the bytes of the pattern string.
byte[] patternString = argPattern.getByteArray();
int patternOffset = argPattern.getStartOffset();
int patternLen = argPattern.getLength();
// Type check for the second argument.
if (patternString[patternOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 1, patternString[patternOffset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
// Sets the UTF8 String pointables.
argStrPtr.set(srcString, srcOffset + 1, srcLen - 1);
argPatternPtr.set(patternString, patternOffset + 1, patternLen - 1);
// Gets the string length of the source string.
int inputStringLen = UTF8StringUtil.getUTFLength(srcString, srcOffset + 1);
int inputStringStart = srcOffset + 1 + UTF8StringUtil.getNumBytesToStoreLength(inputStringLen);
// Gets the string length of the pattern string.
int inputPatternLen = UTF8StringUtil.getUTFLength(patternString, patternOffset + 1);
// Handles the case that the pattern is "".
boolean emptyStringPattern = inputPatternLen == 0;
// Builds a list of strings.
listBuilder.reset(intListType);
int itemStrStart = 0;
int nextMatchStart;
while (itemStrStart < inputStringLen && (nextMatchStart = UTF8StringPointable.find(argStrPtr, argPatternPtr, false, itemStrStart)) >= 0) {
// Adds an item string.
addItemString(srcString, inputStringStart, itemStrStart, emptyStringPattern ? nextMatchStart + 1 : nextMatchStart);
itemStrStart = nextMatchStart + (emptyStringPattern ? 1 : inputPatternLen);
}
if (!emptyStringPattern) {
addItemString(srcString, inputStringStart, itemStrStart, inputStringLen);
}
listBuilder.write(out, true);
result.set(resultStorage);
} catch (IOException e1) {
throw new HyracksDataException(e1);
}
}
private void addItemString(byte[] srcString, int inputStringStart, int itemStartOffset, int nextMatchStart) throws IOException {
int itemLen = nextMatchStart - itemStartOffset;
int cbytes = UTF8StringUtil.encodeUTF8Length(itemLen, tempLengthArray, 0);
itemStorge.reset();
itemOut.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
itemOut.write(tempLengthArray, 0, cbytes);
if (itemLen > 0) {
itemOut.write(srcString, inputStringStart + itemStartOffset, itemLen);
}
listBuilder.addItem(itemStorge);
}
};
}
};
}
use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.
the class StringToCodePointDescriptor 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() {
protected final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
protected final DataOutput out = resultStorage.getDataOutput();
protected final IPointable argPtr = new VoidPointable();
protected final IScalarEvaluator stringEval = args[0].createScalarEvaluator(ctx);
protected final AOrderedListType intListType = new AOrderedListType(BuiltinType.AINT64, null);
private OrderedListBuilder listBuilder = new OrderedListBuilder();
private ArrayBackedValueStorage inputVal = new ArrayBackedValueStorage();
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<AInt64> int64Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
private final AMutableInt64 aInt64 = new AMutableInt64(0);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
try {
resultStorage.reset();
stringEval.evaluate(tuple, argPtr);
byte[] serString = argPtr.getByteArray();
int offset = argPtr.getStartOffset();
if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
int len = UTF8StringUtil.getUTFLength(serString, offset + 1);
int start = offset + 1 + UTF8StringUtil.getNumBytesToStoreLength(len);
int pos = 0;
listBuilder.reset(intListType);
while (pos < len) {
int codePoint = UTF8StringUtil.UTF8ToCodePoint(serString, start + pos);
pos += UTF8StringUtil.charSize(serString, start + pos);
inputVal.reset();
aInt64.setValue(codePoint);
int64Serde.serialize(aInt64, inputVal.getDataOutput());
listBuilder.addItem(inputVal);
}
listBuilder.write(out, true);
} else {
throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
result.set(resultStorage);
} catch (IOException e1) {
throw new HyracksDataException(e1);
}
}
};
}
};
}
Aggregations