use of org.apache.asterix.runtime.exceptions.TypeMismatchException in project asterixdb by apache.
the class GetRecordFieldsEvalFactory method createScalarEvaluator.
@Override
public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private final ARecordPointable recordPointable = (ARecordPointable) ARecordPointable.FACTORY.createPointable();
private IPointable inputArg0 = new VoidPointable();
private IScalarEvaluator eval0 = recordEvalFactory.createScalarEvaluator(ctx);
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private RecordFieldsUtil rfu = new RecordFieldsUtil();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval0.evaluate(tuple, inputArg0);
byte[] data = inputArg0.getByteArray();
int offset = inputArg0.getStartOffset();
int len = inputArg0.getLength();
if (data[offset] != ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
throw new TypeMismatchException(BuiltinFunctions.GET_RECORD_FIELDS, 0, data[offset], ATypeTag.SERIALIZED_RECORD_TYPE_TAG);
}
recordPointable.set(data, offset, len);
try {
rfu.processRecord(recordPointable, recordType, out, 0);
} catch (IOException e) {
throw new HyracksDataException(e);
} catch (AsterixException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
use of org.apache.asterix.runtime.exceptions.TypeMismatchException in project asterixdb by apache.
the class DayTimeDurationComparatorDescriptor 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 IPointable argPtr1 = new VoidPointable();
private IScalarEvaluator eval0 = args[0].createScalarEvaluator(ctx);
private IScalarEvaluator eval1 = args[1].createScalarEvaluator(ctx);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ABoolean> boolSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABOOLEAN);
@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();
if (bytes0[offset0] != ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, bytes0[offset0], ATypeTag.SERIALIZED_DURATION_TYPE_TAG);
}
if (bytes1[offset1] != ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1], ATypeTag.SERIALIZED_DURATION_TYPE_TAG);
}
if ((ADurationSerializerDeserializer.getYearMonth(bytes0, offset0 + 1) != 0) || (ADurationSerializerDeserializer.getYearMonth(bytes1, offset1 + 1) != 0)) {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_YEAR_MONTH_DURATION_TYPE_TAG);
}
if (ADurationSerializerDeserializer.getDayTime(bytes0, offset0 + 1) > ADurationSerializerDeserializer.getDayTime(bytes1, offset1 + 1)) {
boolSerde.serialize(isGreaterThan ? ABoolean.TRUE : ABoolean.FALSE, out);
} else {
boolSerde.serialize(isGreaterThan ? ABoolean.FALSE : ABoolean.TRUE, out);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.runtime.exceptions.TypeMismatchException in project asterixdb by apache.
the class DurationEqualDescriptor 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 IPointable argPtr1 = new VoidPointable();
private IScalarEvaluator eval0 = args[0].createScalarEvaluator(ctx);
private IScalarEvaluator eval1 = args[1].createScalarEvaluator(ctx);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ABoolean> boolSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABOOLEAN);
@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();
if (bytes0[offset0] != ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, bytes0[offset0], ATypeTag.SERIALIZED_DURATION_TYPE_TAG);
}
if (bytes1[offset1] != ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1], ATypeTag.SERIALIZED_DURATION_TYPE_TAG);
}
if ((ADurationSerializerDeserializer.getDayTime(bytes0, offset0 + 1) == ADurationSerializerDeserializer.getDayTime(bytes1, offset1 + 1)) && (ADurationSerializerDeserializer.getYearMonth(bytes0, offset0 + 1) == ADurationSerializerDeserializer.getYearMonth(bytes1, offset1 + 1))) {
boolSerde.serialize(ABoolean.TRUE, out);
} else {
boolSerde.serialize(ABoolean.FALSE, out);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.runtime.exceptions.TypeMismatchException in project asterixdb by apache.
the class DurationFromIntervalDescriptor 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);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ADayTimeDuration> dayTimeDurationSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADAYTIMEDURATION);
private AMutableDayTimeDuration aDayTimeDuration = new AMutableDayTimeDuration(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_INTERVAL_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
}
long chrononStart = AIntervalSerializerDeserializer.getIntervalStart(bytes, offset + 1);
long chrononEnd = AIntervalSerializerDeserializer.getIntervalEnd(bytes, offset + 1);
byte intervalTypeTag = AIntervalSerializerDeserializer.getIntervalTimeType(bytes, offset + 1);
if (intervalTypeTag == ATypeTag.SERIALIZED_DATE_TYPE_TAG) {
chrononStart *= GregorianCalendarSystem.CHRONON_OF_DAY;
chrononEnd *= GregorianCalendarSystem.CHRONON_OF_DAY;
}
aDayTimeDuration.setMilliseconds(chrononEnd - chrononStart);
dayTimeDurationSerde.serialize(aDayTimeDuration, out);
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.runtime.exceptions.TypeMismatchException in project asterixdb by apache.
the class DatetimeFromDateAndTimeDescriptor 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);
// possible returning 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();
eval0.evaluate(tuple, argPtr0);
eval1.evaluate(tuple, argPtr1);
byte[] bytes0 = argPtr0.getByteArray();
int offset0 = argPtr0.getStartOffset();
byte[] bytes1 = argPtr1.getByteArray();
int offset1 = argPtr1.getStartOffset();
if (bytes0[offset0] != ATypeTag.SERIALIZED_DATE_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, bytes0[offset0], ATypeTag.SERIALIZED_DATE_TYPE_TAG);
}
if (bytes1[offset1] != ATypeTag.SERIALIZED_TIME_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1], ATypeTag.SERIALIZED_TIME_TYPE_TAG);
}
long datetimeChronon = ADateSerializerDeserializer.getChronon(bytes0, offset0 + 1) * GregorianCalendarSystem.CHRONON_OF_DAY + ATimeSerializerDeserializer.getChronon(bytes1, offset1 + 1);
aDateTime.setValue(datetimeChronon);
datetimeSerde.serialize(aDateTime, out);
result.set(resultStorage);
}
};
}
};
}
Aggregations