Sha256: 7792a68846521e38b1396709bbed76c35867e64b761dfdd243178c6808bbd46b

Contents?: true

Size: 814 Bytes

Versions: 1

Compression:

Stored size: 814 Bytes

Contents

# encoding: utf-8

module Piglet
  module Relation
    class Join # :nodoc:
      include Relation
    
      def initialize(relation, interpreter, description)
        @interpreter = interpreter
        @join_fields = Hash[*description.select { |k, v| k.is_a?(Relation) }.flatten]
        @sources = @join_fields.keys
        @using = description[:using]
        @parallel = description[:parallel]
      end
      
      def schema
        schemas = @sources.map { |s| s.schema }
        schemas.first.union(schemas[1..-1])
      end
    
      def to_s
        joins = @sources.map { |s| "#{s.alias} BY #{@join_fields[s]}" }.join(', ')
        str  = "JOIN #{joins}"
        str << " USING \"#{@using.to_s}\"" if @using
        str << " PARALLEL #{@parallel}" if @parallel
        str
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
piglet-0.3.0 lib/piglet/relation/join.rb