Class: Alf::Optimizer::Restrict

Inherits:
Base show all
Defined in:
lib/alf/optimizer/restrict.rb

Instance Method Summary collapse

Methods inherited from Base

#call

Methods included from Lang::Functional

#Heading, #Relation, #Tuple, def_aggregator_method, def_operator_method

Methods inherited from Algebra::Rewriter

#call, #not_supported, #on_shortcut

Methods included from Algebra::Visitor

#copy_and_apply

Instance Method Details

#_call(restrict, search) ⇒ Object


11
12
13
# File 'lib/alf/optimizer/restrict.rb', line 11

def _call(restrict, search)
  apply(restrict.operand, restrict.predicate, search)
end

#apply(operand, predicate, search) ⇒ Object


19
20
21
22
23
# File 'lib/alf/optimizer/restrict.rb', line 19

def apply(operand, predicate, search)
  check_constant(operand, predicate){ super }
rescue NotSupportedError
  restrict(operand, predicate)
end

#on_autonum(expr, predicate, search) ⇒ Object

non relational


62
63
64
# File 'lib/alf/optimizer/restrict.rb', line 62

def on_autonum(expr, predicate, search)
  unary_split(expr, predicate, AttrList[expr.as], search)
end

#on_binary_optimizable(expr, predicate, search) ⇒ Object Also known as: on_join, on_matching, on_not_matching


53
54
55
# File 'lib/alf/optimizer/restrict.rb', line 53

def on_binary_optimizable(expr, predicate, search)
  binary_split(expr, predicate, search)
end

#on_coerce(expr, predicate, search) ⇒ Object


66
67
68
# File 'lib/alf/optimizer/restrict.rb', line 66

def on_coerce(expr, predicate, search)
  unary_split(expr, predicate, expr.coercions.to_attr_list, search)
end

#on_defaults(expr, predicate, search) ⇒ Object


70
71
72
# File 'lib/alf/optimizer/restrict.rb', line 70

def on_defaults(expr, predicate, search)
  unary_split(expr, predicate, expr.defaults.to_attr_list, search)
end

#on_extend(expr, predicate, search) ⇒ Object

relational


76
77
78
# File 'lib/alf/optimizer/restrict.rb', line 76

def on_extend(expr, predicate, search)
  unary_split(expr, predicate, expr.ext.to_attr_list, search)
end

#on_group(expr, predicate, search) ⇒ Object


80
81
82
# File 'lib/alf/optimizer/restrict.rb', line 80

def on_group(expr, predicate, search)
  unary_split(expr, predicate, AttrList[expr.as], search)
end

#on_leaf_operand(expr, predicate, search) ⇒ Object Also known as: on_missing

leaf Operand, recursion end :-)


27
28
29
# File 'lib/alf/optimizer/restrict.rb', line 27

def on_leaf_operand(expr, predicate, search)
  restrict(expr, predicate)
end

#on_pass_through(expr, predicate, search) ⇒ Object Also known as: on_allbut, on_clip, on_compact, on_sort, on_project, on_intersect, on_minus, on_union

pass through, unoptimizable, binary optimizable


34
35
36
# File 'lib/alf/optimizer/restrict.rb', line 34

def on_pass_through(expr, predicate, search)
  expr.with_operands(*expr.operands.map{|op| apply(op, predicate, search) })
end

#on_quota(expr, predicate, search) ⇒ Object


84
85
86
# File 'lib/alf/optimizer/restrict.rb', line 84

def on_quota(expr, predicate, search)
  unary_split(expr, predicate, expr.summarization.to_attr_list, search)
end

#on_rank(expr, predicate, search) ⇒ Object


88
89
90
# File 'lib/alf/optimizer/restrict.rb', line 88

def on_rank(expr, predicate, search)
  unary_split(expr, predicate, AttrList[expr.as], search)
end

#on_rename(expr, predicate, search) ⇒ Object


92
93
94
95
# File 'lib/alf/optimizer/restrict.rb', line 92

def on_rename(expr, predicate, search)
  predicate = predicate.rename(expr.renaming.invert)
  on_pass_through(expr, predicate, search)
end

#on_restrict(expr, predicate, search) ⇒ Object


97
98
99
100
101
102
103
# File 'lib/alf/optimizer/restrict.rb', line 97

def on_restrict(expr, predicate, search)
  if predicate.native? or expr.predicate.native?
    restrict(expr, predicate)
  else
    apply(expr.operand, predicate & expr.predicate, search)
  end
end

#on_summarize(expr, predicate, search) ⇒ Object


105
106
107
# File 'lib/alf/optimizer/restrict.rb', line 105

def on_summarize(expr, predicate, search)
  unary_split(expr, predicate, expr.summarization.to_attr_list, search)
end

#on_ungroup(expr, predicate, search) ⇒ Object


109
110
111
112
# File 'lib/alf/optimizer/restrict.rb', line 109

def on_ungroup(expr, predicate, search)
  # TODO:
  restrict(expr, predicate)
end

#on_unoptimizable(expr, predicate, search) ⇒ Object Also known as: on_generator, on_page, on_frame


46
47
48
# File 'lib/alf/optimizer/restrict.rb', line 46

def on_unoptimizable(expr, predicate, search)
  restrict(search.call(expr), predicate)
end

#on_unwrap(expr, predicate, search) ⇒ Object


114
115
116
117
118
119
120
121
122
# File 'lib/alf/optimizer/restrict.rb', line 114

def on_unwrap(expr, predicate, search)
  wrapped_type = expr.operand.heading[expr.attribute]
  if wrapped_type < Tuple
    attributes = wrapped_type.to_heading.to_attr_list
    unary_split(expr, predicate, attributes, search)
  else
    restrict(expr, predicate)
  end
end

#on_wrap(expr, predicate, search) ⇒ Object


124
125
126
# File 'lib/alf/optimizer/restrict.rb', line 124

def on_wrap(expr, predicate, search)
  unary_split(expr, predicate, AttrList[expr.as], search)
end

#restrict(operand, predicate) ⇒ Object


15
16
17
# File 'lib/alf/optimizer/restrict.rb', line 15

def restrict(operand, predicate)
  check_constant(operand, predicate){ super }
end

#search_predicateObject

overridings


7
8
9
# File 'lib/alf/optimizer/restrict.rb', line 7

def search_predicate
  Algebra::Restrict
end