Interface ExpressionRealizer


public interface ExpressionRealizer

Produces realized (and evaluation-ready) expressions from an AST and an input type as scope. This interface will eventually be used by pipelines when realizing their parameters against input data.

  • Field Details

    • NO_SUCH_MEMBER

      static final ProblemCode NO_SUCH_MEMBER

      Problem code for when a member is missing from the scope of an expression - used by realizeConstant

  • Method Details

    • getImplicitTypeName

      static String getImplicitTypeName(RealizationContext context, Type type)
      Returns:
      a succinct and descriptive name for the given type for use with getImplicitName
    • getImplicitName

      static String getImplicitName(RealizationContext context, RealizedExpression realized, Collection<String> used)

      Return a name we can use to represent the given realized expression in a struct where no member name has been given.

      ## Examples:

      { # literals 1, # as integer, 2.0, # as floating, 'three', # as text,

      # member access
       foo, # as foo,
       foo.bar, # as bar
       
       # function calls
       str(foo),  # as str_foo
       if_then_else(a, b, c), # as if_then_else
       lookup(foo, bookmark('bar')).event_id # as event_id
       

      } ```

      Parameters:
      used - the names that have already been assigned. If the implicit name would happen to collide with one of these then a counter style suffix is appended to the name to make it distinct, e.g. {foo, foo, foo} is equivalent to {foo: foo, foo_2: foo, foo_3: foo}
    • makeUnique

      static String makeUnique(String identifier, Collection<String> used)
      Returns:
      a new identifier based on the given one that is unique among used - will append a _2, _3 to the given identifier until it finds one that is not in used.
    • realizeConstant

      default ResultOrProblems<RealizedExpression> realizeConstant(Expression expression)

      Attempts to realize the given expression against an empty struct, returning a meaningful problem if it looks like it failed to realize because it had property access problems (meaning it wasn't constant as it relies on the input scope)

      Returns:
      a RealizedExpression that is constant, i.e should succeed when called like expr.evaluate(Tuple.EMPTY_TUPLE) and should always return the same result.
    • realize

      ResultOrProblems<RealizedExpression> realize(Type inputType, Expression expression)
    • realize

      ResultOrProblems<RealizedExpression> realize(Type inputType, String unparsedExpression)
    • realizeAggregate

      ResultOrProblems<RealizedAggregateExpression> realizeAggregate(Type inputType, Expression expression)
      Returns:
      a RealizedAggregateExpression that can aggregate rows of the given input type.
    • parse

      Expression parse(String unparsedExpression)

      Convenience method for parsing an rl expression in to an Expression ast.

      Parameters:
      unparsedExpression - the string of rl to parse
      Returns:
      the parsed Expression
    • asStruct

      Convert a realized expression to one that always returns a Tuple and has return type that is a Struct. Note that this is a simpler routine than type coercion, and is offered to simplify user input cases where a pipeline wants a struct, but the user doesn't need to know or care about this, e.g. select(foo) is simpler than select({foo}) but they do exactly the same thing.