sqllineage icon indicating copy to clipboard operation
sqllineage copied to clipboard

Problem with generator stament

Open tyatabe opened this issue 3 years ago • 3 comments

This is a contribed example of something I'm trying to do using Snowflake sql (where this query works correctly): SELECT 'HELLO' AS FEATURE FROM TABLE (GENERATOR(ROWCOUNT => (24)))) This is the error message I get SQLLineageException: An Identifier is expected, got Token[value: )] instead from the sqllineage heroku app I get this somewhat more specific message An Identifier is expected, got Parenthesis[value: (GENERATOR(ROWCOUNT => (24)))] instead

I'm using sqllineage version 1.2.4

tyatabe avatar Jan 27 '22 12:01 tyatabe

Sorry for the late reply, been really busy recently.

GENERATOR is special from other table names. As you can see, usually table name is parsed as Identifier(https://en.wikipedia.org/wiki/Identifier_(computer_languages)). You can think of identifier as string literal.

here we have a Parenthesis, which is clearly not a string literal.

I see what generator is doing in snowflake. So what's your expected output here?

Reference for myself: https://docs.snowflake.com/en/sql-reference/functions/generator.html

reata avatar Feb 19 '22 14:02 reata

Apologies for being late, also been busy. From this toy example what I'm expecting to get is a table with the column FEATURE containing the value HELLO 24 times. For my application I wanted to use it to generate sequences of hours between two dates, for example see this:

SET date_start_window ='2021-01-01'; SET date_end_window = '2030-12-31'; SET NUM_HOURS = (Select DATEDIFF(HOUR, $date_start_window::DATE, $date_end_window::DATE)); SELECT DATEADD( HOUR, '-' || ROW_NUMBER() OVER (ORDER BY NULL), $date_end_window::DATE) AS TS_HOUR FROM TABLE (GENERATOR(ROWCOUNT => ($NUM_HOURS))) ORDER BY TS_HOUR;

tyatabe avatar Apr 01 '22 10:04 tyatabe

Apologies for being late, also been busy. From this toy example what I'm expecting to get is a table with the column FEATURE containing the value HELLO 24 times. For my application I wanted to use it to generate sequences of hours between two dates, for example see this:

SET date_start_window ='2021-01-01'; SET date_end_window = '2030-12-31'; SET NUM_HOURS = (Select DATEDIFF(HOUR, $date_start_window::DATE, $date_end_window::DATE)); SELECT DATEADD( HOUR, '-' || ROW_NUMBER() OVER (ORDER BY NULL), $date_end_window::DATE) AS TS_HOUR FROM TABLE (GENERATOR(ROWCOUNT => ($NUM_HOURS))) ORDER BY TS_HOUR;

Yeah, thanks for explaining, I understand the GENERATOR expression and your use case now. The thing I'm more interested to know is what would you expect sqllineage to return for this syntax. A source table named 'GENERATOR', or 'GENERATOR(ROWCOUNT => ($NUM_HOURS))'? Or should we create another class for this, like we did previous for Path?

reata avatar Apr 06 '22 13:04 reata