Class: ActiveRecord::Materialized::ViewDefinition Private
- Inherits:
-
Object
- Object
- ActiveRecord::Materialized::ViewDefinition
- Defined in:
- lib/activerecord/materialized/view_definition.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Inspects a source relation for its partition (maintenance) keys and builds partition scopes.
The keys are the relation's GROUP BY columns, or — for a SELECT DISTINCT a, b with no GROUP BY
and no aggregate — its projected columns, since a distinct lookup partitions exactly like a
GROUP BY of those columns.
Instance Method Summary collapse
- #group_key_columns ⇒ Object private
- #incrementally_maintainable? ⇒ Boolean private
-
#initialize(source, explicit_group_keys: nil) ⇒ ViewDefinition
constructor
private
A new instance of ViewDefinition.
-
#partition_scope(key_tuples) ⇒ Object
private
Restrict the source relation to the given partitions.
-
#partition_scope_on(model, key_tuples) ⇒ Object
private
Restrict a model/cache table to the given partitions.
Constructor Details
#initialize(source, explicit_group_keys: nil) ⇒ ViewDefinition
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ViewDefinition.
12 13 14 15 |
# File 'lib/activerecord/materialized/view_definition.rb', line 12 def initialize(source, explicit_group_keys: nil) @source = source @explicit_group_keys = explicit_group_keys end |
Instance Method Details
#group_key_columns ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
21 22 23 |
# File 'lib/activerecord/materialized/view_definition.rb', line 21 def group_key_columns @group_key_columns ||= resolve_group_key_columns end |
#incrementally_maintainable? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
17 18 19 |
# File 'lib/activerecord/materialized/view_definition.rb', line 17 def incrementally_maintainable? group_key_columns.any? end |
#partition_scope(key_tuples) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Restrict the source relation to the given partitions. Qualify each key to
its GROUP BY attribute's own table, which may be a joined table (e.g.
name.gender) rather than the source's base table.
38 39 40 41 42 43 |
# File 'lib/activerecord/materialized/view_definition.rb', line 38 def partition_scope(key_tuples) validate_partition_keys!(key_tuples) base = source.klass.arel_table attributes = group_key_columns.map { |column| source_attribute(column, base) } PartitionFilter.new(attributes, key_tuples).apply(source) end |
#partition_scope_on(model, key_tuples) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Restrict a model/cache table to the given partitions. The partition
columns are real columns on model, so qualify them to its own table.
27 28 29 30 31 32 33 |
# File 'lib/activerecord/materialized/view_definition.rb', line 27 def partition_scope_on(model, key_tuples) validate_partition_keys!(key_tuples) # On the cache/model table the key is the projected column, so a qualified # GROUP BY name (e.g. "authors.country") maps to the bare column ("country"). attributes = group_key_columns.map { |column| model.arel_table[unqualified(column)] } PartitionFilter.new(attributes, key_tuples).apply(model.unscoped) end |