Sha256: be8129b062bdba95376228385aaa5baaa11390d418b09c876a573dafabbd1ed1

Contents?: true

Size: 566 Bytes

Versions: 1

Compression:

Stored size: 566 Bytes

Contents

require_relative 'pass_thru'

module ConceptQL
  module Operators
    class Count < PassThru
      desc 'Counts the number of results the exactly match across all columns.'
      allows_one_upstream

      def query(db)
        db.from(unioned(db))
          .group(*COLUMNS)
          .select(*(COLUMNS - [:value_as_number]))
          .select_append{count(1).as(:value_as_number)}
          .from_self
      end

      def unioned(db)
        upstreams.map { |c| c.evaluate(db) }.inject do |uni, q|
          uni.union(q)
        end
      end
    end
  end
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
conceptql-0.2.0 lib/conceptql/operators/count.rb