Search in sources :

Example 21 with ARecordType

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];
}
Also used : AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ARecordType(org.apache.asterix.om.types.ARecordType) IAType(org.apache.asterix.om.types.IAType)

Example 22 with ARecordType

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;
}
Also used : AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ARecordType(org.apache.asterix.om.types.ARecordType) IAType(org.apache.asterix.om.types.IAType)

Example 23 with ARecordType

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());
}
Also used : AOrderedListType(org.apache.asterix.om.types.AOrderedListType) ArrayList(java.util.ArrayList) AbstractCollectionType(org.apache.asterix.om.types.AbstractCollectionType) ARecordType(org.apache.asterix.om.types.ARecordType) IAType(org.apache.asterix.om.types.IAType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with ARecordType

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);
}
Also used : ArrayList(java.util.ArrayList) ARecordType(org.apache.asterix.om.types.ARecordType) IAType(org.apache.asterix.om.types.IAType) Test(org.junit.Test)

Example 25 with ARecordType

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);
}
Also used : ARecord(org.apache.asterix.om.base.ARecord) AUnorderedList(org.apache.asterix.om.base.AUnorderedList) ARecordType(org.apache.asterix.om.types.ARecordType) AUnorderedListType(org.apache.asterix.om.types.AUnorderedListType) Test(org.junit.Test)

Aggregations

ARecordType (org.apache.asterix.om.types.ARecordType)105 IAType (org.apache.asterix.om.types.IAType)73 ArrayList (java.util.ArrayList)48 List (java.util.List)24 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)22 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)20 Dataset (org.apache.asterix.metadata.entities.Dataset)19 AString (org.apache.asterix.om.base.AString)19 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)19 Test (org.junit.Test)16 AsterixException (org.apache.asterix.common.exceptions.AsterixException)15 Index (org.apache.asterix.metadata.entities.Index)15 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)15 CompilationException (org.apache.asterix.common.exceptions.CompilationException)13 AOrderedListType (org.apache.asterix.om.types.AOrderedListType)13 Mutable (org.apache.commons.lang3.mutable.Mutable)13 IOException (java.io.IOException)12 MetadataException (org.apache.asterix.metadata.MetadataException)12 AUnionType (org.apache.asterix.om.types.AUnionType)11 Pair (org.apache.hyracks.algebricks.common.utils.Pair)10