use of org.apache.hyracks.api.context.IHyracksTaskContext in project asterixdb by apache.
the class DurationFromMonthsDescriptor 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 argPtr0 = new VoidPointable();
private IScalarEvaluator eval0 = args[0].createScalarEvaluator(ctx);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ADuration> durationSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADURATION);
AMutableDuration aDuration = new AMutableDuration(0, 0);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval0.evaluate(tuple, argPtr0);
byte[] bytes = argPtr0.getByteArray();
int offset = argPtr0.getStartOffset();
aDuration.setValue(ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 0, bytes, offset), 0);
durationSerde.serialize(aDuration, out);
result.set(resultStorage);
}
};
}
};
}
use of org.apache.hyracks.api.context.IHyracksTaskContext in project asterixdb by apache.
the class DatetimeFromUnixTimeInSecsDescriptor 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 argPtr = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
// possible output types
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ADateTime> datetimeSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATETIME);
private AMutableDateTime aDatetime = new AMutableDateTime(0);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval.evaluate(tuple, argPtr);
byte[] bytes = argPtr.getByteArray();
int offset = argPtr.getStartOffset();
ATypeTag argPtrTypeTag = ATypeTag.VALUE_TYPE_MAPPING[bytes[offset]];
switch(argPtrTypeTag) {
case TINYINT:
aDatetime.setValue(AInt8SerializerDeserializer.getByte(bytes, offset + 1) * 1000l);
break;
case SMALLINT:
aDatetime.setValue(AInt16SerializerDeserializer.getShort(bytes, offset + 1) * 1000l);
break;
case INTEGER:
aDatetime.setValue(AInt32SerializerDeserializer.getInt(bytes, offset + 1) * 1000l);
break;
case BIGINT:
aDatetime.setValue(AInt64SerializerDeserializer.getLong(bytes, offset + 1) * 1000l);
break;
default:
throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_INT8_TYPE_TAG, ATypeTag.SERIALIZED_INT16_TYPE_TAG, ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT64_TYPE_TAG);
}
datetimeSerde.serialize(aDatetime, out);
result.set(resultStorage);
}
};
}
};
}
use of org.apache.hyracks.api.context.IHyracksTaskContext in project asterixdb by apache.
the class DayOfWeekDescriptor 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 argPtr = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
// possible returning types
@SuppressWarnings("unchecked")
private ISerializerDeserializer<AInt64> int64Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
private AMutableInt64 aInt64 = new AMutableInt64(0);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval.evaluate(tuple, argPtr);
byte[] bytes = argPtr.getByteArray();
int offset = argPtr.getStartOffset();
int daysSinceAnchor;
int reminder = 0;
if (bytes[offset] == ATypeTag.SERIALIZED_DATETIME_TYPE_TAG) {
daysSinceAnchor = (int) (ADateTimeSerializerDeserializer.getChronon(bytes, offset + 1) / GregorianCalendarSystem.CHRONON_OF_DAY);
reminder = (int) (ADateTimeSerializerDeserializer.getChronon(bytes, offset + 1) % GregorianCalendarSystem.CHRONON_OF_DAY);
} else if (bytes[offset] == ATypeTag.SERIALIZED_DATE_TYPE_TAG) {
daysSinceAnchor = ADateSerializerDeserializer.getChronon(bytes, offset + 1);
} else {
throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_DATETIME_TYPE_TAG, ATypeTag.SERIALIZED_DATE_TYPE_TAG);
}
// adjust the day before 1970-01-01
if (daysSinceAnchor < 0 && reminder != 0) {
daysSinceAnchor -= 1;
}
// compute the weekday (0-based, and 0 = Sunday). Adjustment is needed as
// the anchor day is Thursday.
int weekday = (daysSinceAnchor + ANCHOR_WEEKDAY) % 7;
// handle the negative weekday
if (weekday < 0) {
weekday += 7;
}
// convert from 0-based to 1-based (so 7 = Sunday)
if (weekday == 0) {
weekday = 7;
}
aInt64.setValue(weekday);
int64Serde.serialize(aInt64, out);
result.set(resultStorage);
}
};
}
};
}
use of org.apache.hyracks.api.context.IHyracksTaskContext in project asterixdb by apache.
the class TopKRunGeneratorTest method testHybridTopKShouldSwitchToFrameSorterWhenFlushed.
@Test
public void testHybridTopKShouldSwitchToFrameSorterWhenFlushed() {
int topK = 1;
IHyracksTaskContext ctx = AbstractRunGeneratorTest.testUtils.create(PAGE_SIZE);
AbstractSortRunGenerator sorter = new HybridTopKSortRunGenerator(ctx, SORT_FRAME_LIMIT, topK, SortFields, null, ComparatorFactories, RecordDesc);
}
use of org.apache.hyracks.api.context.IHyracksTaskContext in project asterixdb by apache.
the class TopKRunGeneratorTest method testHybridTopKShouldNotGenerateAnyRuns.
@Test
public void testHybridTopKShouldNotGenerateAnyRuns() throws HyracksDataException {
int topK = 1;
IHyracksTaskContext ctx = AbstractRunGeneratorTest.testUtils.create(PAGE_SIZE);
AbstractSortRunGenerator sorter = new HybridTopKSortRunGenerator(ctx, SORT_FRAME_LIMIT, topK, SortFields, null, ComparatorFactories, RecordDesc);
testInMemoryOnly(ctx, topK, ORDER.REVERSE, sorter);
}
Aggregations