Interface Exprs
Expression
building methods- Since:
- 14.0 - Caribou Lou
-
Method Summary
Modifier and TypeMethodDescriptionBuilds an expression computing the absolute value of the given value.abs
(BigDecimal e) Builds an expression computing the absolute value of the given value.abs
(Expression e) Builds an expression computing the absolute value of the given value.acos
(Expression radians) Builds an expression computing the value of the acos function applied to the given value.and
(Expression... exprs) Builds the logical conjunction of the given expressions.asin
(Expression radians) Builds an expression computing the value of the asin function applied to the given value.atan
(Expression radians) Builds an expression computing the value of the atan function applied to the given value.atan2
(Expression y, Expression x) Builds an expression computing the value of the atan2 function applied to the given y and x values.avg
(Expression e) Builds an expression computing the value of the aggregated average of a given expression.Builds a literal boolean expression.caseWhen
(Expression condition, Expression thenExpr, Expression elseExpr) Builds a conditional CASE WHEN expression.cbrt
(Expression e) Builds an expression computing the value of the cube root function applied to the given value.ceil
(Expression e) Builds an expression computing the value of the ceil function applied to the given value.coalesce
(Expression... exprs) Builds an expression that will return the value of the first non-null resulting given expression.cos
(Expression radians) Builds an expression computing the value of the cos function applied to the given value.count()
Deprecated.count
(Expression e) Deprecated.usecountNonNull(Expression)
orcountDistinctNonNull(Expression)
insteadcountAll()
Builds an expression computing the number of aggregated rows.Builds an expression computing the number of distinct non-null values for the given expression.Builds an expression computing the number of rows having a non-null value for the given expression.Builds a literal date expression from aLocalDate
object.Builds a literal date expression from aDate
object ignoring all time related values.Builds a literal datetime expression from aDate
object.dateTime
(DateTime dateTime) Builds a literal datetime expression from aDateTime
object.Builds an expression computing the value of the degrees function applied to the given value.Builds an expression computing the value of the exponential function applied to the given value.exp
(BigDecimal e) Builds an expression computing the value of the exponential function applied to the given value.exp
(Expression e) Builds an expression computing the value of the exponential function applied to the given value.Builds an expression computing the value of the factorial function applied to the given value.floor
(Expression e) Builds an expression computing the value of the floor function applied to the given value.fromDataSlice
(Tables.Columns columns, DatamartContext.DataSlice dataSlice) Translates a PADatamartContext.DataSlice
into a query apiExpression
.Builds a literal integer expression.ln
(Expression e) Builds an expression computing the value of the ln (natural logarithm) function applied to the given value.log
(Number base, Expression e) Builds an expression computing the value of the log function applied to the given value.log
(Expression e) Builds an expression computing the value of the log (base 10) function applied to the given value.log
(Expression base, Expression e) Builds an expression computing the value of the log function applied to the given value.max
(Expression e) Builds an expression computing the value of the aggregated maximum of a given expression.min
(Expression e) Builds an expression computing the value of the aggregated minimum of a given expression.not
(Expression e) Builds the logical negation of the given expression.nullIf
(Expression e1, Expression e2) Builds an expression that will return NULL if both arguments are equal, otherwise return the first one.or
(Expression... exprs) Builds the logical disjunction of the given expressions.pi()
Builds an expression computing the value of pi.power
(Expression base, Number exponent) Builds an expression computing the value of the power function applied to the given base and exponent.power
(Expression base, Expression exponent) Builds an expression computing the value of the power function applied to the given base and exponent.Builds an expression computing the value of the radians function applied to the given value.random()
Builds an expression computing a random value.real
(BigDecimal value) Builds a literal real expression.round
(Expression e) Builds an expression computing the value of the round function applied to the given value (will round to the nearest integer).round
(Expression e, Long s) Builds an expression computing the value of the round function applied to the given value with a specified scale.round
(Expression e, Expression s) Builds an expression computing the value of the round function applied to the given value with a specified scale.sign
(Expression e) Builds an expression computing the value of the sign function applied to the given value.sin
(Expression radians) Builds an expression computing the value of the sin function applied to the given value.sqrt
(Expression e) Builds an expression computing the value of the square root function applied to the given value.Builds a literal string expression.sum
(Expression e) Builds an expression computing the value of the aggregated sum of a given expression.tan
(Expression radians) Builds an expression computing the value of the tan function applied to the given value.trunc
(Expression e) Builds an expression computing the value of the truncate function applied to the given value (will truncate towards zero).trunc
(Expression value, Long scale) Builds an expression computing the value of the truncate function applied to the given value with a specified scale.trunc
(Expression value, Expression scale) Builds an expression computing the value of the truncate function applied to the given value with a specified scale.width_bucket
(Expression operand, Number b1, Number b2, Long count) Builds an expression that will return the bucket number to which operand would be assigned in a histogram having count equal-width buckets spanning the range b1 to b2width_bucket
(Expression operand, Expression b1, Expression b2, Expression count) Builds an expression that will return the bucket number to which operand would be assigned in a histogram having count equal-width buckets spanning the range b1 to b2window()
Gives access to window functions building methods.
-
Method Details
-
and
Builds the logical conjunction of the given expressions.- Parameters:
exprs
- the expressions to be part of the conjunction- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
-
or
Builds the logical disjunction of the given expressions.- Parameters:
exprs
- the expressions to be part of the disjunction- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
-
not
Builds the logical negation of the given expression.- Parameters:
e
- the expressions to be negated- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
-
abs
Builds an expression computing the absolute value of the given value.- Parameters:
e
- the value on which to apply the abs operator- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
- See Also:
-
abs
Builds an expression computing the absolute value of the given value.- Parameters:
e
- the value on which to apply the abs operator- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
- See Also:
-
abs
Builds an expression computing the absolute value of the given value.- Parameters:
e
- the value on which to apply the abs operator- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
- See Also:
-
exp
Builds an expression computing the value of the exponential function applied to the given value.- Parameters:
e
- the value on which to apply the exponential function- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
- See Also:
-
exp
Builds an expression computing the value of the exponential function applied to the given value.- Parameters:
e
- the value on which to apply the exponential function- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
- See Also:
-
exp
Builds an expression computing the value of the exponential function applied to the given value.- Parameters:
e
- the value on which to apply the exponential function- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
- See Also:
-
sum
Builds an expression computing the value of the aggregated sum of a given expression.This aggregation function is meant to be used in
PipelineStage.aggregateBy(Function, Function)
andPipelineStage.aggregate(Function)
.- Parameters:
e
- the expression to be aggregated- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
- See Also:
-
avg
Builds an expression computing the value of the aggregated average of a given expression.This aggregation function is meant to be used in
PipelineStage.aggregateBy(Function, Function)
andPipelineStage.aggregate(Function)
.- Parameters:
e
- the expression to be aggregated- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
- See Also:
-
min
Builds an expression computing the value of the aggregated minimum of a given expression.This aggregation function is meant to be used in
PipelineStage.aggregateBy(Function, Function)
andPipelineStage.aggregate(Function)
.- Parameters:
e
- the expression to be aggregated- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
- See Also:
-
max
Builds an expression computing the value of the aggregated maximum of a given expression.This aggregation function is meant to be used in
PipelineStage.aggregateBy(Function, Function)
andPipelineStage.aggregate(Function)
.- Parameters:
e
- the expression to be aggregated- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
- See Also:
-
cbrt
Builds an expression computing the value of the cube root function applied to the given value.- Parameters:
e
- the value on which to apply the cube root function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
ceil
Builds an expression computing the value of the ceil function applied to the given value.- Parameters:
e
- the value on which to apply the ceil function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
radians
Builds an expression computing the value of the radians function applied to the given value.- Parameters:
e
- the value on which to apply the radians function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
factorial
Builds an expression computing the value of the factorial function applied to the given value.- Parameters:
e
- the value on which to apply the factorial function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
floor
Builds an expression computing the value of the floor function applied to the given value.- Parameters:
e
- the value on which to apply the floor function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
ln
Builds an expression computing the value of the ln (natural logarithm) function applied to the given value.- Parameters:
e
- the value on which to apply the ln (natural logarithm) function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
log
Builds an expression computing the value of the log (base 10) function applied to the given value.- Parameters:
e
- the value on which to apply the log (base 10) function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
log
Builds an expression computing the value of the log function applied to the given value.- Parameters:
base
- the base of the logarithme
- the value on which to apply the log function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
log
Builds an expression computing the value of the log function applied to the given value.- Parameters:
base
- the base of the logarithme
- the value on which to apply the log function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
pi
Expression pi()Builds an expression computing the value of pi.- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
power
Builds an expression computing the value of the power function applied to the given base and exponent.- Parameters:
base
- the base of the power functionexponent
- the exponent of the power function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
power
Builds an expression computing the value of the power function applied to the given base and exponent.- Parameters:
base
- the base of the power functionexponent
- the exponent of the power function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
degrees
Builds an expression computing the value of the degrees function applied to the given value.- Parameters:
e
- the value on which to apply the degrees function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
round
Builds an expression computing the value of the round function applied to the given value (will round to the nearest integer).- Parameters:
e
- the value on which to apply the round function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
round
Builds an expression computing the value of the round function applied to the given value with a specified scale.- Parameters:
e
- the value on which to apply the round functions
- the scale to which the value should be rounded (round to this much decimal places)- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
round
Builds an expression computing the value of the round function applied to the given value with a specified scale.- Parameters:
e
- the value on which to apply the round functions
- the scale to which the value should be rounded (round to this much decimal places)- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
sign
Builds an expression computing the value of the sign function applied to the given value.The sign function returns -1 for negative values, 0 for zero and 1 for positive values.
- Parameters:
e
- the value on which to apply the sign function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
sqrt
Builds an expression computing the value of the square root function applied to the given value.- Parameters:
e
- the value on which to apply the square root function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
trunc
Builds an expression computing the value of the truncate function applied to the given value (will truncate towards zero).- Parameters:
e
- the value on which to apply the truncate function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
trunc
Builds an expression computing the value of the truncate function applied to the given value with a specified scale.- Parameters:
value
- the value on which to apply the truncate functionscale
- the scale to which the value should be truncated (truncate to this much decimal places)- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
trunc
Builds an expression computing the value of the truncate function applied to the given value with a specified scale.- Parameters:
value
- the value on which to apply the truncate functionscale
- the scale to which the value should be truncated (truncate to this much decimal places)- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
random
Expression random()Builds an expression computing a random value.The random value is uniformly distributed between 0 (inclusive) and 1 (exclusive).
- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
width_bucket
Builds an expression that will return the bucket number to which operand would be assigned in a histogram having count equal-width buckets spanning the range b1 to b2- Parameters:
operand
- the value to be evaluatedb1
- the lower bound of the first bucketb2
- the upper bound of the last bucketcount
- the number of buckets- Returns:
- the bucket number to which operand would be assigned, or 0 or count+1 for an input outside the range
- Since:
- 15.0 - Caribou Lou
-
width_bucket
Builds an expression that will return the bucket number to which operand would be assigned in a histogram having count equal-width buckets spanning the range b1 to b2- Parameters:
operand
- the value to be evaluatedb1
- the lower bound of the first bucketb2
- the upper bound of the last bucketcount
- the number of buckets- Returns:
- the bucket number to which operand would be assigned, or 0 or count+1 for an input outside the range
- Since:
- 15.0 - Caribou Lou
-
acos
Builds an expression computing the value of the acos function applied to the given value.- Parameters:
radians
- the value on which to apply the arc cosine function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
asin
Builds an expression computing the value of the asin function applied to the given value.- Parameters:
radians
- the value on which to apply the arc sine function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
atan
Builds an expression computing the value of the atan function applied to the given value.- Parameters:
radians
- the value on which to apply the arc tangent function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
atan2
Builds an expression computing the value of the atan2 function applied to the given y and x values.- Parameters:
y
- the y valuex
- the x value- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
cos
Builds an expression computing the value of the cos function applied to the given value.- Parameters:
radians
- the value on which to apply the cosine function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
sin
Builds an expression computing the value of the sin function applied to the given value.- Parameters:
radians
- the value on which to apply the sine function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
tan
Builds an expression computing the value of the tan function applied to the given value.- Parameters:
radians
- the value on which to apply the tangent function- Returns:
- the built expression
- Since:
- 15.1 - Southside
-
count
Deprecated.usecountAll()
insteadBuilds an expression computing the number of aggregated rows.This aggregation function is meant to be used in
PipelineStage.aggregateBy(Function, Function)
andPipelineStage.aggregate(Function)
.- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
- See Also:
-
count
Deprecated.usecountNonNull(Expression)
orcountDistinctNonNull(Expression)
insteadBuilds an expression computing the number of aggregated non-null values of the given expression.This aggregation function is meant to be used in
PipelineStage.aggregateBy(Function, Function)
andPipelineStage.aggregate(Function)
.- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
- See Also:
-
countAll
Expression countAll()Builds an expression computing the number of aggregated rows.This aggregation function is meant to be used in
PipelineStage.aggregateBy(Function, Function)
andPipelineStage.aggregate(Function)
.- Returns:
- the built expression
- Since:
- 14.3 - Caribou Lou
- See Also:
-
countNonNull
Builds an expression computing the number of rows having a non-null value for the given expression.This aggregation function is meant to be used in
PipelineStage.aggregateBy(Function, Function)
andPipelineStage.aggregate(Function)
.- Parameters:
e
- the expression to count on- Returns:
- the built expression
- Since:
- 14.3 - Caribou Lou
- See Also:
-
countDistinctNonNull
Builds an expression computing the number of distinct non-null values for the given expression.This aggregation function is meant to be used in
PipelineStage.aggregateBy(Function, Function)
andPipelineStage.aggregate(Function)
.- Parameters:
expr
- the expression to count on- Returns:
- the built expression
- Since:
- 14.3 - Caribou Lou
- See Also:
-
caseWhen
Builds a conditional CASE WHEN expression.For example, the following expression will evaluate to a different value depending on whether the sku contains "foo" or not.
def qapi = api.queryApi() def p = qapi.tables().products() def mealType = qapi.exprs().caseWhen( p.sku().like("%spamEgg%"), // boolean condition qapi.exprs().string("breakfast"), // value when condition evaluates to true qapi.exprs().string("generic meal") // value when condition evaluates to false )
- Parameters:
condition
- the conditional expressionthenExpr
- the resulting expression when condition is trueelseExpr
- the resulting expression when condition is false- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
-
coalesce
Builds an expression that will return the value of the first non-null resulting given expression.- Parameters:
exprs
- the ordered list of expressions from which the first non-null evaluated value will be chosen- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
-
nullIf
Builds an expression that will return NULL if both arguments are equal, otherwise return the first one.- Parameters:
e1
- the first argumente2
- the second argument- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
-
string
Builds a literal string expression.- Parameters:
value
- the literal value- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
-
real
Builds a literal real expression.- Parameters:
value
- the literal value- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
-
integer
Builds a literal integer expression.- Parameters:
value
- the literal value- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
-
bool
Builds a literal boolean expression.- Parameters:
value
- the literal value- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
-
dateOnly
Builds a literal date expression from aDate
object ignoring all time related values.Note that even if
Date
objects can contain time value, this function will only extract the date related data (i.e., year, month and day), ignoring all time related values.- Parameters:
dateOnly
- the literal value- Returns:
- the built expression
- Since:
- 14.0 - Caribou Lou
-
dateOnly
Builds a literal date expression from aLocalDate
object.- Parameters:
dateOnly
- the literal value- Returns:
- the built expression
- Since:
- 15.0 - Caribou Lou
-
dateTime
Builds a literal datetime expression from aDate
object.- Parameters:
dateTime
- the literal value- Returns:
- the built expression
-
dateTime
Builds a literal datetime expression from aDateTime
object.- Parameters:
dateTime
- the literal value- Returns:
- the built expression
-
window
WindowFunction.Frame window()Gives access to window functions building methods.A window function is a very powerful mean to compute aggregate-like functions over some portion of the row selected by a query. This api provides standard SQL window functions equivalent.
For example, here is a query returning the skus having the 3 lowest cost by category:
def qapi = api.queryApi() def table = qapi.tables().dataSource("costs") qapi.source( table, [ table.sku, table.category table.cost, qapi.exprs().window() .expanding() .partitionBy([table.category]) .sortBy([qapi.orders().ascNullsLast(table.cost)]) .rank() .as("costRank") ] ).filter(t -> t.costRank.lessOrEqual(3)) .stream { it.toList() }
- Returns:
- the window functions building methods
- Since:
- 15.0 - Southside
- See Also:
-
fromDataSlice
Translates a PADatamartContext.DataSlice
into a query apiExpression
.For example the following code fetches all rows of the Product data source belonging to a specific
DatamartContext.DataSlice
.
Note: this method only works on PA FieldCollections. If the givenDataSlice dataSlice = api.getDatamartContext().newDatamartSlice() // input generated by api.inputBuilderFactory().createProductGroupEntry() dataSlice.include(ProductGroup.fromMap(input.MyProductGroup)) // input generated by api.inputBuilderFactory().createDmFilterBuilder() or createDmFilterBuilderMultiple() dataSlice.addFilter(api.filterFromMap(input.MyDmFilter)) def qapi = api.queryApi() def products = qapi.tables().dataSource("ProductDS") qapi.source( products, [ products.sku(), products.label(), ], qapi.exprs().fromDataSlice(products, dataSlice) ).stream { it.toList() }
DatamartContext.DataSlice
is built from aProductGroup
or aCustomerGroup
, then the filtered field collection should contain columns with same names as the Product DS or the Customer DS.- Parameters:
columns
- the table or previous stage onto which the filter is builtdataSlice
- the dataSlice to get the filter from.- Returns:
- the expression representing the given
DatamartContext.DataSlice
filter - Since:
- 15.0 - Southside
-
countAll()
instead