Skip to content

v0.37 pubsub/kvindexer: Handle big ints#771

Merged
jmalicevic merged 28 commits intov0.37.xfrom
jasmina/726-pubsub-int-overflow
May 3, 2023
Merged

v0.37 pubsub/kvindexer: Handle big ints#771
jmalicevic merged 28 commits intov0.37.xfrom
jasmina/726-pubsub-int-overflow

Conversation

@jmalicevic
Copy link
Collaborator

@jmalicevic jmalicevic commented Apr 27, 2023

Closes #726 for 0.37.x.

This is a draft PR. The main goal is to make sure that big integers are parsed properly without a loss of precision. Int64 values will be processed as before.
It also fixes the old logic where ints and floats were treated the same if a float had a fraction due to the fact that the float was converted to an int before comparison.


PR checklist

  • Tests written/updated
  • Changelog entry added in .changelog (we use unclog to manage our changelog)
  • Updated relevant documentation (docs/ or spec/) and code comments

@jmalicevic jmalicevic added this to the 2023-Q2 milestone Apr 27, 2023
@jmalicevic jmalicevic self-assigned this Apr 27, 2023
@jmalicevic jmalicevic linked an issue Apr 27, 2023 that may be closed by this pull request
@jmalicevic jmalicevic changed the base branch from main to v0.37.x April 27, 2023 10:11
@jmalicevic jmalicevic changed the title pubsub: Handle big ints (WIP) pubsub: Handle big ints Apr 27, 2023
@jmalicevic jmalicevic marked this pull request as ready for review April 28, 2023 10:30
@jmalicevic jmalicevic requested a review from a team as a code owner April 28, 2023 10:30
@jmalicevic jmalicevic changed the title (WIP) pubsub: Handle big ints v0.37 pubsub: Handle big ints Apr 28, 2023
valueBig, ok := valueBig.SetString(number, 10)
if !ok {
err := fmt.Errorf(
"problem parsing %s as bigint (should never happen if the grammar is correct)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"if the grammar is correct" is not very helpful to the user.
Could we replace it for something like "please report the error to the development team"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is the default message in a bunch of other places and it actually makes sense - comparing the query to the query grammar, I would leave this?

Copy link
Collaborator

@sergio-mena sergio-mena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I payed a lot of attention, but added some questions on parts I didn't fully understand.

q: query.MustParse("block.height < 2 AND block.height > 0 AND block.height > 0"),
results: []int64{1},
},
"query matches fields with big int and height - no match": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a similar test case that is testing an off-by-1 bigint value? (testing precision not lost, as done further up in another file)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a use case, let me know if it covers what oyu had in mind.

@jmalicevic jmalicevic marked this pull request as draft May 1, 2023 21:42
@jmalicevic jmalicevic marked this pull request as ready for review May 2, 2023 13:19
jmalicevic and others added 3 commits May 2, 2023 16:43
Co-authored-by: Lasaro <lasaro@informal.systems>
Co-authored-by: Sergio Mena <sergio@informal.systems>
Copy link
Collaborator

@sergio-mena sergio-mena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

@jmalicevic jmalicevic merged commit 9267594 into v0.37.x May 3, 2023
@jmalicevic jmalicevic deleted the jasmina/726-pubsub-int-overflow branch May 3, 2023 08:38
@jmalicevic jmalicevic changed the title v0.37 pubsub: Handle big ints v0.37 pubsub/kvindexer: Handle big ints May 5, 2023
jmalicevic added a commit that referenced this pull request May 5, 2023
Replaced int64 with big.int

Co-authored-by: Lasaro <lasaro@informal.systems>
Co-authored-by: Sergio Mena <sergio@informal.systems>
jmalicevic added a commit that referenced this pull request May 11, 2023
Replaced int64 with big.int

Co-authored-by: Lasaro <lasaro@informal.systems>
Co-authored-by: Sergio Mena <sergio@informal.systems>
Co-authored-by: Thane Thomson <connect@thanethomson.com>
occurred within the same event.

# Event attribute value types
Users can use anything as an event value. However, if the even attrbute value is a number, the following restrictions apply:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: even => event

DongLieu pushed a commit to DongCoNY/cometbft that referenced this pull request May 13, 2024
Replaced int64 with big.int

Co-authored-by: Lasaro <lasaro@informal.systems>
Co-authored-by: Sergio Mena <sergio@informal.systems>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

Using pubsub query with big values results in an int64 overflow

4 participants