# Operator syntax for Merge-like Query

Bug introduced in 10.0.0 and fixed in 10.0.2

Is it possible to take advantage of Dataset's Query operator syntax to Merge parallel queries thereby avoiding Function's that are otherwise required?

Using the planets data:

 planets = ExampleData[{"Dataset", "Planets"}];

{moonMasses, nMoons } = {planets[All, "Moons", Median, "Mass"],
planets[All, "Moons", Length, "Mass"]}


These queries are nearly equivalent merges:

(1) Merge[{moonMasses // Normal, nMoons // Normal}, List]

(2) planets[All, "Moons", {Median[#], Length[#]} &, "Mass"] // Normal

The values in (1) are unfortunately wrapped in an extra nested list (and further requres normalizing the data as Merge doesn't take Dataset arguments).

(2) is preferred (normalizing here only because 10.0.0 Dataset Format is not usable).

How to avoid using Function in (2), eg, to shorten the query to a syntax similar to:

planets[All, "Moons", {Median, Length}, "Mass"]

-
Am I wrong to understand from the documentation that your proposed short query syntax should work? –  Rojo Jul 31 '14 at 5:26
In the meantime, a subquery seems to work planets[All, "Moons", Query[{Median, Length}], "Mass"] –  Rojo Jul 31 '14 at 5:29
@Rojo, that works - I had tried {Query[Median],Query[Length]} but didn't think of this variation. Write it up as an answer, will accept. –  alancalvitti Jul 31 '14 at 5:46
This bug is not yet fixed in Mathematica 10.0.1 –  Mr.Wizard Sep 17 '14 at 13:53
@Mr.Wizard Seems to be fixed in 10.0.2 –  Gordon Coale Dec 18 '14 at 9:25

In the meantime, a subquery seems to work planets[All, "Moons", Query[{Median, Length}], "Mass"]
planets[All, "Moons", {Median, Length}, "Mass"] should work, because Median and Length on their own are ascending, so {Median, Length} should clearly also be considered to be ascending. Thanks for finding! –  Taliesin Beynon Jul 31 '14 at 17:37
@TaliesinBeynon are Apply, or MapIndexed given some special treatment (such as descending operators)? Because I usually find issues with them but they aren't descending –  Rojo Aug 9 '14 at 4:23
It doesn't really make sense for Map to be descending, because Map[f] is really All, f. Apply could be descending, but it's more useful for it be ascending, because it is a useful sugar on top of other ascending functions, e.g. Apply[#1 + #2&] <=> #[[1]] + #[[2]]&. Not sure about MapIndexed. –  Taliesin Beynon Aug 11 '14 at 21:41
@TaliesinBeynon, makes sense, thx. So for example the fact that this doesn't work Dataset[{1}][Apply[f]] but this does Dataset[{1}][Apply[f, #] &] is a simple bug –  Rojo Aug 11 '14 at 22:53