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

Analyzer extractTableNamesFromStatement - returning incorrect table names #123

Open
jrbangit opened this issue Nov 22, 2022 · 0 comments
Open

Comments

@jrbangit
Copy link

jrbangit commented Nov 22, 2022

I'm using ZetaSQL in our streaming application that basically consumes from GCP audit log. As you can imagine, there are lots possibilities that a weird query will occur and flow in the audit log and eventually into our application.

I've encountered an issue specifically on the extractTableNamesFromStatement method of Analyzer which only occurs on specific type of query. Particularly for queries having the same table name for both target and source, like the query below.

CREATE OR REPLACE TABLE project_test.dataset_test.test_table AS SELECT DISTINCT * FROM project_test.dataset_test.test_table

the expected result based on my tests with various types of statements should return [project_test.dataset_test.test_table]

However, in the query above, the analyzer returns [project_test, dataset_test, test_table] instead.

here's how I used it:

        LanguageOptions languageOptions = new LanguageOptions();
        languageOptions.enableMaximumLanguageFeatures();
        languageOptions.setSupportsAllStatementKinds();

        AnalyzerOptions analyzerOptions = new AnalyzerOptions();
        analyzerOptions.setLanguageOptions(languageOptions);
        analyzerOptions.setPruneUnusedColumns(true);
        
        
        Analyzer.extractTableNamesFromStatement(query, analyzerOptions)
                    .stream()
                    .flatMap(List::stream)
                    .collect(Collectors.toList());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant