Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-7712 Window Function Improvements
  3. SPARK-8816

Improve Performance of Unbounded Following Window Frame Processing

    XMLWordPrintableJSON

    Details

    • Type: Sub-task
    • Status: Closed
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 1.4.0
    • Fix Version/s: None
    • Component/s: SQL
    • Labels:
      None

      Description

      The performance of Unbounded Following frames in both the current and the proposed (SPARK-8638) implementation of Window Functions is quite bad: O(N*(N-1)/2).

      A solution to this is to process such frames in reverse. This would effectively reduce the complexity to O(N). The problem with this approach that it assumes that AggregateExpression are communitative. Most are, but some are actually order based: FIRST/LAST. There are two solution for this:

      • Only allow communitative aggregates to processed in reverse order. In practice this would mean, that a white list containing all allowed aggregates is used, e.g. Sum, Average, Min, Max, ...
      • Add functionality to WindowFunction or even better AggregateExpression, which would allow us to get the reverse operator from the expression, and use this reverse for processing, for example:
        case class Max(child: Expression) extends AggregateExpression with Ordered {
          ...
          
          def reverse: Min = Min(child)
        }
        

      The impact and extensibility of the first option are lower than of the second.

      We might also want to asses how often such frames are used. It might not be a problem at all.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              hvanhovell Herman van Hövell
              Shepherd:
              Yin Huai
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: