<commit_before># encoding: utf-8
require_relative './column'
require_relative './job'
require_relative './query_batcher'
require_relative './content_guesser'

require_relative '../../../../lib/cartodb/stats/importer'
require_relative '../../../dataservices-metrics/lib/geocoder_usage_metrics'

module CartoDB
  module Importer2
    class Georeferencer
      DEFAULT_BATCH_SIZE = 50000
      GEOMETRY_POSSIBLE_NAMES   = %w{ geometry the_geom wkb_geometry geom geojson wkt }
      DEFAULT_SCHEMA            = 'cdb_importer'
      THE_GEOM_WEBMERCATOR      = 'the_geom_webmercator'
      DIRECT_STATEMENT_TIMEOUT  = 1.hour * 1000

      def initialize(db, table_name, options, schema=DEFAULT_SCHEMA, job=nil, geometry_columns=nil, logger=nil)
        @db         = db
        @job        = job || Job.new({  logger: logger } )
        @table_name = table_name
        @schema     = schema
        @geometry_columns = geometry_columns || GEOMETRY_POSSIBLE_NAMES
        @from_geojson_with_transform = false
        @options = options
        @tracker = @options[:tracker] || lambda { |state| state }
        @content_guesser = CartoDB::Importer2::ContentGuesser.new(@db, @table_name, @schema, @options, @job)
        @importer_stats = CartoDB::Stats::Importer.instance
      end

      def set_importer_stats(importer_stats)
        @importer_stats = importer_stats
      end

      def mark_as_from_geojson_with_transform
        @from_geojson_with_transform = true
      end

      def run
        disable_autovacuum

        drop_the_geom_webmercator

        the_geom_column_name = create_the_geom_from_geometry_column  ||
          create_the_geom_from_ip_guessing      ||
          create_the_geom_from_country_guessing ||
          create_the_geom_from_namedplaces_guessing ||
          create_the_geom_in(table_name)

        enable_autovacuum

        raise GeometryCollectionNotSupportedError if get_geometry_type(the_geom_column_name || 'the_geom') == 'GEOMETRYCOLLECTION'
        self
      end

      def disable_autovacuum
        job.log "Disabling autovacuum for #{qualified_table_name}"<commit_msg>Change order of content guessing #7854<commit_after># encoding: utf-8
require_relative './column'
require_relative './job'
require_relative './query_batcher'
require_relative './content_guesser'

require_relative '../../../../lib/cartodb/stats/importer'
require_relative '../../../dataservices-metrics/lib/geocoder_usage_metrics'

module CartoDB
  module Importer2
    class Georeferencer
      DEFAULT_BATCH_SIZE = 50000
      GEOMETRY_POSSIBLE_NAMES   = %w{ geometry the_geom wkb_geometry geom geojson wkt }
      DEFAULT_SCHEMA            = 'cdb_importer'
      THE_GEOM_WEBMERCATOR      = 'the_geom_webmercator'
      DIRECT_STATEMENT_TIMEOUT  = 1.hour * 1000

      def initialize(db, table_name, options, schema=DEFAULT_SCHEMA, job=nil, geometry_columns=nil, logger=nil)
        @db         = db
        @job        = job || Job.new({  logger: logger } )
        @table_name = table_name
        @schema     = schema
        @geometry_columns = geometry_columns || GEOMETRY_POSSIBLE_NAMES
        @from_geojson_with_transform = false
        @options = options
        @tracker = @options[:tracker] || lambda { |state| state }
        @content_guesser = CartoDB::Importer2::ContentGuesser.new(@db, @table_name, @schema, @options, @job)
        @importer_stats = CartoDB::Stats::Importer.instance
      end

      def set_importer_stats(importer_stats)
        @importer_stats = importer_stats
      end

      def mark_as_from_geojson_with_transform
        @from_geojson_with_transform = true
      end

      def run
        disable_autovacuum

        drop_the_geom_webmercator

        the_geom_column_name = create_the_geom_from_geometry_column  ||
          create_the_geom_from_ip_guessing      ||
          create_the_geom_from_namedplaces_guessing ||
          create_the_geom_from_country_guessing ||
          create_the_geom_in(table_name)

        enable_autovacuum

        raise GeometryCollectionNotSupportedError if get_geometry_type(the_geom_column_name || 'the_geom') == 'GEOMETRYCOLLECTION'
        self
      end

      def disable_autovacuum
        job.log "Disabling autovacuum for #{qualified_table_name}"
{'fraction_non_alphanumeric': 0.08170473275253119, 'fraction_numerical': 0.007063809748057453, 'mean_word_length': 3.022727272727273, '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': '6979240', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1343, 'n_words': 232}