def to_sql
      sql = ["select"]
      select_values << "*" if select_values.empty?

      sql << select_values.uniq.join(", ")

      sql << "from #{build_series_name}"

      sql << "where #{where_values.join(' and ')}" unless where_values.empty?

      unless group_values.empty? && time_value.nil?
        group_fields = (time_value.nil? ? [] : ['time(' + @values[:time] + ')']) + group_values
        group_fields.uniq!
        sql << "group by #{group_fields.join(', ')}"
      end

      sql << "fill(#{fill_value})" unless fill_value.nil?

      sql << "order by #{order_values.uniq.join(',')}" unless order_values.empty?

      sql << "limit #{limit_value}" unless limit_value.nil?
      sql << "offset #{offset_value}" unless offset_value.nil?
      sql << "slimit #{slimit_value}" unless slimit_value.nil?
      sql << "soffset #{soffset_value}" unless soffset_value.nil?
      sql.join " "
    end
def to_sql
      sql = ["select"]
      select_values << "*" if select_values.empty?

      sql << select_values.uniq.join(", ")

      sql << "from #{build_series_name}"

      sql << "where #{where_values.join(' and ')}" unless where_values.empty?

      unless group_values.empty? && time_value.nil?
        group_fields = (time_value.nil? ? [] : ['time(' + @values[:time] + ')']) + group_values
        group_fields.uniq!
        sql << "group by #{group_fields.join(', ')}"
      end

      sql << "fill(#{fill_value})" unless fill_value.nil?

      sql << "order by #{order_values.uniq.join(',')}" unless order_values.empty?

      sql << "limit #{limit_value}" unless limit_value.nil?
      sql << "offset #{offset_value}" unless offset_value.nil?
      sql << "slimit #{slimit_value}" unless slimit_value.nil?
      sql << "soffset #{soffset_value}" unless soffset_value.nil?
      sql.join " "
    end
rubocop:disable Metrics/AbcSize
 rubocop:disable Metrics/CyclomaticComplexity
 rubocop:disable Metrics/MethodLength
 rubocop:disable Metrics/PerceivedComplexity