mirror of https://github.com/tidwall/tile38.git
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
This commit is contained in:
parent
1ef53941b2
commit
aa1caa6131
|
@ -91,6 +91,7 @@ func newExprPool(s *Server) *exprPool {
|
|||
return resultToValue(r), nil
|
||||
}
|
||||
}
|
||||
return expr.Number(0), nil
|
||||
} else {
|
||||
switch v := info.Value.Value().(type) {
|
||||
case gjson.Result:
|
||||
|
@ -102,8 +103,8 @@ func newExprPool(s *Server) *exprPool {
|
|||
return expr.Function("match"), nil
|
||||
}
|
||||
}
|
||||
return expr.Undefined, nil
|
||||
}
|
||||
return expr.Undefined, nil
|
||||
},
|
||||
// call
|
||||
func(info expr.CallInfo, ctx *expr.Context) (expr.Value, error) {
|
||||
|
|
|
@ -600,6 +600,17 @@ func keys_FIELDS_test(mc *mockServer) error {
|
|||
Do("SCAN", "fleet", "WHERE", "props.speed > 53", "IDS").JSON().Str(`{"ok":true,"ids":[],"count":0,"cursor":0}`),
|
||||
Do("SCAN", "fleet", "WHERE", "Props.speed > 53", "IDS").JSON().Str(`{"ok":true,"ids":[],"count":0,"cursor":0}`),
|
||||
Do("SCAN", "fleet", "WHERE", "Props.Speed > 53", "IDS").JSON().Str(`{"ok":true,"ids":[],"count":0,"cursor":0}`),
|
||||
|
||||
Do("DROP", "fleet").JSON().OK(),
|
||||
Do("SET", "fleet", "1", "field", "teamId", "1", "field", "optionalId", "999", "point", "0", "0").JSON().OK(),
|
||||
Do("SET", "fleet", "2", "field", "teamId", "1", "point", "0", "0").JSON().OK(),
|
||||
Do("SCAN", "fleet", "COUNT").JSON().Str(`{"ok":true,"count":2,"cursor":0}`),
|
||||
Do("SCAN", "fleet", "WHEREIN", "teamId", "1", "1", "COUNT").JSON().Str(`{"ok":true,"count":2,"cursor":0}`),
|
||||
|
||||
Do("SCAN", "fleet", "WHEREIN", "teamId", "1", "1", "WHERE", "!optionalId || optionalId == 999", "count").JSON().Str(`{"ok":true,"count":2,"cursor":0}`),
|
||||
Do("SCAN", "fleet", "WHEREIN", "teamId", "1", "1", "WHERE", "!!!optionalId || optionalId == 999", "count").JSON().Str(`{"ok":true,"count":2,"cursor":0}`),
|
||||
Do("SCAN", "fleet", "WHEREIN", "teamId", "1", "1", "WHERE", "optionalId == 0 || optionalId == 999", "count").JSON().Str(`{"ok":true,"count":2,"cursor":0}`),
|
||||
Do("SCAN", "fleet", "WHEREIN", "teamId", "1", "1", "WHERE", "1 == 1 || optionalId == 999", "count").JSON().Str(`{"ok":true,"count":2,"cursor":0}`),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue