<commit_before>module ActiveRecord::Turntable
  module ActiveRecordExt
    module AbstractAdapter
      def translate_exception_class(e, sql)
        begin
          message = "#{e.class.name}: #{e.message}: #{sql} : #{turntable_shard_name}"
        rescue Encoding::CompatibilityError
          message = "#{e.class.name}: #{e.message.force_encoding sql.encoding}: #{sql} : #{turntable_shard_name}"
        end

        exception = translate_exception(e, message)
        exception.set_backtrace e.backtrace
        exception
      end

      # @note override for append current shard name
      # rubocop:disable Style/HashSyntax, Style/MultilineMethodCallBraceLayout
      def log(sql, name = "SQL", binds = [], statement_name = nil)
        @instrumenter.instrument(
          "sql.active_record",
          :sql                  => sql,
          :name                 => name,
          :connection_id        => object_id,
          :statement_name       => statement_name,
          :binds                => binds,
          :turntable_shard_name => turntable_shard_name) { yield }
      rescue => e
        raise translate_exception_class(e, sql)
      end
      # rubocop:enable Style/HashSyntax, Style/MultilineMethodCallBraceLayout

      protected :translate_exception_class, :log

      def turntable_shard_name=(name)
        @turntable_shard_name = name.to_s
      end

      def turntable_shard_name
        instance_variable_defined?(:@turntable_shard_name) ? @turntable_shard_name : nil
      end
    end
  end
end<commit_msg>Follow AbstractAdapter#log impl changes on 5.0.3<commit_after>module ActiveRecord::Turntable
  module ActiveRecordExt
    module AbstractAdapter
      def translate_exception_class(e, sql)
        begin
          message = "#{e.class.name}: #{e.message}: #{sql} : #{turntable_shard_name}"
        rescue Encoding::CompatibilityError
          message = "#{e.class.name}: #{e.message.force_encoding sql.encoding}: #{sql} : #{turntable_shard_name}"
        end

        exception = translate_exception(e, message)
        exception.set_backtrace e.backtrace
        exception
      end

      # @note override for append current shard name
      # rubocop:disable Style/HashSyntax, Style/MultilineMethodCallBraceLayout
      if ActiveRecord::Turntable::Util.ar_version_equals_or_later?("5.0.3")
        def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil)
          @instrumenter.instrument(
            "sql.active_record",
            sql:                  sql,
            name:                 name,
            binds:                binds,
            type_casted_binds:    type_casted_binds,
            statement_name:       statement_name,
            connection_id:        object_id,
            turntable_shard_name: turntable_shard_name) { yield }
        rescue => e
          raise translate_exception_class(e, sql)
        end
      else
        def log(sql, name = "SQL", binds = [], statement_name = nil)
          @instrumenter.instrument(
            "sql.active_record",
            :sql                  => sql,
            :name                 => name,
            :connection_id        => object_id,
            :statement_name       => statement_name,
            :binds                => binds,
            :turntable_shard_name => turntable_shard_name) { yield }
        rescue => e
          raise translate_exception_class(e, sql)
        end
      end
      # rubocop:enable Style/HashSyntax, Style/MultilineMethodCallBraceLayout

      protected :translate_exception_class, :log

      def turntable_shard_name=(name)
        @turntable_shard_name = name.to_s
      end

      def turntable_shard_name
        instance_variable_defined?(:@turntable_shard_name) ? @turntable_shard_name : nil
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08817373103087389, 'fraction_numerical': 0.0015698587127158557, 'mean_word_length': 2.151690024732069, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '3227704', 'n_tokens_mistral': 1128, 'n_tokens_neox': 1070, 'n_words': 217}