Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@
"{ \"tableRegex\": \"(?i)^(?:public\\\\.)?(?:pg_.*|current_schema|information_schema)\" }"
]
}
// dbInternalString
//
],
"configurations": [
// ATTACH
Expand Down
52 changes: 52 additions & 0 deletions internal/stackql/astanalysis/annotatedast/annotated_ast.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package annotatedast

import (
"github.com/stackql/stackql/internal/stackql/astindirect"
"vitess.io/vitess/go/vt/sqlparser"
)

type AnnotatedAst interface {
GetAST() sqlparser.Statement
GetIndirect(sqlparser.SQLNode) (astindirect.Indirect, bool)
GetIndirects() map[string]astindirect.Indirect
SetIndirect(node sqlparser.SQLNode, indirect astindirect.Indirect)
}

type standardAnnotatedAst struct {
ast sqlparser.Statement
tableIndirects map[string]astindirect.Indirect
}

func (aa *standardAnnotatedAst) GetAST() sqlparser.Statement {
return aa.ast
}

func (aa *standardAnnotatedAst) GetIndirect(node sqlparser.SQLNode) (astindirect.Indirect, bool) {
switch n := node.(type) {
case sqlparser.TableName:
rv, ok := aa.tableIndirects[n.GetRawVal()]
return rv, ok
default:
return nil, false
}
}

func (aa *standardAnnotatedAst) GetIndirects() map[string]astindirect.Indirect {
return aa.tableIndirects
}

func (aa *standardAnnotatedAst) SetIndirect(node sqlparser.SQLNode, indirect astindirect.Indirect) {
switch n := node.(type) {
case sqlparser.TableName:
aa.tableIndirects[n.GetRawVal()] = indirect
default:
}
}

func NewAnnotatedAst(ast sqlparser.Statement) (AnnotatedAst, error) {
rv := &standardAnnotatedAst{
ast: ast,
tableIndirects: make(map[string]astindirect.Indirect),
}
return rv, nil
}
Loading