trait AggregateKeywords extends AnyRef
Aggregate keywords to mark aggregate expressions on attributes.
// Aggregates on any attribute type Person.age(count).get.head === 3 // count of asserted `age` attribute values Person.age(countDistinct).get.head === 3 // count of asserted distinct `age` attribute values Person.age(max).get.head === 38 // maximum `age` value (using `compare`) Person.age(min).get.head === 5 // maximum `age` value (using `compare`) Person.age(rand).get.head === 25 // single random `age` value Person.age(sample).get.head === 27 // single sample `age` value (when single value, same as random) // Aggregates on any attribute type, returning multiple values Person.age(distinct).get.head === Vector(5, 7, 38) // distinct `age` values Person.age(max(2)).get.head === Vector(38, 7) // 2 maximum `age` values Person.age(min(2)).get.head === Vector(5, 7) // 2 minimum `age` values Person.age(rand(2)).get.head === Stream(5, ?) // 2 random `age` values (values can re-occur) Person.age(sample(2)).get.head === Vector(7, 38) // 2 sample `age` values // Aggregates on number attributes Person.age(sum).get.head === 50 // sum of all `age` numbers Person.age(avg).get.head === 16.66666667 // average of all `age` numbers Person.age(median).get.head === 7 // median of all `age` numbers Person.age(stddev).get.head === 15.107025591499 // standard deviation of all `age` numbers Person.age(variance).get.head === 228.2222222222 // variance of all `age` numbers
- Source
- AggregateKeywords.scala
- See also
- Grouped
- Alphabetic
- By Inheritance
- AggregateKeywords
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- trait avg extends AnyRef
Average of attribute values.
Average of attribute values.
Applyavg
keyword to attribute to return average of attribute values of entities matching the molecule.Match.score.insert(1, 2, 4) Match.score(avg).get.head === 2.3333333333333335 // (1 + 2 + 4) / 3
- returns
Double
- trait count extends AnyRef
Count of attribute values.
Count of attribute values.
Applycount
keyword to attribute to return count of attribute values of entities matching the molecule.Person.firstName.lastName.age insert List( ("Ben", "Hayday", 42), ("Liz", "Taylor", 34), ("Liz", "Swifty", 34), ("Liz", "Mooray", 25) ) Person.firstName.age(count).get === List( ("Ben", 1), ("Liz", 3) // 34, 34, 25 )
- returns
Int
- trait countDistinct extends AnyRef
Count of distinct attribute values.
Count of distinct attribute values.
ApplycountDistinct
keyword to attribute to return count of distinct attribute values of entities matching the molecule.Person.firstName.lastName.age insert List( ("Ben", "Hayday", 42), ("Liz", "Taylor", 34), ("Liz", "Swifty", 34), ("Liz", "Mooray", 25) ) Person.firstName.age(countDistinct).get === List( ("Ben", 1), ("Liz", 2) // 34, 25 )
- returns
Int
- trait distinct extends AnyRef
Distinct attribute values.
Distinct attribute values.
Applydistinct
keyword to attribute to return Vector of distinct attribute values of entities matching the molecule.Person.firstName.lastName.age insert List( ("Ben", "Hayday", 42), ("Liz", "Taylor", 34), ("Liz", "Swifty", 34), ("Liz", "Mooray", 25) ) Person.firstName.age(distinct) insert List( ("Ben", 42), ("Liz", Vector(34, 25)) // only single 34 returned )
- returns
List[attribute-type]
- trait max extends AnyRef
Maximum attribute value(s).
Maximum attribute value(s).
Applymax
keyword to attribute to return the maximum attribute value of entities matching the molecule.Person.age.insert(25, 34, 37, 42, 70) Person.age(max).get.head === 70
Apply
max(n)
to return Vector of the n biggest values.Person.age(max(3)).get.head === Vector(37, 42, 70)
- Note
max
/max(n)
supports all value types (via comparators).max(n)
Can at most return the number of values that match.
- trait maxs extends AnyRef
- trait median extends AnyRef
Median of attribute values.
Median of attribute values.
Applymedian
keyword to attribute to return median of attribute values of entities matching the molecule.Match.score.insert(1, 2, 4) Match.score(median).get.head === 2
OBS: When it comes to an even number of values, Datomic has a special implementation of median that is different from the one described on the Wiki entry on the median function.
Datomic calculates the median of even number of values as the average of the two middle numbers rounded down to nearest whole numberMatch.score.insert(1, 2, 3, 4) Match.score(median).get.head === 2 // (2 + 3) / 2 = 2.5 rounded down to 2
With decimal numbers this can go wrong:
Match.score.insert(1.0, 2.5, 2.5, 3.0) Match.score(median).get.head === 2 // (2.5 + 2.5) / 2 = 2.5 rounded down to 2 (This is wrong and bug report has been filed)
- returns
Value of Attribute type
- trait min extends AnyRef
Minimum attribute value(s).
Minimum attribute value(s).
Applymin
keyword to attribute to return the minimum attribute value of entities matching the molecule.Person.age.insert(25, 34, 37, 42, 70) Person.age(min).get.head === 25
Apply
min(n)
to return Vector of the n smallest values.Person.age(min(3)).get.head === Vector(25, 34, 37)
- Note
min
/min(n)
supports all value types (via comparators).min(n)
Can at most return the number of values that match.
- trait mins extends AnyRef
- trait rand extends AnyRef
Random attribute value(s).
Random attribute value(s).
Applyrandom
keyword to attribute to return a single random attribute of entities matching the molecule.Person.age.insert(25, 34, 37, 42, 70) Person.age(random).get.head === 34 // or other..
Apply
random(n)
to return Vector of n random values. Observe though that duplicate random values can re-occur.Person.age(random(3)).get.head === Vector(42, 25, 42) // or other..
To get distinct values only, use the
sample(n)
keyword instead. - trait rands extends AnyRef
- trait sample extends AnyRef
Sample attribute value(s).
Sample attribute value(s).
Applysample
keyword to attribute to return a single sample (random) attribute value of entities matching the molecule.Person.age.insert(25, 34, 37, 42, 70) Person.age(sample).get.head === 42 // or other..
Apply
sample(n)
to return Vector of up to n distinct sample values.Person.age(sample(3)).get.head === Vector(70, 25, 37) // or other..
If values don't need to be distinct,
random(n)
can be used also.- Note
Can at most return the number of values that match.
- trait samples extends AnyRef
- trait stddev extends AnyRef
Variance of attribute values.
Variance of attribute values.
Applystddev
keyword to attribute to return variance of attribute values of entities matching the molecule.Match.score.insert(1, 2, 4) Match.score(stddev).get.head === 1.247219128924647
- returns
Double
- trait sum extends AnyRef
Sum of attribute values.
Sum of attribute values.
Applysum
keyword to attribute to return sum of attribute values of entities matching the molecule.Match.score.insert(1, 2, 4) Match.score(sum).get.head === 7
- returns
Value of Attribute type
- trait variance extends AnyRef
Variance of attribute values.
Variance of attribute values.
Applyvariance
keyword to attribute to return variance of attribute values of entities matching the molecule.Match.score.insert(1, 2, 4) Match.score(variance).get.head === 1.5555555555555556
- returns
Double
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
Inherited from AnyRef
Inherited from Any
Aggregate keywords
Keywords applied to attributes that return aggregated value(s).
Number aggregation keywords
Keywords applied to number attributes that return aggregated value(s).
Documentation/API for the Molecule library - a meta DSL for the Datomic database.
Manual | scalamolecule.org | Github | Forum