# EntityFunction

EntityFunction[x,body]

is a function with a single formal parameter x, to be used in EntityValue and related functions.

EntityFunction[{x1,x2,},body]

is an EntityFunction with a list of formal parameters.

# Details    • EntityFunction[x, body] behaves exactly like an EntityProperty and can be used directly in EntityValue.
• In EntityFunction[x,body], x is usually bound to a single Entity at a time. The second argument of AggregatedEntityClass is an exception to this rule, since the formal parameter will bind to each group of entities.
• In the context of the second argument of for relational-database-backed entities, the following aggregation functions are supported:
•  Min minimum of values Max maximum of values Length number of values Total sum of values Mean the mean value StandardDeviation sample standard deviation Variance sample variance
• EntityFunction[{left,right},body] can appear as the condition for CombinedEntityClass. Here, left will bind to each Entity in the first argument of CombinedEntityClass and right to each Entity in the second argument.
• When dealing with entities registered in a relational-database-backed EntityStore, only the following forms can be compiled to SQL:
•  a+b additions between numbers, dates and time quantities a-b differences between numbers or dates a*b multiplications between numbers a/b ratios between numbers a^b powers between numbers Quotient[a,b] integer division Mod[a,b] remainder of division between integers Sqrt[a] square root Exp[a] exponential of numbers Log,Log10,Log2 logarithms in different bases Abs[a] absolute value OddQ[a],EvenQ[a] parity checks on integers ab,a>b,a≠b,… comparisons between numbers, dates, strings a&&b,a||b,!a,… Boolean algebra If[a,b,c] if statements Which[…] which statements MissingQ[a] check whether an element is missing Length[list]0 check whether a list is empty OrderedQ[a,b] check the alphabetical order of strings MemberQ[list,a] check whether an element is in a list or an entity in a class StringJoin[a,b,…] string concatenation StringMatchQ[…],StringStartsQ[…],… basic string matching operations Now,Today getting the current date AllTrue,AnyTrue Boolean operations on lists SelectFirst[list,Not@*MissingQ] select the first non-missing value in a list BitNot,BitAnd,BitOr,BitShiftLeft,… bitwise operations Sin,Cos,Tan,… trigonometric functions ArcSin,ArcCos,ArcTan,… inverse trigonometric functions Sinh,Cosh,Tanh,… hyperbolic functions ArcSinh,ArcCosh,ArcTanh inverse hyperbolic functions Round,Floor,Ceiling rounding functions Min,Max minimum and maximum (outside aggregations) StringTake,StringDrop extract a subpart of a string (including UpTo support) ToString[a] convert a number or date to string N[a] convert an integer to real IntegerPart[a] extract the integer part of a real number FromDigits[a] convert a string to integer Boole[a] convert a Boolean to 0 or 1 Interpreter["StructuredDate"][a],Interpreter["StructuredTime"][a],Interpreter["StructuredDateTime"][a] convert a string to date or time object UnixTime[a] convert a date object with time to a number FromUnixTime[a] convert a number to a date object with time JulianDate[a] convert a date object to a number FromJulianDate[a] convert a number to a date object DateValue[a,"SecondsFromMidnight"] convert a time object to a number DateValue[UnixTime[a],"TimeObject"] convert a number to a time object
• In the context of relational-database-backed entities, the functions above might have limited functionality with respect to their Wolfram Language counterpart. For example, SQL lacks support for complex numbers; because of this, the domains of numerical functions are limited to regions where they are real valued. Symbolic evaluation is generally not available. Precision-tracking semantics may also vary.

# Examples

open allclose all

## Basic Examples(3)

Compute the ratio between atomic mass and atomic number for all noble gases:

EntityFunction can be applied directly to a single entity, like EntityProperty:

Use EntityFunction as a condition for FilteredEntityClass:

## Properties & Relations(6)

Use in ExtendedEntityClass to add a new computed property:

Use in FilteredEntityClass as a predicate to select certain entities:

Use in SortedEntityClass as a sorting criterion:

Use in the second argument of AggregatedEntityClass as an aggregator:

Use in the third argument of AggregatedEntityClass as a grouping criterion:

Use in CombinedEntityClass as a combining criterion:

## Possible Issues(1)

SQL doesn't support all operations supported by the Wolfram Language: Mathematical operations in SQL only support real numbers; performing operations that would return a complex number might result in Missing or a runtime error, depending on the backend:

SQL doesn't support returning anything but scalars from properties or EntityFunction: 