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

Added support for JSON.DEBUG #579

Merged
merged 6 commits into from
Sep 16, 2024
Merged

Conversation

psrvere
Copy link
Contributor

@psrvere psrvere commented Sep 14, 2024

Fixes #491 #492 #493

@lucifercr07 @JyotinderSingh - please review.

@psrvere psrvere changed the title JSON.debug command implementation Added support for JSON.DEBUG Sep 14, 2024
Copy link
Collaborator

@JyotinderSingh JyotinderSingh left a comment

Choose a reason for hiding this comment

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

Thanks for adding support for JSON.DEBUG command, @psrvere! The changes look good overall.
I've left a few comments.

internal/eval/eval.go Outdated Show resolved Hide resolved
internal/eval/eval.go Show resolved Hide resolved
internal/server/utils/array.go Outdated Show resolved Hide resolved
internal/eval/eval.go Outdated Show resolved Hide resolved
Comment on lines 420 to 432
reg := regexp.MustCompile(`^\$(\.|)\[(\d+|\*)\]`)
matches := reg.FindStringSubmatch(path)

if len(matches) == 3 {
index, err := strconv.Atoi(matches[2])
if err != nil {
return diceerrors.NewErrWithMessage("unable to extract index")
}
if index >= len(arr) {
return clientio.RespEmptyArray
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you help me understand what's happening here? Maybe add a few comments here too.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, we should avoid using regex in general since it is slow to compile and evaluate. However, if there is no better way, we can live with it.

Copy link
Contributor Author

@psrvere psrvere Sep 15, 2024

Choose a reason for hiding this comment

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

@JyotinderSingh - this handles an edge case where memory is requested for out of bound index in an array json. Without this bit of code, program would return an error Err Path '$.[4]' does not exist for an array of length 3. Redis returns an empty array.

So this bit of code matches if arg is $[4] type, extracts the value 4 and compares it with array length to handle this case.

I will add comments here.

internal/eval/eval.go Outdated Show resolved Hide resolved
@JyotinderSingh
Copy link
Collaborator

Please fix the linter warnings too.

Copy link
Collaborator

@JyotinderSingh JyotinderSingh left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the reviews. LGTM.

@JyotinderSingh JyotinderSingh merged commit cea0ff8 into DiceDB:master Sep 16, 2024
2 checks passed
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.

Add support for command JSON.DEBUG
2 participants