Search in sources :

Example 1 with UnsupportedTypeException

use of org.apache.asterix.om.exceptions.UnsupportedTypeException in project asterixdb by apache.

the class RecordRemoveFieldsTypeComputer method getPathFromConstantExpression.

private void getPathFromConstantExpression(String funcName, ILogicalExpression expression, Set<String> fieldNameSet, List<List<String>> pathList) throws AlgebricksException {
    ConstantExpression ce = (ConstantExpression) expression;
    if (!(ce.getValue() instanceof AsterixConstantValue)) {
        throw new InvalidExpressionException(funcName, 1, ce, LogicalExpressionTag.CONSTANT);
    }
    IAObject item = ((AsterixConstantValue) ce.getValue()).getObject();
    ATypeTag type = item.getType().getTypeTag();
    switch(type) {
        case STRING:
            String fn = ((AString) item).getStringValue();
            fieldNameSet.add(fn);
            break;
        case ARRAY:
            AOrderedList pathOrdereList = (AOrderedList) item;
            String fieldName = ((AString) pathOrdereList.getItem(0)).getStringValue();
            fieldNameSet.add(fieldName);
            List<String> path = new ArrayList<>();
            for (int i = 0; i < pathOrdereList.size(); i++) {
                path.add(((AString) pathOrdereList.getItem(i)).getStringValue());
            }
            pathList.add(path);
            break;
        default:
            throw new UnsupportedTypeException(funcName, type);
    }
}
Also used : AOrderedList(org.apache.asterix.om.base.AOrderedList) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) ATypeTag(org.apache.asterix.om.types.ATypeTag) InvalidExpressionException(org.apache.asterix.om.exceptions.InvalidExpressionException) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) IAObject(org.apache.asterix.om.base.IAObject) ArrayList(java.util.ArrayList) UnsupportedTypeException(org.apache.asterix.om.exceptions.UnsupportedTypeException) AString(org.apache.asterix.om.base.AString) AString(org.apache.asterix.om.base.AString)

Example 2 with UnsupportedTypeException

use of org.apache.asterix.om.exceptions.UnsupportedTypeException 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;
}
Also used : AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) IAObject(org.apache.asterix.om.base.IAObject) ArrayList(java.util.ArrayList) AString(org.apache.asterix.om.base.AString) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) ATypeTag(org.apache.asterix.om.types.ATypeTag) InvalidExpressionException(org.apache.asterix.om.exceptions.InvalidExpressionException) UnsupportedTypeException(org.apache.asterix.om.exceptions.UnsupportedTypeException)

Aggregations

ArrayList (java.util.ArrayList)2 AString (org.apache.asterix.om.base.AString)2 IAObject (org.apache.asterix.om.base.IAObject)2 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)2 InvalidExpressionException (org.apache.asterix.om.exceptions.InvalidExpressionException)2 UnsupportedTypeException (org.apache.asterix.om.exceptions.UnsupportedTypeException)2 ATypeTag (org.apache.asterix.om.types.ATypeTag)2 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)2 AOrderedList (org.apache.asterix.om.base.AOrderedList)1 Mutable (org.apache.commons.lang3.mutable.Mutable)1 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)1 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)1