public interface Exprs
Collection of Expression building methods
Since:
14.0 - Caribou Lou
  • Method Details

    • and

      Expression and(Expression... exprs)
      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

      Expression or(Expression... exprs)
      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

      Expression abs(Long e)
      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

      Expression exp(Long e)
      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) and PipelineStage.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) and PipelineStage.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) and PipelineStage.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) and PipelineStage.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

      Expression radians(Expression e)
      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

      Expression factorial(Expression e)
      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 logarithm
      e - the value on which to apply the log function
      Returns:
      the built expression
      Since:
      15.1 - Southside
    • log

      Expression log(Number base, Expression e)
      Builds an expression computing the value of the log function applied to the given value.
      Parameters:
      base - the base of the logarithm
      e - the value on which to apply the log function
      Returns:
      the built expression
      Since:
      15.1 - Southside
    • pi

      Builds an expression computing the value of pi.
      Returns:
      the built expression
      Since:
      15.1 - Southside
    • power

      Expression power(Expression base, Expression exponent)
      Builds an expression computing the value of the power function applied to the given base and exponent.
      Parameters:
      base - the base of the power function
      exponent - the exponent of the power function
      Returns:
      the built expression
      Since:
      15.1 - Southside
    • power

      Expression power(Expression base, Number exponent)
      Builds an expression computing the value of the power function applied to the given base and exponent.
      Parameters:
      base - the base of the power function
      exponent - the exponent of the power function
      Returns:
      the built expression
      Since:
      15.1 - Southside
    • degrees

      Expression degrees(Expression e)
      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 function
      s - the scale to which the value should be rounded (round to this much decimal places)
      Returns:
      the built expression
      Since:
      15.1 - Southside
    • round

      Expression round(Expression e, Long s)
      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 function
      s - 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

      Expression trunc(Expression value, Expression scale)
      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 function
      scale - the scale to which the value should be truncated (truncate to this much decimal places)
      Returns:
      the built expression
      Since:
      15.1 - Southside
    • trunc

      Expression trunc(Expression value, Long scale)
      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 function
      scale - 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

      Expression width_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 b2
      Parameters:
      operand - the value to be evaluated
      b1 - the lower bound of the first bucket
      b2 - the upper bound of the last bucket
      count - 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

      Expression 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 b2
      Parameters:
      operand - the value to be evaluated
      b1 - the lower bound of the first bucket
      b2 - the upper bound of the last bucket
      count - 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

      Expression acos(Expression radians)
      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

      Expression asin(Expression radians)
      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

      Expression atan(Expression radians)
      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 value
      x - the x value
      Returns:
      the built expression
      Since:
      15.1 - Southside
    • cos

      Expression cos(Expression radians)
      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

      Expression sin(Expression radians)
      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

      Expression tan(Expression radians)
      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.
      use countAll() instead
      Builds an expression computing the number of aggregated rows.

      This aggregation function is meant to be used in PipelineStage.aggregateBy(Function, Function) and PipelineStage.aggregate(Function).

      Returns:
      the built expression
      Since:
      14.0 - Caribou Lou
      See Also:
    • count

      Builds 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) and PipelineStage.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) and PipelineStage.aggregate(Function).

      Returns:
      the built expression
      Since:
      14.3 - Caribou Lou
      See Also:
    • countNonNull

      Expression countNonNull(Expression e)
      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) and PipelineStage.aggregate(Function).

      Parameters:
      e - the expression to count on
      Returns:
      the built expression
      Since:
      14.3 - Caribou Lou
      See Also:
    • countDistinctNonNull

      Expression countDistinctNonNull(Expression expr)
      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) and PipelineStage.aggregate(Function).

      Parameters:
      expr - the expression to count on
      Returns:
      the built expression
      Since:
      14.3 - Caribou Lou
      See Also:
    • caseWhen

      Expression caseWhen(Expression condition, Expression thenExpr, Expression elseExpr)
      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 expression
      thenExpr - the resulting expression when condition is true
      elseExpr - the resulting expression when condition is false
      Returns:
      the built expression
      Since:
      14.0 - Caribou Lou
    • coalesce

      Expression coalesce(Expression... exprs)
      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

      Expression nullIf(Expression e1, Expression e2)
      Builds an expression that will return NULL if both arguments are equal, otherwise return the first one.
      Parameters:
      e1 - the first argument
      e2 - the second argument
      Returns:
      the built expression
      Since:
      14.0 - Caribou Lou
    • string

      Expression string(String value)
      Builds a literal string expression.
      Parameters:
      value - the literal value
      Returns:
      the built expression
      Since:
      14.0 - Caribou Lou
    • real

      Expression real(BigDecimal value)
      Builds a literal real expression.
      Parameters:
      value - the literal value
      Returns:
      the built expression
      Since:
      14.0 - Caribou Lou
    • integer

      Expression integer(Long value)
      Builds a literal integer expression.
      Parameters:
      value - the literal value
      Returns:
      the built expression
      Since:
      14.0 - Caribou Lou
    • bool

      Expression bool(Boolean value)
      Builds a literal boolean expression.
      Parameters:
      value - the literal value
      Returns:
      the built expression
      Since:
      14.0 - Caribou Lou
    • dateOnly

      Expression dateOnly(Date dateOnly)
      Builds a literal date expression from a Date 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

      Expression dateOnly(LocalDate dateOnly)
      Builds a literal date expression from a LocalDate object.
      Parameters:
      dateOnly - the literal value
      Returns:
      the built expression
      Since:
      15.0 - Caribou Lou
    • dateTime

      Expression dateTime(Date dateTime)
      Builds a literal datetime expression from a Date object.
      Parameters:
      dateTime - the literal value
      Returns:
      the built expression
    • dateTime

      Expression dateTime(DateTime dateTime)
      Builds a literal datetime expression from a DateTime object.
      Parameters:
      dateTime - the literal value
      Returns:
      the built expression
    • 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

      Expression fromDataSlice(Tables.Columns columns, DatamartContext.DataSlice dataSlice)
      Translates a PA DatamartContext.DataSlice into a query api Expression.

      For example the following code fetches all rows of the Product data source belonging to a specific DatamartContext.DataSlice.

      
       DataSlice 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() }
       
      Note: this method only works on PA FieldCollections. If the given DatamartContext.DataSlice is built from a ProductGroup or a CustomerGroup, 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 built
      dataSlice - the dataSlice to get the filter from.
      Returns:
      the expression representing the given DatamartContext.DataSlice filter
      Since:
      15.0 - Southside