use of org.apache.hyracks.data.std.util.GrowableArray in project asterixdb by apache.
the class SubstringBeforeDescriptor 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 array0 = new VoidPointable();
private IPointable array1 = new VoidPointable();
private IScalarEvaluator evalString = args[0].createScalarEvaluator(ctx);
private IScalarEvaluator evalPattern = args[1].createScalarEvaluator(ctx);
private final GrowableArray array = new GrowableArray();
private final UTF8StringBuilder builder = new UTF8StringBuilder();
private final UTF8StringPointable stringPtr = new UTF8StringPointable();
private final UTF8StringPointable patternPtr = new UTF8StringPointable();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
evalString.evaluate(tuple, array0);
byte[] src = array0.getByteArray();
int srcOffset = array0.getStartOffset();
int srcLen = array0.getLength();
evalPattern.evaluate(tuple, array1);
byte[] pattern = array1.getByteArray();
int patternOffset = array1.getStartOffset();
int patternLen = array1.getLength();
if (src[srcOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, src[srcOffset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
if (pattern[patternOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 1, pattern[patternOffset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
try {
stringPtr.set(src, srcOffset + 1, srcLen - 1);
patternPtr.set(pattern, patternOffset + 1, patternLen - 1);
array.reset();
UTF8StringPointable.substrBefore(stringPtr, patternPtr, builder, array);
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.hyracks.data.std.util.GrowableArray 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.hyracks.data.std.util.GrowableArray 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.hyracks.data.std.util.GrowableArray in project asterixdb by apache.
the class UTF8StringPointableTest method testUppercase.
@Test
public void testUppercase() throws Exception {
UTF8StringBuilder builder = new UTF8StringBuilder();
GrowableArray storage = new GrowableArray();
UTF8StringPointable result = new UTF8StringPointable();
STRING_UTF8_MIX_LOWERCASE.uppercase(builder, storage);
result.set(storage.getByteArray(), 0, storage.getLength());
UTF8StringPointable expected = generateUTF8Pointable(UTF8StringSample.STRING_UTF8_MIX_LOWERCASE.toUpperCase());
assertEquals(0, expected.compareTo(result));
}
use of org.apache.hyracks.data.std.util.GrowableArray in project asterixdb by apache.
the class UTF8StringPointableTest method testSubstrBefore.
@Test
public void testSubstrBefore() throws Exception {
UTF8StringBuilder builder = new UTF8StringBuilder();
GrowableArray storage = new GrowableArray();
STRING_LEN_128.substrBefore(STRING_LEN_127, builder, storage);
UTF8StringPointable result = new UTF8StringPointable();
result.set(storage.getByteArray(), 0, storage.getLength());
assertEquals(0, STRING_EMPTY.compareTo(result));
storage.reset();
UTF8StringPointable testPtr = generateUTF8Pointable("Mix中文123");
UTF8StringPointable pattern = generateUTF8Pointable("文");
UTF8StringPointable expect = generateUTF8Pointable("Mix中");
testPtr.substrBefore(pattern, builder, storage);
result.set(storage.getByteArray(), 0, storage.getLength());
assertEquals(0, expect.compareTo(result));
}
Aggregations