use of org.apache.asterix.om.base.AMutableInt8 in project asterixdb by apache.
the class InternalDatasetDetails method writeDatasetDetailsRecordType.
@Override
public void writeDatasetDetailsRecordType(DataOutput out) throws HyracksDataException {
IARecordBuilder internalRecordBuilder = new RecordBuilder();
OrderedListBuilder listBuilder = new OrderedListBuilder();
ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
ArrayBackedValueStorage itemValue = new ArrayBackedValueStorage();
OrderedListBuilder primaryKeyListBuilder = new OrderedListBuilder();
AOrderedListType stringList = new AOrderedListType(BuiltinType.ASTRING, null);
AOrderedListType int8List = new AOrderedListType(BuiltinType.AINT8, null);
AOrderedListType heterogeneousList = new AOrderedListType(BuiltinType.ANY, null);
internalRecordBuilder.reset(MetadataRecordTypes.INTERNAL_DETAILS_RECORDTYPE);
AMutableString aString = new AMutableString("");
AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
@SuppressWarnings("unchecked") ISerializerDeserializer<ABoolean> booleanSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABOOLEAN);
@SuppressWarnings("unchecked") ISerializerDeserializer<AString> stringSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
@SuppressWarnings("unchecked") ISerializerDeserializer<AInt8> int8Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT8);
// write field 0
fieldValue.reset();
aString.setValue(getFileStructure().toString());
stringSerde.serialize(aString, fieldValue.getDataOutput());
internalRecordBuilder.addField(MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_FILESTRUCTURE_FIELD_INDEX, fieldValue);
// write field 1
fieldValue.reset();
aString.setValue(getPartitioningStrategy().toString());
stringSerde.serialize(aString, fieldValue.getDataOutput());
internalRecordBuilder.addField(MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_PARTITIONSTRATEGY_FIELD_INDEX, fieldValue);
// write field 2
primaryKeyListBuilder.reset((AOrderedListType) MetadataRecordTypes.INTERNAL_DETAILS_RECORDTYPE.getFieldTypes()[MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_PARTITIONKEY_FIELD_INDEX]);
for (List<String> field : partitioningKeys) {
listBuilder.reset(stringList);
for (String subField : field) {
itemValue.reset();
aString.setValue(subField);
stringSerde.serialize(aString, itemValue.getDataOutput());
listBuilder.addItem(itemValue);
}
itemValue.reset();
listBuilder.write(itemValue.getDataOutput(), true);
primaryKeyListBuilder.addItem(itemValue);
}
fieldValue.reset();
primaryKeyListBuilder.write(fieldValue.getDataOutput(), true);
internalRecordBuilder.addField(MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_PARTITIONKEY_FIELD_INDEX, fieldValue);
// write field 3
primaryKeyListBuilder.reset((AOrderedListType) MetadataRecordTypes.INTERNAL_DETAILS_RECORDTYPE.getFieldTypes()[MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_PRIMARYKEY_FIELD_INDEX]);
for (List<String> field : primaryKeys) {
listBuilder.reset(stringList);
for (String subField : field) {
itemValue.reset();
aString.setValue(subField);
stringSerde.serialize(aString, itemValue.getDataOutput());
listBuilder.addItem(itemValue);
}
itemValue.reset();
listBuilder.write(itemValue.getDataOutput(), true);
primaryKeyListBuilder.addItem(itemValue);
}
fieldValue.reset();
primaryKeyListBuilder.write(fieldValue.getDataOutput(), true);
internalRecordBuilder.addField(MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_PRIMARYKEY_FIELD_INDEX, fieldValue);
// write field 4
fieldValue.reset();
ABoolean b = isAutogenerated() ? ABoolean.TRUE : ABoolean.FALSE;
booleanSerde.serialize(b, fieldValue.getDataOutput());
internalRecordBuilder.addField(MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_AUTOGENERATED_FIELD_INDEX, fieldValue);
// write filter fields if any
List<String> filterField = getFilterField();
if (filterField != null) {
listBuilder.reset(heterogeneousList);
ArrayBackedValueStorage nameValue = new ArrayBackedValueStorage();
nameValue.reset();
aString.setValue(FILTER_FIELD_NAME);
stringSerde.serialize(aString, nameValue.getDataOutput());
for (String field : filterField) {
itemValue.reset();
aString.setValue(field);
stringSerde.serialize(aString, itemValue.getDataOutput());
listBuilder.addItem(itemValue);
}
fieldValue.reset();
listBuilder.write(fieldValue.getDataOutput(), true);
internalRecordBuilder.addField(nameValue, fieldValue);
}
// write key source indicators if any
List<Integer> keySourceIndicator = getKeySourceIndicator();
boolean needSerialization = false;
if (keySourceIndicator != null) {
for (int source : keySourceIndicator) {
if (source != 0) {
needSerialization = true;
break;
}
}
}
if (needSerialization) {
listBuilder.reset(int8List);
ArrayBackedValueStorage nameValue = new ArrayBackedValueStorage();
nameValue.reset();
aString.setValue(KEY_FILD_SOURCE_INDICATOR_FIELD_NAME);
stringSerde.serialize(aString, nameValue.getDataOutput());
for (int source : keySourceIndicator) {
itemValue.reset();
aInt8.setValue((byte) source);
int8Serde.serialize(aInt8, itemValue.getDataOutput());
listBuilder.addItem(itemValue);
}
fieldValue.reset();
listBuilder.write(fieldValue.getDataOutput(), true);
internalRecordBuilder.addField(nameValue, fieldValue);
}
internalRecordBuilder.write(out, true);
}
use of org.apache.asterix.om.base.AMutableInt8 in project asterixdb by apache.
the class NumericRoundHalfToEven2Descriptor 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 argValue = new VoidPointable();
private IPointable argPrecision = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private IScalarEvaluator precision = args[1].createScalarEvaluator(ctx);
private AMutableDouble aDouble = new AMutableDouble(0);
private AMutableFloat aFloat = new AMutableFloat(0);
private AMutableInt64 aInt64 = new AMutableInt64(0);
private AMutableInt32 aInt32 = new AMutableInt32(0);
private AMutableInt16 aInt16 = new AMutableInt16((short) 0);
private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
@SuppressWarnings("rawtypes")
private ISerializerDeserializer serde;
private int getPrecision() throws HyracksDataException {
byte[] bytes = argPrecision.getByteArray();
int offset = argPrecision.getStartOffset();
if (bytes[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
return AInt8SerializerDeserializer.getByte(bytes, offset + 1);
} else if (bytes[offset] == ATypeTag.SERIALIZED_INT16_TYPE_TAG) {
return AInt16SerializerDeserializer.getShort(bytes, offset + 1);
} else if (bytes[offset] == ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
return AInt32SerializerDeserializer.getInt(bytes, offset + 1);
} else if (bytes[offset] == ATypeTag.SERIALIZED_INT64_TYPE_TAG) {
return (int) AInt64SerializerDeserializer.getLong(bytes, offset + 1);
} else {
throw new TypeMismatchException(getIdentifier(), 1, bytes[offset], ATypeTag.SERIALIZED_INT8_TYPE_TAG, ATypeTag.SERIALIZED_INT16_TYPE_TAG, ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT64_TYPE_TAG);
}
}
@SuppressWarnings("unchecked")
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval.evaluate(tuple, argValue);
precision.evaluate(tuple, argPrecision);
byte[] data = argValue.getByteArray();
int offset = argValue.getStartOffset();
if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT8);
byte val = AInt8SerializerDeserializer.getByte(data, offset + 1);
aInt8.setValue(val);
serde.serialize(aInt8, out);
} else if (data[offset] == ATypeTag.SERIALIZED_INT16_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT16);
short val = AInt16SerializerDeserializer.getShort(data, offset + 1);
aInt16.setValue(val);
serde.serialize(aInt16, out);
} else if (data[offset] == ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
int val = AInt32SerializerDeserializer.getInt(data, offset + 1);
aInt32.setValue(val);
serde.serialize(aInt32, out);
} else if (data[offset] == ATypeTag.SERIALIZED_INT64_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
long val = AInt64SerializerDeserializer.getLong(data, offset + 1);
aInt64.setValue(val);
serde.serialize(aInt64, out);
} else if (data[offset] == ATypeTag.SERIALIZED_FLOAT_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
float val = AFloatSerializerDeserializer.getFloat(data, offset + 1);
if (Float.isNaN(val) || Float.isInfinite(val) || Float.compare(val, -0.0F) == 0 || Float.compare(val, 0.0F) == 0) {
aFloat.setValue(val);
serde.serialize(aFloat, out);
} else {
BigDecimal r = new BigDecimal(Float.toString(val));
aFloat.setValue(r.setScale(getPrecision(), BigDecimal.ROUND_HALF_EVEN).floatValue());
serde.serialize(aFloat, out);
}
} else if (data[offset] == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
double val = ADoubleSerializerDeserializer.getDouble(data, offset + 1);
if (Double.isNaN(val) || Double.isInfinite(val) || Double.compare(val, -0.0D) == 0 || Double.compare(val, 0.0D) == 0) {
aDouble.setValue(val);
serde.serialize(aDouble, out);
} else {
BigDecimal r = new BigDecimal(Double.toString(val));
aDouble.setValue(r.setScale(getPrecision(), BigDecimal.ROUND_HALF_EVEN).doubleValue());
serde.serialize(aDouble, out);
}
} else {
throw new TypeMismatchException(getIdentifier(), 0, data[offset], ATypeTag.SERIALIZED_INT8_TYPE_TAG, ATypeTag.SERIALIZED_INT16_TYPE_TAG, ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT64_TYPE_TAG, ATypeTag.SERIALIZED_FLOAT_TYPE_TAG, ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.om.base.AMutableInt8 in project asterixdb by apache.
the class AInt8ConstructorDescriptor method createEvaluatorFactory.
@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 ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private IPointable inputArg = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private byte value;
private int offset;
private boolean positive;
private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<AInt8> int8Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT8);
private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
try {
resultStorage.reset();
eval.evaluate(tuple, inputArg);
byte[] serString = inputArg.getByteArray();
int startOffset = inputArg.getStartOffset();
int len = inputArg.getLength();
if (serString[startOffset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
utf8Ptr.set(serString, startOffset + 1, len - 1);
offset = utf8Ptr.getCharStartOffset();
//accumulating value in negative domain
//otherwise Byte.MIN_VALUE = -(Byte.MAX_VALUE + 1) would have caused overflow
value = 0;
positive = true;
byte limit = -Byte.MAX_VALUE;
if (serString[offset] == '+') {
offset++;
} else if (serString[offset] == '-') {
offset++;
positive = false;
limit = Byte.MIN_VALUE;
}
int end = startOffset + len;
for (; offset < end; offset++) {
int digit;
if (serString[offset] >= '0' && serString[offset] <= '9') {
value = (byte) (value * 10);
digit = serString[offset] - '0';
} else if (serString[offset] == 'i' && serString[offset + 1] == '8' && offset + 2 == end) {
break;
} else {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INT8_TYPE_TAG);
}
if (value < limit + digit) {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INT8_TYPE_TAG);
}
value = (byte) (value - digit);
}
if (value > 0) {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INT8_TYPE_TAG);
}
if (value < 0 && positive) {
value *= -1;
}
aInt8.setValue(value);
int8Serde.serialize(aInt8, out);
} else {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INT8_TYPE_TAG);
}
result.set(resultStorage);
} catch (IOException e1) {
throw new InvalidDataFormatException(getIdentifier(), e1, ATypeTag.SERIALIZED_INT8_TYPE_TAG);
}
}
};
}
};
}
use of org.apache.asterix.om.base.AMutableInt8 in project asterixdb by apache.
the class NumericRoundDescriptor 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);
private AMutableDouble aDouble = new AMutableDouble(0);
private AMutableFloat aFloat = new AMutableFloat(0);
private AMutableInt64 aInt64 = new AMutableInt64(0);
private AMutableInt32 aInt32 = new AMutableInt32(0);
private AMutableInt16 aInt16 = new AMutableInt16((short) 0);
private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
@SuppressWarnings("rawtypes")
private ISerializerDeserializer serde;
@SuppressWarnings("unchecked")
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval.evaluate(tuple, argPtr);
byte[] data = argPtr.getByteArray();
int offset = argPtr.getStartOffset();
if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT8);
byte val = AInt8SerializerDeserializer.getByte(data, offset + 1);
aInt8.setValue(val);
serde.serialize(aInt8, out);
} else if (data[offset] == ATypeTag.SERIALIZED_INT16_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT16);
short val = AInt16SerializerDeserializer.getShort(data, offset + 1);
aInt16.setValue(val);
serde.serialize(aInt16, out);
} else if (data[offset] == ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
int val = AInt32SerializerDeserializer.getInt(data, offset + 1);
aInt32.setValue(val);
serde.serialize(aInt32, out);
} else if (data[offset] == ATypeTag.SERIALIZED_INT64_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
long val = AInt64SerializerDeserializer.getLong(data, offset + 1);
aInt64.setValue(val);
serde.serialize(aInt64, out);
} else if (data[offset] == ATypeTag.SERIALIZED_FLOAT_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
float val = AFloatSerializerDeserializer.getFloat(data, offset + 1);
val = Math.round(val);
aFloat.setValue(val);
serde.serialize(aFloat, out);
} else if (data[offset] == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
double val = ADoubleSerializerDeserializer.getDouble(data, offset + 1);
val = Math.round(val);
aDouble.setValue(val);
serde.serialize(aDouble, out);
} else {
throw new TypeMismatchException(getIdentifier(), 0, data[offset], ATypeTag.SERIALIZED_INT8_TYPE_TAG, ATypeTag.SERIALIZED_INT16_TYPE_TAG, ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT64_TYPE_TAG, ATypeTag.SERIALIZED_FLOAT_TYPE_TAG, ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.om.base.AMutableInt8 in project asterixdb by apache.
the class NumericRoundHalfToEvenDescriptor 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);
private AMutableDouble aDouble = new AMutableDouble(0);
private AMutableFloat aFloat = new AMutableFloat(0);
private AMutableInt64 aInt64 = new AMutableInt64(0);
private AMutableInt32 aInt32 = new AMutableInt32(0);
private AMutableInt16 aInt16 = new AMutableInt16((short) 0);
private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
@SuppressWarnings("rawtypes")
private ISerializerDeserializer serde;
@SuppressWarnings("unchecked")
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval.evaluate(tuple, argPtr);
byte[] data = argPtr.getByteArray();
int offset = argPtr.getStartOffset();
if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT8);
byte val = AInt8SerializerDeserializer.getByte(data, offset + 1);
aInt8.setValue(val);
serde.serialize(aInt8, out);
} else if (data[offset] == ATypeTag.SERIALIZED_INT16_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT16);
short val = AInt16SerializerDeserializer.getShort(data, offset + 1);
aInt16.setValue(val);
serde.serialize(aInt16, out);
} else if (data[offset] == ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
int val = AInt32SerializerDeserializer.getInt(data, offset + 1);
aInt32.setValue(val);
serde.serialize(aInt32, out);
} else if (data[offset] == ATypeTag.SERIALIZED_INT64_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
long val = AInt64SerializerDeserializer.getLong(data, offset + 1);
aInt64.setValue(val);
serde.serialize(aInt64, out);
} else if (data[offset] == ATypeTag.SERIALIZED_FLOAT_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
float val = AFloatSerializerDeserializer.getFloat(data, offset + 1);
aFloat.setValue((float) Math.rint(val));
serde.serialize(aFloat, out);
} else if (data[offset] == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
double val = ADoubleSerializerDeserializer.getDouble(data, offset + 1);
aDouble.setValue(Math.rint(val));
serde.serialize(aDouble, out);
} else {
throw new TypeMismatchException(getIdentifier(), 0, data[offset], ATypeTag.SERIALIZED_INT8_TYPE_TAG, ATypeTag.SERIALIZED_INT16_TYPE_TAG, ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT64_TYPE_TAG, ATypeTag.SERIALIZED_FLOAT_TYPE_TAG, ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
}
result.set(resultStorage);
}
};
}
};
}
Aggregations