Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis State Store: numeric operators do not work correctly on large numbers due to formatting logic in Go #3332

Closed
gspadotto opened this issue Feb 5, 2024 · 0 comments · Fixed by #3334
Labels
kind/bug Something isn't working

Comments

@gspadotto
Copy link
Contributor

Expected Behavior

Define a numeric index on a Redis State Store (i.e. an index with a Timestamp attribute), then search with criteria that involve it.

The criteria should be correctly evaluated and applied.

Actual Behavior

When the numeric is larger than https://pkg.go.dev/fmt configured threshold, scientific notation is used to represent the number and comparisons do not work anymore in the generated Redis Query.

Steps to Reproduce the Problem

Create a Redis State Store with an index on a numeric attribute, as described here.

Then invoke the Query API on it with this template curl command:

curl -v --location 'http://localhost:3500/v1.0-alpha1/state/redis-state-store/query?metadata.contentType=application/json&metadata.queryIndexName=myRedisIndexName' \ --header 'Content-Type: application/json' \ --data '{ "filter": { "GT": { "header.timestamp": NUMBER_HERE } }, "page":{ "limit": 2 }, "sort":[ { "key":"header.timestamp", "order":"DESC" } ] }'
Connect to Redis with RedisCLI and launch the "MONITOR" command.

When NUMBER_HERE is 1.2 or 100000 you'll see the following outputs:

"FT.SEARCH" "rawEventsIndx" "@var1:[(1.2 +inf]" "SORTBY" "var1" "DESC" "LIMIT" "0" "2" "RETURN" "2" "$.data" "$.version"

"FT.SEARCH" "rawEventsIndx" "@var1:[(100000 +inf]" "SORTBY" "var1" "DESC" "LIMIT" "0" "2" "RETURN" "2" "$.data" "$.version"

and you get the correct results, but when NUMBER_HERE is 1000000, you get

"FT.SEARCH" "rawEventsIndx" "@var1:[(1e+06 +inf]" "SORTBY" "var1" "DESC" "LIMIT" "0" "2" "RETURN" "2" "$.data" "$.version"

and no result.

The solution might be (I do not know GoLang at all) in all occurrences of these lines:
https://github.com/dapr/components-contrib/blob/main/state/redis/redis_query.go#L107-L112

use "%d" as format specifier in the default branch and add a branch for float64, float32 types
that uses "%f" as format specifier.

Release Note

RELEASE NOTE: FIX Numeric operators on Redis State Store query API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
1 participant