Search in sources :

Example 36 with IAType

use of org.apache.asterix.om.types.IAType in project asterixdb by apache.

the class NumericAggTypeComputer method getResultType.

@Override
protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
    ATypeTag tag = strippedInputTypes[0].getTypeTag();
    IAType type = null;
    switch(tag) {
        case DOUBLE:
        case FLOAT:
        case BIGINT:
        case INTEGER:
        case SMALLINT:
        case TINYINT:
        case ANY:
            type = strippedInputTypes[0];
            break;
        default:
            break;
    }
    return AUnionType.createNullableType(type, "AggResult");
}
Also used : ATypeTag(org.apache.asterix.om.types.ATypeTag) IAType(org.apache.asterix.om.types.IAType)

Example 37 with IAType

use of org.apache.asterix.om.types.IAType 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 38 with IAType

use of org.apache.asterix.om.types.IAType 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 39 with IAType

use of org.apache.asterix.om.types.IAType in project asterixdb by apache.

the class TypeComputeUtils method resolveCateogry.

private static byte resolveCateogry(IAType... inputTypes) {
    byte category = CERTAIN;
    boolean meetNull = false;
    for (IAType inputType : inputTypes) {
        switch(inputType.getTypeTag()) {
            case UNION:
                AUnionType unionType = (AUnionType) inputType;
                if (unionType.isNullableType()) {
                    category |= NULLABLE;
                }
                if (unionType.isMissableType()) {
                    category |= MISSABLE;
                }
                break;
            case MISSING:
                return MISSING;
            case NULL:
                meetNull = true;
                break;
            case ANY:
                category |= NULLABLE;
                category |= MISSABLE;
                break;
            default:
                break;
        }
    }
    if (meetNull) {
        return NULL;
    }
    return category;
}
Also used : AUnionType(org.apache.asterix.om.types.AUnionType) IAType(org.apache.asterix.om.types.IAType)

Example 40 with IAType

use of org.apache.asterix.om.types.IAType 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)

Aggregations

IAType (org.apache.asterix.om.types.IAType)190 ARecordType (org.apache.asterix.om.types.ARecordType)73 ArrayList (java.util.ArrayList)64 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)42 ATypeTag (org.apache.asterix.om.types.ATypeTag)40 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)37 List (java.util.List)32 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)32 AUnionType (org.apache.asterix.om.types.AUnionType)31 AString (org.apache.asterix.om.base.AString)28 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)27 Mutable (org.apache.commons.lang3.mutable.Mutable)25 Pair (org.apache.hyracks.algebricks.common.utils.Pair)24 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)20 Dataset (org.apache.asterix.metadata.entities.Dataset)18 AsterixException (org.apache.asterix.common.exceptions.AsterixException)17 AOrderedListType (org.apache.asterix.om.types.AOrderedListType)16 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)16 IVisitablePointable (org.apache.asterix.om.pointables.base.IVisitablePointable)15 IVariableTypeEnvironment (org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment)15