sql-metadata icon indicating copy to clipboard operation
sql-metadata copied to clipboard

Handle when column name wildcard is prefixed by table name

Open sumartoyo opened this issue 3 years ago • 4 comments

Query to reproduce:

parsed = Parser("""
with cte_one as (
    select table_one.*
    from table_one
)

select cte_one.column_one
from cte_one
""")

Above code will fail when getting parsed.columns. But if the query of cte_one is select * from table_one it is succeeded.

This PR add handler for if f"{table}.*" in subparser.columns to make above query success to parse.

sumartoyo avatar Mar 11 '22 10:03 sumartoyo

@sumartoyo, thanks for your PR. Please add a test case(s) that cover your changes.

Then we'll review your pull request.

FAIL Required test coverage of 100.0% not reached. Total coverage: 99.65%

macbre avatar Mar 11 '22 16:03 macbre

@macbre I have added the test and now it's 100% coverage. Please let me know if the test is wrong.

sumartoyo avatar Mar 11 '22 17:03 sumartoyo

@sumartoyo, black formatting tool is complaining. And linting does fail. Please fix these and we'll review your changes. Thanks!

macbre avatar Mar 17 '22 11:03 macbre

I have re-format the test, but I think I will need to rewrite the implementation.

flake8 says "C901 'Parser._resolve_nested_query' is too complex (10)". I tried to write it to be less complex (less if-else) but I don't think it's possible unless I move some logic into a new function. Is it okay to introduce a new function? Are there any conventions I can follow for creating a function?

sumartoyo avatar Mar 18 '22 07:03 sumartoyo