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 · 3 comments

Comments

Projects
None yet
3 participants
@pjdufour

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

This comment has been minimized.

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

This comment has been minimized.

Contributor

moorereason commented Nov 24, 2018

Does where XYZ "gt" 0.0 work?

@pjdufour

This comment has been minimized.

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 from Where Function with Greater Than (or equal) Operator Not Working to 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 in #5473 Nov 27, 2018

@bep bep added this to the v0.52 milestone Nov 27, 2018

bep added a commit that referenced this issue Nov 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment