google / google/googlesql

ExtractTableNamesFromScript handling DDL statements unexpectedly

Open
#102 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.6k
Forks
260
PR merge metrics
No merged PRs in 30d

Description

Given a script
```
BEGIN

CREATE TABLE `project1.dataset1.table1` AS
SELECT *
FROM `project2.dataset2.table2`;

CREATE TABLE `project3.dataset3.table3` (
foo STRING,
bar STRING
);

ALTER TABLE `project4.dataset4.table4`
ADD COLUMN IF NOT EXISTS foo STRING;

END;
```
I would expect `ExtractTableNamesFromScript` to parse out 4 tables:
* project1.dataset1.table1
* project2.dataset2.table2
* project3.dataset3.table3
* project4.dataset4.table4

but with the following options set
```
zetasql::LanguageOptions ConfigureLanguage() {
zetasql::LanguageOptions language_options =
zetasql::LanguageOptions::MaximumFeatures();
language_options.SetSupportsAllStatementKinds();
language_options.EnableLanguageFeature(zetasql::FEATURE_V_1_3_SCRIPT_LABEL);
return language_options;
}

zetasql::AnalyzerOptions ConfigureOptions() {
zetasql::LanguageOptions language_options = ConfigureLanguage();
zetasql::AnalyzerOptions analyzer_options(language_options);
return analyzer_options;
}
```
i.e. called with
```
zetasql::TableNamesSet table_names;
zetasql::AnalyzerOptions analyzer_options = ConfigureOptions();
absl::Status status =
zetasql::ExtractTableNamesFromScript(sproc, analyzer_options, &table_names);
```
`ExtractTableNamesFromScript` only identifies `project2.dataset2.table2`.

Is there a language option I'm missing? Or does this method handle top level DDL statements differently than any supporting nodes?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.