Module: ActiveRecord::ConnectionAdapters::ClickHouse::RelationWindowing

Defined in:
lib/active_record/connection_adapters/clickhouse/querying.rb

Overview

Projects one window expression per call, e.g. window(:sum, :battery, as: :drained, partition_by: :device_id, order_by: :observed_at). Arel's own Window/Over nodes do the rendering; the function name, alias and frame are the only free-form strings, so they are validated here.

Constant Summary collapse

WINDOW_IDENTIFIER =
/\A[A-Za-z_]\w*\z/
WINDOW_FRAME =
/\A(?:ROWS|RANGE|GROUPS)\b[\w\s]+\z/i

Instance Method Summary collapse

Instance Method Details

#window(function, *columns, as:, partition_by: nil, order_by: nil, frame: nil) ⇒ Object



161
162
163
# File 'lib/active_record/connection_adapters/clickhouse/querying.rb', line 161

def window(function, *columns, as:, partition_by: nil, order_by: nil, frame: nil)
  spawn.window!(function, *columns, as: as, partition_by: partition_by, order_by: order_by, frame: frame)
end

#window!(function, *columns, as:, partition_by: nil, order_by: nil, frame: nil) ⇒ Object



165
166
167
168
169
170
# File 'lib/active_record/connection_adapters/clickhouse/querying.rb', line 165

def window!(function, *columns, as:, partition_by: nil, order_by: nil, frame: nil)
  projection = window_projection(function, columns, window_definition(partition_by, order_by, frame))
  self.select_values += [klass.arel_table[::Arel.star]] if select_values.empty?
  self.select_values += [::Arel::Nodes::As.new(projection, ::Arel.sql(window_identifier(as, "alias")))]
  self
end