<commit_before>require 'chicago/etl/sink'

module Chicago
  module ETL
    # Wrapper around a dataset to allowed buffered inserts.
    #
    # @api public
    class BufferingInsertWriter < Sink
      # The number of rows written before inserting to the DB.
      BUFFER_SIZE = 10_000
      
      def initialize(dataset, column_names, key=nil)
        super([], column_names, key)
        @dataset = dataset
      end
      
      def flush
        @dataset.insert_replace.multi_insert(output)
        output.clear
      end

      protected

      def write(row)
        output << @column_names.map {|name| row[name] }
        flush if reached_buffer_limit?
      end

      private

      def reached_buffer_limit?
        output.size >= BUFFER_SIZE
      end
    end
  end
end
<commit_msg>Fix buffering insert writer.<commit_after>require 'chicago/etl/sink'

module Chicago
  module ETL
    # Wrapper around a dataset to allowed buffered inserts.
    #
    # @api public
    class BufferingInsertWriter < Sink
      # The number of rows written before inserting to the DB.
      BUFFER_SIZE = 10_000
      
      def initialize(dataset, column_names, key=nil)
        super([], column_names, key)
        @dataset = dataset
      end
      
      def flush
        @dataset.insert_replace.import(@column_names, output)
        output.clear
      end

      protected

      def write(row)
        output << @column_names.map {|name| row[name] }
        flush if reached_buffer_limit?
      end

      private

      def reached_buffer_limit?
        output.size >= BUFFER_SIZE
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.06654228855721393, 'fraction_numerical': 0.006218905472636816, 'mean_word_length': 2.106177606177606, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '2482253', 'n_tokens_mistral': 481, 'n_tokens_neox': 456, 'n_words': 136}