Skip to content

Commit

Permalink
Merge pull request #19 from Matts966/alphasql
Browse files Browse the repository at this point in the history
 Fix bugs resolving dependencies of temp table references and add a sample case
  • Loading branch information
Matts966 authored Jul 21, 2020
2 parents d7465c8 + 0cd4efb commit fd9bfb8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
.PHONY: build-and-check
build-and-check: test sample

.PHONY: osx
osx:
CC=g++ bazel build //alphasql:all
sudo cp ./bazel-bin/alphasql/dag /usr/local/bin
sudo cp ./bazel-bin/alphasql/pipeline_type_checker /usr/local/bin

.PHONY: sample
sample:
sample: osx
ls -d samples/*/ | while read sample; do \
dag $$sample --output_path $$sample/dag.dot; \
dot -Tpng $$sample/dag.dot -o $$sample/dag.png; \
Expand All @@ -14,5 +17,5 @@ sample:
done;

.PHONY: test
test:
test: osx
CC=g++ bazel test //alphasql:all
6 changes: 6 additions & 0 deletions alphasql/identifier_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ absl::Status IdentifierResolver::FindInStatement(const ASTStatement* statement)
if (query == nullptr) {
if (analyzer_options_->language().SupportsStatementKind(
RESOLVED_CREATE_TABLE_STMT)) {
if (create_statement->scope() == ASTCreateStatement::TEMPORARY) {
return absl::OkStatus();
}
_node_kind_to_table_names[RESOLVED_CREATE_TABLE_STMT].insert(
create_statement->name()->ToIdentifierVector()
);
Expand All @@ -270,6 +273,9 @@ absl::Status IdentifierResolver::FindInStatement(const ASTStatement* statement)
} else {
if (analyzer_options_->language().SupportsStatementKind(
RESOLVED_CREATE_TABLE_AS_SELECT_STMT)) {
if (create_statement->scope() == ASTCreateStatement::TEMPORARY) {
return absl::OkStatus();
}
_node_kind_to_table_names[RESOLVED_CREATE_TABLE_AS_SELECT_STMT].insert(
create_statement->name()->ToIdentifierVector()
);
Expand Down
4 changes: 4 additions & 0 deletions samples/create-temp-table-test/dag.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
digraph G {
0[label="samples/create-temp-table-test/reference.sql"];
1[label="samples/create-temp-table-test/temp_table.sql"];
}
Binary file added samples/create-temp-table-test/dag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions samples/create-temp-table-test/reference.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TEMP TABLE tmp AS SELECT 1 as tmp_column;
SELECT * FROM tmp;
1 change: 1 addition & 0 deletions samples/create-temp-table-test/temp_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TEMP TABLE tmp AS SELECT 1 as tmp_column;

0 comments on commit fd9bfb8

Please sign in to comment.