use of org.apache.asterix.om.base.IAObject in project asterixdb by apache.
the class RecordRemoveFieldsTypeComputer method getListFromExpression.
private List<String> getListFromExpression(String funcName, ILogicalExpression expression) throws AlgebricksException {
AbstractFunctionCallExpression funcExp = (AbstractFunctionCallExpression) expression;
List<Mutable<ILogicalExpression>> args = funcExp.getArguments();
List<String> list = new ArrayList<>();
for (Mutable<ILogicalExpression> arg : args) {
// At this point all elements has to be a constant
// Input list has only one level of nesting (list of list or list of strings)
ConstantExpression ce = (ConstantExpression) arg.getValue();
if (!(ce.getValue() instanceof AsterixConstantValue)) {
throw new InvalidExpressionException(funcName, 1, ce, LogicalExpressionTag.CONSTANT);
}
IAObject item = ((AsterixConstantValue) ce.getValue()).getObject();
ATypeTag type = item.getType().getTypeTag();
if (type == ATypeTag.STRING) {
list.add(((AString) item).getStringValue());
} else {
throw new UnsupportedTypeException(funcName, type);
}
}
return list;
}
use of org.apache.asterix.om.base.IAObject in project asterixdb by apache.
the class SerializerDeserializerTestUtils method concurrentSerDeTestRun.
@SuppressWarnings("rawtypes")
public static void concurrentSerDeTestRun(ISerializerDeserializer serde, IAObject[] records) {
Thread[] threads = new Thread[records.length];
AtomicInteger errorCount = new AtomicInteger(0);
for (int i = 0; i < threads.length; ++i) {
final int index = i;
threads[i] = new Thread(new Runnable() {
@SuppressWarnings("unchecked")
@Override
public void run() {
try {
int round = 0;
while (round++ < 100000) {
// serialize
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutput dos = new DataOutputStream(bos);
serde.serialize(records[index], dos);
bos.close();
// deserialize
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
DataInput dis = new DataInputStream(bis);
IAObject object = (IAObject) serde.deserialize(dis);
bis.close();
// asserts the equivalence of objects before and after serde.
Assert.assertTrue(object.deepEqual(records[index]));
Assert.assertTrue(records[index].deepEqual(object));
}
} catch (Exception e) {
errorCount.incrementAndGet();
e.printStackTrace();
}
}
});
// Kicks off test threads.
threads[i].start();
}
// Joins all the threads.
try {
for (int i = 0; i < threads.length; ++i) {
threads[i].join();
}
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
// Asserts no failure.
Assert.assertTrue(errorCount.get() == 0);
}
use of org.apache.asterix.om.base.IAObject in project asterixdb by apache.
the class ATypeHierarchy method getAsterixConstantValueFromNumericTypeObject.
// Get an AsterixConstantValue from a source Object
public static AsterixConstantValue getAsterixConstantValueFromNumericTypeObject(IAObject sourceObject, ATypeTag targetTypeTag, boolean strictDemote) throws HyracksDataException {
ATypeTag sourceTypeTag = sourceObject.getType().getTypeTag();
if (sourceTypeTag == targetTypeTag) {
return new AsterixConstantValue(sourceObject);
}
// if the constant type and target type does not match, we do a type conversion
ITypeConvertComputer convertComputer = null;
if (canPromote(sourceTypeTag, targetTypeTag)) {
convertComputer = ATypeHierarchy.getTypePromoteComputer(sourceTypeTag, targetTypeTag);
} else if (canDemote(sourceTypeTag, targetTypeTag)) {
convertComputer = ATypeHierarchy.getTypeDemoteComputer(sourceTypeTag, targetTypeTag, strictDemote);
}
if (convertComputer == null) {
return null;
}
IAObject targetObject = convertComputer.convertType(sourceObject);
return new AsterixConstantValue(targetObject);
}
use of org.apache.asterix.om.base.IAObject in project asterixdb by apache.
the class SerializerDeserializerProvider method addTag.
@SuppressWarnings("rawtypes")
private ISerializerDeserializer addTag(final ISerializerDeserializer nonTaggedSerde, final ATypeTag typeTag) {
return new ISerializerDeserializer<IAObject>() {
private static final long serialVersionUID = 1L;
@Override
public IAObject deserialize(DataInput in) throws HyracksDataException {
try {
ATypeTag tag = SerializerDeserializerUtil.deserializeTag(in);
//deserialize the tag (move input cursor forward) and check if it's not NULL tag
if (tag == ATypeTag.MISSING) {
return AMissing.MISSING;
}
if (tag == ATypeTag.NULL) {
return ANull.NULL;
}
} catch (IOException e) {
throw new HyracksDataException(e);
}
return (IAObject) nonTaggedSerde.deserialize(in);
}
@SuppressWarnings("unchecked")
@Override
public void serialize(IAObject instance, DataOutput out) throws HyracksDataException {
SerializerDeserializerUtil.serializeTag(instance, out);
nonTaggedSerde.serialize(instance, out);
}
};
}
use of org.apache.asterix.om.base.IAObject in project asterixdb by apache.
the class AOrderedListSerializerDeserializer method deserialize.
@Override
public AOrderedList deserialize(DataInput in) throws HyracksDataException {
try {
ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(in.readByte());
IAType currentItemType = itemType;
@SuppressWarnings("rawtypes") ISerializerDeserializer currentDeserializer = deserializer;
if (itemType.getTypeTag() == ATypeTag.ANY && typeTag != ATypeTag.ANY) {
currentItemType = TypeTagUtil.getBuiltinTypeByTag(typeTag);
currentDeserializer = SerializerDeserializerProvider.INSTANCE.getNonTaggedSerializerDeserializer(currentItemType);
}
List<IAObject> items = new ArrayList<IAObject>();
// list size
in.readInt();
int numberOfitems;
numberOfitems = in.readInt();
if (numberOfitems > 0) {
if (!NonTaggedFormatUtil.isFixedSizedCollection(currentItemType)) {
for (int i = 0; i < numberOfitems; i++) in.readInt();
}
for (int i = 0; i < numberOfitems; i++) {
IAObject v = (IAObject) currentDeserializer.deserialize(in);
items.add(v);
}
}
AOrderedListType type = new AOrderedListType(currentItemType, "orderedlist");
return new AOrderedList(type, items);
} catch (Exception e) {
throw new HyracksDataException(e);
}
}
Aggregations