@@ -15,9 +15,17 @@ type Filter struct {
15
15
RawMinZoom interface {} `yaml:"min_zoom"`
16
16
Table string `yaml:"table"`
17
17
18
- MinZoom NumExpression `yaml:"-"`
19
- Filter Condition `yaml:"-"`
20
- Output map [string ]Expression `yaml:"-"`
18
+ MinZoom NumExpression `yaml:"-"`
19
+ Filter Condition `yaml:"-"`
20
+ // Output map[string]Expression `yaml:"-"`
21
+ Output []OutputExpression `yaml:"-"`
22
+ }
23
+
24
+ // OutputExpression has the key and expression value for the outputs.
25
+ // Using a slice vs a key value map was much cleaner.
26
+ type OutputExpression struct {
27
+ Key string
28
+ Expr Expression
21
29
}
22
30
23
31
// Compile will compile the parsed yaml into the expressions
@@ -52,16 +60,22 @@ func (f *Filter) Compile() error {
52
60
}
53
61
54
62
if f .RawOutput != nil {
55
- f .Output = make (map [ string ] Expression , len (f .RawOutput ))
63
+ f .Output = make ([] OutputExpression , 0 , len (f .RawOutput ))
56
64
for k , v := range f .RawOutput {
57
- var err error
58
- f .Output [k ], err = CompileExpression (v )
65
+ expr , err := CompileExpression (v )
59
66
if err != nil {
60
67
return & CompileError {
61
68
Cause : errors .WithMessage (err , fmt .Sprintf ("output %s" , k )),
62
69
Input : v ,
63
70
}
64
71
}
72
+
73
+ if _ , ok := expr .(* nilExpr ); expr != nil && ! ok {
74
+ f .Output = append (f .Output , OutputExpression {
75
+ Key : k ,
76
+ Expr : expr ,
77
+ })
78
+ }
65
79
}
66
80
}
67
81
@@ -82,10 +96,10 @@ func (f *Filter) Match(ctx *Context) bool {
82
96
// Must call Compile() first to initialize the output expressions.
83
97
func (f * Filter ) Properties (ctx * Context ) map [string ]interface {} {
84
98
result := make (map [string ]interface {}, len (f .Output ))
85
- for k , expr := range f .Output {
86
- o := expr .Eval (ctx )
99
+ for i := range f .Output {
100
+ o := f . Output [ i ]. Expr .Eval (ctx )
87
101
if o != nil {
88
- result [k ] = o
102
+ result [f . Output [ i ]. Key ] = o
89
103
}
90
104
}
91
105
0 commit comments