parseSubquery parses a subquery by recursively evaluating it's condition(s). If the subquery contains references to aliases from the superquery, it's Subquery attribute is set. Otherwise, we evaluate it's Subquery and set it's Value to the result.
(condition *query.Condition)
| 178 | // Subquery attribute is set. Otherwise, we evaluate it's Subquery and set |
| 179 | // it's Value to the result. |
| 180 | func (p *parser) parseSubquery(condition *query.Condition) error { |
| 181 | q, err := Run(condition.Value.(string)) |
| 182 | if err != nil { |
| 183 | return err |
| 184 | } |
| 185 | |
| 186 | // If the subquery has aliases, we'll have to parse the subquery against |
| 187 | // each file, so we don't do anything here. |
| 188 | if len(q.SourceAliases) > 0 { |
| 189 | condition.Subquery = q |
| 190 | return nil |
| 191 | } |
| 192 | |
| 193 | value := make(map[interface{}]bool, 0) |
| 194 | workFunc := func(path string, info os.FileInfo, res map[string]interface{}) { |
| 195 | for _, attr := range [...]string{"name", "size", "time", "mode"} { |
| 196 | if q.HasAttribute(attr) { |
| 197 | value[res[attr]] = true |
| 198 | return |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | if err = q.Execute(workFunc); err != nil { |
| 204 | return err |
| 205 | } |
| 206 | |
| 207 | condition.Value = value |
| 208 | condition.IsSubquery = false |
| 209 | return nil |
| 210 | } |