public boolean rewritePre()

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


    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
            throws AlgebricksException {
        Mutable<ILogicalExpression> exprRef;
        if (opRef.getValue().getOperatorTag() == LogicalOperatorTag.INNERJOIN) {
            InnerJoinOperator selectOp = (InnerJoinOperator) opRef.getValue();
            exprRef = selectOp.getCondition();
        } else if (opRef.getValue().getOperatorTag() == LogicalOperatorTag.SELECT) {
            SelectOperator selectOp = (SelectOperator) opRef.getValue();
            exprRef = selectOp.getCondition();
        } else {
            return false;
        }

        Set<Mutable<ILogicalExpression>> activeFunctionSet = new HashSet<>();
        Set<LogicalVariable> needPrevDsSet = new HashSet<>();
        Set<LogicalVariable> needCurrDsSet = new HashSet<>();
        String channelName =
                (String) context.getMetadataProvider().getConfig().getOrDefault(BADConstants.CONFIG_CHANNEL_NAME, "");

        // collect active functions
        boolean rewriteFunc = collectChannelTimeFunctions(exprRef, activeFunctionSet, needPrevDsSet, needCurrDsSet,
                true, channelName);
        if (activeFunctionSet.size() == 0) {
            return rewriteFunc;
        }

        // add assigns for active functions
        Map<LogicalVariable, LogicalVariable> prevMap = new HashMap<>();
        Map<LogicalVariable, LogicalVariable> currMap = new HashMap<>();
        createChannelTimeAssignOps(opRef, needPrevDsSet, needCurrDsSet, prevMap, currMap, context, channelName);

        // update expressions with new vars
        updateActiveFuncExprsWithVars(prevMap, currMap, activeFunctionSet);

        context.computeAndSetTypeEnvironmentForOperator(opRef.getValue());
        return true;
    }