<commit_before>module Bigqueryid
  module Criteria
    # Defines behaviour for query operations.
    module Queryable
      extend ActiveSupport::Concern

      class_methods do

        def run(query)
          result = bigquery.query query
          new(result.first) if result.count == 1
        end

        def fetch(query)
          result = bigquery.query query
          if result.count > 0
            result.map { |element| new(element) }
          else
            []
          end
        end
      end
    end
  end
end<commit_msg>Add method .where to search rows<commit_after>module Bigqueryid
  module Criteria
    # Defines behaviour for query operations.
    module Queryable
      extend ActiveSupport::Concern

      class_methods do

        def where(filter)
          return [] if filter.empty?

          where = []
          filter.each do |key, value|
            filter[key] = coercer.coerce(key, value)
            where << "#{key} = @#{key}"
          end

          query = "SELECT * FROM #{dataset_name}.#{table_name}" \
                  " WHERE #{where.join(' AND ')}"

          result = bigquery.query(query, params: filter)
          result.map do |row|
            new(row.select { |f| attributes.include?(f) })
          end
        end

        def run(query)
          result = bigquery.query query
          new(result.first) if result.count == 1
        end

        def fetch(query)
          result = bigquery.query query
          if result.count > 0
            result.map { |element| new(element) }
          else
            []
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08538083538083538, 'fraction_numerical': 0.002457002457002457, 'mean_word_length': 1.5413416536661466, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1867663', 'n_tokens_mistral': 449, 'n_tokens_neox': 433, 'n_words': 126}