Basic Examples (2)
Take a highly formatted Dataset and use DatasetQuery to select just the females but have the resulting Dataset inherit all options:
Select just the females but do not inherit options for HeaderAlignment and override the ItemStyle so that items appear Blue:
Scope (2)
You can apply Normal to a DatasetQuery in which only the query operators and any DatasetQuery options are present and there is no underlying Dataset to which DatasetQuery is applied. In this case, Normal operates the same way it does on Query:
A Query, however, can both increase or decrease the number of levels in the Dataset. Although various formatting overrides and deletions may be appropriate in these circumstances (see "Inheritance" option), Dataset does not generally "break" when option specifications assume levels and descriptions of data that no longer exist:
Format the Titanic data:
Write a sequence of operators that reduces the number of levels in the data:
Write a sequence of operators that increases the number of levels in the data:
Options (7)
Inheritance (4)
Setting the "Inheritance" option to None, makes DatasetQuery perform like Query:
Setting the "Inheritance" option to an Association with keys "Additions" and/or "Deletions" allows one to override formatting inheritance that would otherwise occur:
Use an ItemStyle option to format data to make the class column green and to emphasize that a 65 year old male in 1st class did not survive:
Use an "Additions" key-value pair with the "Inheritance" option to preserve the green coloring of the class column but eliminate the special coloring of the second row:
You can use "Additions" and "Deletions" where the sequence of operators changes the number of levels in the data.
Output (3)
Setting the "Output"option to "OptionsOnly" yields the presentation options that the new Dataset would have but does not perform the actual Query on the Dataset. This option value may be useful in determining how to hand-tweak the presentation options, particularly where running the underlying Query is time-consuming or where one anticipates the nature of the Query will pose option inheritance complications:
Hand - tweak the inherited options to replace Brown in the HeaderBackground with Purple:
Setting the "Output" option to All yields an Association in which the inherited options, the query result (stripped of options), and the query result (with options) are shown:
Applications (4)
Format data so that the row backgrounds cycle between different shades of green, so that only 10 rows appear, so that survival is hidden, and so that the "sex" header is displayed as "gender":
Select only those passengers age 18 or less but preserve the formatting options from the original Dataset:
Perform the same selection but reveal the hidden survival column:
Write a sequence of operators that computes survival on the Titanic by cabin class and gender but add new item styling and delete formatting resulting from the HeaderDisplayFunction:
Possible Issues (3)
DatasetQuery will not transform any Wolfram Language expression except a Dataset:
Queries that change the number of levels in an expression can sometimes create issues where, for example, application of an ItemDisplayFunction or HeaderDisplayFunction no longer makes sense:
The HeaderDisplayFunction fails to perform as desired because, as a result of the grouping, the second level header is now a Boolean value which, when compared with a string ("sex"), fails to evaluate to True or False:
We can fix this by deleting the HeaderDisplayFunction:
Or, we could write a HeaderDisplayFunction that anticipates the issue:
The following operation works in Query:
But not in DatasetQuery:
Use MapAt instead: