question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fail to parse WITH query if it contains WINDOW

See original GitHub issue

If a query contains the WINDOW clause parser fails with the following error:

self = <sql_metadata.parser.Parser object at 0x101e62990>

    @property
    def with_names(self) -> List[str]:
        """
        Returns with statements aliases list from a given query
    
        E.g. WITH database1.tableFromWith AS (SELECT * FROM table3)
             SELECT "xxxxx" FROM database1.tableFromWith alias
             LEFT JOIN database2.table2 ON ("tt"."ttt"."fff" = "xx"."xxx")
        will return ["database1.tableFromWith"]
        """
        if self._with_names is not None:
            return self._with_names
        with_names = UniqueList()
        for token in self._not_parsed_tokens:
            if token.previous_token.normalized == "WITH":
                self._is_in_with_block = True
                while self._is_in_with_block and token.next_token:
                    if token.next_token.is_as_keyword:
                        self._handle_with_name_save(token=token, with_names=with_names)
                        while token.next_token and not token.is_with_query_end:
                            token = token.next_token
>                       if token.next_token.normalized in WITH_ENDING_KEYWORDS:
E                       AttributeError: 'NoneType' object has no attribute 'normalized'

../../venv/lib/python3.7/site-packages/sql_metadata/parser.py:449: AttributeError

Query example:

WITH cte_1 AS (
    SELECT
        column_1
     FROM
         table_1
     WINDOW window_1 AS (
         PARTITION BY column_2
     )
)
SELECT
    column_1
FROM
    cte_1 AS alias_1

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
macbrecommented, Apr 26, 2022

@vakhmenin, can we close this one as fixed after today’s release?

1reaction
vakhmenincommented, Apr 26, 2022

Thanks a lot!🙏🏻

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed to parse the query, no additional information is available.
Hi,. I am getting the below error when I execute a union analytics query. Failed to parse the query, no additional information is...
Read more >
URI Search fails with parse error when query string ... - GitHub
I get an error message when including a slash in query string. The query is of the following form: ...
Read more >
Parse query string in JavaScript [duplicate] - Stack Overflow
Here is a fast and easy way of parsing query strings in JavaScript: function getQueryVariable(variable) { var query = window.location.search.substring(1); ...
Read more >
failed to parse SQL query: ORA-01403 No Data Found
Hi, i ´ve a query that gives me that error when i´m working with a special user. 3 others users don´t get this...
Read more >
KB484403: Unable to parse the command line output when ...
In a Spanish localized Windows environments, MicroStrategy has observed that the error, 'Unable to parse the Command Line Output,' may ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found