Sha256: f2be4d2cd72f69dbc529d44634e25721d3f1c558d093165739d0f22b36f6209e

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

module Alf
  module Sql
    class Processor
      class Merge < Processor

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

        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

        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
        alias :on_union      :on_nonjoin_exp
        alias :on_except     :on_nonjoin_exp
        alias :on_intersect  :on_nonjoin_exp
        alias :on_select_exp :on_nonjoin_exp

      end # class Merge
    end # class Processor
  end # module Sql
end # module Alf

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alf-sql-0.16.3 lib/alf/sql/processor/merge.rb
alf-sql-0.16.2 lib/alf/sql/processor/merge.rb
alf-sql-0.16.1 lib/alf/sql/processor/merge.rb
alf-sql-0.16.0 lib/alf/sql/processor/merge.rb
alf-sql-0.15.0 lib/alf/sql/processor/merge.rb