in zetasql-toolkit-core/src/main/java/com/google/zetasql/toolkit/tools/lineage/ExpressionParentFinder.java [69:109]
public void visitResolvedFunctionCallBase(ResolvedFunctionCallBase functionCallBase) {
Function function = functionCallBase.getFunction();
List<ResolvedExpr> arguments = functionCallBase.getArgumentList();
int numberOfArguments = arguments.size();
List<ResolvedExpr> expressionsToVisit;
switch (function.getName().toLowerCase()) {
case "$case_no_value":
// Must keep all odd arguments (the WHEN expressions), plus the last one (the ELSE
// expr)
expressionsToVisit =
IntStream.range(0, numberOfArguments)
.filter(i -> i % 2 == 1 || i == numberOfArguments - 1)
.mapToObj(arguments::get)
.collect(Collectors.toList());
break;
case "$case_with_value":
// Must keep all even arguments (the WHEN expressions) but the first one (the CASE
// value),
// plus the last one (the ELSE expr)
expressionsToVisit =
IntStream.range(0, numberOfArguments)
.filter(i -> (i != 0 && i % 2 == 0) || i == numberOfArguments - 1)
.mapToObj(arguments::get)
.collect(Collectors.toList());
break;
case "if":
// Remove the first argument (the condition)
expressionsToVisit = arguments.subList(1, arguments.size());
break;
case "nullif":
// Keep only the first argument (the value)
expressionsToVisit = ImmutableList.of(arguments.get(0));
break;
default:
expressionsToVisit = arguments;
}
expressionsToVisit.forEach(expression -> expression.accept(this));
}