Skip to content

Commit

Permalink
Fix ignored function calls problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Matts966 committed Jul 31, 2020
1 parent f38b4f1 commit d7ba360
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 273 deletions.
3 changes: 3 additions & 0 deletions alphasql/dag_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ namespace alphasql {
return function_information_or_status.status();
}
auto function_info = function_information_or_status.value();

// TODO(Matts966): Multiple function definitions lead to cycles like tables
// and we should think if we should raise error here.
for (auto const& defined : function_info.defined) {
const std::string function_name = absl::StrJoin(defined, ".");

Expand Down
201 changes: 8 additions & 193 deletions alphasql/function_name_resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,21 @@ zetasql_base::StatusOr<function_info> GetFunctionInformation(
return resolver.function_information;
}

// Each instance should be used only once.
void FunctionNameResolver::visitASTModelClause(const ASTModelClause* node, void* data) {
return;
}

void FunctionNameResolver::visitASTTemplatedParameterType(
const ASTTemplatedParameterType* node, void* data) {
return;
}
// TODO:(Matts966) Check if this node is callee or caller and implement correctly
// void FunctionNameResolver::visitASTTVF(const ASTTVF* node, void* data) {
// function_information.called.insert(node->name()->ToIdentifierVector());
// }

void FunctionNameResolver::visitASTConnectionClause(const ASTConnectionClause* node,
void* data) {
return;
}

void FunctionNameResolver::visitASTCreateDatabaseStatement(
const ASTCreateDatabaseStatement* node, void* data) {
return;
void FunctionNameResolver::visitASTFunctionCall(const ASTFunctionCall* node, void* data) {
function_information.called.insert(node->function()->ToIdentifierVector());
visitASTChildren(node, data);
}

void FunctionNameResolver::visitASTFunctionDeclaration(
const ASTFunctionDeclaration* node, void* data) {
function_information.defined.insert(node->name()->ToIdentifierVector());
}

void FunctionNameResolver::visitASTTVF(const ASTTVF* node, void* data) {
function_information.called.insert(node->name()->ToIdentifierVector());
}

void FunctionNameResolver::visitASTCreateFunctionStatement(
const ASTCreateFunctionStatement* node, void* data) {
if (node->is_temp()) {
Expand All @@ -128,62 +114,9 @@ void FunctionNameResolver::visitASTCreateTableFunctionStatement(
}
}

void FunctionNameResolver::visitASTCreateEntityStatement(
const ASTCreateEntityStatement* node, void* data) {
return;
}

void FunctionNameResolver::visitASTNotNullColumnAttribute(
const ASTNotNullColumnAttribute* node, void* data) {
return;
}

void FunctionNameResolver::visitASTHiddenColumnAttribute(
const ASTHiddenColumnAttribute* node, void* data) {
return;
}

void FunctionNameResolver::visitASTPrimaryKeyColumnAttribute(
const ASTPrimaryKeyColumnAttribute* node, void* data) {
return;
}

void FunctionNameResolver::visitASTColumnDefinition(const ASTColumnDefinition* node,
void* data) {
return;
}

void FunctionNameResolver::visitASTWithPartitionColumnsClause(
const ASTWithPartitionColumnsClause* node, void* data) {
return;
}

void FunctionNameResolver::visitASTCreateExternalTableStatement(
const ASTCreateExternalTableStatement* node, void* data) {
return;
}

void FunctionNameResolver::visitASTGrantToClause(const ASTGrantToClause* node, void* data) {
return;
}

void FunctionNameResolver::visitASTFilterUsingClause(const ASTFilterUsingClause* node,
void* data) {
return;
}

void FunctionNameResolver::visitASTCreateRowAccessPolicyStatement(
const ASTCreateRowAccessPolicyStatement* node, void* data) {
return;
}

void FunctionNameResolver::visitASTExportModelStatement(const ASTExportModelStatement* node,
void* data) {
return;
}

void FunctionNameResolver::visitASTCallStatement(
const ASTCallStatement* node, void* data) {
node->ChildrenAccept(this, data);
// print("CALL");
// node->procedure_name()->Accept(this, data);
// print("(");
Expand All @@ -194,123 +127,5 @@ void FunctionNameResolver::visitASTCallStatement(
return;
}

void FunctionNameResolver::visitASTDefineTableStatement(
const ASTDefineTableStatement* node, void* data) {
return;
}

void FunctionNameResolver::visitASTDescribeStatement(const ASTDescribeStatement* node,
void* data) {
return;
}

void FunctionNameResolver::visitASTDescriptorColumn(const ASTDescriptorColumn* node,
void* data) {
return;
}

void FunctionNameResolver::visitASTDescriptor(const ASTDescriptor* node, void* data) {
return;
}

void FunctionNameResolver::visitASTShowStatement(const ASTShowStatement* node, void* data) {
return;
}

void FunctionNameResolver::visitASTBeginStatement(
const ASTBeginStatement* node, void* data) {
return;
}

void FunctionNameResolver::visitASTTransactionIsolationLevel(
const ASTTransactionIsolationLevel* node, void* data) {
return;
}

void FunctionNameResolver::visitASTTransactionReadWriteMode(
const ASTTransactionReadWriteMode* node, void* data) {
return;
}

void FunctionNameResolver::visitASTTransactionModeList(const ASTTransactionModeList* node,
void* data) {
return;
}

void FunctionNameResolver::visitASTSetTransactionStatement(
const ASTSetTransactionStatement* node, void* data) {
return;
}

void FunctionNameResolver::visitASTCommitStatement(const ASTCommitStatement* node,
void* data) {
return;
}

void FunctionNameResolver::visitASTRollbackStatement(const ASTRollbackStatement* node,
void* data) {
return;
}

void FunctionNameResolver::visitASTStartBatchStatement(const ASTStartBatchStatement* node,
void* data) {
return;
}

void FunctionNameResolver::visitASTRunBatchStatement(const ASTRunBatchStatement* node,
void* data) {
return;
}

void FunctionNameResolver::visitASTAbortBatchStatement(const ASTAbortBatchStatement* node,
void* data) {
return;
}

void FunctionNameResolver::visitASTDropStatement(const ASTDropStatement* node, void* data) {
return;
}

void FunctionNameResolver::visitASTDropEntityStatement(const ASTDropEntityStatement* node,
void* data) {
return;
}

void FunctionNameResolver::visitASTDropFunctionStatement(
const ASTDropFunctionStatement* node, void* data) {
//TODO: prioritize reference?
return;
}

void FunctionNameResolver::visitASTDropRowAccessPolicyStatement(
const ASTDropRowAccessPolicyStatement* node, void* data) {
return;
}

void FunctionNameResolver::visitASTDropAllRowAccessPoliciesStatement(
const ASTDropAllRowAccessPoliciesStatement* node, void* data) {
return;
}

void FunctionNameResolver::visitASTDropMaterializedViewStatement(
const ASTDropMaterializedViewStatement* node, void* data) {
return;
}

void FunctionNameResolver::visitASTRenameStatement(const ASTRenameStatement* node,
void* data) {
return;
}

void FunctionNameResolver::visitASTImportStatement(const ASTImportStatement* node,
void* data) {
return;
}

void FunctionNameResolver::visitASTModuleStatement(const ASTModuleStatement* node,
void* data) {
return;
}

} // namespace function_name_resolver
} // namespace alphasql
78 changes: 1 addition & 77 deletions alphasql/function_name_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,91 +66,15 @@ class FunctionNameResolver : public DefaultParseTreeVisitor {
}

// Visitor implementation.
void visitASTModelClause(const ASTModelClause* node, void* data) override;
void visitASTTemplatedParameterType(
const ASTTemplatedParameterType* node, void* data) override;
void visitASTConnectionClause(const ASTConnectionClause* node,
void* data) override;
void visitASTCreateDatabaseStatement(const ASTCreateDatabaseStatement* node,
void* data) override;
void visitASTFunctionCall(const ASTFunctionCall* node, void* data);
void visitASTFunctionDeclaration(
const ASTFunctionDeclaration* node, void* data) override;
void visitASTTVF(
const ASTTVF* node, void* data) override;
void visitASTCreateFunctionStatement(const ASTCreateFunctionStatement* node,
void* data) override;
void visitASTCreateTableFunctionStatement(
const ASTCreateTableFunctionStatement* node, void* data) override;
void visitASTCreateEntityStatement(const ASTCreateEntityStatement* node,
void* data) override;
void visitASTNotNullColumnAttribute(
const ASTNotNullColumnAttribute* node, void* data) override;
void visitASTHiddenColumnAttribute(
const ASTHiddenColumnAttribute* node, void* data) override;
void visitASTPrimaryKeyColumnAttribute(
const ASTPrimaryKeyColumnAttribute* node, void* data) override;
void visitASTColumnDefinition(const ASTColumnDefinition* node,
void* data) override;
void visitASTWithPartitionColumnsClause(
const ASTWithPartitionColumnsClause* node, void* data) override;
void visitASTCreateExternalTableStatement(
const ASTCreateExternalTableStatement* node, void* data) override;
void visitASTGrantToClause(const ASTGrantToClause* node, void* data) override;
void visitASTFilterUsingClause(const ASTFilterUsingClause* node,
void* data) override;
void visitASTCreateRowAccessPolicyStatement(
const ASTCreateRowAccessPolicyStatement* node, void* data) override;
void visitASTExportModelStatement(const ASTExportModelStatement* node,
void* data) override;
void visitASTCallStatement(const ASTCallStatement* node,
void* data) override;
void visitASTDefineTableStatement(const ASTDefineTableStatement* node,
void* data) override;
void visitASTDescribeStatement(const ASTDescribeStatement* node,
void* data) override;
void visitASTDescriptorColumn(const ASTDescriptorColumn* node,
void* data) override;
void visitASTDescriptor(const ASTDescriptor* node, void* data) override;
void visitASTShowStatement(const ASTShowStatement* node,
void* data) override;
void visitASTBeginStatement(const ASTBeginStatement* node,
void* data) override;
void visitASTTransactionIsolationLevel(
const ASTTransactionIsolationLevel* node, void* data) override;
void visitASTTransactionReadWriteMode(const ASTTransactionReadWriteMode* node,
void* data) override;
void visitASTTransactionModeList(const ASTTransactionModeList* node,
void* data) override;
void visitASTSetTransactionStatement(const ASTSetTransactionStatement* node,
void* data) override;

void visitASTCommitStatement(const ASTCommitStatement* node,
void* data) override;
void visitASTRollbackStatement(const ASTRollbackStatement* node,
void* data) override;
void visitASTStartBatchStatement(const ASTStartBatchStatement* node,
void* data) override;
void visitASTRunBatchStatement(const ASTRunBatchStatement* node,
void* data) override;
void visitASTAbortBatchStatement(const ASTAbortBatchStatement* node,
void* data) override;
void visitASTDropStatement(const ASTDropStatement* node, void* data) override;
void visitASTDropEntityStatement(const ASTDropEntityStatement* node,
void* data) override;
void visitASTDropFunctionStatement(
const ASTDropFunctionStatement* node, void* data) override;
void visitASTDropRowAccessPolicyStatement(
const ASTDropRowAccessPolicyStatement* node, void* data) override;
void visitASTDropAllRowAccessPoliciesStatement(
const ASTDropAllRowAccessPoliciesStatement* node, void* data) override;
void visitASTDropMaterializedViewStatement(
const ASTDropMaterializedViewStatement* node, void* data) override;
void visitASTRenameStatement(const ASTRenameStatement* node,
void* data) override;
void visitASTImportStatement(const ASTImportStatement* node,
void* data) override;
void visitASTModuleStatement(const ASTModuleStatement* node,
void* data) override;
};

} // namespace alphasql
Expand Down
9 changes: 6 additions & 3 deletions samples/sample-function-dependency/dag.dot
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
digraph G {
0[label="./samples/sample2/udf1.sql"];
1[label="./samples/sample2/udf2.sql"];
2[label="./samples/sample2/with-udf.sql"];
0[label="samples/sample-function-dependency/udf1.sql"];
1[label="samples/sample-function-dependency/udf2.sql"];
2[label="samples/sample-function-dependency/with-udf.sql"];
0->2 ;
1->2 ;
1->0 ;
}
Binary file modified samples/sample-function-dependency/dag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d7ba360

Please sign in to comment.