All Implemented Interfaces:
NamedWriteable, Writeable, PostAnalysisPlanVerificationAware, PostOptimizationVerificationAware, Resolvable, ToAggregator

public class Sample extends AggregateFunction implements ToAggregator, PostOptimizationVerificationAware
  • Field Details

  • Constructor Details

    • Sample

      public Sample(Source source, Expression field, Expression limit)
    • Sample

      public Sample(Source source, Expression field, Expression filter, Expression window, Expression limit, Expression uuid)
      The query "FROM data | STATS s1=SAMPLE(x,N), s2=SAMPLE(x,N)" should give two different samples of size N. The uuid is used to ensure that the optimizer does not optimize both expressions to one, resulting in identical samples.
  • Method Details

    • resolveType

      protected Expression.TypeResolution resolveType()
      Description copied from class: Expression
      The implementation of Expression.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 Expression.childrenResolved() returns false.

      Overrides:
      resolveType in class AggregateFunction
    • getWriteableName

      public String getWriteableName()
      Specified by:
      getWriteableName in interface NamedWriteable
    • dataType

      public DataType dataType()
      Description copied from class: Expression
      The DataType returned by executing the tree rooted at this expression. If Expression.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.
      Specified by:
      dataType in class Expression
    • info

      protected NodeInfo<Sample> info()
      Description copied from class: Node
      Normally, you want to use one of the static create methods to implement this.

      For QueryPlans, it is very important that the properties contain all of the expressions and references relevant to this node, and that all the properties are used in the provided constructor; otherwise query plan transformations like QueryPlan#transformExpressionsOnly(Function) will not have an effect.

      Specified by:
      info in class Node<Expression>
    • replaceChildren

      public Sample replaceChildren(List<Expression> newChildren)
      Specified by:
      replaceChildren in class Node<Expression>
    • supplier

      public AggregatorFunctionSupplier supplier()
      Specified by:
      supplier in interface ToAggregator
    • withFilter

      public Sample withFilter(Expression filter)
      Description copied from class: AggregateFunction
      Attach a filter to the aggregate function.
      Specified by:
      withFilter in class AggregateFunction
    • postOptimizationVerification

      public void postOptimizationVerification(Failures failures)
      Description copied from interface: PostOptimizationVerificationAware
      Validates the implementing expression - discovered failures are reported to the given Failures class.

      Example: the Bucket function, which produces buckets over a numerical or date field, based on a number of literal arguments needs to check if its arguments are all indeed literals. This is how this verification is performed:

           
      
            @Override
            public void postOptimizationVerification(Failures failures) {
                String operation = sourceText();
      
                failures.add(isFoldable(buckets, operation, SECOND))
                    .add(from != null ? isFoldable(from, operation, THIRD) : null)
                    .add(to != null ? isFoldable(to, operation, FOURTH) : null);
            }
           
           
      Specified by:
      postOptimizationVerification in interface PostOptimizationVerificationAware