java.lang.Object
org.elasticsearch.xpack.esql.core.tree.Node<Expression>
org.elasticsearch.xpack.esql.core.expression.Expression
All Implemented Interfaces:
NamedWriteable, Writeable, Resolvable
Direct Known Subclasses:
EntryExpression, Function, LeafExpression, MapExpression, NamedExpression, UnaryExpression

public abstract class Expression extends Node<Expression> implements Resolvable
In a SQL statement, an Expression is whatever a user specifies inside an action, so for instance: SELECT a, b, ABS(c) FROM i a, b, ABS(c), and i are all Expressions, with ABS(c) being a Function (which is a type of expression) with a single child, c.
  • Constructor Details

  • Method Details

    • foldable

      public boolean foldable()
      Whether the expression can be evaluated statically, aka "folded", or not.
    • fold

      public Object fold(FoldContext ctx)
      Evaluate this expression statically to a constant. It is an error to call this if foldable() returns false.
    • nullable

      public abstract Nullability nullable()
    • references

      public AttributeSet references()
    • childrenResolved

      public boolean childrenResolved()
    • typeResolved

      public final Expression.TypeResolution typeResolved()
      Does the tree rooted at this expression have valid types at all nodes?

      For example, SIN(1.2) has a valid type and should return Expression.TypeResolution.TYPE_RESOLVED to signal "this type is fine". Another example, SIN("cat") has an invalid type in the tree. The value passed to the SIN function is a string which doesn't make any sense. So this method should return a "failure" resolution which it can build by calling TypeResolution(String).

      Take SIN(1.2) + COS(ATAN("cat")), this tree should also fail, specifically because ATAN("cat") is invalid. This should fail even though + is perfectly valid when run on the results of SIN and COS. And COS can operate on the results of any valid call to ATAN. For this method to return a "valid" result the whole tree rooted at this expression must be valid.

    • resolveType

      protected Expression.TypeResolution resolveType()
      The implementation of typeResolved(), which is just a caching wrapper around this method. See it's javadoc for what this method should return.

      Implementations will rarely interact with the Expression.TypeResolution class directly, instead usually calling the utility methods on TypeResolutions.

      Implementations should fail if childrenResolved() returns false.

    • canonical

      public final Expression canonical()
    • canonicalize

      protected Expression canonicalize()
    • semanticEquals

      public boolean semanticEquals(Expression other)
    • semanticHash

      public int semanticHash()
    • resolved

      public boolean resolved()
      Specified by:
      resolved in interface Resolvable
    • dataType

      public abstract DataType dataType()
      The DataType returned by executing the tree rooted at this expression. If typeResolved() returns an error then the behavior of this method is undefined. It may return a valid type. Or it may throw an exception. Or it may return a totally nonsensical type.
    • toString

      public String toString()
      Overrides:
      toString in class Node<Expression>
    • propertiesToString

      public String propertiesToString(boolean skipIfChild)
      Description copied from class: Node
      Render the properties of this Node one by one like foo bar baz. These go inside the [ and ] of the output of Node.treeString(java.lang.StringBuilder, int, java.util.BitSet).
      Overrides:
      propertiesToString in class Node<Expression>