<commit_before>module ActiveRecord
  module MTI
    module QueryMethods

      private

      def build_arel
        arel = Arel::SelectManager.new(table.engine, table)

        build_joins(arel, joins_values.flatten) unless joins_values.empty?

        collapse_wheres(arel, (where_values - [''])) #TODO: Add uniq with real value comparison / ignore uniqs that have binds

        arel.having(*having_values.uniq.reject(&:blank?)) unless having_values.empty?

        build_mti(arel)

        arel.take(connection.sanitize_limit(limit_value)) if limit_value
        arel.skip(offset_value.to_i) if offset_value
        arel.group(*arel_columns(group_values.uniq.reject(&:blank?))) unless group_values.empty?

        build_order(arel)

        build_select(arel)

        arel.distinct(distinct_value)
        arel.from(build_from) if from_value
        arel.lock(lock_value) if lock_value

        arel
      end

      # Retrieve the OID as well on a default select
      def build_mti(arel)

        select_by_tableoid = select_values.delete(:tableoid) == :tableoid
        group_by_tableoid = group_values.delete(:tableoid) == :tableoid

        if tableoid?(@klass) || group_by_tableoid || select_by_tableoid
          arel.project(tableoid_project(@klass))
          arel.group(tableoid_group(@klass)) if group_values.any? || group_by_tableoid
        end

      end

      def tableoid?(klass)
        !@skip_tableoid_cast &&<commit_msg>build_arel is not private<commit_after>module ActiveRecord
  module MTI
    module QueryMethods

      def build_arel
        arel = Arel::SelectManager.new(table.engine, table)

        build_joins(arel, joins_values.flatten) unless joins_values.empty?

        collapse_wheres(arel, (where_values - [''])) #TODO: Add uniq with real value comparison / ignore uniqs that have binds

        arel.having(*having_values.uniq.reject(&:blank?)) unless having_values.empty?

        build_mti(arel)

        arel.take(connection.sanitize_limit(limit_value)) if limit_value
        arel.skip(offset_value.to_i) if offset_value
        arel.group(*arel_columns(group_values.uniq.reject(&:blank?))) unless group_values.empty?

        build_order(arel)

        build_select(arel)

        arel.distinct(distinct_value)
        arel.from(build_from) if from_value
        arel.lock(lock_value) if lock_value

        arel
      end

      private

      # Retrieve the OID as well on a default select
      def build_mti(arel)

        select_by_tableoid = select_values.delete(:tableoid) == :tableoid
        group_by_tableoid = group_values.delete(:tableoid) == :tableoid

        if tableoid?(@klass) || group_by_tableoid || select_by_tableoid
          arel.project(tableoid_project(@klass))
          arel.group(tableoid_group(@klass)) if group_values.any? || group_by_tableoid
        end

      end

      def tableoid?(klass)
        !@skip_tableoid_cast &&
{'fraction_non_alphanumeric': 0.09166092350103378, 'fraction_numerical': 0.0, 'mean_word_length': 3.020775623268698, 'pattern_counts': {'":': 0, '<': 3, '<?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': '235176', 'n_tokens_mistral': 928, 'n_tokens_neox': 873, 'n_words': 173}