use of org.apache.asterix.om.types.ARecordType in project asterixdb by apache.
the class FieldAccessByIndexResultType method getResultType.
@Override
protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
IAType firstArgType = strippedInputTypes[0];
if (firstArgType.getTypeTag() != ATypeTag.OBJECT) {
return BuiltinType.ANY;
}
AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
Integer pos = ConstantExpressionUtil.getIntArgument(funcExpr, 1);
if (pos == null) {
return BuiltinType.ANY;
}
ARecordType recType = (ARecordType) firstArgType;
return recType.getFieldTypes()[pos];
}
use of org.apache.asterix.om.types.ARecordType in project asterixdb by apache.
the class FieldAccessByNameResultType method getResultType.
@Override
protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
IAType firstArgType = strippedInputTypes[0];
if (firstArgType.getTypeTag() != ATypeTag.OBJECT) {
return BuiltinType.ANY;
}
AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
String fieldName = ConstantExpressionUtil.getStringArgument(funcExpr, 1);
if (fieldName == null) {
return BuiltinType.ANY;
}
ARecordType recType = (ARecordType) firstArgType;
IAType fieldType = recType.getFieldType(fieldName);
return fieldType == null ? BuiltinType.ANY : fieldType;
}
use of org.apache.asterix.om.types.ARecordType in project asterixdb by apache.
the class TypeResolverUtilTest method testOrderedListType.
@Test
public void testOrderedListType() {
// Constructs input types.
ARecordType leftRecordType = new ARecordType("null", new String[] { "a", "b" }, new IAType[] { BuiltinType.ASTRING, BuiltinType.AINT32 }, true, Collections.singleton("d"));
AOrderedListType leftListType = new AOrderedListType(leftRecordType, "null");
ARecordType rightRecordType = new ARecordType("null", new String[] { "b", "c" }, new IAType[] { BuiltinType.AINT32, BuiltinType.ABINARY }, true, Collections.singleton("e"));
AOrderedListType rightListType = new AOrderedListType(rightRecordType, "null");
// Gets the actual resolved type.
List<IAType> inputTypes = new ArrayList<>();
inputTypes.add(leftListType);
inputTypes.add(rightListType);
AbstractCollectionType resolvedType = (AbstractCollectionType) TypeResolverUtil.resolve(inputTypes);
ARecordType resolvedRecordType = (ARecordType) resolvedType.getItemType();
// Gets the expected generalized type.
Set<String> possibleAdditionalFields = new HashSet<>();
possibleAdditionalFields.add("a");
possibleAdditionalFields.add("c");
possibleAdditionalFields.add("d");
possibleAdditionalFields.add("e");
ARecordType expectedRecordType = new ARecordType(null, new String[] { "b" }, new IAType[] { BuiltinType.AINT32 }, true, possibleAdditionalFields);
AOrderedListType expectedListType = new AOrderedListType(expectedRecordType, null);
// Compares the resolved type and the expected type.
Assert.assertEquals(resolvedType, expectedListType);
Assert.assertEquals(resolvedRecordType.getAllPossibleAdditonalFieldNames(), expectedRecordType.getAllPossibleAdditonalFieldNames());
}
use of org.apache.asterix.om.types.ARecordType in project asterixdb by apache.
the class TypeResolverUtilTest method testIsmophicRecordType.
@Test
public void testIsmophicRecordType() {
// Constructs input types.
ARecordType leftRecordType = new ARecordType(null, new String[] { "a", "b" }, new IAType[] { BuiltinType.ASTRING, BuiltinType.AINT32 }, false, null);
ARecordType rightRecordType = new ARecordType(null, new String[] { "b", "a" }, new IAType[] { BuiltinType.AINT32, BuiltinType.ASTRING }, false, null);
// Resolves input types to a generalized type.
List<IAType> inputTypes = new ArrayList<>();
inputTypes.add(leftRecordType);
inputTypes.add(rightRecordType);
ARecordType resolvedType = (ARecordType) TypeResolverUtil.resolve(inputTypes);
// Compares the resolved type with the expected type.
Assert.assertEquals(resolvedType, leftRecordType);
}
use of org.apache.asterix.om.types.ARecordType in project asterixdb by apache.
the class AUnorderedListSerializerDeserializerTest method test.
@Test
public void test() {
// Generates types.
ARecordType addrRecordType = SerializerDeserializerTestUtils.generateAddressRecordType();
ARecordType employeeType = SerializerDeserializerTestUtils.generateEmployeeRecordType(addrRecordType);
AUnorderedListType employeeListType = new AUnorderedListType(employeeType, "employee_list");
//Generates records.
ARecord[] records = SerializerDeserializerTestUtils.generateRecords(addrRecordType, employeeType);
// Generates lists
AUnorderedList[] lists = new AUnorderedList[4];
for (int index = 0; index < lists.length; ++index) {
lists[index] = new AUnorderedList(employeeListType, Arrays.asList(records));
}
AUnorderedListSerializerDeserializer serde = new AUnorderedListSerializerDeserializer(employeeListType);
// Run four test threads to serialize/deserialize lists concurrently.
SerializerDeserializerTestUtils.concurrentSerDeTestRun(serde, lists);
}
Aggregations