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

MAX() function always returns 0 #148

Closed
Matthieu-LAURENT39 opened this issue May 10, 2024 · 4 comments
Closed

MAX() function always returns 0 #148

Matthieu-LAURENT39 opened this issue May 10, 2024 · 4 comments

Comments

@Matthieu-LAURENT39
Copy link
Contributor

Matthieu-LAURENT39 commented May 10, 2024

On 0.8.5, as well as on master (9d165b2), the MAX() function seems to always return 0 for anything related to dates.
Here are some queries i tried that have this issue:

  • fselect "MAX(modified) from /tmp/test"
  • fselect "MAX(YEAR(modified)) from /tmp/test"

However, this works:

  • fselect "MAX(size) from /tmp/test"

Also note that

  • fselect "YEAR(modified) from /tmp/test"
  • fselect "modified from /tmp/test"
    work just fine

i'm currently trying to find the issue, i'll open a PR if i do find it

@Matthieu-LAURENT39
Copy link
Contributor Author

Well, i found the issues.

The MAX function only works if it can cast the value to usize, otherwise it ignores the value, so that explains why fselect "MAX(modified) from /tmp/test" didn't work. I assume that's intended behavior.

The issue with fselect "MAX(YEAR(modified)) from /tmp/test" (as well as fselect "MIN(YEAR(modified)) from /home/user", which is an example from the docs) is that it will look for Year(Modified) in the hasmap from the raw_output_buffer, but that hasmap only contains the raw Modified and an empty Min(Year(Modified)).
That means a really simple workaround is to use this query: MIN(YEAR(modified)), YEAR(modified) from /tmp/test., which will make fselect compute the needed Year(Modified).

I tried fixing it myself, but i can't really understand the structure of the code, especially since it doesn't have many comments.

@jhspetersson
Copy link
Owner

Thank you very much for this issue!

Indeed, the code is an undocumented mess... It appears, a deliberate "shortcut" has been made at some point, so the aggregates didn't work with the enclosed functions.

I added a small fix to the master branch. It would be great to check if it works for you now.

MIN and MAX for datetime fields is actually an another problem. Will add it soon, I guess :)

@Matthieu-LAURENT39
Copy link
Contributor Author

Works fine now!
About the lack of code comments, would you accept a PR that reformats / documents some of the code?

@jhspetersson
Copy link
Owner

jhspetersson commented May 11, 2024 via email

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

No branches or pull requests

2 participants