Class: Rooq::WindowFunction

Inherits:
Expression show all
Extended by:
T::Sig
Defined in:
lib/rooq/expression.rb

Overview

Window function expression

Constant Summary collapse

FrameBound =
T.type_alias { T.any(Symbol, T::Array[T.any(Symbol, Integer)]) }

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Expression

#%, #*, #+, #-, #/, #as, #asc, #between, #desc, #eq, #gt, #gte, #in, #is_not_null, #is_null, #like, #lt, #lte, #ne, #to_sql

Constructor Details

#initialize(function, partition_fields: [], order_specs: [], frame: nil) ⇒ void

Parameters:



253
254
255
256
257
258
# File 'lib/rooq/expression.rb', line 253

def initialize(function, partition_fields: [], order_specs: [], frame: nil)
  @function = function
  @partition_fields = T.let(Array(partition_fields).freeze, T::Array[Expression])
  @order_specs = T.let(Array(order_specs).freeze, T::Array[OrderSpecification])
  @frame = frame
end

Instance Attribute Details

#frameWindowFrame? (readonly)

Returns:



243
244
245
# File 'lib/rooq/expression.rb', line 243

def frame
  @frame
end

#functionFunctionCall (readonly)

Returns:



240
241
242
# File 'lib/rooq/expression.rb', line 240

def function
  @function
end

Instance Method Details

#order_by(*specs) ⇒ Array<OrderSpecification>, WindowFunction

Parameters:

Returns:



267
268
269
270
# File 'lib/rooq/expression.rb', line 267

def order_by(*specs)
  return @order_specs if specs.empty?
  WindowFunction.new(@function, partition_fields: @partition_fields, order_specs: @order_specs + specs.flatten, frame: @frame)
end

#over(partition_by: [], order_by: [], frame: nil) ⇒ WindowFunction

Parameters:

Returns:



297
298
299
# File 'lib/rooq/expression.rb', line 297

def over(partition_by: [], order_by: [], frame: nil)
  WindowFunction.new(@function, partition_fields: partition_by, order_specs: order_by, frame: frame)
end

#partition_by(*fields) ⇒ Array<Expression>, WindowFunction

Parameters:

Returns:



261
262
263
264
# File 'lib/rooq/expression.rb', line 261

def partition_by(*fields)
  return @partition_fields if fields.empty?
  WindowFunction.new(@function, partition_fields: @partition_fields + fields.flatten, order_specs: @order_specs, frame: @frame)
end

#range_between(start_bound, end_bound) ⇒ WindowFunction

Parameters:

Returns:



285
286
287
288
# File 'lib/rooq/expression.rb', line 285

def range_between(start_bound, end_bound)
  new_frame = WindowFrame.new(WindowFrame::RANGE, start_bound, end_bound)
  WindowFunction.new(@function, partition_fields: @partition_fields, order_specs: @order_specs, frame: new_frame)
end

#rows(start_bound, end_bound = nil) ⇒ WindowFunction

Parameters:

Returns:



273
274
275
276
# File 'lib/rooq/expression.rb', line 273

def rows(start_bound, end_bound = nil)
  new_frame = WindowFrame.new(WindowFrame::ROWS, start_bound, end_bound)
  WindowFunction.new(@function, partition_fields: @partition_fields, order_specs: @order_specs, frame: new_frame)
end

#rows_between(start_bound, end_bound) ⇒ WindowFunction

Parameters:

Returns:



279
280
281
282
# File 'lib/rooq/expression.rb', line 279

def rows_between(start_bound, end_bound)
  new_frame = WindowFrame.new(WindowFrame::ROWS, start_bound, end_bound)
  WindowFunction.new(@function, partition_fields: @partition_fields, order_specs: @order_specs, frame: new_frame)
end