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

fix(core): Auto cast doubles to ints in lua scripts #922

Merged
merged 1 commit into from
Mar 8, 2023

Conversation

dranikpg
Copy link
Contributor

@dranikpg dranikpg commented Mar 8, 2023

No description provided.

@dranikpg dranikpg requested review from romange and removed request for romange March 8, 2023 14:37
@dranikpg dranikpg force-pushed the fix-interpreter-double branch from 24e0f84 to 725c9ba Compare March 8, 2023 14:47
@dranikpg dranikpg requested a review from romange March 8, 2023 14:47
// Here is the use-case:
// local foo = redis.call('zscore', 'myzset', 'one')
// assert(type(foo) == "number")
// We return doubles as strings likewise to Redis to maintain compatibility.
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 at least use a run-time flag for this?

@@ -381,6 +381,10 @@ TEST_F(MultiTest, Eval) {
ASSERT_THAT(resp, ArrLen(3));
const auto& arr = resp.GetVec();
EXPECT_THAT(arr, ElementsAre("a", "b", "c"));

Run({"zadd", "z1", "123", "a"});
resp = Run({"eval", "return redis.call('ZSCORE', KEYS[1], 'a') .. '-is-int'", "1", "z1"});
Copy link
Collaborator

Choose a reason for hiding this comment

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

I still need to understand. What did it return before?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Specifically, maybe you can show the difference with tonumber command? I did not understand from your comment above where DF fails

Copy link
Contributor Author

Choose a reason for hiding this comment

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

123.0-is-int

@dranikpg dranikpg force-pushed the fix-interpreter-double branch from 725c9ba to 25eb5aa Compare March 8, 2023 15:38
@dranikpg dranikpg changed the title fix(core): Return doubles as strings in lua scripts fix(core): Auto cast doubles to ints in lua scripts Mar 8, 2023
@dranikpg dranikpg force-pushed the fix-interpreter-double branch from 25eb5aa to 7359de0 Compare March 8, 2023 15:49
@dranikpg dranikpg requested a review from romange March 8, 2023 15:52
@dranikpg dranikpg force-pushed the fix-interpreter-double branch from 7359de0 to 7601c43 Compare March 8, 2023 15:52
Comment on lines +88 to +91
static constexpr double kConvertEps = std::numeric_limits<double>::epsilon();

double fractpart, intpart;
fractpart = modf(d, &intpart);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure epsilon is correct if the fractional part is taken from a large number. Does it hold up to max long?

Copy link
Contributor Author

@dranikpg dranikpg Mar 8, 2023

Choose a reason for hiding this comment

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

They scale in the example for comparing the difference, https://en.cppreference.com/w/cpp/types/numeric_limits/epsilon and in my mind modf cant improve on accuracy if a large number is already stored skewed

But I checked in the range of int64-max and values far from power of twos and it seems that modf(d) < double_eps is always the case 🔦

Copy link
Collaborator

Choose a reason for hiding this comment

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

lgtm

@dranikpg dranikpg merged commit a37ccbf into dragonflydb:main Mar 8, 2023
@dranikpg dranikpg deleted the fix-interpreter-double branch March 14, 2023 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants