@@ -44,49 +44,39 @@ import (
4444// }
4545//
4646// // If not found return string as is, and an error.
47- // return s , fmt.Errorf("column not found")
47+ // return nil , fmt.Errorf("column not found")
4848// }
4949//
5050// // Check and replace user identifiers with the SQL table column names,
51- // // and get a list of all identifiers used in the tree.
51+ // // and return the new tree.
5252// //
5353// // If the input tree contains: `spec.pages > 100 AND author = "Joe"`,
54- // // the identifiers list will contain: ["spec.pages", "author"]
55- // //
5654// // the new tree will contain: `pages > 100 AND author = "Joe"`
57- // newTree, identifiers, err = ident.Walk(tree, check)
55+ // newTree, err = ident.Walk(tree, check)
5856// defer newTree.Free()
59- func Walk (n * tsl.TSLNode , check func (s string ) (string , error )) (* tsl.TSLNode , [] string , error ) {
57+ func Walk (n * tsl.TSLNode , check func (s string ) (string , error )) (* tsl.TSLNode , error ) {
6058 if n == nil {
61- return nil , nil , nil
59+ return nil , nil
6260 }
6361
6462 // Create a deep copy of the input tree to avoid mutations
6563 treeCopy := n .Clone ()
6664 if treeCopy == nil {
67- return nil , nil , fmt .Errorf ("failed to clone input tree" )
65+ return nil , fmt .Errorf ("failed to clone input tree" )
6866 }
6967
70- identifiers := make (map [string ]bool )
71- newTree , err := walkAndReplace (treeCopy , check , identifiers )
68+ newTree , err := walkAndReplace (treeCopy , check )
7269 if err != nil {
7370 treeCopy .Free () // Clean up the copy if there's an error
74- return nil , nil , err
75- }
76-
77- // Convert map to slice
78- identList := make ([]string , 0 , len (identifiers ))
79- for ident := range identifiers {
80- identList = append (identList , ident )
71+ return nil , err
8172 }
8273
83- return newTree , identList , nil
74+ return newTree , nil
8475}
8576
8677// processIdentifier handles the common logic for processing identifier nodes
87- func processIdentifier (n * tsl.TSLNode , identifiers map [ string ] bool , check func (s string ) (string , error )) (* tsl.TSLNode , error ) {
78+ func processIdentifier (n * tsl.TSLNode , check func (s string ) (string , error )) (* tsl.TSLNode , error ) {
8879 ident := n .Value ().(string )
89- identifiers [ident ] = true
9080
9181 newIdent , err := check (ident )
9282 if err != nil {
@@ -96,7 +86,7 @@ func processIdentifier(n *tsl.TSLNode, identifiers map[string]bool, check func(s
9686 return tsl .ParseTSL (newIdent )
9787}
9888
99- func walkAndReplace (n * tsl.TSLNode , check func (s string ) (string , error ), identifiers map [ string ] bool ) (* tsl.TSLNode , error ) {
89+ func walkAndReplace (n * tsl.TSLNode , check func (s string ) (string , error )) (* tsl.TSLNode , error ) {
10090 if n == nil {
10191 return nil , nil
10292 }
@@ -108,27 +98,27 @@ func walkAndReplace(n *tsl.TSLNode, check func(s string) (string, error), identi
10898 // Process both sides of the binary expression
10999 left := op .Left
110100 if left .Type () == tsl .KindIdentifier {
111- newNode , err := processIdentifier (left , identifiers , check )
101+ newNode , err := processIdentifier (left , check )
112102 if err != nil {
113103 return nil , err
114104 }
115105 n .AttachLeft (newNode )
116106 } else {
117- _ , err := walkAndReplace (left , check , identifiers )
107+ _ , err := walkAndReplace (left , check )
118108 if err != nil {
119109 return nil , err
120110 }
121111 }
122112
123113 right := op .Right
124114 if right .Type () == tsl .KindIdentifier {
125- newNode , err := processIdentifier (right , identifiers , check )
115+ newNode , err := processIdentifier (right , check )
126116 if err != nil {
127117 return nil , err
128118 }
129119 n .AttachRight (newNode )
130120 } else {
131- _ , err := walkAndReplace (right , check , identifiers )
121+ _ , err := walkAndReplace (right , check )
132122 if err != nil {
133123 return nil , err
134124 }
@@ -142,13 +132,13 @@ func walkAndReplace(n *tsl.TSLNode, check func(s string) (string, error), identi
142132 // Process the operand
143133 right := op .Right
144134 if right .Type () == tsl .KindIdentifier {
145- newNode , err := processIdentifier (right , identifiers , check )
135+ newNode , err := processIdentifier (right , check )
146136 if err != nil {
147137 return nil , err
148138 }
149139 n .AttachChild (newNode )
150140 } else {
151- _ , err := walkAndReplace (right , check , identifiers )
141+ _ , err := walkAndReplace (right , check )
152142 if err != nil {
153143 return nil , err
154144 }
@@ -157,7 +147,7 @@ func walkAndReplace(n *tsl.TSLNode, check func(s string) (string, error), identi
157147 return n , nil
158148
159149 case tsl .KindIdentifier :
160- return processIdentifier (n , identifiers , check )
150+ return processIdentifier (n , check )
161151
162152 default :
163153 return n , nil
0 commit comments