You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: stage_query_helpers.rb
    path of file: ./repos/gitlabhq/lib/gitlab/analytics/cycle_analytics
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

module Gitlab
  module Analytics
    module CycleAnalytics
      module StageQueryHelpers
        def execute_query(query)
          ApplicationRecord.connection.execute(query.to_sql)
        end

        def zero_interval
          Arel::Nodes::NamedFunction.new('CAST', [Arel.sql("'0' AS INTERVAL")])
        end

        def round_duration_to_seconds
          Arel::Nodes::NamedFunction.new('ROUND', [
            Arel::Nodes::NamedFunction.new('CAST', [Arel::Nodes::Extract.new(duration, :epoch).as('double precision')])
          ])
        end

        def duration
        
    
        def order_by(query, sort, direction, extra_columns_to_select = [:id])
          ordered_query = Gitlab::Analytics::CycleAnalytics::Sorting.new(stage: stage, query: query, params: params).apply(sort, direction)

          # When filtering for more than one label, postgres requires the columns in ORDER BY to be present in the GROUP BY clause
          if requires_grouping?
            column_list = [].tap do |array|
              array.concat(extra_columns_to_select)
              array.concat(stage.end_event.column_list) unless in_progress?
              array.concat(stage.start_event.column_list)
            end

            ordered_query = ordered_query.group(column_list)
          end