Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parenthesis confuse parsing of insert/create view #377

Closed
jgeralnik opened this issue May 28, 2023 · 1 comment
Closed

Parenthesis confuse parsing of insert/create view #377

jgeralnik opened this issue May 28, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@jgeralnik
Copy link

Hi!

sqllineage fails to parse the following query:

insert into tab3 (with tab1 as (SELECT * FROM tab2) SELECT * FROM tab1);

The problem seems to be that DmlInsertExtractor does not handle bracketed segments.

I would think that the fix would be something like adding

            if segment.type == "bracketed":
                holder |=self.extract(
                    segment,
                    AnalyzerContext(prev_cte=holder.cte, prev_write=holder.write),
                )

to DmlInsertExtractor.extract but that doesn't work because the segments returned on the next iteration don't contain "with_compound_statement" but instead the individual parts [<KeywordSegment: ([L: 1, P: 19]) 'with'>, <CTEDefinitionSegment: ([L: 1, P: 24])>,<SelectStatementSegment: ([L: 1, P: 53])>].

I would love to hear any other suggestions and would be happy to open a PR myself with some tests if we can find a solution

@reata
Copy link
Owner

reata commented May 31, 2023

This is definitely a bug and I think you're very close to it.

Here's what my instinct tells me, not guarantee it will work. But you can try after going into "bracketed", based on it starts with CTE or not, you can call DmlCteExtractor or DmlSelectExtractor. Look forward to your PR.

@reata reata added the bug Something isn't working label May 31, 2023
@reata reata closed this as completed Jun 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants