6
$\begingroup$

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?

$\endgroup$
5
  • $\begingroup$ Your code has a syntax error - I think there shouldn't be a ] after Select[#"A". $\endgroup$
    – Gerli
    Commented Apr 17, 2015 at 16:05
  • $\begingroup$ 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 &]]? $\endgroup$
    – Stefan R
    Commented Apr 17, 2015 at 16:13
  • $\begingroup$ @StefanR - yes - apologies, there were some errors in the question I have now corrected. $\endgroup$
    – Ymareth
    Commented Apr 17, 2015 at 16:33
  • $\begingroup$ Reported "officially" to Wolfram. $\endgroup$
    – Ymareth
    Commented Apr 20, 2015 at 8:30
  • $\begingroup$ Note that this issue is fixed in Mathematica 10.2.0. $\endgroup$
    – Stefan R
    Commented Jul 16, 2015 at 20:24

2 Answers 2

9
$\begingroup$

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"]]
(* GeneralUtilities`Slice["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.

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

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 &]]]
$\endgroup$
2
  • $\begingroup$ You're right, trying to work out if I still have a problem... $\endgroup$
    – Ymareth
    Commented Apr 17, 2015 at 16:16
  • $\begingroup$ After "These both work" the first one succeeds, the second one fails. $\endgroup$
    – Ymareth
    Commented Apr 17, 2015 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.