Max_index

Aggregation functions max_index

syntax

  • max_index(a)
  • max_index(a, relation)

definition

  • max_index(a) results in a parameter with the index numbers of the maximum value of the non Null values of Attribute a.
  • max_index(a, relation) results in an attribute with the index numbers of the maximum values of the non null values of attribute a, grouped by relation. The Domain unit of the resulting attribute is the Values unit of the relation.

description

The max_index function is not defined for string data items.

applies to

  • attribute a with Numeric, Point or boolean value type.
  • relation with value type of the group CanBeDomainUnit

conditions

The values unit of the resulting data item should be the domain unit of Argument a.

A value is taken only when it exceeds the smallest value of its value type, which for unsigned and boolean data is 0. So for an attribute, or a group of the relation, whose values are all 0, max_index results in Null: of boolean data it gives the index of the first true, and null where there is none, which configurations use to tell that nothing was selected.

since version

7.184

performance

  • Without relation: O(n) where n = number of elements in the domain of a. Single pass tracking maximum value and its index.
  • With relation: O(n) where n = number of elements in the domain of a. Tracks maximum value and index per group during a single pass.

example

parameter<City> max_index_NrInh                := max_index(City/NrInhabitants); result = 0
attribute<City> max_index_NrInhRegion (Region) := max_index(City/NrInhabitants, City/Region_rel);
City/NrInhabitants City/Region_rel
550 0
525 1
300 2
500 1
200 3
175 null
null 3

domain City, nr of rows = 7

max_index_NrInhRegion
0
1
2
4
null

domain Region, nr of rows = 5

see also