Class: Alf::Sql::Processor::Merge

Inherits:
Alf::Sql::Processor show all
Defined in:
lib/alf/sql/processor/merge.rb

Constant Summary

Constants inherited from Alf::Sql::Processor

UnexpectedError

Instance Attribute Summary

Attributes inherited from Alf::Sql::Processor

#builder

Instance Method Summary collapse

Methods inherited from Alf::Sql::Processor

#on_set_operator

Constructor Details

#initialize(kind, right, builder) ⇒ Merge

Returns a new instance of Merge.



6
7
8
9
10
# File 'lib/alf/sql/processor/merge.rb', line 6

def initialize(kind, right, builder)
  super(builder)
  @kind = kind
  @right = right
end

Instance Method Details

#on_nonjoin_exp(sexpr) ⇒ Object Also known as: on_union, on_except, on_intersect, on_select_exp



24
25
26
27
28
29
30
31
32
33
# File 'lib/alf/sql/processor/merge.rb', line 24

def on_nonjoin_exp(sexpr)
  reordered = Reorder.new(sexpr.to_attr_list, builder).call(@right)
  if @right.with_exp?
    [ :with_exp,
      reordered.with_spec,
      [ @kind, builder.distinct, sexpr, reordered.select_exp ] ]
  else
    [ @kind, builder.distinct, sexpr, reordered ]
  end
end

#on_with_exp(sexpr) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/alf/sql/processor/merge.rb', line 12

def on_with_exp(sexpr)
  if @right.with_exp?
    reordered = Reorder.new(sexpr.to_attr_list, builder).call(@right)
    main = [ @kind, builder.distinct, sexpr.select_exp, reordered.select_exp ]
    merge_with_exps(sexpr, reordered, main)
  else
    [ :with_exp,
      sexpr.with_spec,
      apply(sexpr.last) ]
  end
end