Skip to content

Commit aa1caa6

Browse files
committed
Use zero for undefined fields in where expressions
This commit fixes an issue where expressions were silently failing when encountering undefined fields. Instead they should be treating the undefined field like the number zero. This is required to stay compatible with how Tile38 handles zeros. https://tile38.com/commands/intersects/#fields Fixes #754
1 parent 1ef5394 commit aa1caa6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

internal/server/expr.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func newExprPool(s *Server) *exprPool {
9191
return resultToValue(r), nil
9292
}
9393
}
94+
return expr.Number(0), nil
9495
} else {
9596
switch v := info.Value.Value().(type) {
9697
case gjson.Result:
@@ -102,8 +103,8 @@ func newExprPool(s *Server) *exprPool {
102103
return expr.Function("match"), nil
103104
}
104105
}
106+
return expr.Undefined, nil
105107
}
106-
return expr.Undefined, nil
107108
},
108109
// call
109110
func(info expr.CallInfo, ctx *expr.Context) (expr.Value, error) {

tests/keys_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,17 @@ func keys_FIELDS_test(mc *mockServer) error {
600600
Do("SCAN", "fleet", "WHERE", "props.speed > 53", "IDS").JSON().Str(`{"ok":true,"ids":[],"count":0,"cursor":0}`),
601601
Do("SCAN", "fleet", "WHERE", "Props.speed > 53", "IDS").JSON().Str(`{"ok":true,"ids":[],"count":0,"cursor":0}`),
602602
Do("SCAN", "fleet", "WHERE", "Props.Speed > 53", "IDS").JSON().Str(`{"ok":true,"ids":[],"count":0,"cursor":0}`),
603+
604+
Do("DROP", "fleet").JSON().OK(),
605+
Do("SET", "fleet", "1", "field", "teamId", "1", "field", "optionalId", "999", "point", "0", "0").JSON().OK(),
606+
Do("SET", "fleet", "2", "field", "teamId", "1", "point", "0", "0").JSON().OK(),
607+
Do("SCAN", "fleet", "COUNT").JSON().Str(`{"ok":true,"count":2,"cursor":0}`),
608+
Do("SCAN", "fleet", "WHEREIN", "teamId", "1", "1", "COUNT").JSON().Str(`{"ok":true,"count":2,"cursor":0}`),
609+
610+
Do("SCAN", "fleet", "WHEREIN", "teamId", "1", "1", "WHERE", "!optionalId || optionalId == 999", "count").JSON().Str(`{"ok":true,"count":2,"cursor":0}`),
611+
Do("SCAN", "fleet", "WHEREIN", "teamId", "1", "1", "WHERE", "!!!optionalId || optionalId == 999", "count").JSON().Str(`{"ok":true,"count":2,"cursor":0}`),
612+
Do("SCAN", "fleet", "WHEREIN", "teamId", "1", "1", "WHERE", "optionalId == 0 || optionalId == 999", "count").JSON().Str(`{"ok":true,"count":2,"cursor":0}`),
613+
Do("SCAN", "fleet", "WHEREIN", "teamId", "1", "1", "WHERE", "1 == 1 || optionalId == 999", "count").JSON().Str(`{"ok":true,"count":2,"cursor":0}`),
603614
)
604615
}
605616

0 commit comments

Comments
 (0)