Sha256: 447c13528e8ce428bf51f2684a4bbc578f08e565048ad7912b9e897a8e27d3ec

Contents?: true

Size: 1012 Bytes

Versions: 5

Compression:

Stored size: 1012 Bytes

Contents

module Alf
  module Engine
    #
    # Provides hash-based join.
    #
    class Join::Hash
      include Join
      include Cog

      # @return [Enumerable] The left operand
      attr_reader :left

      # @return [Enumerable] The right operand
      attr_reader :right

      # Creates a Join::Hash instance
      def initialize(left, right, expr = nil, compiler = nil)
        super(expr, compiler)
        @left = left
        @right = right
      end

      # Returns left and right operands in an array
      def operands
        [ left, right ]
      end

      # (see Cog#each)
      def _each(&block)
        index = nil
        left.each do |left_tuple|
          index ||= Materialize::Hash.new(right, lambda{|t|
            AttrList.new(left_tuple.keys & t.keys)
          }, false, expr).prepare
          index[left_tuple, true].each do |right_tuple|
            yield left_tuple.merge(right_tuple)
          end
        end
      end

    end # class Hash
  end # module Engine
end # module Alf

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alf-core-0.16.3 lib/alf/engine/join/hash.rb
alf-core-0.16.2 lib/alf/engine/join/hash.rb
alf-core-0.16.1 lib/alf/engine/join/hash.rb
alf-core-0.16.0 lib/alf/engine/join/hash.rb
alf-core-0.15.0 lib/alf/engine/join/hash.rb