in asterix-bad/src/main/java/org/apache/asterix/bad/rules/RewriteActiveFunctionsRule.java [99:141]
private boolean visit(Mutable<ILogicalExpression> exprRef, Mutable<ILogicalOperator> opRef,
IOptimizationContext context) throws AlgebricksException {
boolean changed = false;
if (exprRef.getValue().getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) exprRef.getValue();
if (funcExpr.getFunctionIdentifier() == BADFunctions.IS_NEW) {
exprRef.setValue(makeAndForIsNew(funcExpr));
changed = true;
} else if (funcExpr.getFunctionIdentifier() == BADFunctions.ACTIVE_TIMESTAMP) {
LogicalVariable channelTimeVar = context.newVar();
LogicalVariable dsVar = getDsVar(funcExpr);
ILogicalExpression activeTsFunc =
new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.META),
new MutableObject<>(new VariableReferenceExpression(dsVar)));
ScalarFunctionCallExpression faExpr = new ScalarFunctionCallExpression(
FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_NAME),
new MutableObject<>(activeTsFunc), new MutableObject<>(new ConstantExpression(
new AsterixConstantValue(new AString(BADConstants.FIELD_NAME_ACTIVE_TS)))));
AssignOperator assignOp = new AssignOperator(channelTimeVar, new MutableObject<>(faExpr));
List<LogicalVariable> liveVars = new ArrayList<>();
for (int i = 0; i < opRef.getValue().getInputs().size(); i++) {
Mutable<ILogicalOperator> inputOpRef = opRef.getValue().getInputs().get(i);
VariableUtilities.getLiveVariables(inputOpRef.getValue(), liveVars);
if (liveVars.contains(dsVar)) {
assignOp.getInputs().add(new MutableObject<>(inputOpRef.getValue()));
inputOpRef.setValue(assignOp);
exprRef.setValue(new VariableReferenceExpression(channelTimeVar));
context.computeAndSetTypeEnvironmentForOperator(assignOp);
}
}
changed = true;
} else {
for (Mutable<ILogicalExpression> argExpr : funcExpr.getArguments()) {
changed = changed || visit(argExpr, opRef, context);
}
}
}
return changed;
}