alphasql icon indicating copy to clipboard operation
alphasql copied to clipboard

create view statements are not recognized

Open lukas-at-harren opened this issue 3 years ago • 4 comments

Hi,

I wanted to open a discussion about "CREATE VIEW" statements, as I think they should show up in the dependency graph.

What do you think? Using alphadag with the option --with_tables. Maybe another option --with_views would be a non breaking backwards compatible change to add these statements to the graph.

lukas-at-harren avatar Feb 21 '22 06:02 lukas-at-harren

Yes, they should be handled. Thank you for filing this issue!

Matts966 avatar Feb 21 '22 11:02 Matts966

Can I help somehow? Frankly, I am a novice when it comes to C++ programming, but I "made" this patch here:

diff --git a/alphasql/identifier_resolver.cc b/alphasql/identifier_resolver.cc
index 1ee2aab..a9aa332 100644
--- a/alphasql/identifier_resolver.cc
+++ b/alphasql/identifier_resolver.cc
@@ -130,6 +130,20 @@ void IdentifierResolver::visitASTCreateTableStatement(
   visitASTChildren(node, data);
 }
 
+void IdentifierResolver::visitASTCreateViewStatement(const ASTCreateViewStatement *node,
+    void *data) {
+  const auto &name_vector = node->name()->ToIdentifierVector();
+  if (node->scope() == ASTCreateStatement::TEMPORARY) {
+    const std::string path_str = absl::StrJoin(name_vector, ".");
+    temporary_tables.insert(path_str);
+    visitASTChildren(node, data);
+    return;
+  }
+
+  identifier_information.table_information.created.insert(name_vector);
+  visitASTChildren(node, data);
+}
+
 // TODO:(Matts966) Check if this node is callee or caller and implement
 // correctly void IdentifierResolver::visitASTTVF(const ASTTVF* node, void*
 // data) {

I had a problem using docker/dev.Dockerfile to build the project. It fails at some point. Do you know if the development Dockerfile is up to date?

lukas-at-harren avatar Feb 21 '22 11:02 lukas-at-harren

This is the error I am getting on building the project using docker/dev.Dockerfile:

ERROR: /root/.cache/bazel/_bazel_root/29fd748aa9e1514cd3d2c2cf7c5b0dfd/external/com_google_zetasql/bazel/BUILD:40:1: TreeArtifact external/com_google_zetasql/bazel/copy_m4/m4 was not created
ERROR: /root/.cache/bazel/_bazel_root/29fd748aa9e1514cd3d2c2cf7c5b0dfd/external/com_google_zetasql/bazel/BUILD:40:1: not all outputs were created or valid
INFO: Elapsed time: 1572.566s, Critical Path: 88.75s
INFO: 175 processes: 175 processwrapper-sandbox.
FAILED: Build did NOT complete successfully

lukas-at-harren avatar Feb 21 '22 14:02 lukas-at-harren

TVF can be used as parameterized view for now.

Matts966 avatar Apr 18 '22 15:04 Matts966