| |
| |
| <!DOCTYPE html> |
| |
| |
| <html > |
| |
| <head> |
| <meta charset="utf-8" /> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| <title>pyspark.sql.window — PySpark 4.0.0-preview2 documentation</title> |
| |
| |
| |
| <script data-cfasync="false"> |
| document.documentElement.dataset.mode = localStorage.getItem("mode") || ""; |
| document.documentElement.dataset.theme = localStorage.getItem("theme") || "light"; |
| </script> |
| |
| <!-- Loaded before other Sphinx assets --> |
| <link href="../../../_static/styles/theme.css?digest=e353d410970836974a52" rel="stylesheet" /> |
| <link href="../../../_static/styles/bootstrap.css?digest=e353d410970836974a52" rel="stylesheet" /> |
| <link href="../../../_static/styles/pydata-sphinx-theme.css?digest=e353d410970836974a52" rel="stylesheet" /> |
| |
| |
| <link href="../../../_static/vendor/fontawesome/6.1.2/css/all.min.css?digest=e353d410970836974a52" rel="stylesheet" /> |
| <link rel="preload" as="font" type="font/woff2" crossorigin href="../../../_static/vendor/fontawesome/6.1.2/webfonts/fa-solid-900.woff2" /> |
| <link rel="preload" as="font" type="font/woff2" crossorigin href="../../../_static/vendor/fontawesome/6.1.2/webfonts/fa-brands-400.woff2" /> |
| <link rel="preload" as="font" type="font/woff2" crossorigin href="../../../_static/vendor/fontawesome/6.1.2/webfonts/fa-regular-400.woff2" /> |
| |
| <link rel="stylesheet" type="text/css" href="../../../_static/pygments.css" /> |
| <link rel="stylesheet" type="text/css" href="../../../_static/copybutton.css" /> |
| <link rel="stylesheet" type="text/css" href="../../../_static/css/pyspark.css" /> |
| |
| <!-- Pre-loaded scripts that we'll load fully later --> |
| <link rel="preload" as="script" href="../../../_static/scripts/bootstrap.js?digest=e353d410970836974a52" /> |
| <link rel="preload" as="script" href="../../../_static/scripts/pydata-sphinx-theme.js?digest=e353d410970836974a52" /> |
| |
| <script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script> |
| <script src="../../../_static/jquery.js"></script> |
| <script src="../../../_static/underscore.js"></script> |
| <script src="../../../_static/doctools.js"></script> |
| <script src="../../../_static/clipboard.min.js"></script> |
| <script src="../../../_static/copybutton.js"></script> |
| <script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script> |
| <script>DOCUMENTATION_OPTIONS.pagename = '_modules/pyspark/sql/window';</script> |
| <link rel="canonical" href="https://spark.apache.org/docs/latest/api/python/_modules/pyspark/sql/window.html" /> |
| <link rel="search" title="Search" href="../../../search.html" /> |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| <meta name="docsearch:language" content="None"> |
| |
| |
| <!-- Matomo --> |
| <script type="text/javascript"> |
| var _paq = window._paq = window._paq || []; |
| /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ |
| _paq.push(["disableCookies"]); |
| _paq.push(['trackPageView']); |
| _paq.push(['enableLinkTracking']); |
| (function() { |
| var u="https://analytics.apache.org/"; |
| _paq.push(['setTrackerUrl', u+'matomo.php']); |
| _paq.push(['setSiteId', '40']); |
| var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; |
| g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); |
| })(); |
| </script> |
| <!-- End Matomo Code --> |
| |
| </head> |
| |
| |
| <body data-bs-spy="scroll" data-bs-target=".bd-toc-nav" data-offset="180" data-bs-root-margin="0px 0px -60%" data-default-mode=""> |
| |
| |
| |
| <a class="skip-link" href="#main-content">Skip to main content</a> |
| |
| <input type="checkbox" |
| class="sidebar-toggle" |
| name="__primary" |
| id="__primary"/> |
| <label class="overlay overlay-primary" for="__primary"></label> |
| |
| <input type="checkbox" |
| class="sidebar-toggle" |
| name="__secondary" |
| id="__secondary"/> |
| <label class="overlay overlay-secondary" for="__secondary"></label> |
| |
| <div class="search-button__wrapper"> |
| <div class="search-button__overlay"></div> |
| <div class="search-button__search-container"> |
| <form class="bd-search d-flex align-items-center" |
| action="../../../search.html" |
| method="get"> |
| <i class="fa-solid fa-magnifying-glass"></i> |
| <input type="search" |
| class="form-control" |
| name="q" |
| id="search-input" |
| placeholder="Search the docs ..." |
| aria-label="Search the docs ..." |
| autocomplete="off" |
| autocorrect="off" |
| autocapitalize="off" |
| spellcheck="false"/> |
| <span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd></span> |
| </form></div> |
| </div> |
| |
| <nav class="bd-header navbar navbar-expand-lg bd-navbar"> |
| <div class="bd-header__inner bd-page-width"> |
| <label class="sidebar-toggle primary-toggle" for="__primary"> |
| <span class="fa-solid fa-bars"></span> |
| </label> |
| |
| <div class="navbar-header-items__start"> |
| |
| <div class="navbar-item"> |
| |
| |
| <a class="navbar-brand logo" href="../../../index.html"> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <img src="https://spark.apache.org/images/spark-logo.png" class="logo__image only-light" alt="Logo image"/> |
| <script>document.write(`<img src="https://spark.apache.org/images/spark-logo-rev.svg" class="logo__image only-dark" alt="Logo image"/>`);</script> |
| |
| |
| </a></div> |
| |
| </div> |
| |
| |
| <div class="col-lg-9 navbar-header-items"> |
| |
| <div class="me-auto navbar-header-items__center"> |
| |
| <div class="navbar-item"><nav class="navbar-nav"> |
| <p class="sidebar-header-items__title" |
| role="heading" |
| aria-level="1" |
| aria-label="Site Navigation"> |
| Site Navigation |
| </p> |
| <ul class="bd-navbar-elements navbar-nav"> |
| |
| <li class="nav-item"> |
| <a class="nav-link nav-internal" href="../../../index.html"> |
| Overview |
| </a> |
| </li> |
| |
| |
| <li class="nav-item"> |
| <a class="nav-link nav-internal" href="../../../getting_started/index.html"> |
| Getting Started |
| </a> |
| </li> |
| |
| |
| <li class="nav-item"> |
| <a class="nav-link nav-internal" href="../../../user_guide/index.html"> |
| User Guides |
| </a> |
| </li> |
| |
| |
| <li class="nav-item"> |
| <a class="nav-link nav-internal" href="../../../reference/index.html"> |
| API Reference |
| </a> |
| </li> |
| |
| |
| <li class="nav-item"> |
| <a class="nav-link nav-internal" href="../../../development/index.html"> |
| Development |
| </a> |
| </li> |
| |
| |
| <li class="nav-item"> |
| <a class="nav-link nav-internal" href="../../../migration_guide/index.html"> |
| Migration Guides |
| </a> |
| </li> |
| |
| </ul> |
| </nav></div> |
| |
| </div> |
| |
| |
| <div class="navbar-header-items__end"> |
| |
| <div class="navbar-item navbar-persistent--container"> |
| |
| <script> |
| document.write(` |
| <button class="btn btn-sm navbar-btn search-button search-button__button" title="Search" aria-label="Search" data-bs-placement="bottom" data-bs-toggle="tooltip"> |
| <i class="fa-solid fa-magnifying-glass"></i> |
| </button> |
| `); |
| </script> |
| </div> |
| |
| |
| <div class="navbar-item"><!-- |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| |
| <div id="version-button" class="dropdown"> |
| <button type="button" class="btn btn-secondary btn-sm navbar-btn dropdown-toggle" id="version_switcher_button" data-toggle="dropdown"> |
| 4.0.0-preview2 |
| <span class="caret"></span> |
| </button> |
| <div id="version_switcher" class="dropdown-menu list-group-flush py-0" aria-labelledby="version_switcher_button"> |
| <!-- dropdown will be populated by javascript on page load --> |
| </div> |
| </div> |
| |
| <script type="text/javascript"> |
| // Function to construct the target URL from the JSON components |
| function buildURL(entry) { |
| var template = "https://spark.apache.org/docs/{version}/api/python/index.html"; // supplied by jinja |
| template = template.replace("{version}", entry.version); |
| return template; |
| } |
| |
| // Function to check if corresponding page path exists in other version of docs |
| // and, if so, go there instead of the homepage of the other docs version |
| function checkPageExistsAndRedirect(event) { |
| const currentFilePath = "_modules/pyspark/sql/window.html", |
| otherDocsHomepage = event.target.getAttribute("href"); |
| let tryUrl = `${otherDocsHomepage}${currentFilePath}`; |
| $.ajax({ |
| type: 'HEAD', |
| url: tryUrl, |
| // if the page exists, go there |
| success: function() { |
| location.href = tryUrl; |
| } |
| }).fail(function() { |
| location.href = otherDocsHomepage; |
| }); |
| return false; |
| } |
| |
| // Function to populate the version switcher |
| (function () { |
| // get JSON config |
| $.getJSON("https://spark.apache.org/static/versions.json", function(data, textStatus, jqXHR) { |
| // create the nodes first (before AJAX calls) to ensure the order is |
| // correct (for now, links will go to doc version homepage) |
| $.each(data, function(index, entry) { |
| // if no custom name specified (e.g., "latest"), use version string |
| if (!("name" in entry)) { |
| entry.name = entry.version; |
| } |
| // construct the appropriate URL, and add it to the dropdown |
| entry.url = buildURL(entry); |
| const node = document.createElement("a"); |
| node.setAttribute("class", "list-group-item list-group-item-action py-1"); |
| node.setAttribute("href", `${entry.url}`); |
| node.textContent = `${entry.name}`; |
| node.onclick = checkPageExistsAndRedirect; |
| $("#version_switcher").append(node); |
| }); |
| }); |
| })(); |
| </script></div> |
| |
| <div class="navbar-item"> |
| <script> |
| document.write(` |
| <button class="theme-switch-button btn btn-sm btn-outline-primary navbar-btn rounded-circle" title="light/dark" aria-label="light/dark" data-bs-placement="bottom" data-bs-toggle="tooltip"> |
| <span class="theme-switch" data-mode="light"><i class="fa-solid fa-sun"></i></span> |
| <span class="theme-switch" data-mode="dark"><i class="fa-solid fa-moon"></i></span> |
| <span class="theme-switch" data-mode="auto"><i class="fa-solid fa-circle-half-stroke"></i></span> |
| </button> |
| `); |
| </script></div> |
| |
| <div class="navbar-item"><ul class="navbar-icon-links navbar-nav" |
| aria-label="Icon Links"> |
| <li class="nav-item"> |
| |
| |
| |
| |
| |
| |
| |
| |
| <a href="https://github.com/apache/spark" title="GitHub" class="nav-link" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><span><i class="fa-brands fa-github"></i></span> |
| <label class="sr-only">GitHub</label></a> |
| </li> |
| <li class="nav-item"> |
| |
| |
| |
| |
| |
| |
| |
| |
| <a href="https://pypi.org/project/pyspark" title="PyPI" class="nav-link" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><span><i class="fa-solid fa-box"></i></span> |
| <label class="sr-only">PyPI</label></a> |
| </li> |
| </ul></div> |
| |
| </div> |
| |
| </div> |
| |
| |
| <div class="navbar-persistent--mobile"> |
| <script> |
| document.write(` |
| <button class="btn btn-sm navbar-btn search-button search-button__button" title="Search" aria-label="Search" data-bs-placement="bottom" data-bs-toggle="tooltip"> |
| <i class="fa-solid fa-magnifying-glass"></i> |
| </button> |
| `); |
| </script> |
| </div> |
| |
| |
| |
| </div> |
| |
| </nav> |
| |
| <div class="bd-container"> |
| <div class="bd-container__inner bd-page-width"> |
| |
| <div class="bd-sidebar-primary bd-sidebar hide-on-wide"> |
| |
| |
| |
| <div class="sidebar-header-items sidebar-primary__section"> |
| |
| |
| <div class="sidebar-header-items__center"> |
| |
| <div class="navbar-item"><nav class="navbar-nav"> |
| <p class="sidebar-header-items__title" |
| role="heading" |
| aria-level="1" |
| aria-label="Site Navigation"> |
| Site Navigation |
| </p> |
| <ul class="bd-navbar-elements navbar-nav"> |
| |
| <li class="nav-item"> |
| <a class="nav-link nav-internal" href="../../../index.html"> |
| Overview |
| </a> |
| </li> |
| |
| |
| <li class="nav-item"> |
| <a class="nav-link nav-internal" href="../../../getting_started/index.html"> |
| Getting Started |
| </a> |
| </li> |
| |
| |
| <li class="nav-item"> |
| <a class="nav-link nav-internal" href="../../../user_guide/index.html"> |
| User Guides |
| </a> |
| </li> |
| |
| |
| <li class="nav-item"> |
| <a class="nav-link nav-internal" href="../../../reference/index.html"> |
| API Reference |
| </a> |
| </li> |
| |
| |
| <li class="nav-item"> |
| <a class="nav-link nav-internal" href="../../../development/index.html"> |
| Development |
| </a> |
| </li> |
| |
| |
| <li class="nav-item"> |
| <a class="nav-link nav-internal" href="../../../migration_guide/index.html"> |
| Migration Guides |
| </a> |
| </li> |
| |
| </ul> |
| </nav></div> |
| |
| </div> |
| |
| |
| |
| <div class="sidebar-header-items__end"> |
| |
| <div class="navbar-item"><!-- |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| |
| <div id="version-button" class="dropdown"> |
| <button type="button" class="btn btn-secondary btn-sm navbar-btn dropdown-toggle" id="version_switcher_button" data-toggle="dropdown"> |
| 4.0.0-preview2 |
| <span class="caret"></span> |
| </button> |
| <div id="version_switcher" class="dropdown-menu list-group-flush py-0" aria-labelledby="version_switcher_button"> |
| <!-- dropdown will be populated by javascript on page load --> |
| </div> |
| </div> |
| |
| <script type="text/javascript"> |
| // Function to construct the target URL from the JSON components |
| function buildURL(entry) { |
| var template = "https://spark.apache.org/docs/{version}/api/python/index.html"; // supplied by jinja |
| template = template.replace("{version}", entry.version); |
| return template; |
| } |
| |
| // Function to check if corresponding page path exists in other version of docs |
| // and, if so, go there instead of the homepage of the other docs version |
| function checkPageExistsAndRedirect(event) { |
| const currentFilePath = "_modules/pyspark/sql/window.html", |
| otherDocsHomepage = event.target.getAttribute("href"); |
| let tryUrl = `${otherDocsHomepage}${currentFilePath}`; |
| $.ajax({ |
| type: 'HEAD', |
| url: tryUrl, |
| // if the page exists, go there |
| success: function() { |
| location.href = tryUrl; |
| } |
| }).fail(function() { |
| location.href = otherDocsHomepage; |
| }); |
| return false; |
| } |
| |
| // Function to populate the version switcher |
| (function () { |
| // get JSON config |
| $.getJSON("https://spark.apache.org/static/versions.json", function(data, textStatus, jqXHR) { |
| // create the nodes first (before AJAX calls) to ensure the order is |
| // correct (for now, links will go to doc version homepage) |
| $.each(data, function(index, entry) { |
| // if no custom name specified (e.g., "latest"), use version string |
| if (!("name" in entry)) { |
| entry.name = entry.version; |
| } |
| // construct the appropriate URL, and add it to the dropdown |
| entry.url = buildURL(entry); |
| const node = document.createElement("a"); |
| node.setAttribute("class", "list-group-item list-group-item-action py-1"); |
| node.setAttribute("href", `${entry.url}`); |
| node.textContent = `${entry.name}`; |
| node.onclick = checkPageExistsAndRedirect; |
| $("#version_switcher").append(node); |
| }); |
| }); |
| })(); |
| </script></div> |
| |
| <div class="navbar-item"> |
| <script> |
| document.write(` |
| <button class="theme-switch-button btn btn-sm btn-outline-primary navbar-btn rounded-circle" title="light/dark" aria-label="light/dark" data-bs-placement="bottom" data-bs-toggle="tooltip"> |
| <span class="theme-switch" data-mode="light"><i class="fa-solid fa-sun"></i></span> |
| <span class="theme-switch" data-mode="dark"><i class="fa-solid fa-moon"></i></span> |
| <span class="theme-switch" data-mode="auto"><i class="fa-solid fa-circle-half-stroke"></i></span> |
| </button> |
| `); |
| </script></div> |
| |
| <div class="navbar-item"><ul class="navbar-icon-links navbar-nav" |
| aria-label="Icon Links"> |
| <li class="nav-item"> |
| |
| |
| |
| |
| |
| |
| |
| |
| <a href="https://github.com/apache/spark" title="GitHub" class="nav-link" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><span><i class="fa-brands fa-github"></i></span> |
| <label class="sr-only">GitHub</label></a> |
| </li> |
| <li class="nav-item"> |
| |
| |
| |
| |
| |
| |
| |
| |
| <a href="https://pypi.org/project/pyspark" title="PyPI" class="nav-link" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><span><i class="fa-solid fa-box"></i></span> |
| <label class="sr-only">PyPI</label></a> |
| </li> |
| </ul></div> |
| |
| </div> |
| |
| </div> |
| |
| |
| <div class="sidebar-primary-items__end sidebar-primary__section"> |
| </div> |
| |
| <div id="rtd-footer-container"></div> |
| |
| |
| </div> |
| |
| <main id="main-content" class="bd-main"> |
| |
| |
| <div class="bd-content"> |
| <div class="bd-article-container"> |
| |
| <div class="bd-header-article"> |
| <div class="header-article-items header-article__inner"> |
| |
| <div class="header-article-items__start"> |
| |
| <div class="header-article-item"> |
| |
| |
| |
| <nav aria-label="Breadcrumbs"> |
| <ul class="bd-breadcrumbs" role="navigation" aria-label="Breadcrumb"> |
| |
| <li class="breadcrumb-item breadcrumb-home"> |
| <a href="../../../index.html" class="nav-link" aria-label="Home"> |
| <i class="fa-solid fa-home"></i> |
| </a> |
| </li> |
| |
| <li class="breadcrumb-item"><a href="../../index.html" class="nav-link">Module code</a></li> |
| |
| <li class="breadcrumb-item active" aria-current="page">pyspark.sql.window</li> |
| </ul> |
| </nav> |
| </div> |
| |
| </div> |
| |
| |
| </div> |
| </div> |
| |
| |
| |
| |
| <div id="searchbox"></div> |
| <article class="bd-article" role="main"> |
| |
| <h1>Source code for pyspark.sql.window</h1><div class="highlight"><pre> |
| <span></span><span class="c1">#</span> |
| <span class="c1"># Licensed to the Apache Software Foundation (ASF) under one or more</span> |
| <span class="c1"># contributor license agreements. See the NOTICE file distributed with</span> |
| <span class="c1"># this work for additional information regarding copyright ownership.</span> |
| <span class="c1"># The ASF licenses this file to You under the Apache License, Version 2.0</span> |
| <span class="c1"># (the "License"); you may not use this file except in compliance with</span> |
| <span class="c1"># the License. You may obtain a copy of the License at</span> |
| <span class="c1">#</span> |
| <span class="c1"># http://www.apache.org/licenses/LICENSE-2.0</span> |
| <span class="c1">#</span> |
| <span class="c1"># Unless required by applicable law or agreed to in writing, software</span> |
| <span class="c1"># distributed under the License is distributed on an "AS IS" BASIS,</span> |
| <span class="c1"># WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span> |
| <span class="c1"># See the License for the specific language governing permissions and</span> |
| <span class="c1"># limitations under the License.</span> |
| <span class="c1">#</span> |
| |
| <span class="c1"># mypy: disable-error-code="empty-body"</span> |
| |
| <span class="kn">import</span> <span class="nn">sys</span> |
| <span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Sequence</span><span class="p">,</span> <span class="n">TYPE_CHECKING</span><span class="p">,</span> <span class="n">Union</span> |
| |
| <span class="kn">from</span> <span class="nn">pyspark.sql.utils</span> <span class="kn">import</span> <span class="n">dispatch_window_method</span> |
| <span class="kn">from</span> <span class="nn">pyspark.util</span> <span class="kn">import</span> <span class="p">(</span> |
| <span class="n">JVM_LONG_MIN</span><span class="p">,</span> |
| <span class="n">JVM_LONG_MAX</span><span class="p">,</span> |
| <span class="p">)</span> |
| |
| <span class="k">if</span> <span class="n">TYPE_CHECKING</span><span class="p">:</span> |
| <span class="kn">from</span> <span class="nn">py4j.java_gateway</span> <span class="kn">import</span> <span class="n">JavaObject</span> |
| <span class="kn">from</span> <span class="nn">pyspark.sql._typing</span> <span class="kn">import</span> <span class="n">ColumnOrName</span> |
| |
| <span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"Window"</span><span class="p">,</span> <span class="s2">"WindowSpec"</span><span class="p">]</span> |
| |
| |
| <div class="viewcode-block" id="Window"><a class="viewcode-back" href="../../../reference/pyspark.sql/api/pyspark.sql.Window.html#pyspark.sql.Window">[docs]</a><span class="k">class</span> <span class="nc">Window</span><span class="p">:</span> |
| <span class="w"> </span><span class="sd">"""</span> |
| <span class="sd"> Utility functions for defining window in DataFrames.</span> |
| |
| <span class="sd"> .. versionadded:: 1.4.0</span> |
| |
| <span class="sd"> .. versionchanged:: 3.4.0</span> |
| <span class="sd"> Supports Spark Connect.</span> |
| |
| <span class="sd"> Notes</span> |
| <span class="sd"> -----</span> |
| <span class="sd"> When ordering is not defined, an unbounded window frame (rowFrame,</span> |
| <span class="sd"> unboundedPreceding, unboundedFollowing) is used by default. When ordering is defined,</span> |
| <span class="sd"> a growing window frame (rangeFrame, unboundedPreceding, currentRow) is used by default.</span> |
| |
| <span class="sd"> Examples</span> |
| <span class="sd"> --------</span> |
| <span class="sd"> >>> # ORDER BY date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW</span> |
| <span class="sd"> >>> window = Window.orderBy("date").rowsBetween(Window.unboundedPreceding, Window.currentRow)</span> |
| |
| <span class="sd"> >>> # PARTITION BY country ORDER BY date RANGE BETWEEN 3 PRECEDING AND 3 FOLLOWING</span> |
| <span class="sd"> >>> window = Window.orderBy("date").partitionBy("country").rangeBetween(-3, 3)</span> |
| <span class="sd"> """</span> |
| |
| <span class="n">_PRECEDING_THRESHOLD</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="o">-</span><span class="n">sys</span><span class="o">.</span><span class="n">maxsize</span><span class="p">,</span> <span class="n">JVM_LONG_MIN</span><span class="p">)</span> |
| <span class="n">_FOLLOWING_THRESHOLD</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">maxsize</span><span class="p">,</span> <span class="n">JVM_LONG_MAX</span><span class="p">)</span> |
| |
| <span class="n">unboundedPreceding</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="n">JVM_LONG_MIN</span> |
| |
| <span class="n">unboundedFollowing</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="n">JVM_LONG_MAX</span> |
| |
| <span class="n">currentRow</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">0</span> |
| |
| <div class="viewcode-block" id="Window.partitionBy"><a class="viewcode-back" href="../../../reference/pyspark.sql/api/pyspark.sql.Window.partitionBy.html#pyspark.sql.Window.partitionBy">[docs]</a> <span class="nd">@staticmethod</span> |
| <span class="nd">@dispatch_window_method</span> |
| <span class="k">def</span> <span class="nf">partitionBy</span><span class="p">(</span><span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="s2">"ColumnOrName"</span><span class="p">,</span> <span class="n">Sequence</span><span class="p">[</span><span class="s2">"ColumnOrName"</span><span class="p">]])</span> <span class="o">-></span> <span class="s2">"WindowSpec"</span><span class="p">:</span> |
| <span class="w"> </span><span class="sd">"""</span> |
| <span class="sd"> Creates a :class:`WindowSpec` with the partitioning defined.</span> |
| |
| <span class="sd"> .. versionadded:: 1.4.0</span> |
| |
| <span class="sd"> Parameters</span> |
| <span class="sd"> ----------</span> |
| <span class="sd"> cols : str, :class:`Column` or list</span> |
| <span class="sd"> names of columns or expressions</span> |
| |
| <span class="sd"> Returns</span> |
| <span class="sd"> -------</span> |
| <span class="sd"> :class: `WindowSpec`</span> |
| <span class="sd"> A :class:`WindowSpec` with the partitioning defined.</span> |
| |
| <span class="sd"> Examples</span> |
| <span class="sd"> --------</span> |
| <span class="sd"> >>> from pyspark.sql import Window</span> |
| <span class="sd"> >>> from pyspark.sql.functions import row_number</span> |
| <span class="sd"> >>> df = spark.createDataFrame(</span> |
| <span class="sd"> ... [(1, "a"), (1, "a"), (2, "a"), (1, "b"), (2, "b"), (3, "b")], ["id", "category"])</span> |
| <span class="sd"> >>> df.show()</span> |
| <span class="sd"> +---+--------+</span> |
| <span class="sd"> | id|category|</span> |
| <span class="sd"> +---+--------+</span> |
| <span class="sd"> | 1| a|</span> |
| <span class="sd"> | 1| a|</span> |
| <span class="sd"> | 2| a|</span> |
| <span class="sd"> | 1| b|</span> |
| <span class="sd"> | 2| b|</span> |
| <span class="sd"> | 3| b|</span> |
| <span class="sd"> +---+--------+</span> |
| |
| <span class="sd"> Show row number order by ``id`` in partition ``category``.</span> |
| |
| <span class="sd"> >>> window = Window.partitionBy("category").orderBy("id")</span> |
| <span class="sd"> >>> df.withColumn("row_number", row_number().over(window)).show()</span> |
| <span class="sd"> +---+--------+----------+</span> |
| <span class="sd"> | id|category|row_number|</span> |
| <span class="sd"> +---+--------+----------+</span> |
| <span class="sd"> | 1| a| 1|</span> |
| <span class="sd"> | 1| a| 2|</span> |
| <span class="sd"> | 2| a| 3|</span> |
| <span class="sd"> | 1| b| 1|</span> |
| <span class="sd"> | 2| b| 2|</span> |
| <span class="sd"> | 3| b| 3|</span> |
| <span class="sd"> +---+--------+----------+</span> |
| <span class="sd"> """</span> |
| <span class="o">...</span></div> |
| |
| <div class="viewcode-block" id="Window.orderBy"><a class="viewcode-back" href="../../../reference/pyspark.sql/api/pyspark.sql.Window.orderBy.html#pyspark.sql.Window.orderBy">[docs]</a> <span class="nd">@staticmethod</span> |
| <span class="nd">@dispatch_window_method</span> |
| <span class="k">def</span> <span class="nf">orderBy</span><span class="p">(</span><span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="s2">"ColumnOrName"</span><span class="p">,</span> <span class="n">Sequence</span><span class="p">[</span><span class="s2">"ColumnOrName"</span><span class="p">]])</span> <span class="o">-></span> <span class="s2">"WindowSpec"</span><span class="p">:</span> |
| <span class="w"> </span><span class="sd">"""</span> |
| <span class="sd"> Creates a :class:`WindowSpec` with the ordering defined.</span> |
| |
| <span class="sd"> .. versionadded:: 1.4.0</span> |
| |
| <span class="sd"> Parameters</span> |
| <span class="sd"> ----------</span> |
| <span class="sd"> cols : str, :class:`Column` or list</span> |
| <span class="sd"> names of columns or expressions</span> |
| |
| <span class="sd"> Returns</span> |
| <span class="sd"> -------</span> |
| <span class="sd"> :class: `WindowSpec`</span> |
| <span class="sd"> A :class:`WindowSpec` with the ordering defined.</span> |
| |
| <span class="sd"> Examples</span> |
| <span class="sd"> --------</span> |
| <span class="sd"> >>> from pyspark.sql import Window</span> |
| <span class="sd"> >>> from pyspark.sql.functions import row_number</span> |
| <span class="sd"> >>> df = spark.createDataFrame(</span> |
| <span class="sd"> ... [(1, "a"), (1, "a"), (2, "a"), (1, "b"), (2, "b"), (3, "b")], ["id", "category"])</span> |
| <span class="sd"> >>> df.show()</span> |
| <span class="sd"> +---+--------+</span> |
| <span class="sd"> | id|category|</span> |
| <span class="sd"> +---+--------+</span> |
| <span class="sd"> | 1| a|</span> |
| <span class="sd"> | 1| a|</span> |
| <span class="sd"> | 2| a|</span> |
| <span class="sd"> | 1| b|</span> |
| <span class="sd"> | 2| b|</span> |
| <span class="sd"> | 3| b|</span> |
| <span class="sd"> +---+--------+</span> |
| |
| <span class="sd"> Show row number order by ``category`` in partition ``id``.</span> |
| |
| <span class="sd"> >>> window = Window.partitionBy("id").orderBy("category")</span> |
| <span class="sd"> >>> df.withColumn("row_number", row_number().over(window)).show()</span> |
| <span class="sd"> +---+--------+----------+</span> |
| <span class="sd"> | id|category|row_number|</span> |
| <span class="sd"> +---+--------+----------+</span> |
| <span class="sd"> | 1| a| 1|</span> |
| <span class="sd"> | 1| a| 2|</span> |
| <span class="sd"> | 1| b| 3|</span> |
| <span class="sd"> | 2| a| 1|</span> |
| <span class="sd"> | 2| b| 2|</span> |
| <span class="sd"> | 3| b| 1|</span> |
| <span class="sd"> +---+--------+----------+</span> |
| <span class="sd"> """</span> |
| <span class="o">...</span></div> |
| |
| <div class="viewcode-block" id="Window.rowsBetween"><a class="viewcode-back" href="../../../reference/pyspark.sql/api/pyspark.sql.Window.rowsBetween.html#pyspark.sql.Window.rowsBetween">[docs]</a> <span class="nd">@staticmethod</span> |
| <span class="nd">@dispatch_window_method</span> |
| <span class="k">def</span> <span class="nf">rowsBetween</span><span class="p">(</span><span class="n">start</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">end</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="s2">"WindowSpec"</span><span class="p">:</span> |
| <span class="w"> </span><span class="sd">"""</span> |
| <span class="sd"> Creates a :class:`WindowSpec` with the frame boundaries defined,</span> |
| <span class="sd"> from `start` (inclusive) to `end` (inclusive).</span> |
| |
| <span class="sd"> Both `start` and `end` are relative positions from the current row.</span> |
| <span class="sd"> For example, "0" means "current row", while "-1" means the row before</span> |
| <span class="sd"> the current row, and "5" means the fifth row after the current row.</span> |
| |
| <span class="sd"> We recommend users use ``Window.unboundedPreceding``, ``Window.unboundedFollowing``,</span> |
| <span class="sd"> and ``Window.currentRow`` to specify special boundary values, rather than using integral</span> |
| <span class="sd"> values directly.</span> |
| |
| <span class="sd"> A row based boundary is based on the position of the row within the partition.</span> |
| <span class="sd"> An offset indicates the number of rows above or below the current row, the frame for the</span> |
| <span class="sd"> current row starts or ends. For instance, given a row based sliding frame with a lower bound</span> |
| <span class="sd"> offset of -1 and a upper bound offset of +2. The frame for row with index 5 would range from</span> |
| <span class="sd"> index 4 to index 7.</span> |
| |
| <span class="sd"> .. versionadded:: 2.1.0</span> |
| |
| <span class="sd"> Parameters</span> |
| <span class="sd"> ----------</span> |
| <span class="sd"> start : int</span> |
| <span class="sd"> boundary start, inclusive.</span> |
| <span class="sd"> The frame is unbounded if this is ``Window.unboundedPreceding``, or</span> |
| <span class="sd"> any value less than or equal to -9223372036854775808.</span> |
| <span class="sd"> end : int</span> |
| <span class="sd"> boundary end, inclusive.</span> |
| <span class="sd"> The frame is unbounded if this is ``Window.unboundedFollowing``, or</span> |
| <span class="sd"> any value greater than or equal to 9223372036854775807.</span> |
| |
| <span class="sd"> Returns</span> |
| <span class="sd"> -------</span> |
| <span class="sd"> :class: `WindowSpec`</span> |
| <span class="sd"> A :class:`WindowSpec` with the frame boundaries defined,</span> |
| <span class="sd"> from `start` (inclusive) to `end` (inclusive).</span> |
| |
| <span class="sd"> Examples</span> |
| <span class="sd"> --------</span> |
| <span class="sd"> >>> from pyspark.sql import Window</span> |
| <span class="sd"> >>> from pyspark.sql import functions as func</span> |
| <span class="sd"> >>> df = spark.createDataFrame(</span> |
| <span class="sd"> ... [(1, "a"), (1, "a"), (2, "a"), (1, "b"), (2, "b"), (3, "b")], ["id", "category"])</span> |
| <span class="sd"> >>> df.show()</span> |
| <span class="sd"> +---+--------+</span> |
| <span class="sd"> | id|category|</span> |
| <span class="sd"> +---+--------+</span> |
| <span class="sd"> | 1| a|</span> |
| <span class="sd"> | 1| a|</span> |
| <span class="sd"> | 2| a|</span> |
| <span class="sd"> | 1| b|</span> |
| <span class="sd"> | 2| b|</span> |
| <span class="sd"> | 3| b|</span> |
| <span class="sd"> +---+--------+</span> |
| |
| <span class="sd"> Calculate sum of ``id`` in the range from currentRow to currentRow + 1</span> |
| <span class="sd"> in partition ``category``</span> |
| |
| <span class="sd"> >>> window = Window.partitionBy("category").orderBy("id").rowsBetween(Window.currentRow, 1)</span> |
| <span class="sd"> >>> df.withColumn("sum", func.sum("id").over(window)).sort("id", "category", "sum").show()</span> |
| <span class="sd"> +---+--------+---+</span> |
| <span class="sd"> | id|category|sum|</span> |
| <span class="sd"> +---+--------+---+</span> |
| <span class="sd"> | 1| a| 2|</span> |
| <span class="sd"> | 1| a| 3|</span> |
| <span class="sd"> | 1| b| 3|</span> |
| <span class="sd"> | 2| a| 2|</span> |
| <span class="sd"> | 2| b| 5|</span> |
| <span class="sd"> | 3| b| 3|</span> |
| <span class="sd"> +---+--------+---+</span> |
| |
| <span class="sd"> """</span> |
| <span class="o">...</span></div> |
| |
| <div class="viewcode-block" id="Window.rangeBetween"><a class="viewcode-back" href="../../../reference/pyspark.sql/api/pyspark.sql.Window.rangeBetween.html#pyspark.sql.Window.rangeBetween">[docs]</a> <span class="nd">@staticmethod</span> |
| <span class="nd">@dispatch_window_method</span> |
| <span class="k">def</span> <span class="nf">rangeBetween</span><span class="p">(</span><span class="n">start</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">end</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="s2">"WindowSpec"</span><span class="p">:</span> |
| <span class="w"> </span><span class="sd">"""</span> |
| <span class="sd"> Creates a :class:`WindowSpec` with the frame boundaries defined,</span> |
| <span class="sd"> from `start` (inclusive) to `end` (inclusive).</span> |
| |
| <span class="sd"> Both `start` and `end` are relative from the current row. For example,</span> |
| <span class="sd"> "0" means "current row", while "-1" means one off before the current row,</span> |
| <span class="sd"> and "5" means the five off after the current row.</span> |
| |
| <span class="sd"> We recommend users use ``Window.unboundedPreceding``, ``Window.unboundedFollowing``,</span> |
| <span class="sd"> and ``Window.currentRow`` to specify special boundary values, rather than using integral</span> |
| <span class="sd"> values directly.</span> |
| |
| <span class="sd"> A range-based boundary is based on the actual value of the ORDER BY</span> |
| <span class="sd"> expression(s). An offset is used to alter the value of the ORDER BY expression, for</span> |
| <span class="sd"> instance if the current ORDER BY expression has a value of 10 and the lower bound offset</span> |
| <span class="sd"> is -3, the resulting lower bound for the current row will be 10 - 3 = 7. This however puts a</span> |
| <span class="sd"> number of constraints on the ORDER BY expressions: there can be only one expression and this</span> |
| <span class="sd"> expression must have a numerical data type. An exception can be made when the offset is</span> |
| <span class="sd"> unbounded, because no value modification is needed, in this case multiple and non-numeric</span> |
| <span class="sd"> ORDER BY expression are allowed.</span> |
| |
| <span class="sd"> .. versionadded:: 2.1.0</span> |
| |
| <span class="sd"> Parameters</span> |
| <span class="sd"> ----------</span> |
| <span class="sd"> start : int</span> |
| <span class="sd"> boundary start, inclusive.</span> |
| <span class="sd"> The frame is unbounded if this is ``Window.unboundedPreceding``, or</span> |
| <span class="sd"> any value less than or equal to max(-sys.maxsize, -9223372036854775808).</span> |
| <span class="sd"> end : int</span> |
| <span class="sd"> boundary end, inclusive.</span> |
| <span class="sd"> The frame is unbounded if this is ``Window.unboundedFollowing``, or</span> |
| <span class="sd"> any value greater than or equal to min(sys.maxsize, 9223372036854775807).</span> |
| |
| <span class="sd"> Returns</span> |
| <span class="sd"> -------</span> |
| <span class="sd"> :class: `WindowSpec`</span> |
| <span class="sd"> A :class:`WindowSpec` with the frame boundaries defined,</span> |
| <span class="sd"> from `start` (inclusive) to `end` (inclusive).</span> |
| |
| <span class="sd"> Examples</span> |
| <span class="sd"> --------</span> |
| <span class="sd"> >>> from pyspark.sql import Window</span> |
| <span class="sd"> >>> from pyspark.sql import functions as func</span> |
| <span class="sd"> >>> df = spark.createDataFrame(</span> |
| <span class="sd"> ... [(1, "a"), (1, "a"), (2, "a"), (1, "b"), (2, "b"), (3, "b")], ["id", "category"])</span> |
| <span class="sd"> >>> df.show()</span> |
| <span class="sd"> +---+--------+</span> |
| <span class="sd"> | id|category|</span> |
| <span class="sd"> +---+--------+</span> |
| <span class="sd"> | 1| a|</span> |
| <span class="sd"> | 1| a|</span> |
| <span class="sd"> | 2| a|</span> |
| <span class="sd"> | 1| b|</span> |
| <span class="sd"> | 2| b|</span> |
| <span class="sd"> | 3| b|</span> |
| <span class="sd"> +---+--------+</span> |
| |
| <span class="sd"> Calculate sum of ``id`` in the range from ``id`` of currentRow to ``id`` of currentRow + 1</span> |
| <span class="sd"> in partition ``category``</span> |
| |
| <span class="sd"> >>> window = Window.partitionBy("category").orderBy("id").rangeBetween(Window.currentRow, 1)</span> |
| <span class="sd"> >>> df.withColumn("sum", func.sum("id").over(window)).sort("id", "category").show()</span> |
| <span class="sd"> +---+--------+---+</span> |
| <span class="sd"> | id|category|sum|</span> |
| <span class="sd"> +---+--------+---+</span> |
| <span class="sd"> | 1| a| 4|</span> |
| <span class="sd"> | 1| a| 4|</span> |
| <span class="sd"> | 1| b| 3|</span> |
| <span class="sd"> | 2| a| 2|</span> |
| <span class="sd"> | 2| b| 5|</span> |
| <span class="sd"> | 3| b| 3|</span> |
| <span class="sd"> +---+--------+---+</span> |
| |
| <span class="sd"> """</span> |
| <span class="o">...</span></div></div> |
| |
| |
| <span class="k">class</span> <span class="nc">WindowSpec</span><span class="p">:</span> |
| <span class="w"> </span><span class="sd">"""</span> |
| <span class="sd"> A window specification that defines the partitioning, ordering,</span> |
| <span class="sd"> and frame boundaries.</span> |
| |
| <span class="sd"> Use the static methods in :class:`Window` to create a :class:`WindowSpec`.</span> |
| |
| <span class="sd"> .. versionadded:: 1.4.0</span> |
| |
| <span class="sd"> .. versionchanged:: 3.4.0</span> |
| <span class="sd"> Supports Spark Connect.</span> |
| <span class="sd"> """</span> |
| |
| <span class="k">def</span> <span class="fm">__new__</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">jspec</span><span class="p">:</span> <span class="s2">"JavaObject"</span><span class="p">)</span> <span class="o">-></span> <span class="s2">"WindowSpec"</span><span class="p">:</span> |
| <span class="kn">from</span> <span class="nn">pyspark.sql.classic.WindowSpec</span> <span class="kn">import</span> <span class="n">WindowSpec</span> <span class="c1"># type: ignore[import-not-found]</span> |
| |
| <span class="k">return</span> <span class="n">WindowSpec</span><span class="o">.</span><span class="fm">__new__</span><span class="p">(</span><span class="n">WindowSpec</span><span class="p">,</span> <span class="n">jspec</span><span class="p">)</span> |
| |
| <div class="viewcode-block" id="WindowSpec.partitionBy"><a class="viewcode-back" href="../../../reference/pyspark.sql/api/pyspark.sql.WindowSpec.partitionBy.html#pyspark.sql.WindowSpec.partitionBy">[docs]</a> <span class="k">def</span> <span class="nf">partitionBy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="s2">"ColumnOrName"</span><span class="p">,</span> <span class="n">Sequence</span><span class="p">[</span><span class="s2">"ColumnOrName"</span><span class="p">]])</span> <span class="o">-></span> <span class="s2">"WindowSpec"</span><span class="p">:</span> |
| <span class="w"> </span><span class="sd">"""</span> |
| <span class="sd"> Defines the partitioning columns in a :class:`WindowSpec`.</span> |
| |
| <span class="sd"> .. versionadded:: 1.4.0</span> |
| |
| <span class="sd"> Parameters</span> |
| <span class="sd"> ----------</span> |
| <span class="sd"> cols : str, :class:`Column` or list</span> |
| <span class="sd"> names of columns or expressions</span> |
| <span class="sd"> """</span> |
| <span class="o">...</span></div> |
| |
| <div class="viewcode-block" id="WindowSpec.orderBy"><a class="viewcode-back" href="../../../reference/pyspark.sql/api/pyspark.sql.WindowSpec.orderBy.html#pyspark.sql.WindowSpec.orderBy">[docs]</a> <span class="k">def</span> <span class="nf">orderBy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="s2">"ColumnOrName"</span><span class="p">,</span> <span class="n">Sequence</span><span class="p">[</span><span class="s2">"ColumnOrName"</span><span class="p">]])</span> <span class="o">-></span> <span class="s2">"WindowSpec"</span><span class="p">:</span> |
| <span class="w"> </span><span class="sd">"""</span> |
| <span class="sd"> Defines the ordering columns in a :class:`WindowSpec`.</span> |
| |
| <span class="sd"> .. versionadded:: 1.4.0</span> |
| |
| <span class="sd"> Parameters</span> |
| <span class="sd"> ----------</span> |
| <span class="sd"> cols : str, :class:`Column` or list</span> |
| <span class="sd"> names of columns or expressions</span> |
| <span class="sd"> """</span> |
| <span class="o">...</span></div> |
| |
| <div class="viewcode-block" id="WindowSpec.rowsBetween"><a class="viewcode-back" href="../../../reference/pyspark.sql/api/pyspark.sql.WindowSpec.rowsBetween.html#pyspark.sql.WindowSpec.rowsBetween">[docs]</a> <span class="k">def</span> <span class="nf">rowsBetween</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">end</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="s2">"WindowSpec"</span><span class="p">:</span> |
| <span class="w"> </span><span class="sd">"""</span> |
| <span class="sd"> Defines the frame boundaries, from `start` (inclusive) to `end` (inclusive).</span> |
| |
| <span class="sd"> Both `start` and `end` are relative positions from the current row.</span> |
| <span class="sd"> For example, "0" means "current row", while "-1" means the row before</span> |
| <span class="sd"> the current row, and "5" means the fifth row after the current row.</span> |
| |
| <span class="sd"> We recommend users use ``Window.unboundedPreceding``, ``Window.unboundedFollowing``,</span> |
| <span class="sd"> and ``Window.currentRow`` to specify special boundary values, rather than using integral</span> |
| <span class="sd"> values directly.</span> |
| |
| <span class="sd"> .. versionadded:: 1.4.0</span> |
| |
| <span class="sd"> Parameters</span> |
| <span class="sd"> ----------</span> |
| <span class="sd"> start : int</span> |
| <span class="sd"> boundary start, inclusive.</span> |
| <span class="sd"> The frame is unbounded if this is ``Window.unboundedPreceding``, or</span> |
| <span class="sd"> any value less than or equal to max(-sys.maxsize, -9223372036854775808).</span> |
| <span class="sd"> end : int</span> |
| <span class="sd"> boundary end, inclusive.</span> |
| <span class="sd"> The frame is unbounded if this is ``Window.unboundedFollowing``, or</span> |
| <span class="sd"> any value greater than or equal to min(sys.maxsize, 9223372036854775807).</span> |
| <span class="sd"> """</span> |
| <span class="o">...</span></div> |
| |
| <div class="viewcode-block" id="WindowSpec.rangeBetween"><a class="viewcode-back" href="../../../reference/pyspark.sql/api/pyspark.sql.WindowSpec.rangeBetween.html#pyspark.sql.WindowSpec.rangeBetween">[docs]</a> <span class="k">def</span> <span class="nf">rangeBetween</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">end</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="s2">"WindowSpec"</span><span class="p">:</span> |
| <span class="w"> </span><span class="sd">"""</span> |
| <span class="sd"> Defines the frame boundaries, from `start` (inclusive) to `end` (inclusive).</span> |
| |
| <span class="sd"> Both `start` and `end` are relative from the current row. For example,</span> |
| <span class="sd"> "0" means "current row", while "-1" means one off before the current row,</span> |
| <span class="sd"> and "5" means the five off after the current row.</span> |
| |
| <span class="sd"> We recommend users use ``Window.unboundedPreceding``, ``Window.unboundedFollowing``,</span> |
| <span class="sd"> and ``Window.currentRow`` to specify special boundary values, rather than using integral</span> |
| <span class="sd"> values directly.</span> |
| |
| <span class="sd"> .. versionadded:: 1.4.0</span> |
| |
| <span class="sd"> Parameters</span> |
| <span class="sd"> ----------</span> |
| <span class="sd"> start : int</span> |
| <span class="sd"> boundary start, inclusive.</span> |
| <span class="sd"> The frame is unbounded if this is ``Window.unboundedPreceding``, or</span> |
| <span class="sd"> any value less than or equal to max(-sys.maxsize, -9223372036854775808).</span> |
| <span class="sd"> end : int</span> |
| <span class="sd"> boundary end, inclusive.</span> |
| <span class="sd"> The frame is unbounded if this is ``Window.unboundedFollowing``, or</span> |
| <span class="sd"> any value greater than or equal to min(sys.maxsize, 9223372036854775807).</span> |
| <span class="sd"> """</span> |
| <span class="o">...</span></div> |
| </pre></div> |
| |
| </article> |
| |
| |
| |
| <footer class="bd-footer-article"> |
| |
| <div class="footer-article-items footer-article__inner"> |
| |
| <div class="footer-article-item"><!-- Previous / next buttons --> |
| <div class="prev-next-area"> |
| </div></div> |
| |
| </div> |
| |
| </footer> |
| |
| </div> |
| |
| |
| |
| |
| </div> |
| <footer class="bd-footer-content"> |
| |
| </footer> |
| |
| </main> |
| </div> |
| </div> |
| |
| <!-- Scripts loaded after <body> so the DOM is not blocked --> |
| <script src="../../../_static/scripts/bootstrap.js?digest=e353d410970836974a52"></script> |
| <script src="../../../_static/scripts/pydata-sphinx-theme.js?digest=e353d410970836974a52"></script> |
| |
| <footer class="bd-footer"> |
| <div class="bd-footer__inner bd-page-width"> |
| |
| <div class="footer-items__start"> |
| |
| <div class="footer-item"><p class="copyright"> |
| Copyright @ 2024 The Apache Software Foundation, Licensed under the <a href="https://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>. |
| </p></div> |
| |
| <div class="footer-item"> |
| <p class="sphinx-version"> |
| Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.5.0. |
| <br/> |
| </p> |
| </div> |
| |
| </div> |
| |
| |
| <div class="footer-items__end"> |
| |
| <div class="footer-item"><p class="theme-version"> |
| Built with the <a href="https://pydata-sphinx-theme.readthedocs.io/en/stable/index.html">PyData Sphinx Theme</a> 0.13.3. |
| </p></div> |
| |
| </div> |
| |
| </div> |
| |
| </footer> |
| </body> |
| </html> |