Class: Polars::QueryOptFlags

Inherits:
Object
  • Object
show all
Defined in:
lib/polars/query_opt_flags.rb

Overview

Note:

This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.

The set of the optimizations considered during query optimization.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(predicate_pushdown: nil, projection_pushdown: nil, simplify_expression: nil, slice_pushdown: nil, comm_subplan_elim: nil, comm_subexpr_elim: nil, cluster_with_columns: nil, collapse_joins: nil, check_order_observe: nil, fast_projection: nil, sort_collapse: nil) ⇒ QueryOptFlags

Returns a new instance of QueryOptFlags.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/polars/query_opt_flags.rb', line 11

def initialize(
  predicate_pushdown: nil,
  projection_pushdown: nil,
  simplify_expression: nil,
  slice_pushdown: nil,
  comm_subplan_elim: nil,
  comm_subexpr_elim: nil,
  cluster_with_columns: nil,
  collapse_joins: nil,
  check_order_observe: nil,
  fast_projection: nil,
  sort_collapse: nil
)
  self._rboptflags = RbOptFlags.default
  update(
    predicate_pushdown: predicate_pushdown,
    projection_pushdown: projection_pushdown,
    simplify_expression: simplify_expression,
    slice_pushdown: slice_pushdown,
    comm_subplan_elim: comm_subplan_elim,
    comm_subexpr_elim: comm_subexpr_elim,
    cluster_with_columns: cluster_with_columns,
    collapse_joins: collapse_joins,
    check_order_observe: check_order_observe,
    fast_projection: fast_projection,
    sort_collapse: sort_collapse
  )
end

Class Method Details

._eagerObject

Create new empty set off optimizations.



128
129
130
131
132
133
134
# File 'lib/polars/query_opt_flags.rb', line 128

def self._eager
  optflags = QueryOptFlags.new
  optflags.no_optimizations
  optflags._rboptflags.eager = true
  optflags.simplify_expression = true
  optflags
end

.none(predicate_pushdown: nil, projection_pushdown: nil, simplify_expression: nil, slice_pushdown: nil, comm_subplan_elim: nil, comm_subexpr_elim: nil, cluster_with_columns: nil, collapse_joins: nil, check_order_observe: nil, fast_projection: nil, sort_collapse: nil) ⇒ Object

Create new empty set off optimizations.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/polars/query_opt_flags.rb', line 41

def self.none(
  predicate_pushdown: nil,
  projection_pushdown: nil,
  simplify_expression: nil,
  slice_pushdown: nil,
  comm_subplan_elim: nil,
  comm_subexpr_elim: nil,
  cluster_with_columns: nil,
  collapse_joins: nil,
  check_order_observe: nil,
  fast_projection: nil,
  sort_collapse: nil
)
  optflags = QueryOptFlags.new
  optflags.no_optimizations
  optflags.update(
    predicate_pushdown: predicate_pushdown,
    projection_pushdown: projection_pushdown,
    simplify_expression: simplify_expression,
    slice_pushdown: slice_pushdown,
    comm_subplan_elim: comm_subplan_elim,
    comm_subexpr_elim: comm_subexpr_elim,
    cluster_with_columns: cluster_with_columns,
    collapse_joins: collapse_joins,
    check_order_observe: check_order_observe,
    fast_projection: fast_projection,
    sort_collapse: sort_collapse
  )
end

Instance Method Details

#check_order_observeObject

Do not maintain order if the order would not be observed.



205
206
207
# File 'lib/polars/query_opt_flags.rb', line 205

def check_order_observe
  _rboptflags.check_order_observe
end

#check_order_observe=(value) ⇒ Object



209
210
211
# File 'lib/polars/query_opt_flags.rb', line 209

def check_order_observe=(value)
  _rboptflags.check_order_observe = value
end

#cluster_with_columnsObject

Cluster sequential with_columns calls to independent calls.



160
161
162
# File 'lib/polars/query_opt_flags.rb', line 160

def cluster_with_columns
  _rboptflags.cluster_with_columns
end

#cluster_with_columns=(value) ⇒ Object



164
165
166
# File 'lib/polars/query_opt_flags.rb', line 164

def cluster_with_columns=(value)
  _rboptflags.cluster_with_columns = value
end

#comm_subexpr_elimObject

Elide duplicate expressions and caches their outputs.



196
197
198
# File 'lib/polars/query_opt_flags.rb', line 196

def comm_subexpr_elim
  _rboptflags.comm_subexpr_elim
end

#comm_subexpr_elim=(value) ⇒ Object



200
201
202
# File 'lib/polars/query_opt_flags.rb', line 200

def comm_subexpr_elim=(value)
  _rboptflags.comm_subexpr_elim = value
end

#comm_subplan_elimObject

Elide duplicate plans and caches their outputs.



187
188
189
# File 'lib/polars/query_opt_flags.rb', line 187

def comm_subplan_elim
  _rboptflags.comm_subplan_elim
end

#comm_subplan_elim=(value) ⇒ Object



191
192
193
# File 'lib/polars/query_opt_flags.rb', line 191

def comm_subplan_elim=(value)
  _rboptflags.comm_subplan_elim = value
end

#fast_projectionObject

Replace simple projections with a faster inlined projection that skips the expression engine.



214
215
216
# File 'lib/polars/query_opt_flags.rb', line 214

def fast_projection
  _rboptflags.fast_projection
end

#fast_projection=(value) ⇒ Object



218
219
220
# File 'lib/polars/query_opt_flags.rb', line 218

def fast_projection=(value)
  _rboptflags.fast_projection = value
end

#no_optimizationsObject

Remove selected optimizations.



137
138
139
# File 'lib/polars/query_opt_flags.rb', line 137

def no_optimizations
  _rboptflags.no_optimizations
end

#predicate_pushdownObject

Apply predicates/filters as early as possible.



151
152
153
# File 'lib/polars/query_opt_flags.rb', line 151

def predicate_pushdown
  _rboptflags.predicate_pushdown
end

#predicate_pushdown=(value) ⇒ Object



155
156
157
# File 'lib/polars/query_opt_flags.rb', line 155

def predicate_pushdown=(value)
  _rboptflags.predicate_pushdown = value
end

#projection_pushdownObject

Only read columns that are used later in the query.



142
143
144
# File 'lib/polars/query_opt_flags.rb', line 142

def projection_pushdown
  _rboptflags.projection_pushdown
end

#projection_pushdown=(value) ⇒ Object



146
147
148
# File 'lib/polars/query_opt_flags.rb', line 146

def projection_pushdown=(value)
  _rboptflags.projection_pushdown = value
end

#simplify_expressionObject

Run many expression optimization rules until fixed point.



169
170
171
# File 'lib/polars/query_opt_flags.rb', line 169

def simplify_expression
  _rboptflags.simplify_expression
end

#simplify_expression=(value) ⇒ Object



173
174
175
# File 'lib/polars/query_opt_flags.rb', line 173

def simplify_expression=(value)
  _rboptflags.simplify_expression = value
end

#slice_pushdownObject

Pushdown slices/limits.



178
179
180
# File 'lib/polars/query_opt_flags.rb', line 178

def slice_pushdown
  _rboptflags.slice_pushdown
end

#slice_pushdown=(value) ⇒ Object



182
183
184
# File 'lib/polars/query_opt_flags.rb', line 182

def slice_pushdown=(value)
  _rboptflags.slice_pushdown = value
end

#sort_collapseObject

Collapse sequential sort nodes into a single sort node.



223
224
225
# File 'lib/polars/query_opt_flags.rb', line 223

def sort_collapse
  _rboptflags.sort_collapse
end

#sort_collapse=(value) ⇒ Object



227
228
229
# File 'lib/polars/query_opt_flags.rb', line 227

def sort_collapse=(value)
  _rboptflags.sort_collapse = value
end

#to_sObject Also known as: inspect



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/polars/query_opt_flags.rb', line 231

def to_s
  <<~STR
    QueryOptFlags {
        type_coercion: #{_rboptflags.type_coercion}
        type_check: #{_rboptflags.type_check}

        predicate_pushdown: #{predicate_pushdown}
        projection_pushdown: #{projection_pushdown}
        simplify_expression: #{simplify_expression}
        slice_pushdown: #{slice_pushdown}
        comm_subplan_elim: #{comm_subplan_elim}
        comm_subexpr_elim: #{comm_subexpr_elim}
        cluster_with_columns: #{cluster_with_columns}
        check_order_observe: #{check_order_observe}
        fast_projection: #{fast_projection}

        eager: #{_rboptflags.eager}
        streaming: #{_rboptflags.streaming}
    }
  STR
end

#update(predicate_pushdown: nil, projection_pushdown: nil, simplify_expression: nil, slice_pushdown: nil, comm_subplan_elim: nil, comm_subexpr_elim: nil, cluster_with_columns: nil, collapse_joins: nil, check_order_observe: nil, fast_projection: nil, sort_collapse: nil) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/polars/query_opt_flags.rb', line 71

def update(
  predicate_pushdown: nil,
  projection_pushdown: nil,
  simplify_expression: nil,
  slice_pushdown: nil,
  comm_subplan_elim: nil,
  comm_subexpr_elim: nil,
  cluster_with_columns: nil,
  collapse_joins: nil,
  check_order_observe: nil,
  fast_projection: nil,
  sort_collapse: nil
)
  if !predicate_pushdown.nil?
    self.predicate_pushdown = predicate_pushdown
  end
  if !projection_pushdown.nil?
    self.projection_pushdown = projection_pushdown
  end
  if !simplify_expression.nil?
    self.simplify_expression = simplify_expression
  end
  if !slice_pushdown.nil?
    self.slice_pushdown = slice_pushdown
  end
  if !comm_subplan_elim.nil?
    self.comm_subplan_elim = comm_subplan_elim
  end
  if !comm_subexpr_elim.nil?
    self.comm_subexpr_elim = comm_subexpr_elim
  end
  if !cluster_with_columns.nil?
    self.cluster_with_columns = cluster_with_columns
  end
  if !collapse_joins.nil?
    Utils.issue_deprecation_warning(
      "the `collapse_joins` parameter for `QueryOptFlags` is deprecated. " +
      "Use `predicate_pushdown` instead."
    )
    if !collapse_joins
      self.predicate_pushdown = false
    end
  end
  if !check_order_observe.nil?
    self.check_order_observe = check_order_observe
  end
  if !fast_projection.nil?
    self.fast_projection = fast_projection
  end
  if !sort_collapse.nil?
    self.sort_collapse = sort_collapse
  end

  self
end