private boolean collectChannelTimeFunctions()

in asterix-bad/src/main/java/org/apache/asterix/bad/rules/RewriteChannelTimeFunctionToLocalVarRule.java [145:184]


    private boolean collectChannelTimeFunctions(Mutable<ILogicalExpression> exprRef,
            Set<Mutable<ILogicalExpression>> activeFunctionSet, Set<LogicalVariable> needPrevDsSet,
            Set<LogicalVariable> needCurrDsSet, boolean disjunctiveFlag, String channelName) {
        boolean rewriteFunc = false;
        if (exprRef.getValue().getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
            AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) exprRef.getValue();
            if (funcExpr.getFunctionIdentifier().equals(BuiltinFunctions.OR)) {
                disjunctiveFlag = false;
            }
            if (funcExpr.getFunctionIdentifier() == BADFunctions.PREVIOUS_CHANNEL_TIME
                    || funcExpr.getFunctionIdentifier() == BADFunctions.CURRENT_CHANNEL_TIME) {
                // collect ds var to see what assign op needs to be added
                LogicalExpressionTag arg0ExprTag = funcExpr.getArguments().get(0).getValue().getExpressionTag();
                if (arg0ExprTag == LogicalExpressionTag.CONSTANT) {
                    return false;
                }
                if (!disjunctiveFlag) {
                    LogicalVariable dsVar = ((VariableReferenceExpression) funcExpr.getArguments().get(0).getValue())
                            .getVariableReference();
                    activeFunctionSet.add(exprRef);
                    if (funcExpr.getFunctionIdentifier() == BADFunctions.PREVIOUS_CHANNEL_TIME) {
                        needPrevDsSet.add(dsVar);
                    } else if (funcExpr.getFunctionIdentifier() == BADFunctions.CURRENT_CHANNEL_TIME) {
                        needCurrDsSet.add(dsVar);
                    }
                } else {
                    // if disjunctive, modify to get ts and wait for introduce filter rule to work
                    funcExpr.getArguments().set(0, new MutableObject<>(
                            new ConstantExpression(new AsterixConstantValue(new AString(channelName)))));
                    rewriteFunc = true;
                }
            } else {
                for (Mutable<ILogicalExpression> argExpr : funcExpr.getArguments()) {
                    rewriteFunc = rewriteFunc || collectChannelTimeFunctions(argExpr, activeFunctionSet, needPrevDsSet,
                            needCurrDsSet, disjunctiveFlag, channelName);
                }
            }
        }
        return rewriteFunc;
    }