Search in sources :

Example 66 with ILogicalExpression

use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.

the class OperatorDeepCopyVisitor method visitTokenizeOperator.

@Override
public ILogicalOperator visitTokenizeOperator(TokenizeOperator op, Void arg) throws AlgebricksException {
    List<Mutable<ILogicalExpression>> newPrimaryKeyExpressions = new ArrayList<>();
    deepCopyExpressionRefs(newPrimaryKeyExpressions, op.getPrimaryKeyExpressions());
    List<Mutable<ILogicalExpression>> newSecondaryKeyExpressions = new ArrayList<>();
    deepCopyExpressionRefs(newSecondaryKeyExpressions, op.getSecondaryKeyExpressions());
    List<LogicalVariable> newTokenizeVars = new ArrayList<>();
    deepCopyVars(newTokenizeVars, op.getTokenizeVars());
    Mutable<ILogicalExpression> newFilterExpression = new MutableObject<>(((AbstractLogicalExpression) op.getFilterExpression()).cloneExpression());
    List<Object> newTokenizeVarTypes = new ArrayList<>();
    deepCopyObjects(newTokenizeVarTypes, op.getTokenizeVarTypes());
    TokenizeOperator tokenizeOp = new TokenizeOperator(op.getDataSourceIndex(), newPrimaryKeyExpressions, newSecondaryKeyExpressions, newTokenizeVars, newFilterExpression, op.getOperation(), op.isBulkload(), op.isPartitioned(), newTokenizeVarTypes);
    return tokenizeOp;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) TokenizeOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.TokenizeOperator) ArrayList(java.util.ArrayList) MutableObject(org.apache.commons.lang3.mutable.MutableObject) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Example 67 with ILogicalExpression

use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.

the class IsomorphismVariableMappingVisitor method mapVariablesForAbstractAssign.

private void mapVariablesForAbstractAssign(List<LogicalVariable> variablesLeft, List<Mutable<ILogicalExpression>> exprsLeft, List<LogicalVariable> variablesRight, List<Mutable<ILogicalExpression>> exprsRight) {
    if (variablesLeft.size() != variablesRight.size()) {
        return;
    }
    int size = variablesLeft.size();
    // Keeps track of already matched right side variables.
    Set<LogicalVariable> matchedRightVars = new HashSet<>();
    for (int i = 0; i < size; i++) {
        ILogicalExpression exprLeft = exprsLeft.get(i).getValue();
        LogicalVariable left = variablesLeft.get(i);
        for (int j = 0; j < size; j++) {
            ILogicalExpression exprRight = copyExpressionAndSubtituteVars(exprsRight.get(j)).getValue();
            LogicalVariable right = variablesRight.get(j);
            if (exprLeft.equals(exprRight) && !matchedRightVars.contains(right)) {
                variableMapping.put(right, left);
                // The added variable will not be considered in next rounds.
                matchedRightVars.add(right);
                break;
            }
        }
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) HashSet(java.util.HashSet)

Example 68 with ILogicalExpression

use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.

the class IsomorphismVariableMappingVisitor method mapVarExprPairList.

private void mapVarExprPairList(List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> leftPairs, List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> rightPairs) {
    if (leftPairs.size() != rightPairs.size()) {
        return;
    }
    for (int i = 0; i < leftPairs.size(); i++) {
        ILogicalExpression exprLeft = leftPairs.get(i).second.getValue();
        LogicalVariable leftVar = leftPairs.get(i).first;
        for (int j = 0; j < leftPairs.size(); j++) {
            ILogicalExpression exprRight = copyExpressionAndSubtituteVars(rightPairs.get(j).second).getValue();
            if (exprLeft.equals(exprRight)) {
                LogicalVariable rightVar = rightPairs.get(j).first;
                if (rightVar != null && leftVar != null) {
                    variableMapping.put(rightVar, leftVar);
                }
                break;
            }
        }
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)

Example 69 with ILogicalExpression

use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.

the class IsomorphismVariableMappingVisitor method mapVariablesForGroupBy.

private void mapVariablesForGroupBy(ILogicalOperator left, ILogicalOperator right) throws AlgebricksException {
    if (left.getOperatorTag() != right.getOperatorTag()) {
        return;
    }
    GroupByOperator leftOp = (GroupByOperator) left;
    GroupByOperator rightOp = (GroupByOperator) right;
    List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> leftPairs = leftOp.getGroupByList();
    List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> rightPairs = rightOp.getGroupByList();
    mapVarExprPairList(leftPairs, rightPairs);
    leftPairs = leftOp.getDecorList();
    rightPairs = rightOp.getDecorList();
    mapVarExprPairList(leftPairs, rightPairs);
}
Also used : ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) GroupByOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 70 with ILogicalExpression

use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.

the class ExceptionTest method testTypeComputer.

private void testTypeComputer(Class<? extends IResultTypeComputer> c) throws Exception {
    // Mocks the type environment.
    IVariableTypeEnvironment mockTypeEnv = mock(IVariableTypeEnvironment.class);
    // Mocks the metadata provider.
    IMetadataProvider<?, ?> mockMetadataProvider = mock(IMetadataProvider.class);
    // Mocks function expression.
    AbstractFunctionCallExpression mockExpr = mock(AbstractFunctionCallExpression.class);
    FunctionIdentifier fid = mock(FunctionIdentifier.class);
    when(mockExpr.getFunctionIdentifier()).thenReturn(fid);
    when(fid.getName()).thenReturn("testFunction");
    int numCombination = (int) Math.pow(ATypeTag.values().length, 2);
    // Sets two arguments for the mocked function expression.
    for (int index = 0; index < numCombination; ++index) {
        try {
            List<Mutable<ILogicalExpression>> argRefs = new ArrayList<>();
            for (int argIndex = 0; argIndex < 2; ++argIndex) {
                int base = (int) Math.pow(ATypeTag.values().length, argIndex);
                ILogicalExpression mockArg = mock(ILogicalExpression.class);
                argRefs.add(new MutableObject<>(mockArg));
                IAType mockType = mock(IAType.class);
                when(mockTypeEnv.getType(mockArg)).thenReturn(mockType);
                int serializedTypeTag = (index / base) % ATypeTag.values().length + 1;
                ATypeTag typeTag = ATypeTag.VALUE_TYPE_MAPPING[serializedTypeTag];
                if (typeTag == null) {
                    // For some reason, type tag 39 does not exist.
                    typeTag = ATypeTag.ANY;
                }
                when(mockType.getTypeTag()).thenReturn(typeTag);
            }
            // Sets up arguments for the mocked expression.
            when(mockExpr.getArguments()).thenReturn(argRefs);
            // Sets up required/actual types of the mocked expression.
            Object[] opaqueParameters = new Object[2];
            opaqueParameters[0] = BuiltinType.ANY;
            opaqueParameters[1] = BuiltinType.ANY;
            when(mockExpr.getOpaqueParameters()).thenReturn(opaqueParameters);
            // Invokes a type computer.
            IResultTypeComputer instance = (IResultTypeComputer) c.getField("INSTANCE").get(null);
            instance.computeType(mockExpr, mockTypeEnv, mockMetadataProvider);
        } catch (AlgebricksException ae) {
            String msg = ae.getMessage();
            if (msg.startsWith("ASX")) {
                // Verifies the error code.
                int errorCode = Integer.parseInt(msg.substring(3, 7));
                Assert.assertTrue(errorCode >= 1000 && errorCode < 2000);
                continue;
            } else {
                // Any root-level compilation exceptions thrown from type computers should have an error code.
                Assert.assertTrue(!(ae instanceof AlgebricksException) || (ae.getCause() != null));
            }
        } catch (ClassCastException e) {
            continue;
        }
    }
}
Also used : IResultTypeComputer(org.apache.asterix.om.typecomputer.base.IResultTypeComputer) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ArrayList(java.util.ArrayList) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) ATypeTag(org.apache.asterix.om.types.ATypeTag) MutableObject(org.apache.commons.lang3.mutable.MutableObject) IVariableTypeEnvironment(org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment) IAType(org.apache.asterix.om.types.IAType)

Aggregations

ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)312 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)182 Mutable (org.apache.commons.lang3.mutable.Mutable)160 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)130 ArrayList (java.util.ArrayList)125 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)125 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)121 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)84 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)75 Pair (org.apache.hyracks.algebricks.common.utils.Pair)70 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)68 MutableObject (org.apache.commons.lang3.mutable.MutableObject)62 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)50 IAType (org.apache.asterix.om.types.IAType)42 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)38 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)36 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)34 FunctionIdentifier (org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier)34 HashSet (java.util.HashSet)32 AString (org.apache.asterix.om.base.AString)32