use of org.apache.asterix.runtime.exceptions.TypeMismatchException in project asterixdb by apache.
the class TimeFromDatetimeDescriptor 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 returning types
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ATime> timeSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ATIME);
private AMutableTime aTime = new AMutableTime(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();
if (bytes[offset] != ATypeTag.SERIALIZED_DATETIME_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
}
long datetimeChronon = ADateTimeSerializerDeserializer.getChronon(bytes, offset + 1);
int timeChronon = (int) (datetimeChronon % GregorianCalendarSystem.CHRONON_OF_DAY);
if (timeChronon < 0) {
timeChronon += GregorianCalendarSystem.CHRONON_OF_DAY;
}
aTime.setValue(timeChronon);
timeSerde.serialize(aTime, out);
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.runtime.exceptions.TypeMismatchException in project asterixdb by apache.
the class UnixTimeFromDateInDaysDescriptor 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
private AMutableInt64 aInt64 = new AMutableInt64(0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<AInt64> int64Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval.evaluate(tuple, argPtr);
byte[] bytes = argPtr.getByteArray();
int offset = argPtr.getStartOffset();
if (bytes[offset] != ATypeTag.SERIALIZED_DATE_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_DATE_TYPE_TAG);
}
long dateChronon = ADateSerializerDeserializer.getChronon(bytes, offset + 1);
aInt64.setValue(dateChronon);
int64Serde.serialize(aInt64, out);
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.runtime.exceptions.TypeMismatchException in project asterixdb by apache.
the class UnixTimeFromDatetimeInMsDescriptor 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
private AMutableInt64 aInt64 = new AMutableInt64(0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<AInt64> int64Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval.evaluate(tuple, argPtr);
byte[] bytes = argPtr.getByteArray();
int offset = argPtr.getStartOffset();
if (bytes[offset] != ATypeTag.SERIALIZED_DATETIME_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
}
long datetimeChronon = ADateTimeSerializerDeserializer.getChronon(bytes, offset + 1);
aInt64.setValue(datetimeChronon);
int64Serde.serialize(aInt64, out);
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.runtime.exceptions.TypeMismatchException in project asterixdb by apache.
the class UnixTimeFromDatetimeInSecsDescriptor 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 returning types
private AMutableInt64 aInt64 = new AMutableInt64(0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<AInt64> int64Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval.evaluate(tuple, argPtr);
byte[] bytes = argPtr.getByteArray();
int offset = argPtr.getStartOffset();
if (bytes[offset] != SERIALIZED_DATETIME_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
}
long datetimeChronon = ADateTimeSerializerDeserializer.getChronon(bytes, offset + 1);
aInt64.setValue(datetimeChronon / 1000L);
int64Serde.serialize(aInt64, out);
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.runtime.exceptions.TypeMismatchException in project asterixdb by apache.
the class UnixTimeFromTimeInMsDescriptor 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 returning types
private AMutableInt64 aInt64 = new AMutableInt64(0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<AInt64> int64Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval.evaluate(tuple, argPtr);
byte[] bytes = argPtr.getByteArray();
int offset = argPtr.getStartOffset();
if (bytes[offset] != ATypeTag.SERIALIZED_TIME_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_TIME_TYPE_TAG);
}
long timeChronon = ATimeSerializerDeserializer.getChronon(bytes, offset + 1);
aInt64.setValue(timeChronon);
int64Serde.serialize(aInt64, out);
result.set(resultStorage);
}
};
}
};
}
Aggregations