jq icon indicating copy to clipboard operation
jq copied to clipboard

Add `filter` command as an alias for map(select())

Open bseidenberg opened this issue 1 year ago • 4 comments

I (and I've heard others) use this often enough that it makes sense to have more user-friendly syntax.

bseidenberg avatar Sep 21 '24 00:09 bseidenberg

Not sure what is needed to get this PR reviewed - please let me know.

bseidenberg avatar Sep 27 '24 23:09 bseidenberg

Hi, the code itself looks ok but don't think i've heard anyone ask for such addition before. Maybe other maintainers have? we're usually quite conservative with adding new functions.

wader avatar Sep 29 '24 16:09 wader

@wader wrote:

we're usually quite conservative with adding new functions.

Not so long ago, there was a major performance issue that justified such conservatism. It's my understanding that the performance overhead problem has been largely resolved. Does anyone know what the performance overhead these days is?

Even setting aside general considerations concerning bloat, the argument against adding filter is quite strong, so let me articulate two points that may not be obvious. One is that 'select' is a filter that actually filters in a way that is already quite confusing to anyone steeped in SQL's SELECT, so adding 'filter' to jq can be seen as making a potentially confusing situation even more complex.

Another, though admittedly lesser, point concerns the wisdom of having two ways to say (in words) the same thing. ("In words" because I do not mean to include symbolic expressions like [.[]] as a word or phrase.) The cadence of maps and selects in a program has a certain appeal that would be interrupted by an interloper such as filter.

pkoppstein avatar Sep 29 '24 18:09 pkoppstein

Not so long ago, there was a major performance issue that justified such conservatism. It's my understanding that the performance overhead problem has been largely resolved. Does anyone know what the performance overhead these days is?

Don't know but it's my understand also that performance of builtins.jq is not a big issue now. I was mostly thinking about the same issues you also pointed out, adding on to already confusing names and partially overlapping functionality.

wader avatar Sep 29 '24 18:09 wader