use of org.apache.asterix.om.base.AMutableInt64 in project asterixdb by apache.
the class RangeMapBuilder method parseLiteralToBytes.
@SuppressWarnings("unchecked")
private static void parseLiteralToBytes(Expression item, DataOutput out) throws CompilationException {
AMutableDouble aDouble = new AMutableDouble(0);
AMutableFloat aFloat = new AMutableFloat(0);
AMutableInt64 aInt64 = new AMutableInt64(0);
AMutableInt32 aInt32 = new AMutableInt32(0);
AMutableString aString = new AMutableString("");
@SuppressWarnings("rawtypes") ISerializerDeserializer serde;
Literal l = ((LiteralExpr) item).getValue();
try {
switch(l.getLiteralType()) {
case DOUBLE:
DoubleLiteral dl = (DoubleLiteral) l;
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
aDouble.setValue(dl.getValue());
serde.serialize(aDouble, out);
break;
case FLOAT:
FloatLiteral fl = (FloatLiteral) l;
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
aFloat.setValue(fl.getValue());
serde.serialize(aFloat, out);
break;
case INTEGER:
IntegerLiteral il = (IntegerLiteral) l;
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
aInt32.setValue(il.getValue());
serde.serialize(aInt32, out);
break;
case LONG:
LongIntegerLiteral lil = (LongIntegerLiteral) l;
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
aInt64.setValue(lil.getValue());
serde.serialize(aInt64, out);
break;
case STRING:
StringLiteral sl = (StringLiteral) l;
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
aString.setValue(sl.getValue());
serde.serialize(aString, out);
break;
default:
throw new NotImplementedException("The range map builder has not been implemented for " + item.getKind() + " type of expressions.");
}
} catch (HyracksDataException e) {
throw new CompilationException(e.getMessage());
}
}
use of org.apache.asterix.om.base.AMutableInt64 in project asterixdb by apache.
the class BinaryLengthDescriptor 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 AMutableInt64 result = new AMutableInt64(0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<AInt64> intSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable resultPointable) throws HyracksDataException {
resultStorage.reset();
evaluators[0].evaluate(tuple, pointables[0]);
ATypeTag tag = ATypeTag.VALUE_TYPE_MAPPING[pointables[0].getByteArray()[pointables[0].getStartOffset()]];
checkTypeMachingThrowsIfNot(getIdentifier().getName(), EXPECTED_TAGS, tag);
int len = ByteArrayPointable.getContentLength(pointables[0].getByteArray(), pointables[0].getStartOffset() + 1);
result.setValue(len);
intSerde.serialize(result, dataOutput);
resultPointable.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.om.base.AMutableInt64 in project asterixdb by apache.
the class TemporalDayAccessor method createEvaluatorFactory.
/* (non-Javadoc)
* @see org.apache.asterix.om.function.IFunctionDescriptor#createEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory[])
*/
@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 argPtr = new VoidPointable();
private final IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private final GregorianCalendarSystem calSystem = GregorianCalendarSystem.getInstance();
// for output: type integer
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<AInt64> intSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
private final AMutableInt64 aMutableInt64 = new AMutableInt64(0);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
eval.evaluate(tuple, argPtr);
byte[] bytes = argPtr.getByteArray();
int startOffset = argPtr.getStartOffset();
resultStorage.reset();
try {
if (bytes[startOffset] == ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
aMutableInt64.setValue(calSystem.getDurationDay(ADurationSerializerDeserializer.getDayTime(bytes, startOffset + 1)));
intSerde.serialize(aMutableInt64, out);
result.set(resultStorage);
return;
}
if (bytes[startOffset] == ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG) {
aMutableInt64.setValue(calSystem.getDurationDay(ADayTimeDurationSerializerDeserializer.getDayTime(bytes, startOffset + 1)));
intSerde.serialize(aMutableInt64, out);
result.set(resultStorage);
return;
}
long chrononTimeInMs = 0;
if (bytes[startOffset] == ATypeTag.SERIALIZED_DATE_TYPE_TAG) {
chrononTimeInMs = AInt32SerializerDeserializer.getInt(bytes, startOffset + 1) * GregorianCalendarSystem.CHRONON_OF_DAY;
} else if (bytes[startOffset] == ATypeTag.SERIALIZED_DATETIME_TYPE_TAG) {
chrononTimeInMs = AInt64SerializerDeserializer.getLong(bytes, startOffset + 1);
} else {
throw new TypeMismatchException(getIdentifier(), 0, bytes[startOffset], ATypeTag.SERIALIZED_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_DATE_TYPE_TAG, ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
}
int year = calSystem.getYear(chrononTimeInMs);
int month = calSystem.getMonthOfYear(chrononTimeInMs, year);
int day = calSystem.getDayOfMonthYear(chrononTimeInMs, year, month);
aMutableInt64.setValue(day);
intSerde.serialize(aMutableInt64, out);
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.om.base.AMutableInt64 in project asterixdb by apache.
the class TemporalMillisecondAccessor 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(IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
private final IPointable argPtr = new VoidPointable();
private final IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private final GregorianCalendarSystem calSystem = GregorianCalendarSystem.getInstance();
// for output: type integer
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<AInt64> intSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
private final AMutableInt64 aMutableInt64 = new AMutableInt64(0);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
eval.evaluate(tuple, argPtr);
byte[] bytes = argPtr.getByteArray();
int startOffset = argPtr.getStartOffset();
resultStorage.reset();
try {
if (bytes[startOffset] == ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
aMutableInt64.setValue(calSystem.getDurationMillisecond(ADurationSerializerDeserializer.getDayTime(bytes, startOffset + 1)));
intSerde.serialize(aMutableInt64, out);
result.set(resultStorage);
return;
}
if (bytes[startOffset] == ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG) {
aMutableInt64.setValue(calSystem.getDurationMillisecond(ADayTimeDurationSerializerDeserializer.getDayTime(bytes, startOffset + 1)));
intSerde.serialize(aMutableInt64, out);
result.set(resultStorage);
return;
}
long chrononTimeInMs = 0;
if (bytes[startOffset] == ATypeTag.SERIALIZED_TIME_TYPE_TAG) {
chrononTimeInMs = AInt32SerializerDeserializer.getInt(bytes, startOffset + 1);
} else if (bytes[startOffset] == ATypeTag.SERIALIZED_DATETIME_TYPE_TAG) {
chrononTimeInMs = AInt64SerializerDeserializer.getLong(bytes, startOffset + 1);
} else {
throw new TypeMismatchException(getIdentifier(), 0, bytes[startOffset], ATypeTag.SERIALIZED_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_TIME_TYPE_TAG, ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
}
int ms = calSystem.getMillisOfSec(chrononTimeInMs);
aMutableInt64.setValue(ms);
intSerde.serialize(aMutableInt64, out);
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.om.base.AMutableInt64 in project asterixdb by apache.
the class TemporalMinuteAccessor 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(IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
private final IPointable argPtr = new VoidPointable();
private final IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private final GregorianCalendarSystem calSystem = GregorianCalendarSystem.getInstance();
// for output: type integer
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<AInt64> intSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
private final AMutableInt64 aMutableInt64 = new AMutableInt64(0);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
eval.evaluate(tuple, argPtr);
byte[] bytes = argPtr.getByteArray();
int startOffset = argPtr.getStartOffset();
resultStorage.reset();
try {
if (bytes[startOffset] == ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
aMutableInt64.setValue(calSystem.getDurationMinute(ADurationSerializerDeserializer.getDayTime(bytes, startOffset + 1)));
intSerde.serialize(aMutableInt64, out);
result.set(resultStorage);
return;
}
if (bytes[startOffset] == ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG) {
aMutableInt64.setValue(calSystem.getDurationMinute(ADayTimeDurationSerializerDeserializer.getDayTime(bytes, startOffset + 1)));
intSerde.serialize(aMutableInt64, out);
result.set(resultStorage);
return;
}
long chrononTimeInMs = 0;
if (bytes[startOffset] == ATypeTag.SERIALIZED_TIME_TYPE_TAG) {
chrononTimeInMs = AInt32SerializerDeserializer.getInt(bytes, startOffset + 1);
} else if (bytes[startOffset] == ATypeTag.SERIALIZED_DATETIME_TYPE_TAG) {
chrononTimeInMs = AInt64SerializerDeserializer.getLong(bytes, startOffset + 1);
} else {
throw new TypeMismatchException(getIdentifier(), 0, bytes[startOffset], ATypeTag.SERIALIZED_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_TIME_TYPE_TAG, ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
}
int min = calSystem.getMinOfHour(chrononTimeInMs);
aMutableInt64.setValue(min);
intSerde.serialize(aMutableInt64, out);
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
Aggregations