Class: ActiveRecord::Refined::AST::Over

Inherits:
Node
  • Object
show all
Includes:
Arithmetics, Predications
Defined in:
lib/active_record/refined/ast.rb

Overview

A function with a window. The window is built by chaining, the way Arel's own is, and each method returns a new node rather than adding to this one, so a window can be finished more than one way.

Instance Method Summary collapse

Methods included from Arithmetics

#&, #*, #+, #-, #/, #<<, #>>, #^, #bitwise_and, #bitwise_not, #bitwise_or, #bitwise_xor, #|, #~

Methods included from Predications

#!=, #!~, #<, #<=, #==, #=~, #>, #>=, #between?, #bury, #casecmp?, #contains?, #dig, #dig_text, #distinct_from?, #end_with?, #except, #false?, #ilike?, #in?, #include?, #intersect?, #key?, #keys, #like?, #member?, #not_between?, #not_distinct_from?, #not_false?, #not_ilike?, #not_in?, #not_like?, #not_null?, #not_true?, #null?, #start_with?, #subset?, #superset?, #true?, #when

Methods inherited from Node

#as, #asc, #collate, #desc

Constructor Details

#initialize(function, partitions = [], orders = [], frame = nil) ⇒ Over

Returns a new instance of Over.



1699
1700
1701
1702
1703
1704
# File 'lib/active_record/refined/ast.rb', line 1699

def initialize(function, partitions = [], orders = [], frame = nil)
  @function = function
  @partitions = partitions
  @orders = orders
  @frame = frame
end

Instance Method Details

#order(*exprs) ⇒ AST::Over

ORDER BY within the window: columns, or orderings such as :age.desc.

Returns:

Raises:

  • (ArgumentError)


1715
1716
1717
1718
# File 'lib/active_record/refined/ast.rb', line 1715

def order(*exprs)
  raise ArgumentError, "order needs an expression" if exprs.empty?
  Over.new(function, partitions, orders + exprs, frame)
end

#partition(*exprs) ⇒ AST::Over

PARTITION BY, the columns or expressions given.

Returns:

Raises:

  • (ArgumentError)


1708
1709
1710
1711
# File 'lib/active_record/refined/ast.rb', line 1708

def partition(*exprs)
  raise ArgumentError, "partition needs an expression" if exprs.empty?
  Over.new(function, partitions + exprs, orders, frame)
end

#range(bounds) ⇒ AST::Over

RANGE BETWEEN, with the bounds as #rows takes them.

Parameters:

  • bounds (Range)

Returns:



1730
1731
1732
# File 'lib/active_record/refined/ast.rb', line 1730

def range(bounds)
  Over.new(function, partitions, orders, framing(:range, bounds))
end

#rows(bounds) ⇒ AST::Over

ROWS BETWEEN, as a range of rows counted from the current one: negative before it, positive after, 0 the row itself, an open end unbounded. rows(..0) is a running total, rows(-1..1) the row and its neighbours.

Parameters:

  • bounds (Range)

Returns:



1723
1724
1725
# File 'lib/active_record/refined/ast.rb', line 1723

def rows(bounds)
  Over.new(function, partitions, orders, framing(:rows, bounds))
end