The simplest "workaround" I've found to prevent your query from aborting is to set properly the Query
option FailureAction
which is indeed by default set to "Abort"
! ;)
Given your data :
myDataset = <|"1" -> <|"a" -> "hey now"|>, "2" -> <|"a" -> Missing[]|>|> // Dataset;
myQuery = Select[StringMatchQ[#a, "hey*"] &];
the default behavior is to simply abort with a Failure message:
myDataset[myQuery]
unless you set :
myDataset[myQuery, FailureAction -> None]
The query did not abort, the result is correct but a warning message was printed. To suppress the message you can as before simply wrap the command in Quiet
.
Remarks
1/ Regarding this FailureAction
option, I thought first that the solution would be to set it rather to "Drop"
but the query returns Dataset``$DropPlaceholder
... Not sure what happens here ...
2/ There is also another very interesting query option: MissingBehavior
which I thought was even more suited here. Not sure again why it does not work either.
3/ Why (as OP asked) does Select[Quiet@StringMatchQ[#a, "hey*"] &][myDataset]
return the correct result without Failure, whereas myDataset[Select[Quiet@StringMatchQ[#a, "hey*"] &]]
abort ?? It seems that this second form is actually working in version 10.0 according to @Hans answer ? Anyone to confirm ?
(At the time of this answer I'm using v10.2.)
data2[Select[StringMatchQ[ToString@#a, "hey*"] &]]
or the wordierdata2[Select[ Length[Cases[{#a}, x_String /; StringMatchQ[x, "hey*"] ]] > 0 &]]
if you feel the need to avoidToString
$\endgroup$StringMatchQ
does not matchMissing[]
values, and its warning is suppressed byQuiet
though somehow not as aQuery
. $\endgroup$