Robustness
Queries should be able to handle all possible combinations of values of input data. This includes handling any potential variations in the data, and considering the impact of missing or empty values.
Handling Data Variations
It is important to consider variations in the input documents that may cause incorrect results or dynamic errors. Some common problems occur when:
- Sequences of multiple items appear where only one item was expected
For example, the expressions
$prod[name eq "Floppy Sun Hat"]andsubstring($prod/name, 1, 30)raise an error if there is more than onenamechild. The expression$prod/name != "Floppy Sun Hat"evaluates totrueif twonamechildren exist and either one is not equal toFloppy Sun Hat.- Zero items appear where one was expected
For example, the expression
$prod/price - $prod/discountreturns the empty sequence if there is nodiscountelement.- Values do not conform to the expected type
For example, the expression
max($prod/number)raises a type error if the product number isN/Ainstead of an integer.- Values are outside the expected range
Especially zero and negative numbers where a positive number was expected.
You should not assume that because an input document is validated by a schema it must be exactly as you expect. A schema can validate, for example, that a required element is present, but other assumptions might be made that cannot be validated by a schema. For example, the constraint "if the discounted attribute is true, a discount child ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access