Sha256: 2a85a9b210c519e02762d0ed42501a2f41ca02023cdec917c2c8330c709d2a57

Contents?: true

Size: 747 Bytes

Versions: 4

Compression:

Stored size: 747 Bytes

Contents

module Piglet
  module Relation
    class Join # :nodoc:
      include Relation
    
      def initialize(relation, description)
        @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

4 entries across 4 versions & 1 rubygems

Version Path
piglet-0.2.4 lib/piglet/relation/join.rb
piglet-0.2.3 lib/piglet/relation/join.rb
piglet-0.2.2 lib/piglet/relation/join.rb
piglet-0.2.0 lib/piglet/relation/join.rb