<commit_before># encoding: utf-8

module CartoDB
  module Importer2
    # Overviews creation service
    #
    # Pending issues: metrics, quotas/limits, timing, logging, ...
    #
    class Overviews

      DEFAULT_MIN_ROWS = 1000000

      def initialize(runner, user, options = {})
        @runner = runner
        @user = user
        @schema = user.database_schema
        @database = user.in_database
        @min_rows = options[:min_rows] ||
                    Cartodb.get_config(:overviews, 'min_rows') ||
                    DEFAULT_MIN_ROWS
      end

      attr_reader :user, :min_rows, :schema

      # Obtain an object fo thandle the creation of overviews for a dataset
      def dataset(table_name)
        Dataset.new(self, table_name)
      end

      def log(message)
        @runner.log.append(message)
      end

      def get_table(table_name)
        UserTable.find_by_identifier(@user.id, table_name).service
      end

      def run_in_database(sql)
        # TODO: timing, exception handling, ...
        log("Will create overviews for #{@table_name}")
        @database.run sql
        log("Overviews created for #{@table_name}")
      end

      def can_create_overviews?
        @user.reload<commit_msg>Specific statemente timeout for overview creation<commit_after># encoding: utf-8

module CartoDB
  module Importer2
    # Overviews creation service
    #
    # Pending issues: metrics, quotas/limits, timing, logging, ...
    #
    class Overviews

      DEFAULT_MIN_ROWS = 1000000
      DEFAULT_STATEMENT_TIMEOUT = 10 * 60 * 1000 # ms

      def initialize(runner, user, options = {})
        @runner            = runner
        @user              = user
        @schema            = user.database_schema
        @min_rows          = options[:min_rows] ||
                             Cartodb.get_config(:overviews, 'min_rows') ||
                             DEFAULT_MIN_ROWS
        @statement_timeout = options[:statement_timeout] ||
                             Cartodb.get_config(:overviews, 'statement_timeout') ||
                             DEFAULT_STATEMENT_TIMEOUT
      end

      attr_reader :user, :min_rows, :schema

      # Obtain an object fo thandle the creation of overviews for a dataset
      def dataset(table_name)
        Dataset.new(self, table_name)
      end

      def log(message)
        @runner.log.append(message)
      end

      def get_table(table_name)
        UserTable.find_by_identifier(@user.id, table_name).service
      end

      def run_in_database(sql)
        # TODO: timing, exception handling, ...
        @user.transaction_with_timeout statement_timeout: @statement_timeout do |db|
          log("Will create overviews for #{@table_name}")
          db.run sql
          log("Overviews created for #{@table_name}")
        end
      end

      def can_create_overviews?
        @user.reload
{'fraction_non_alphanumeric': 0.08501742160278745, 'fraction_numerical': 0.009059233449477353, 'mean_word_length': 2.0445387062566276, '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': '1778421', 'n_tokens_mistral': 831, 'n_tokens_neox': 796, 'n_words': 196}