<commit_before>require_relative 'binary_operator_operator'

module ConceptQL
  module Operators
    class Except < BinaryOperatorOperator
      register __FILE__

      desc 'If a result in the left hand results (LHR) appears in the right hand results (RHR), it is removed from the output result set.'
      default_query_columns

      def query(db)
        if ignore_dates?
          query = db.from(Sequel.as(left.evaluate(db), :l))
            .left_join(Sequel.as(right.evaluate(db), :r), l__criterion_id: :r__criterion_id, l__criterion_domain: :r__criterion_domain)
            .where(r__criterion_id: nil)
            .select_all(:l)
          db.from(query)
        else
          lquery = left.evaluate(db)
          rquery = right.evaluate(db)

          # Set columns so that impala's EXCEPT emulation doesn't use a query to determine them
          lquery.instance_variable_set(:@columns, query_cols)
          rquery.instance_variable_set(:@columns, query_cols)

          lquery.except(rquery)
        end
      end

      private

      def ignore_dates?
        options[:ignore_dates]
      end
    end
  end
end<commit_msg>Except: Use better except strategy when Impala<commit_after>require_relative 'binary_operator_operator'

module ConceptQL
  module Operators
    class Except < BinaryOperatorOperator
      register __FILE__

      desc 'If a result in the left hand results (LHR) appears in the right hand results (RHR), it is removed from the output result set.'
      default_query_columns

      def query(db)
        if ignore_dates?
          query = db.from(Sequel.as(left.evaluate(db), :l))
            .left_join(Sequel.as(right.evaluate(db), :r), l__criterion_id: :r__criterion_id, l__criterion_domain: :r__criterion_domain)
            .where(r__criterion_id: nil)
            .select_all(:l)
          db.from(query)
        else
          lquery = left.evaluate(db)
          rquery = right.evaluate(db)

          # Set columns so that impala's EXCEPT emulation doesn't use a query to determine them
          lquery.instance_variable_set(:@columns, query_cols)
          rquery.instance_variable_set(:@columns, query_cols)

          if impala?
            lquery = lquery.except_strategy(:not_exists, :person_id, :criterion_id, :criterion_domain)
          end
          lquery.except(rquery)
        end
      end

      private

      def ignore_dates?
        options[:ignore_dates]
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.0762953896368829, 'fraction_numerical': 0.0, 'mean_word_length': 2.538239538239538, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2343060', 'n_tokens_mistral': 741, 'n_tokens_neox': 711, 'n_words': 189}