class BeamSqlSingleElementExpression extends BeamSqlExpression {

  @Override
  public BeamSqlPrimitive evaluate(
      Row inputRow, BoundedWindow window, BeamSqlExpressionEnvironment env) {
    Collection<Object> collection = (Collection) opValueEvaluated(0, inputRow, window, env);

    if (collection.size() <= 1) {
      return collection.isEmpty()
          ? BeamSqlPrimitive.of(outputType, null)
          : BeamSqlPrimitive.of(outputType, collection.iterator().next());
    }

    throw new IllegalArgumentException(
        "ELEMENT expression accepts either empty collections "
            + "or collections with a single element. "
            + "Received collection with "
            + collection.size()
            + " elements");
  }

  public  BeamSqlSingleElementExpression(List<BeamSqlExpression> operands, SqlTypeName sqlTypeName);

}