<commit_before>module Arel
  class Table
    include Relation, Recursion::BaseCase

    cattr_accessor :engine, :tables
    attr_reader :name, :engine, :table_alias, :options

    def initialize(name, options = {})
      @name = name.to_s
      @table_exists = nil

      if options.is_a?(Hash)
        @options = options
        @engine = options[:engine] || Table.engine
        @table_alias = options[:as].to_s if options[:as].present? && options[:as].to_s != @name
      else
        @engine = options # Table.new('foo', engine)
      end

      if @engine.connection
        begin
          require "arel/engines/sql/compilers/#{@engine.adapter_name.downcase}_compiler"
          @@tables ||= engine.tables
        rescue LoadError
          raise "#{@engine.adapter_name} is not supported by Arel."
        end
      end
    end

    def as(table_alias)
      Table.new(name, options.merge(:as => table_alias))
    end

    def table_exists?
      if @table_exists
        true
      else
        @table_exists = @@tables.include?(name) || engine.table_exists?(name)
      end
    end

    def attributes
      return @attributes if defined?(@attributes)
      if table_exists?
        @attributes ||= begin
          attrs = columns.collect do |column|
            Sql::Attributes.for(column).new(column, self, column.name.to_sym)
          end<commit_msg>Allow externally defined AR adapters to define their own compiler.<commit_after>module Arel
  class Table
    include Relation, Recursion::BaseCase

    cattr_accessor :engine, :tables
    attr_reader :name, :engine, :table_alias, :options

    def initialize(name, options = {})
      @name = name.to_s
      @table_exists = nil

      if options.is_a?(Hash)
        @options = options
        @engine = options[:engine] || Table.engine
        @table_alias = options[:as].to_s if options[:as].present? && options[:as].to_s != @name
      else
        @engine = options # Table.new('foo', engine)
      end

      if @engine.connection
        begin
          require "arel/engines/sql/compilers/#{@engine.adapter_name.downcase}_compiler"
        rescue LoadError
          begin
            # try to load an externally defined compiler, in case this adapter has defined the compiler on its own.
            require "#{@engine.adapter_name.downcase}/arel_compiler"
          rescue LoadError
            raise "#{@engine.adapter_name} is not supported by Arel."
          end
        end

        @@tables ||= engine.tables
      end
    end

    def as(table_alias)
      Table.new(name, options.merge(:as => table_alias))
    end

    def table_exists?
      if @table_exists
        true
      else
        @table_exists = @@tables.include?(name) || engine.table_exists?(name)
      end
    end

    def attributes
      return @attributes if defined?(@attributes)
      if table_exists?
        @attributes ||= begin
          attrs = columns.collect do |column|
            Sql::Attributes.for(column).new(column, self, column.name.to_sym)
          end
{'fraction_non_alphanumeric': 0.10489741892786235, 'fraction_numerical': 0.0, 'mean_word_length': 2.3256325632563257, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3091640', 'n_tokens_mistral': 872, 'n_tokens_neox': 860, 'n_words': 222}