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

Where function should support float64 comparisons #5466

Closed
pjdufour opened this issue Nov 24, 2018 · 4 comments · Fixed by #5473
Closed

Where function should support float64 comparisons #5466

pjdufour opened this issue Nov 24, 2018 · 4 comments · Fixed by #5473

Comments

@pjdufour
Copy link

pjdufour commented Nov 24, 2018

I'm trying to filter a JSON array of values returned from the GitHub API where "size" > 0; however, the where XYZ "gt" 0 function is not working and returns an empty array every time. Neither does where XYZ "ge" 1 work. (XYZ is a placeholder). Maybe there's a formatting issue I'm missing, but I've tried numerous different variations.

The full line is:

{{ $repos := getJSON "https://" (getenv "GITHUB_USER") ":" (getenv "GITHUB_TOKEN")  "@api.github.com/orgs/XYZ/repos?per_page=100" }}
{{ $sources := where (where (where $repos "size" "ge" 1) "fork" false) "archived" false }}

This works fine when I just filter boolean values.

{{ $repos := getJSON "https://" (getenv "GITHUB_USER") ":" (getenv "GITHUB_TOKEN")  "@api.github.com/orgs/XYZ/repos?per_page=100" }}
{{ $sources := where (where $repos "fork" false) "archived" false }}
@bep
Copy link
Member

bep commented Nov 24, 2018

The issue title is obviously not correct in general. I suspect this is because the JSON decoder treats all numbers as float64 -- a quick glance on the code (that I don't know in detail) shows that this type isn't handled in where.

@moorereason
Copy link
Contributor

Does where XYZ "gt" 0.0 work?

@pjdufour
Copy link
Author

pjdufour commented Nov 26, 2018

I just tried where xyz "gt" 0.0 and where xyz "ge" 1.0 and neither worked. What is weird is that having and if {{ if ge $repo.size 1 }} within a range works fine, but the where clause doesn't work. Is there any way to debug this to dump the types, without having to download all the source and go run ...? I wish I could provide more info.

@moorereason moorereason changed the title Where Function with Greater Than (or equal) Operator Not Working Where function should support float64 comparisons Nov 27, 2018
moorereason added a commit to moorereason/hugo that referenced this issue Nov 27, 2018
@bep bep closed this as completed in #5473 Nov 27, 2018
@bep bep added this to the v0.52 milestone Nov 27, 2018
bep pushed a commit that referenced this issue Nov 27, 2018
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants