def infer_schema(samples_count: 0, extended: false)
      if db_backend == :postgresql
        # Experimental
        sch = db_adapter.client.schema(read_dataset_name).to_h
        sch = sch.reject{ |k, v| k == :_id }.map { |k,v| [k, {type: v[:type].to_s}] }.to_h
        self.inferred_schema = sch
        save
        return sch
      end

      data_count = samples_count == 0 ? count : samples_count # invoked in the base class
      return {} if data_count == 0

      # find out how many batches are needed
      max_per_process = 1000
      max_per_process = limit_per_process if respond_to?(:limit_per_process) && limit_per_process > 0

      equal_split_per_process = (data_count / Parallel.processor_count.to_f).ceil
      count_per_process = [max_per_process, equal_split_per_process].min

      queries = ordered_system_id_queries(batch_size: count_per_process)[0...data_count]

      self.inferred_schema_at = Time.now
      self.inferred_schema_from = samples_count
      on_schema_inference_started

      sch = schema_inferrer.infer_schema(batch_count: queries.count, extended: extended) do |idx|
        progress = (idx / queries.count.to_f * 100).ceil
        on_schema_inference_progressed(pct_complete: progress)

        all(where: queries[idx])
      end

      self.inferred_schema = sch
      save
      on_schema_inference_finished

      sch
    end
def infer_schema(samples_count: 0, extended: false)
      if db_backend == :postgresql
        # Experimental
        sch = db_adapter.client.schema(read_dataset_name).to_h
        sch = sch.reject{ |k, v| k == :_id }.map { |k,v| [k, {type: v[:type].to_s}] }.to_h
        self.inferred_schema = sch
        save
        return sch
      end

      data_count = samples_count == 0 ? count : samples_count # invoked in the base class
      return {} if data_count == 0

      # find out how many batches are needed
      max_per_process = 1000
      max_per_process = limit_per_process if respond_to?(:limit_per_process) && limit_per_process > 0

      equal_split_per_process = (data_count / Parallel.processor_count.to_f).ceil
      count_per_process = [max_per_process, equal_split_per_process].min

      queries = ordered_system_id_queries(batch_size: count_per_process)[0...data_count]

      self.inferred_schema_at = Time.now
      self.inferred_schema_from = samples_count
      on_schema_inference_started

      sch = schema_inferrer.infer_schema(batch_count: queries.count, extended: extended) do |idx|
        progress = (idx / queries.count.to_f * 100).ceil
        on_schema_inference_progressed(pct_complete: progress)

        all(where: queries[idx])
      end

      self.inferred_schema = sch
      save
      on_schema_inference_finished

      sch
    end
if this change, update the regex that use the character directly in this mixin
 Generate a schema based on this collection's records.
 We evaluate the schema of each record and then merge all
 the information together.
 @param extended [Boolean] Set to true to keep each field as a basic type.
        Set to false to reduce the terminal arrays to a single key (under the type array).
 @return [Hash] with one entry per 'column'/'field'. The values
         contains information about the type and usage.