Movatterモバイル変換


[0]ホーム

URL:


  • Overview
  • View Specification
  • Data / Datasets
  • Transform
  • Mark
  • Encoding
  • Projection
  • View Composition
  • Parameter
  • Config

  • Property Types
  • Tooltip
  • Invalid Data
  • Window

    Edit this page

    The window transform performs calculations over sorted groups of data objects. These calculations including ranking, lead/lag analysis, and aggregates such as running sums and averages. Calculated values are written back to the input data stream. If you only want to set the same aggregated value in a new field, you can use the simplerjoin aggregate transform.

    Documentation Overview

    Window Field Definition

    // Any View Specification{  ...  "transform": [    {      // Window Transform      "window": [{          "op": ...,          "field": ...,          "param": ...,          "as": ...      }],      "sort": [        {"field": ..., "order": ...}      ],      "ignorePeers": ...,      "groupby": [        "..."      ],      "frame": [...,...]    }     ...  ],  ...}

    Window Transform Definition

    PropertyTypeDescription
    windowWindowFieldDef[]

    Required. The definition of the fields in the window, and what calculations to use.

    frame(Null | Number)[]

    A frame specification as a two-element array indicating how the sliding window should proceed. The array entries should either be a number indicating the offset from the current data object, or null to indicate unbounded rows preceding or following the current data object. The default value is[null, 0], indicating that the sliding window includes the current object and all preceding objects. The value[-5, 5] indicates that the window should include five objects preceding and five objects following the current object. Finally,[null, null] indicates that the window frame should always include all data objects. If you this frame and want to assign the same value to add objects, you can use the simplerjoin aggregate transform. The only operators affected are the aggregation operations and thefirst_value,last_value, andnth_value window operations. The other window operations are not affected by this.

    Default value::[null, 0] (includes the current object and all preceding objects)

    ignorePeersBoolean

    Indicates if the sliding window frame should ignore peer values (data that are considered identical by the sort criteria). The default is false, causing the window frame to expand to include all peer values. If set to true, the window frame will be defined by offset values only. This setting only affects those operations that depend on the window frame, namely aggregation operations and the first_value, last_value, and nth_value window operations.

    Default value:false

    groupbyString[]

    The data fields for partitioning the data objects into separate windows. If unspecified, all data points will be in a single window.

    sortSortField[]

    A sort field definition for sorting data objects within a window. If two data objects are considered equal by the comparator, they are considered “peer” values of equal rank. If sort is not specified, the order is undefined: data objects are processed in the order they are observed and none are considered peers (the ignorePeers parameter is ignored and treated as if set totrue).

    Window Transform Field Definition

    PropertyTypeDescription
    opString | String

    Required. The window or aggregation operation to apply within a window (e.g.,"rank","lead","sum","average" or"count"). See the list of all supported operationshere.

    paramNumber

    Parameter values for the window functions. Parameter values can be omitted for operations that do not accept a parameter.

    See the list of all supported operations and their parametershere.

    fieldString

    The data field for which to compute the aggregate or window function. This can be omitted for window functions that do not operate over a field such as"count","rank","dense_rank".

    asString

    Required. The output name for the window operation.

    Sort Field Definition

    PropertyTypeDescription
    fieldString

    Required. The name of the field to sort.

    orderString | Null

    Whether to sort the field in ascending or descending order. One of"ascending" (default),"descending", ornull (do not sort).

    Window Only Operation Reference

    The valid operations include allaggregate operations plus the following window operations.

    OperationParameterDescription
    row_numberNoneAssigns each data object a consecutive row number, starting from 1.
    rankNoneAssigns a rank order value to each data object in a window, starting from 1. Peer values are assigned the same rank. Subsequent rank scores incorporate the number of prior values. For example, if the first two values tie for rank 1, the third value is assigned rank 3.
    dense_rankNoneAssigns dense rank order values to each data object in a window, starting from 1. Peer values are assigned the same rank. Subsequent rank scores do not incorporate the number of prior values. For example, if the first two values tie for rank 1, the third value is assigned rank 2.
    percent_rankNoneAssigns a percentage rank order value to each data object in a window. The percent is calculated as(rank - 1) / (group_size - 1).
    cume_distNoneAssigns a cumulative distribution value between 0 and 1 to each data object in a window.
    ntileNumberAssigns a quantile (e.g., percentile) value to each data object in a window. Accepts an integer parameter indicating the number of buckets to use (e.g., 100 for percentiles, 5 for quintiles).
    lagNumberAssigns a value from the data object that precedes the current object by a specified number of positions. If no such object exists, assignsnull. Accepts an offset parameter (default1) that indicates the number of positions. This operation must have a corresponding entry in thefields parameter array.
    leadNumberAssigns a value from the data object that follows the current object by a specified number of positions. If no such object exists, assignsnull. Accepts an offset parameter (default1) that indicates the number of positions. This operation must have a corresponding entry in thefields parameter array.
    first_valueNoneAssigns a value from the first data object in the current sliding window frame. This operation must have a corresponding entry in thefields parameter array.
    last_valueNoneAssigns a value from the last data object in the current sliding window frame. This operation must have a corresponding entry in thefields parameter array.
    nth_valueNumberAssigns a value from the nth data object in the current sliding window frame. If no such object exists, assignsnull. Requires a non-negative integer parameter that indicates the offset from the start of the window frame. This operation must have a corresponding entry in thefields parameter array.

    Examples

    Below are some common use cases for the window transform.

    Cumulative Frequency Distribution

    Here we use the window transform withframe: [null, 0] to accumulate count in a cumulative frequency distribution plot.

    See also:layered histogram and cumulative histogram

    Rank Chart

    We can also userank operator to calculate ranks over time.

    Top K

    Here we use window transform to derive the total number of students along with the rank of the current student to determine the top K students and display their score.

    Also seethis example for a top-K plot with “others”.

    Cumulative Running Average

    Here we use window transform to visualize how the average MPG for vehicles have changed over the years.

    Percent of Total

    The window transformcan be used to compute an aggregate and attach it to all records in order to derive a percent of total, however, a simpler approach is to use thejoin aggregate transform instead.

    Using window transform to impute missing values


[8]ページ先頭

©2009-2025 Movatter.jp