# Dataset Query using Composition fails but RightComposition works - why?

V10.1 on Win764 Enterprise.

In this (CORRECTED) example the two Queries may be compounded into one using RightComposition sucessfully...

Dataset[{<|"A" -> 1|>, <|"A" -> 2|>}][Query[Select[#["A"] == 1 &]] /* Query[Select[IntegerQ[#["A"]] &]]]


However using Composition (@*) instead fails. Why?

In this case f[g[x]] === g[f[x]] no?

• Your code has a syntax error - I think there shouldn't be a ] after Select[#"A". Apr 17 '15 at 16:05
• Your code seems weird... Why would you do Dataset[...][Query[Select[#"A"]==1&]]? That doesn't seem right. Did you mean Dataset[...][Select[#A == 1 &]]? Apr 17 '15 at 16:13
• @StefanR - yes - apologies, there were some errors in the question I have now corrected. Apr 17 '15 at 16:33
• Reported "officially" to Wolfram. Apr 20 '15 at 8:30
• Note that this issue is fixed in Mathematica 10.2.0. Jul 16 '15 at 20:24

Strictly speaking, the documentation only mentions query operator composition using /*. It may be that @* is not supported or has unrevealed semantics.

However, it seems reasonable to assume that @* would work similarly to /*. If so, then this looks like a query compilation bug in both versions 10.0.2 and 10.1.0.

Analysis

As noted in the question, the query using /* compiles successfully:

Normal@Query[Query[Select[#["A"] == 1 &]] /* Query[Select[IntegerQ[#["A"]] &]]]
(* Select[#1["A"] == 1 &] /* Select[IntegerQ[#1["A"]] &] *)


... but the same query expressed by swapping the operators and using Composition fails to compile:

Normal@Query[Query[Select[IntegerQ[#["A"]] &]] @* Query[Select[#["A"] == 1 &]]
(* Failure[] *)


An error occurs in this simpler query as well:

Normal@Query[Query["a"] /* Query["b"]]
(* GeneralUtilitiesSlice["a", "b"] *)

Normal@Query[Query["b"] @* Query["a"]]
(* Missing[PartInvalid, "a"] *)


And this even simpler query yields a baffling result:

Normal@Query[f /* g]
(* f /* g *)

Normal@Query[g @* f]
(* g[f[Identity]] *)


The result Missing[PartInvalid, "a"] in particular suggests that perhaps there is an evaluation leak or other improper operator structural transformation somewhere in the compilation process.

@* is undocumented, so it seems unlikely but possible that it has some unrevealed semantics that are intentionally different from being the "reverse" of /*. My own guess is that it is a bug.

• Yup it is a bug, already reported to me. Thanks. Will fix for 10.1.1, which is a month or two away. Apr 22 '15 at 5:40
• All of these are now fixed in 10.2 (formerly known as 10.1.1). Although clearly 10.2 took longer than we expected. Jul 2 '15 at 7:36

It looks like you have a square brace in the wrong place your code.

Query[Select[#"A"] == 1 &]


should be

Query[Select[#"A" == 1 &]]


These both work:

Dataset[{<|"A" -> 1|>, <|"A" -> 2|>}][Query[Select[#"A" == 1 &]] /* Query[Select[IntegerQ[#["A"]] &]]]

Dataset[{<|"A" -> 1|>, <|"A" -> 2|>}][Query[Select[IntegerQ[#["A"]] &]]@*Query[Select[#"A" == 1 &]]]
`
• You're right, trying to work out if I still have a problem... Apr 17 '15 at 16:16
• After "These both work" the first one succeeds, the second one fails. Apr 17 '15 at 16:29