johnkerl / miller

Miller is like awk, sed, cut, join, and sort for name-indexed data such as CSV, TSV, and tabular JSON
https://miller.readthedocs.io
Other
9.02k stars 217 forks source link

filter acts as put #1696

Open aborruso opened 1 month ago

aborruso commented 1 month ago

Hi @johnkerl, if write this wrong filter command

echo "a=0" | mlr filter '$a=10'

I get a=10.

I know the filter is wrong, I must use == and not =, however, I think that filter verb should never change the contents of cells. Am I wrong?

Thank you

johnkerl commented 1 month ago

Correct, filter acts as put and the difference is just whether the final statement is used as a boolean to decide whether or not to forward the curent record

https://miller.readthedocs.io/en/6.13.0/reference-dsl/#differences-between-put-and-filter

aborruso commented 1 month ago

Correct, filter acts as put and the difference is just whether the final statement is used as a boolean to decide whether or not to forward the curent record

Okay, so if I understand you, this should not happen and this is a bug. Am I wrong?

johnkerl commented 1 month ago

I guess I can assert that the final filter expression does evaluate to bool and abort the program if it doesn't -- ?

aborruso commented 1 month ago

I guess I can assert that the final filter expression does evaluate to bool and abort the program if it doesn't -- ?

John, I am too basic a user and don't understand you all the time 😢

What I expected in a case like this was to have the same input content in the output, because the filter cannot filter anything out. Or for mlr to fail and exit, because the syntax is wrong.

Thank you

johnkerl commented 1 month ago

What I expected in a case like this was to have the same input content in the output, because the filter cannot filter anything out. Or for mlr to fail and exit, because the syntax is wrong.

I guess my question is, which of those two would you prefer? (My "I guess I can assert that the final filter expression does evaluate to bool and abort the program if it doesn't -- ?" is the same as your "Or for mlr to fail and exit, because the syntax is wrong".)

aborruso commented 1 month ago

Ok, sorry @johnkerl , I understood you, thank you.

I would rather mlr come out and warn me that the syntax is wrong.