use of org.apache.hyracks.data.std.primitive.UTF8StringPointable in project asterixdb by apache.
the class AdjustTimeForTimeZoneDescriptor method createEvaluatorFactory.
/* (non-Javadoc)
* @see org.apache.asterix.runtime.base.IScalarFunctionDynamicDescriptor#createEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory[])
*/
@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 argPtr0 = new VoidPointable();
private IPointable argPtr1 = new VoidPointable();
private IScalarEvaluator eval0 = args[0].createScalarEvaluator(ctx);
private IScalarEvaluator eval1 = args[1].createScalarEvaluator(ctx);
private GregorianCalendarSystem calInstance = GregorianCalendarSystem.getInstance();
private final UTF8StringWriter writer = new UTF8StringWriter();
private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval0.evaluate(tuple, argPtr0);
eval1.evaluate(tuple, argPtr1);
byte[] bytes0 = argPtr0.getByteArray();
int offset0 = argPtr0.getStartOffset();
byte[] bytes1 = argPtr1.getByteArray();
int offset1 = argPtr1.getStartOffset();
int len1 = argPtr1.getLength();
try {
if (bytes0[offset0] != ATypeTag.SERIALIZED_TIME_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, bytes0[offset0], ATypeTag.SERIALIZED_TIME_TYPE_TAG);
}
if (bytes1[offset1] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
utf8Ptr.set(argPtr1.getByteArray(), offset1 + 1, len1 - 1);
int timezone = ATimeParserFactory.parseTimezonePart(bytes1, utf8Ptr.getCharStartOffset());
if (!calInstance.validateTimeZone(timezone)) {
throw new InvalidDataFormatException(getIdentifier(), "timezone");
}
int chronon = ATimeSerializerDeserializer.getChronon(bytes0, offset0 + 1);
chronon = (int) calInstance.adjustChrononByTimezone(chronon, timezone);
StringBuilder sbder = new StringBuilder();
calInstance.getExtendStringRepUntilField(chronon, timezone, sbder, Fields.HOUR, Fields.MILLISECOND, true);
out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
writer.writeUTF8(sbder.toString(), out);
} catch (IOException e1) {
throw new HyracksDataException(e1);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.hyracks.data.std.primitive.UTF8StringPointable in project asterixdb by apache.
the class ADateConstructorDescriptor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private IPointable inputArg = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private AMutableDate aDate = new AMutableDate(0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ADate> dateSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATE);
private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
try {
resultStorage.reset();
eval.evaluate(tuple, inputArg);
byte[] serString = inputArg.getByteArray();
int offset = inputArg.getStartOffset();
int len = inputArg.getLength();
if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
utf8Ptr.set(serString, offset + 1, len - 1);
int stringLength = utf8Ptr.getUTF8Length();
// the string to be parsed should be at least 8 characters: YYYYMMDD
if (stringLength < 8) {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_DATE_TYPE_TAG);
}
int startOffset = utf8Ptr.getCharStartOffset();
while (serString[startOffset] == ' ') {
startOffset++;
}
int endOffset = startOffset + stringLength - 1;
while (serString[endOffset] == ' ') {
endOffset--;
}
long chrononTimeInMs = ADateParserFactory.parseDatePart(serString, startOffset, endOffset - startOffset + 1);
short temp = 0;
if (chrononTimeInMs < 0 && chrononTimeInMs % GregorianCalendarSystem.CHRONON_OF_DAY != 0) {
temp = 1;
}
aDate.setValue((int) (chrononTimeInMs / GregorianCalendarSystem.CHRONON_OF_DAY) - temp);
dateSerde.serialize(aDate, out);
} else {
throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
result.set(resultStorage);
} catch (IOException e) {
throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_DATE_TYPE_TAG);
}
}
};
}
};
}
use of org.apache.hyracks.data.std.primitive.UTF8StringPointable in project asterixdb by apache.
the class ADateTimeConstructorDescriptor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private IPointable inputArg = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private AMutableDateTime aDateTime = new AMutableDateTime(0L);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ADateTime> datetimeSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATETIME);
private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
try {
resultStorage.reset();
eval.evaluate(tuple, inputArg);
byte[] serString = inputArg.getByteArray();
int offset = inputArg.getStartOffset();
int len = inputArg.getLength();
if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
utf8Ptr.set(serString, offset + 1, len - 1);
int stringLength = utf8Ptr.getUTF8Length();
int startOffset = utf8Ptr.getCharStartOffset();
// the string to be parsed should be at least 14 characters: YYYYMMDDhhmmss
if (stringLength < 14) {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
}
// +1 if it is negative (-)
short timeOffset = (short) ((serString[startOffset] == '-') ? 1 : 0);
timeOffset += 8;
if (serString[startOffset + timeOffset] != 'T') {
timeOffset += 2;
if (serString[startOffset + timeOffset] != 'T') {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
}
}
long chrononTimeInMs = ADateParserFactory.parseDatePart(serString, startOffset, timeOffset);
chrononTimeInMs += ATimeParserFactory.parseTimePart(serString, startOffset + timeOffset + 1, stringLength - timeOffset - 1);
aDateTime.setValue(chrononTimeInMs);
datetimeSerde.serialize(aDateTime, out);
} else {
throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
result.set(resultStorage);
} catch (IOException e) {
throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
}
}
};
}
};
}
use of org.apache.hyracks.data.std.primitive.UTF8StringPointable in project asterixdb by apache.
the class ADayTimeDurationConstructorDescriptor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private IPointable inputArg = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private AMutableDayTimeDuration aDayTimeDuration = new AMutableDayTimeDuration(0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ADayTimeDuration> dayTimeDurationSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADAYTIMEDURATION);
private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
try {
resultStorage.reset();
eval.evaluate(tuple, inputArg);
byte[] serString = inputArg.getByteArray();
int offset = inputArg.getStartOffset();
int len = inputArg.getLength();
if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
utf8Ptr.set(serString, offset + 1, len - 1);
int stringLength = utf8Ptr.getUTF8Length();
int startOffset = utf8Ptr.getCharStartOffset();
ADurationParserFactory.parseDuration(serString, startOffset, stringLength, aDayTimeDuration, ADurationParseOption.DAY_TIME);
dayTimeDurationSerde.serialize(aDayTimeDuration, out);
} else {
throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
result.set(resultStorage);
} catch (Exception e) {
throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG);
}
}
};
}
};
}
use of org.apache.hyracks.data.std.primitive.UTF8StringPointable in project asterixdb by apache.
the class ADoubleConstructorDescriptor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
private final IPointable inputArg = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private final byte[] POSITIVE_INF = UTF8StringUtil.writeStringToBytes("INF");
private final byte[] NEGATIVE_INF = UTF8StringUtil.writeStringToBytes("-INF");
private final byte[] NAN = UTF8StringUtil.writeStringToBytes("NaN");
IBinaryComparator utf8BinaryComparator = BinaryComparatorFactoryProvider.UTF8STRING_POINTABLE_INSTANCE.createBinaryComparator();
private AMutableDouble aDouble = new AMutableDouble(0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ADouble> doubleSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
try {
resultStorage.reset();
eval.evaluate(tuple, inputArg);
byte[] serString = inputArg.getByteArray();
int offset = inputArg.getStartOffset();
int len = inputArg.getLength();
if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
if (utf8BinaryComparator.compare(serString, offset + 1, len - 1, POSITIVE_INF, 0, 5) == 0) {
aDouble.setValue(Double.POSITIVE_INFINITY);
} else if (utf8BinaryComparator.compare(serString, offset + 1, len - 1, NEGATIVE_INF, 0, 6) == 0) {
aDouble.setValue(Double.NEGATIVE_INFINITY);
} else if (utf8BinaryComparator.compare(serString, offset + 1, len - 1, NAN, 0, 5) == 0) {
aDouble.setValue(Double.NaN);
} else {
utf8Ptr.set(serString, offset + 1, len - 1);
aDouble.setValue(Double.parseDouble(utf8Ptr.toString()));
}
doubleSerde.serialize(aDouble, out);
} else {
throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
result.set(resultStorage);
} catch (IOException e) {
throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
}
}
};
}
};
}
Aggregations