bea.com | products | dev2dev | support | askBEA

Download Docs | Site Map | Glossary
Search

Building Queries and Data Views

Aggregate Functions

Aggregate functions process a sequence as argument and return a single value computed from values in the sequence. Except for the Count function, if the sequence contains nodes, the function extracts the value from the node and uses it in the computation. The following aggregate functions are available:

- xf:avg

- xf:count

- xf:max

- xf:min

- xf:sum

xf:avg

Returns the average of a sequence of numbers.

Data Types

- Input data type: xs:double*

- Returned data type: xs:double?

Notes

If the source value contains nodes, the value of each node is extracted using the xf:data function. If an empty list occurs, it is discarded.

If the source value contains only numbers, the Avg function returns the average of the numbers, which is the sum of the source sequence divided by the count of the source sequence.

If the source value is an empty list, the function returns an empty list.

If the source value contains non-numeric data, the function returns an error.

XQuery Specification Compliance

Liquid Data requires a list of double precision values instead of a list of items.

Examples

- xf:avg((4, 10)) returns the double precision floating point value 7.0.

- xf:avg((4, (), 10)) also returns the double precision floating point value 7.0.

- xf:avg((4, "10")) generates a compile-time error because the input sequence contains a string.

xf:count

Returns the number of items in the sequence in an unsigned integer.

Data Types

- Input data type: xs:item*

- Returned data type: xs:integer

Notes

If the source value is an empty list, the function returns an empty list.

XQuery Specification Compliance

Liquid Data returns an integer value (xs:integer) instead of an unsigned int (xs:unsignedInt) value.

Examples

- xf:count((3, "10")) returns the integer value 2.

- xf:count(()) returns the integer value 0.

- xf:count((3, "10", (), )) returns the value 3 (the empty list is ignored).

xf:max

Returns the maximum value from a sequence. If there are two or more items with the same value, the specific item whose value is returned is implementation-dependent.

Data Types

- Input data type: xsext:item*

- Returned data type: xsext:item?

Notes

If the source value contains nodes, the value of each node is extracted using the xf:data function. If an empty list occurs, it is discarded.

All values in the list must be instances of one of the following types:

- numeric

- xs:string

- xs:date

- xs:time

- xs:dateTime

For example, if the list contains items with typed values that represent both decimal values and dates, an error will occur.

The values in the sequence must have a total order:

- DateTime values must all contain a time zone or omit a time zone.

- Duration values must contain only years and months or contain only days, hours, minutes and seconds.

Both of these conditions must be true; otherwise, the function returns an error.

XQuery Specification Compliance

- Liquid Data does not support a format with a collation literal.

- Liquid Data has no restrictions on date and time input values.

- Liquid Data supports a correct return type of xs:item? instead of xs:anySimpleType?, which is incorrect.

- Liquid Data supports only numeric, xs:string, xs:date, xs:time, and xs:dateTime data types.

Examples

- xf:max((3, 10)) returns the value 10.

- xf:max((<a>{4}</a>, 3, (), <b >{2}</b>)) returns <a>{4}</a>.

xf:min

Returns the minimum value from a sequence of numbers. If there are two or more items with the same value, the specific item whose value is returned is implementation-dependent.

Data Types

- Input data type: xsext:item*

- Returned data type: xsext:item?

Notes

If the source value contains nodes, the value of each node is extracted using the Data function. If an empty list occurs, it is discarded.

After extracting the values from nodes, the sequence must contain only values of a single type.

The values in the sequence must have a total order:

- DateTime values must all contain a time zone or omit a timezone

- Duration values must contain only years and months or contain only days, hours, minutes and seconds

Both of these conditions must be true; otherwise, the function returns an error.

XQuery Specification Compliance

- Liquid Data does not support a format with a collation literal.

- Liquid Data has no restrictions on date and time input values.

- Liquid Data supports a correct return type of xs:item? instead of xs:anySimpleType?, which is incorrect.

- Liquid Data supports only numeric, xs:string, xs:date, xs:time, and xs:dateTime data types.

Examples

- xf:min((3, 10)) returns the value 3.

- xf:min((<a>{4}</a>, 3, (), <b>{2}</b>)) returns <b>{2}</b>.

- xf:min((3, 4, "2")) generates an error because the sequence contains both numeric and string values.

- xf:min(()) returns an empty list ().

xf:sum

Returns the sum of a sequence of numbers.

Data Types

- Input data type: xsext:anyValue*

- Returned data type: xsext:anyValue?

Notes

If the source value contains nodes, the value of each node is extracted using the Data function. If an empty list occurs, it is discarded.

If the source value contains only numbers, the Sum function returns the sum of the numbers.

If the source value contains non-numeric data, the function returns an error.

If the input sequence is empty, the function returns an empty list.

XQuery Specification Compliance

- Liquid Data adheres to the prior XQuery specification (December, 2001) by returning an empty list if the input sequence is empty.

- Liquid Data output depends on the input type. If the input type is xs:decimal, the returned value is xs:decimal; if the input type is xs:decimal and xs:float, the returned value is xs:float; if the input type is xs:double, the returned value is xs:double.

Examples

- xf:sum((3, 8, (), 1)) returns the value 12.

- xf:sum(()) returns an empty list ().

- xf:sum((<a>{4}</a>, 3)) returns a value of 7.

- xf:sum(("7", 3)) generates a compile-time error because the sequence that is passed in to the function is not homogenous.