<commit_before>require 'rbhive'
require 'tempfile'
require 'yaml'

module HiveTests
  class Connector
    attr_reader :result, :config

    def initialize(configuration)
      @config = configuration
      # transport: :sasl, sasl_params: {username: 'hive', password: ''},
    end

    def start_connection(db_name = HiveTests::DbName.random_name)
      connection = open_connection
      connection.switch_database(db_name)
      config = [
        'SET hive.exec.dynamic.partition = true;',
        'SET hive.exec.dynamic.partition.mode = nonstrict;',
        'SET hive.exec.max.dynamic.partitions.pernodexi=100000;',
        'SET hive.exec.max.dynamic.partitions=100000;'
      ]
      config.each do |c|
        connection.execute(c)
      end

      connection

    rescue Thrift::ApplicationException => _
      stop_connection(connection)
      connection
    end

    def stop_connection(connection)
      connection.close_session if connection.session
      connection.close
    rescue IOError => e
      config.logger.fatal('An exception was thrown during close connection')
      config.logger.fatal(e)
    end

    def tlcli_connect
      RBHive.tcli_connect(@config.host,
                          @config.port,
                          connection_options) do |connection|
        yield HiveTests::ConnectionDelegator.new(connection, @config)
      end
    end

    private

    def open_connection
      connection = RBHive::TCLIConnection.new(
        @config.host,
        @config.port,
        connection_options
      )
      connection = HiveTests::ConnectionDelegator.new(connection, @config)

      connection.open
      connection.open_session
      connection
    end

    def connection_options
      {
        hive_version: @config.hive_version,
        transport: :sasl,
        sasl_params: {},
        logger: @config.logger
      }
    end
  end
end
<commit_msg>Added logging exception to start_connection<commit_after>require 'rbhive'
require 'tempfile'
require 'yaml'

module HiveTests
  class Connector
    attr_reader :result, :config

    def initialize(configuration)
      @config = configuration
      # transport: :sasl, sasl_params: {username: 'hive', password: ''},
    end

    def start_connection(db_name = HiveTests::DbName.random_name)
      connection = open_connection
      connection.switch_database(db_name)
      config = [
        'SET hive.exec.dynamic.partition = true;',
        'SET hive.exec.dynamic.partition.mode = nonstrict;',
        'SET hive.exec.max.dynamic.partitions.pernodexi=100000;',
        'SET hive.exec.max.dynamic.partitions=100000;'
      ]
      config.each do |c|
        connection.execute(c)
      end

      connection

    rescue Thrift::ApplicationException => e
      config.logger.fatal('An exception was thrown during start connection')
      config.logger.fatal(e)
      stop_connection(connection)
      connection
    end

    def stop_connection(connection)
      connection.close_session if connection.session
      connection.close
    rescue IOError => e
      config.logger.fatal('An exception was thrown during close connection')
      config.logger.fatal(e)
    end

    def tlcli_connect
      RBHive.tcli_connect(@config.host,
                          @config.port,
                          connection_options) do |connection|
        yield HiveTests::ConnectionDelegator.new(connection, @config)
      end
    end

    private

    def open_connection
      connection = RBHive::TCLIConnection.new(
        @config.host,
        @config.port,
        connection_options
      )
      connection = HiveTests::ConnectionDelegator.new(connection, @config)

      connection.open
      connection.open_session
      connection
    end

    def connection_options
      {
        hive_version: @config.hive_version,
        transport: :sasl,
        sasl_params: {},
        logger: @config.logger
      }
    end
  end
end

{'fraction_non_alphanumeric': 0.08622448979591837, 'fraction_numerical': 0.006122448979591836, 'mean_word_length': 2.4607237422771404, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6315349', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1108, 'n_words': 231}