use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException in project asterixdb by apache.
the class AbstractSerializableSumAggregateFunction method step.
@Override
public void step(IFrameTupleReference tuple, byte[] state, int start, int len) throws HyracksDataException {
if (skipStep(state, start)) {
return;
}
ATypeTag aggType = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(state[start + AGG_TYPE_OFFSET]);
double sum = BufferSerDeUtil.getDouble(state, start + SUM_OFFSET);
eval.evaluate(tuple, inputVal);
byte[] bytes = inputVal.getByteArray();
int offset = inputVal.getStartOffset();
ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]);
if (typeTag == ATypeTag.MISSING || typeTag == ATypeTag.NULL) {
processNull(state, start);
return;
} else if (aggType == ATypeTag.SYSTEM_NULL) {
aggType = typeTag;
} else if (typeTag != ATypeTag.SYSTEM_NULL && !ATypeHierarchy.isCompatible(typeTag, aggType)) {
throw new IncompatibleTypeException(BuiltinFunctions.SUM, bytes[offset], aggType.serialize());
}
if (ATypeHierarchy.canPromote(aggType, typeTag)) {
aggType = typeTag;
}
switch(typeTag) {
case TINYINT:
{
byte val = AInt8SerializerDeserializer.getByte(bytes, offset + 1);
sum += val;
break;
}
case SMALLINT:
{
short val = AInt16SerializerDeserializer.getShort(bytes, offset + 1);
sum += val;
break;
}
case INTEGER:
{
int val = AInt32SerializerDeserializer.getInt(bytes, offset + 1);
sum += val;
break;
}
case BIGINT:
{
long val = AInt64SerializerDeserializer.getLong(bytes, offset + 1);
sum += val;
break;
}
case FLOAT:
{
float val = AFloatSerializerDeserializer.getFloat(bytes, offset + 1);
sum += val;
break;
}
case DOUBLE:
{
double val = ADoubleSerializerDeserializer.getDouble(bytes, offset + 1);
sum += val;
break;
}
case NULL:
{
aggType = typeTag;
break;
}
case SYSTEM_NULL:
{
processSystemNull();
break;
}
default:
throw new UnsupportedItemTypeException(BuiltinFunctions.SUM, bytes[offset]);
}
state[start + AGG_TYPE_OFFSET] = aggType.serialize();
BufferSerDeUtil.writeDouble(sum, state, start + SUM_OFFSET);
}
use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException in project asterixdb by apache.
the class AbstractAvgAggregateFunction method processDataValues.
protected void processDataValues(IFrameTupleReference tuple) throws HyracksDataException {
if (skipStep()) {
return;
}
eval.evaluate(tuple, inputVal);
byte[] data = inputVal.getByteArray();
int offset = inputVal.getStartOffset();
ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset]);
if (typeTag == ATypeTag.MISSING || typeTag == ATypeTag.NULL) {
processNull();
return;
} else if (aggType == ATypeTag.SYSTEM_NULL) {
aggType = typeTag;
} else if (typeTag != ATypeTag.SYSTEM_NULL && !ATypeHierarchy.isCompatible(typeTag, aggType)) {
throw new IncompatibleTypeException(BuiltinFunctions.AVG, data[offset], aggType.serialize());
} else if (ATypeHierarchy.canPromote(aggType, typeTag)) {
aggType = typeTag;
}
++count;
switch(typeTag) {
case TINYINT:
{
byte val = AInt8SerializerDeserializer.getByte(data, offset + 1);
sum += val;
break;
}
case SMALLINT:
{
short val = AInt16SerializerDeserializer.getShort(data, offset + 1);
sum += val;
break;
}
case INTEGER:
{
int val = AInt32SerializerDeserializer.getInt(data, offset + 1);
sum += val;
break;
}
case BIGINT:
{
long val = AInt64SerializerDeserializer.getLong(data, offset + 1);
sum += val;
break;
}
case FLOAT:
{
float val = AFloatSerializerDeserializer.getFloat(data, offset + 1);
sum += val;
break;
}
case DOUBLE:
{
double val = ADoubleSerializerDeserializer.getDouble(data, offset + 1);
sum += val;
break;
}
default:
{
throw new UnsupportedItemTypeException(BuiltinFunctions.AVG, data[offset]);
}
}
}
use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException in project asterixdb by apache.
the class AbstractSerializableAvgAggregateFunction method processPartialResults.
protected void processPartialResults(IFrameTupleReference tuple, byte[] state, int start, int len) throws HyracksDataException {
if (skipStep(state, start)) {
return;
}
double sum = BufferSerDeUtil.getDouble(state, start + SUM_OFFSET);
long count = BufferSerDeUtil.getLong(state, start + COUNT_OFFSET);
eval.evaluate(tuple, inputVal);
byte[] serBytes = inputVal.getByteArray();
int offset = inputVal.getStartOffset();
ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serBytes[offset]);
switch(typeTag) {
case NULL:
{
processNull(state, start);
break;
}
case SYSTEM_NULL:
{
// Ignore and return.
break;
}
case OBJECT:
{
// Expected.
ATypeTag aggType = ATypeTag.DOUBLE;
int nullBitmapSize = 0;
int offset1 = ARecordSerializerDeserializer.getFieldOffsetById(serBytes, offset, SUM_FIELD_ID, nullBitmapSize, false);
sum += ADoubleSerializerDeserializer.getDouble(serBytes, offset1);
int offset2 = ARecordSerializerDeserializer.getFieldOffsetById(serBytes, offset, COUNT_FIELD_ID, nullBitmapSize, false);
count += AInt64SerializerDeserializer.getLong(serBytes, offset2);
BufferSerDeUtil.writeDouble(sum, state, start + SUM_OFFSET);
BufferSerDeUtil.writeLong(count, state, start + COUNT_OFFSET);
state[start + AGG_TYPE_OFFSET] = aggType.serialize();
break;
}
default:
throw new UnsupportedItemTypeException(BuiltinFunctions.AVG, serBytes[offset]);
}
}
use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException in project asterixdb by apache.
the class AbstractSerializableAvgAggregateFunction method processDataValues.
protected void processDataValues(IFrameTupleReference tuple, byte[] state, int start, int len) throws HyracksDataException {
if (skipStep(state, start)) {
return;
}
eval.evaluate(tuple, inputVal);
byte[] bytes = inputVal.getByteArray();
int offset = inputVal.getStartOffset();
double sum = BufferSerDeUtil.getDouble(state, start + SUM_OFFSET);
long count = BufferSerDeUtil.getLong(state, start + COUNT_OFFSET);
ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]);
ATypeTag aggType = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(state[start + AGG_TYPE_OFFSET]);
if (typeTag == ATypeTag.MISSING || typeTag == ATypeTag.NULL) {
processNull(state, start);
return;
} else if (aggType == ATypeTag.SYSTEM_NULL) {
aggType = typeTag;
} else if (typeTag != ATypeTag.SYSTEM_NULL && !ATypeHierarchy.isCompatible(typeTag, aggType)) {
throw new IncompatibleTypeException(BuiltinFunctions.AVG, bytes[offset], aggType.serialize());
} else if (ATypeHierarchy.canPromote(aggType, typeTag)) {
aggType = typeTag;
}
++count;
switch(typeTag) {
case TINYINT:
{
byte val = AInt8SerializerDeserializer.getByte(bytes, offset + 1);
sum += val;
break;
}
case SMALLINT:
{
short val = AInt16SerializerDeserializer.getShort(bytes, offset + 1);
sum += val;
break;
}
case INTEGER:
{
int val = AInt32SerializerDeserializer.getInt(bytes, offset + 1);
sum += val;
break;
}
case BIGINT:
{
long val = AInt64SerializerDeserializer.getLong(bytes, offset + 1);
sum += val;
break;
}
case FLOAT:
{
float val = AFloatSerializerDeserializer.getFloat(bytes, offset + 1);
sum += val;
break;
}
case DOUBLE:
{
double val = ADoubleSerializerDeserializer.getDouble(bytes, offset + 1);
sum += val;
break;
}
default:
throw new UnsupportedItemTypeException(BuiltinFunctions.AVG, bytes[offset]);
}
BufferSerDeUtil.writeDouble(sum, state, start + SUM_OFFSET);
BufferSerDeUtil.writeLong(count, state, start + COUNT_OFFSET);
state[start + AGG_TYPE_OFFSET] = aggType.serialize();
}
use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException in project asterixdb by apache.
the class PrintBinaryDescriptor 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 StringBuilder stringBuilder = new StringBuilder();
private final ByteArrayPointable byteArrayPtr = new ByteArrayPointable();
private final UTF8StringPointable formatPointable = new UTF8StringPointable();
private final UTF8StringWriter writer = new UTF8StringWriter();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
evaluators[0].evaluate(tuple, pointables[0]);
evaluators[1].evaluate(tuple, pointables[1]);
try {
ATypeTag arg0Tag = ATypeTag.VALUE_TYPE_MAPPING[pointables[0].getByteArray()[pointables[0].getStartOffset()]];
ATypeTag arg1Tag = ATypeTag.VALUE_TYPE_MAPPING[pointables[1].getByteArray()[pointables[1].getStartOffset()]];
checkTypeMachingThrowsIfNot(getIdentifier().getName(), EXPECTED_INPUT_TAGS, arg0Tag, arg1Tag);
byteArrayPtr.set(pointables[0].getByteArray(), pointables[0].getStartOffset() + 1, pointables[0].getLength());
formatPointable.set(pointables[1].getByteArray(), pointables[1].getStartOffset() + 1, pointables[1].getLength());
int lengthBinary = byteArrayPtr.getContentLength();
stringBuilder.setLength(0);
if (HEX_FORMAT.ignoreCaseCompareTo(formatPointable) == 0) {
HexPrinter.printHexString(byteArrayPtr.getByteArray(), byteArrayPtr.getContentStartOffset(), lengthBinary, stringBuilder);
} else if (BASE64_FORMAT.ignoreCaseCompareTo(formatPointable) == 0) {
Base64Printer.printBase64Binary(byteArrayPtr.getByteArray(), byteArrayPtr.getContentStartOffset(), lengthBinary, stringBuilder);
} else {
throw new UnsupportedItemTypeException(getIdentifier(), arg1Tag.serialize());
}
dataOutput.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
writer.writeUTF8(stringBuilder.toString(), dataOutput);
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
Aggregations