<commit_before>require 'salesforce_bulk_query/job'
require 'date'

module SalesforceBulkQuery

  # Abstraction of a single user-given query. It contains multiple jobs, is tied to a specific connection
  class Query

    # if no date_to is given we use the current time with this offset
    # subtracted (to make sure the freshest changes that can be inconsistent
    # aren't there) It's in minutes
    OFFSET_FROM_NOW = 10

    DEFAULT_DATE_FIELD = 'CreatedDate'

    def initialize(sobject, soql, connection, options={})
      @sobject = sobject
      @soql = soql
      @connection = connection
      @logger = options[:logger]
      @date_field = options[:date_field] || DEFAULT_DATE_FIELD
      @date_from = options[:date_from]
      @date_to = options[:date_to]
      @single_batch = options[:single_batch]

      # jobs currently running
      @jobs_in_progress = []

      # successfully finished jobs with no batches to split
      @jobs_done = []

      # finished or timeouted jobs with some batches split into other jobs
      @jobs_restarted = []

      @finished_batch_filenames = []
      @restarted_subqueries = []
    end

    attr_reader :jobs_in_progress, :jobs_restarted, :jobs_done

    DEFAULT_MIN_CREATED = "1999-01-01T00:00:00.000Z"

    # Creates the first job, divides the query to subqueries, puts all the subqueries as batches to the job
    def start(options={})
      # order by and where not allowed
      if (!@single_batch) && (@soql =~ /WHERE/i || @soql =~ /ORDER BY/i)
        raise "You can't have WHERE or ORDER BY in your soql. If you want to download just specific date range use date_from / date_to"
      end

      # create the first job
      job = SalesforceBulkQuery::Job.new(
        @sobject,
        @connection,
        {:logger => @logger, :date_field => @date_field}.merge(options)
      )
      job.create_job

      # get the date when it should start
      min_date = get_min_date

      # generate intervals
      start = DateTime.parse(min_date)
      stop = @date_to ? DateTime.parse(@date_to) : DateTime.now - Rational(options[:offset_from_now] || OFFSET_FROM_NOW, 1440)
      job.generate_batches(@soql, start, stop, @single_batch)<commit_msg>Ignore the WHERE in names of the fields of SOQL query<commit_after>require 'salesforce_bulk_query/job'
require 'date'

module SalesforceBulkQuery

  # Abstraction of a single user-given query. It contains multiple jobs, is tied to a specific connection
  class Query

    # if no date_to is given we use the current time with this offset
    # subtracted (to make sure the freshest changes that can be inconsistent
    # aren't there) It's in minutes
    OFFSET_FROM_NOW = 10

    DEFAULT_DATE_FIELD = 'CreatedDate'

    def initialize(sobject, soql, connection, options={})
      @sobject = sobject
      @soql = soql
      @connection = connection
      @logger = options[:logger]
      @date_field = options[:date_field] || DEFAULT_DATE_FIELD
      @date_from = options[:date_from]
      @date_to = options[:date_to]
      @single_batch = options[:single_batch]

      # jobs currently running
      @jobs_in_progress = []

      # successfully finished jobs with no batches to split
      @jobs_done = []

      # finished or timeouted jobs with some batches split into other jobs
      @jobs_restarted = []

      @finished_batch_filenames = []
      @restarted_subqueries = []
    end

    attr_reader :jobs_in_progress, :jobs_restarted, :jobs_done

    DEFAULT_MIN_CREATED = "1999-01-01T00:00:00.000Z"

    # Creates the first job, divides the query to subqueries, puts all the subqueries as batches to the job
    def start(options={})
      # order by and where not allowed
      if (!@single_batch) && (@soql =~ / WHERE /i || @soql =~ /ORDER BY/i)
        raise "You can't have WHERE or ORDER BY in your soql. If you want to download just specific date range use date_from / date_to"
      end

      # create the first job
      job = SalesforceBulkQuery::Job.new(
        @sobject,
        @connection,
        {:logger => @logger, :date_field => @date_field}.merge(options)
      )
      job.create_job

      # get the date when it should start
      min_date = get_min_date

      # generate intervals
      start = DateTime.parse(min_date)
      stop = @date_to ? DateTime.parse(@date_to) : DateTime.now - Rational(options[:offset_from_now] || OFFSET_FROM_NOW, 1440)
      job.generate_batches(@soql, start, stop, @single_batch)
{'fraction_non_alphanumeric': 0.08681961313540261, 'fraction_numerical': 0.0103463787674314, 'mean_word_length': 3.0317316409791477, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4992100', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1308, 'n_words': 424}