lacquer icon indicating copy to clipboard operation
lacquer copied to clipboard

[gather_columns] Traversing function calls

Open john-bodley opened this issue 9 years ago • 2 comments

This PR augments the print_column_resolution_order method to also examine columns which are function calls, so queries of the form

SELECT SUM(foo) FROM a

associate the column foo with table a, i.e., produces the output,

Checking query:
select sum(foo) from a
[SingleColumn(expression=FunctionCall(name=QualifiedName(sum), distinct=False, arguments=[QualifiedNameReference(name=QualifiedName(foo))]))]
[Table(name=QualifiedName(a))]

Table Column Resolution:
QualifiedNameReference(name=QualifiedName(foo)): [Table(name=QualifiedName(a))]

Note that the column_name variable was unused and thus I deleted it.

john-bodley avatar Mar 25 '17 19:03 john-bodley

I'm happy to merge this as-is, but for the purposes of limited scope on this example, what do you think of checking the function call name to see that it's in one of pre-defined ones in SQL, e.g.: AVG, MAX, MIN, SUM,COUNT? I only say this because I know that we miss expressions of the form select sum(10*a) from foo. Those require a slightly more complicated visitor (or an additional one) I think, but we could work on that.

brianv0 avatar Mar 27 '17 00:03 brianv0

@brianv0 I'm happy to augment the PR to include a whitelist of function names.

john-bodley avatar Mar 27 '17 15:03 john-bodley