diff options
Diffstat (limited to '')
-rw-r--r-- | docs/sqlglot/dataframe/sql.html | 4953 |
1 files changed, 4953 insertions, 0 deletions
diff --git a/docs/sqlglot/dataframe/sql.html b/docs/sqlglot/dataframe/sql.html new file mode 100644 index 0000000..83f5418 --- /dev/null +++ b/docs/sqlglot/dataframe/sql.html @@ -0,0 +1,4953 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <meta name="generator" content="pdoc 12.3.1"/> + <title>sqlglot.dataframe.sql API documentation</title> + + <style>/*! * Bootstrap Reboot v5.0.0 (https://getbootstrap.com/) * Copyright 2011-2021 The Bootstrap Authors * Copyright 2011-2021 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) */*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans","Liberation Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";font-size:1rem;font-weight:400;line-height:1.5;color:#212529;background-color:#fff;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[data-bs-original-title],abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-left:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:left}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]::-webkit-calendar-picker-indicator{display:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:left;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:left}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-text,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:textfield}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::file-selector-button{font:inherit}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important}</style> + <style>/*! syntax-highlighting.css */pre{line-height:125%;}span.linenos{color:inherit; background-color:transparent; padding-left:5px; padding-right:20px;}.pdoc-code .hll{background-color:#ffffcc}.pdoc-code{background:#f8f8f8;}.pdoc-code .c{color:#3D7B7B; font-style:italic}.pdoc-code .err{border:1px solid #FF0000}.pdoc-code .k{color:#008000; font-weight:bold}.pdoc-code .o{color:#666666}.pdoc-code .ch{color:#3D7B7B; font-style:italic}.pdoc-code .cm{color:#3D7B7B; font-style:italic}.pdoc-code .cp{color:#9C6500}.pdoc-code .cpf{color:#3D7B7B; font-style:italic}.pdoc-code .c1{color:#3D7B7B; font-style:italic}.pdoc-code .cs{color:#3D7B7B; font-style:italic}.pdoc-code .gd{color:#A00000}.pdoc-code .ge{font-style:italic}.pdoc-code .gr{color:#E40000}.pdoc-code .gh{color:#000080; font-weight:bold}.pdoc-code .gi{color:#008400}.pdoc-code .go{color:#717171}.pdoc-code .gp{color:#000080; font-weight:bold}.pdoc-code .gs{font-weight:bold}.pdoc-code .gu{color:#800080; font-weight:bold}.pdoc-code .gt{color:#0044DD}.pdoc-code .kc{color:#008000; font-weight:bold}.pdoc-code .kd{color:#008000; font-weight:bold}.pdoc-code .kn{color:#008000; font-weight:bold}.pdoc-code .kp{color:#008000}.pdoc-code .kr{color:#008000; font-weight:bold}.pdoc-code .kt{color:#B00040}.pdoc-code .m{color:#666666}.pdoc-code .s{color:#BA2121}.pdoc-code .na{color:#687822}.pdoc-code .nb{color:#008000}.pdoc-code .nc{color:#0000FF; font-weight:bold}.pdoc-code .no{color:#880000}.pdoc-code .nd{color:#AA22FF}.pdoc-code .ni{color:#717171; font-weight:bold}.pdoc-code .ne{color:#CB3F38; font-weight:bold}.pdoc-code .nf{color:#0000FF}.pdoc-code .nl{color:#767600}.pdoc-code .nn{color:#0000FF; font-weight:bold}.pdoc-code .nt{color:#008000; font-weight:bold}.pdoc-code .nv{color:#19177C}.pdoc-code .ow{color:#AA22FF; font-weight:bold}.pdoc-code .w{color:#bbbbbb}.pdoc-code .mb{color:#666666}.pdoc-code .mf{color:#666666}.pdoc-code .mh{color:#666666}.pdoc-code .mi{color:#666666}.pdoc-code .mo{color:#666666}.pdoc-code .sa{color:#BA2121}.pdoc-code .sb{color:#BA2121}.pdoc-code .sc{color:#BA2121}.pdoc-code .dl{color:#BA2121}.pdoc-code .sd{color:#BA2121; font-style:italic}.pdoc-code .s2{color:#BA2121}.pdoc-code .se{color:#AA5D1F; font-weight:bold}.pdoc-code .sh{color:#BA2121}.pdoc-code .si{color:#A45A77; font-weight:bold}.pdoc-code .sx{color:#008000}.pdoc-code .sr{color:#A45A77}.pdoc-code .s1{color:#BA2121}.pdoc-code .ss{color:#19177C}.pdoc-code .bp{color:#008000}.pdoc-code .fm{color:#0000FF}.pdoc-code .vc{color:#19177C}.pdoc-code .vg{color:#19177C}.pdoc-code .vi{color:#19177C}.pdoc-code .vm{color:#19177C}.pdoc-code .il{color:#666666}</style> + <style>/*! theme.css */:root{--pdoc-background:#fff;}.pdoc{--text:#212529;--muted:#6c757d;--link:#3660a5;--link-hover:#1659c5;--code:#f8f8f8;--active:#fff598;--accent:#eee;--accent2:#c1c1c1;--nav-hover:rgba(255, 255, 255, 0.5);--name:#0066BB;--def:#008800;--annotation:#007020;}</style> + <style>/*! layout.css */html, body{width:100%;height:100%;}html, main{scroll-behavior:smooth;}body{background-color:var(--pdoc-background);}@media (max-width:769px){#navtoggle{cursor:pointer;position:absolute;width:50px;height:40px;top:1rem;right:1rem;border-color:var(--text);color:var(--text);display:flex;opacity:0.8;}#navtoggle:hover{opacity:1;}#togglestate + div{display:none;}#togglestate:checked + div{display:inherit;}main, header{padding:2rem 3vw;}header + main{margin-top:-3rem;}.git-button{display:none !important;}nav input[type="search"]{max-width:77%;}nav input[type="search"]:first-child{margin-top:-6px;}nav input[type="search"]:valid ~ *{display:none !important;}}@media (min-width:770px){:root{--sidebar-width:clamp(12.5rem, 28vw, 22rem);}nav{position:fixed;overflow:auto;height:100vh;width:var(--sidebar-width);}main, header{padding:3rem 2rem 3rem calc(var(--sidebar-width) + 3rem);width:calc(54rem + var(--sidebar-width));max-width:100%;}header + main{margin-top:-4rem;}#navtoggle{display:none;}}#togglestate{position:absolute;height:0;opacity:0;}nav.pdoc{--pad:clamp(0.5rem, 2vw, 1.75rem);--indent:1.5rem;background-color:var(--accent);border-right:1px solid var(--accent2);box-shadow:0 0 20px rgba(50, 50, 50, .2) inset;padding:0 0 0 var(--pad);overflow-wrap:anywhere;scrollbar-width:thin; scrollbar-color:var(--accent2) transparent }nav.pdoc::-webkit-scrollbar{width:.4rem; }nav.pdoc::-webkit-scrollbar-thumb{background-color:var(--accent2); }nav.pdoc > div{padding:var(--pad) 0;}nav.pdoc .module-list-button{display:inline-flex;align-items:center;color:var(--text);border-color:var(--muted);margin-bottom:1rem;}nav.pdoc .module-list-button:hover{border-color:var(--text);}nav.pdoc input[type=search]{display:block;outline-offset:0;width:calc(100% - var(--pad));}nav.pdoc .logo{max-width:calc(100% - var(--pad));max-height:35vh;display:block;margin:0 auto 1rem;transform:translate(calc(-.5 * var(--pad)), 0);}nav.pdoc ul{list-style:none;padding-left:0;}nav.pdoc > div > ul{margin-left:calc(0px - var(--pad));}nav.pdoc li a{padding:.2rem 0 .2rem calc(var(--pad) + var(--indent));}nav.pdoc > div > ul > li > a{padding-left:var(--pad);}nav.pdoc li{transition:all 100ms;}nav.pdoc li:hover{background-color:var(--nav-hover);}nav.pdoc a, nav.pdoc a:hover{color:var(--text);}nav.pdoc a{display:block;}nav.pdoc > h2:first-of-type{margin-top:1.5rem;}nav.pdoc .class:before{content:"class ";color:var(--muted);}nav.pdoc .function:after{content:"()";color:var(--muted);}nav.pdoc footer:before{content:"";display:block;width:calc(100% - var(--pad));border-top:solid var(--accent2) 1px;margin-top:1.5rem;padding-top:.5rem;}nav.pdoc footer{font-size:small;}</style> + <style>/*! content.css */.pdoc{color:var(--text);box-sizing:border-box;line-height:1.5;background:none;}.pdoc .pdoc-button{display:inline-block;border:solid black 1px;border-radius:2px;font-size:.75rem;padding:calc(0.5em - 1px) 1em;transition:100ms all;}.pdoc .pdoc-alert{padding:1rem 1rem 1rem calc(1.5rem + 24px);border:1px solid transparent;border-radius:.25rem;background-repeat:no-repeat;background-position:1rem center;margin-bottom:1rem;}.pdoc .pdoc-alert > *:last-child{margin-bottom:0;}.pdoc .pdoc-alert-note {color:#084298;background-color:#cfe2ff;border-color:#b6d4fe;background-image:url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23084298%22%20viewBox%3D%220%200%2016%2016%22%3E%3Cpath%20d%3D%22M8%2016A8%208%200%201%200%208%200a8%208%200%200%200%200%2016zm.93-9.412-1%204.705c-.07.34.029.533.304.533.194%200%20.487-.07.686-.246l-.088.416c-.287.346-.92.598-1.465.598-.703%200-1.002-.422-.808-1.319l.738-3.468c.064-.293.006-.399-.287-.47l-.451-.081.082-.381%202.29-.287zM8%205.5a1%201%200%201%201%200-2%201%201%200%200%201%200%202z%22/%3E%3C/svg%3E");}.pdoc .pdoc-alert-warning{color:#664d03;background-color:#fff3cd;border-color:#ffecb5;background-image:url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23664d03%22%20viewBox%3D%220%200%2016%2016%22%3E%3Cpath%20d%3D%22M8.982%201.566a1.13%201.13%200%200%200-1.96%200L.165%2013.233c-.457.778.091%201.767.98%201.767h13.713c.889%200%201.438-.99.98-1.767L8.982%201.566zM8%205c.535%200%20.954.462.9.995l-.35%203.507a.552.552%200%200%201-1.1%200L7.1%205.995A.905.905%200%200%201%208%205zm.002%206a1%201%200%201%201%200%202%201%201%200%200%201%200-2z%22/%3E%3C/svg%3E");}.pdoc .pdoc-alert-danger{color:#842029;background-color:#f8d7da;border-color:#f5c2c7;background-image:url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22%23842029%22%20viewBox%3D%220%200%2016%2016%22%3E%3Cpath%20d%3D%22M5.52.359A.5.5%200%200%201%206%200h4a.5.5%200%200%201%20.474.658L8.694%206H12.5a.5.5%200%200%201%20.395.807l-7%209a.5.5%200%200%201-.873-.454L6.823%209.5H3.5a.5.5%200%200%201-.48-.641l2.5-8.5z%22/%3E%3C/svg%3E");}.pdoc .visually-hidden{position:absolute !important;width:1px !important;height:1px !important;padding:0 !important;margin:-1px !important;overflow:hidden !important;clip:rect(0, 0, 0, 0) !important;white-space:nowrap !important;border:0 !important;}.pdoc h1, .pdoc h2, .pdoc h3{font-weight:300;margin:.3em 0;padding:.2em 0;}.pdoc > section:not(.module-info) h1{font-size:1.5rem;font-weight:500;}.pdoc > section:not(.module-info) h2{font-size:1.4rem;font-weight:500;}.pdoc > section:not(.module-info) h3{font-size:1.3rem;font-weight:500;}.pdoc > section:not(.module-info) h4{font-size:1.2rem;}.pdoc > section:not(.module-info) h5{font-size:1.1rem;}.pdoc a{text-decoration:none;color:var(--link);}.pdoc a:hover{color:var(--link-hover);}.pdoc blockquote{margin-left:2rem;}.pdoc pre{border-top:1px solid var(--accent2);border-bottom:1px solid var(--accent2);margin-top:0;margin-bottom:1em;padding:.5rem 0 .5rem .5rem;overflow-x:auto;background-color:var(--code);}.pdoc code{color:var(--text);padding:.2em .4em;margin:0;font-size:85%;background-color:var(--code);border-radius:6px;}.pdoc a > code{color:inherit;}.pdoc pre > code{display:inline-block;font-size:inherit;background:none;border:none;padding:0;}.pdoc > section:not(.module-info){margin-bottom:1.5rem;}.pdoc .modulename{margin-top:0;font-weight:bold;}.pdoc .modulename a{color:var(--link);transition:100ms all;}.pdoc .git-button{float:right;border:solid var(--link) 1px;}.pdoc .git-button:hover{background-color:var(--link);color:var(--pdoc-background);}.view-source-toggle-state,.view-source-toggle-state ~ .pdoc-code{display:none;}.view-source-toggle-state:checked ~ .pdoc-code{display:block;}.view-source-button{display:inline-block;float:right;font-size:.75rem;line-height:1.5rem;color:var(--muted);padding:0 .4rem 0 1.3rem;cursor:pointer;text-indent:-2px;}.view-source-button > span{visibility:hidden;}.module-info .view-source-button{float:none;display:flex;justify-content:flex-end;margin:-1.2rem .4rem -.2rem 0;}.view-source-button::before{position:absolute;content:"View Source";display:list-item;list-style-type:disclosure-closed;}.view-source-toggle-state:checked ~ .attr .view-source-button::before,.view-source-toggle-state:checked ~ .view-source-button::before{list-style-type:disclosure-open;}.pdoc .docstring{margin-bottom:1.5rem;}.pdoc section:not(.module-info) .docstring{margin-left:clamp(0rem, 5vw - 2rem, 1rem);}.pdoc .docstring .pdoc-code{margin-left:1em;margin-right:1em;}.pdoc h1:target,.pdoc h2:target,.pdoc h3:target,.pdoc h4:target,.pdoc h5:target,.pdoc h6:target,.pdoc .pdoc-code > pre > span:target{background-color:var(--active);box-shadow:-1rem 0 0 0 var(--active);}.pdoc .pdoc-code > pre > span:target{display:block;}.pdoc div:target > .attr,.pdoc section:target > .attr,.pdoc dd:target > a{background-color:var(--active);}.pdoc *{scroll-margin:2rem;}.pdoc .pdoc-code .linenos{user-select:none;}.pdoc .attr:hover{filter:contrast(0.95);}.pdoc section, .pdoc .classattr{position:relative;}.pdoc .headerlink{--width:clamp(1rem, 3vw, 2rem);position:absolute;top:0;left:calc(0rem - var(--width));transition:all 100ms ease-in-out;opacity:0;}.pdoc .headerlink::before{content:"#";display:block;text-align:center;width:var(--width);height:2.3rem;line-height:2.3rem;font-size:1.5rem;}.pdoc .attr:hover ~ .headerlink,.pdoc *:target > .headerlink,.pdoc .headerlink:hover{opacity:1;}.pdoc .attr{display:block;margin:.5rem 0 .5rem;padding:.4rem .4rem .4rem 1rem;background-color:var(--accent);overflow-x:auto;}.pdoc .classattr{margin-left:2rem;}.pdoc .name{color:var(--name);font-weight:bold;}.pdoc .def{color:var(--def);font-weight:bold;}.pdoc .signature{background-color:transparent;}.pdoc .param, .pdoc .return-annotation{white-space:pre;}.pdoc .signature.multiline .param{display:block;}.pdoc .signature.condensed .param{display:inline-block;}.pdoc .annotation{color:var(--annotation);}.pdoc .inherited{margin-left:2rem;}.pdoc .inherited dt{font-weight:700;}.pdoc .inherited dt, .pdoc .inherited dd{display:inline;margin-left:0;margin-bottom:.5rem;}.pdoc .inherited dd:not(:last-child):after{content:", ";}.pdoc .inherited .class:before{content:"class ";}.pdoc .inherited .function a:after{content:"()";}.pdoc .search-result .docstring{overflow:auto;max-height:25vh;}.pdoc .search-result.focused > .attr{background-color:var(--active);}.pdoc .attribution{margin-top:2rem;display:block;opacity:0.5;transition:all 200ms;filter:grayscale(100%);}.pdoc .attribution:hover{opacity:1;filter:grayscale(0%);}.pdoc .attribution img{margin-left:5px;height:35px;vertical-align:middle;width:70px;transition:all 200ms;}.pdoc table{display:block;width:max-content;max-width:100%;overflow:auto;margin-bottom:1rem;}.pdoc table th{font-weight:600;}.pdoc table th, .pdoc table td{padding:6px 13px;border:1px solid var(--accent2);}</style> + <style>/*! custom.css */</style></head> +<body> + <nav class="pdoc"> + <label id="navtoggle" for="togglestate" class="pdoc-button"><svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke-linecap='round' stroke="currentColor" stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg></label> + <input id="togglestate" type="checkbox" aria-hidden="true" tabindex="-1"> + <div> <a class="pdoc-button module-list-button" href="../dataframe.html"> +<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-box-arrow-in-left" viewBox="0 0 16 16"> + <path fill-rule="evenodd" d="M10 3.5a.5.5 0 0 0-.5-.5h-8a.5.5 0 0 0-.5.5v9a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-2a.5.5 0 0 1 1 0v2A1.5 1.5 0 0 1 9.5 14h-8A1.5 1.5 0 0 1 0 12.5v-9A1.5 1.5 0 0 1 1.5 2h8A1.5 1.5 0 0 1 11 3.5v2a.5.5 0 0 1-1 0v-2z"/> + <path fill-rule="evenodd" d="M4.146 8.354a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L5.707 7.5H14.5a.5.5 0 0 1 0 1H5.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3z"/> +</svg> sqlglot.dataframe</a> + + + <input type="search" placeholder="Search..." role="searchbox" aria-label="search" + pattern=".+" required> + + + + <h2>API Documentation</h2> + <ul class="memberlist"> + <li> + <a class="class" href="#SparkSession">SparkSession</a> + <ul class="memberlist"> + <li> + <a class="function" href="#SparkSession.__init__">SparkSession</a> + </li> + <li> + <a class="function" href="#SparkSession.table">table</a> + </li> + <li> + <a class="function" href="#SparkSession.createDataFrame">createDataFrame</a> + </li> + <li> + <a class="function" href="#SparkSession.sql">sql</a> + </li> + </ul> + + </li> + <li> + <a class="class" href="#DataFrame">DataFrame</a> + <ul class="memberlist"> + <li> + <a class="function" href="#DataFrame.__init__">DataFrame</a> + </li> + <li> + <a class="function" href="#DataFrame.sql">sql</a> + </li> + <li> + <a class="function" href="#DataFrame.copy">copy</a> + </li> + <li> + <a class="function" href="#DataFrame.select">select</a> + </li> + <li> + <a class="function" href="#DataFrame.alias">alias</a> + </li> + <li> + <a class="function" href="#DataFrame.where">where</a> + </li> + <li> + <a class="function" href="#DataFrame.filter">filter</a> + </li> + <li> + <a class="function" href="#DataFrame.groupBy">groupBy</a> + </li> + <li> + <a class="function" href="#DataFrame.agg">agg</a> + </li> + <li> + <a class="function" href="#DataFrame.join">join</a> + </li> + <li> + <a class="function" href="#DataFrame.orderBy">orderBy</a> + </li> + <li> + <a class="function" href="#DataFrame.sort">sort</a> + </li> + <li> + <a class="function" href="#DataFrame.union">union</a> + </li> + <li> + <a class="function" href="#DataFrame.unionAll">unionAll</a> + </li> + <li> + <a class="function" href="#DataFrame.unionByName">unionByName</a> + </li> + <li> + <a class="function" href="#DataFrame.intersect">intersect</a> + </li> + <li> + <a class="function" href="#DataFrame.intersectAll">intersectAll</a> + </li> + <li> + <a class="function" href="#DataFrame.exceptAll">exceptAll</a> + </li> + <li> + <a class="function" href="#DataFrame.distinct">distinct</a> + </li> + <li> + <a class="function" href="#DataFrame.dropDuplicates">dropDuplicates</a> + </li> + <li> + <a class="function" href="#DataFrame.dropna">dropna</a> + </li> + <li> + <a class="function" href="#DataFrame.fillna">fillna</a> + </li> + <li> + <a class="function" href="#DataFrame.replace">replace</a> + </li> + <li> + <a class="function" href="#DataFrame.withColumn">withColumn</a> + </li> + <li> + <a class="function" href="#DataFrame.withColumnRenamed">withColumnRenamed</a> + </li> + <li> + <a class="function" href="#DataFrame.drop">drop</a> + </li> + <li> + <a class="function" href="#DataFrame.limit">limit</a> + </li> + <li> + <a class="function" href="#DataFrame.hint">hint</a> + </li> + <li> + <a class="function" href="#DataFrame.repartition">repartition</a> + </li> + <li> + <a class="function" href="#DataFrame.coalesce">coalesce</a> + </li> + <li> + <a class="function" href="#DataFrame.cache">cache</a> + </li> + <li> + <a class="function" href="#DataFrame.persist">persist</a> + </li> + </ul> + + </li> + <li> + <a class="class" href="#GroupedData">GroupedData</a> + <ul class="memberlist"> + <li> + <a class="function" href="#GroupedData.__init__">GroupedData</a> + </li> + <li> + <a class="function" href="#GroupedData.agg">agg</a> + </li> + <li> + <a class="function" href="#GroupedData.count">count</a> + </li> + <li> + <a class="function" href="#GroupedData.mean">mean</a> + </li> + <li> + <a class="function" href="#GroupedData.avg">avg</a> + </li> + <li> + <a class="function" href="#GroupedData.max">max</a> + </li> + <li> + <a class="function" href="#GroupedData.min">min</a> + </li> + <li> + <a class="function" href="#GroupedData.sum">sum</a> + </li> + <li> + <a class="function" href="#GroupedData.pivot">pivot</a> + </li> + </ul> + + </li> + <li> + <a class="class" href="#Column">Column</a> + <ul class="memberlist"> + <li> + <a class="function" href="#Column.__init__">Column</a> + </li> + <li> + <a class="function" href="#Column.ensure_col">ensure_col</a> + </li> + <li> + <a class="function" href="#Column.ensure_cols">ensure_cols</a> + </li> + <li> + <a class="function" href="#Column.invoke_anonymous_function">invoke_anonymous_function</a> + </li> + <li> + <a class="function" href="#Column.invoke_expression_over_column">invoke_expression_over_column</a> + </li> + <li> + <a class="function" href="#Column.binary_op">binary_op</a> + </li> + <li> + <a class="function" href="#Column.inverse_binary_op">inverse_binary_op</a> + </li> + <li> + <a class="function" href="#Column.unary_op">unary_op</a> + </li> + <li> + <a class="function" href="#Column.ensure_literal">ensure_literal</a> + </li> + <li> + <a class="function" href="#Column.copy">copy</a> + </li> + <li> + <a class="function" href="#Column.set_table_name">set_table_name</a> + </li> + <li> + <a class="function" href="#Column.sql">sql</a> + </li> + <li> + <a class="function" href="#Column.alias">alias</a> + </li> + <li> + <a class="function" href="#Column.asc">asc</a> + </li> + <li> + <a class="function" href="#Column.desc">desc</a> + </li> + <li> + <a class="function" href="#Column.asc_nulls_first">asc_nulls_first</a> + </li> + <li> + <a class="function" href="#Column.asc_nulls_last">asc_nulls_last</a> + </li> + <li> + <a class="function" href="#Column.desc_nulls_first">desc_nulls_first</a> + </li> + <li> + <a class="function" href="#Column.desc_nulls_last">desc_nulls_last</a> + </li> + <li> + <a class="function" href="#Column.when">when</a> + </li> + <li> + <a class="function" href="#Column.otherwise">otherwise</a> + </li> + <li> + <a class="function" href="#Column.isNull">isNull</a> + </li> + <li> + <a class="function" href="#Column.isNotNull">isNotNull</a> + </li> + <li> + <a class="function" href="#Column.cast">cast</a> + </li> + <li> + <a class="function" href="#Column.startswith">startswith</a> + </li> + <li> + <a class="function" href="#Column.endswith">endswith</a> + </li> + <li> + <a class="function" href="#Column.rlike">rlike</a> + </li> + <li> + <a class="function" href="#Column.like">like</a> + </li> + <li> + <a class="function" href="#Column.ilike">ilike</a> + </li> + <li> + <a class="function" href="#Column.substr">substr</a> + </li> + <li> + <a class="function" href="#Column.isin">isin</a> + </li> + <li> + <a class="function" href="#Column.between">between</a> + </li> + <li> + <a class="function" href="#Column.over">over</a> + </li> + </ul> + + </li> + <li> + <a class="class" href="#DataFrameNaFunctions">DataFrameNaFunctions</a> + <ul class="memberlist"> + <li> + <a class="function" href="#DataFrameNaFunctions.__init__">DataFrameNaFunctions</a> + </li> + <li> + <a class="function" href="#DataFrameNaFunctions.drop">drop</a> + </li> + <li> + <a class="function" href="#DataFrameNaFunctions.fill">fill</a> + </li> + <li> + <a class="function" href="#DataFrameNaFunctions.replace">replace</a> + </li> + </ul> + + </li> + <li> + <a class="class" href="#Window">Window</a> + <ul class="memberlist"> + <li> + <a class="function" href="#Window.__init__">Window</a> + </li> + <li> + <a class="function" href="#Window.partitionBy">partitionBy</a> + </li> + <li> + <a class="function" href="#Window.orderBy">orderBy</a> + </li> + <li> + <a class="function" href="#Window.rowsBetween">rowsBetween</a> + </li> + <li> + <a class="function" href="#Window.rangeBetween">rangeBetween</a> + </li> + </ul> + + </li> + <li> + <a class="class" href="#WindowSpec">WindowSpec</a> + <ul class="memberlist"> + <li> + <a class="function" href="#WindowSpec.__init__">WindowSpec</a> + </li> + <li> + <a class="function" href="#WindowSpec.copy">copy</a> + </li> + <li> + <a class="function" href="#WindowSpec.sql">sql</a> + </li> + <li> + <a class="function" href="#WindowSpec.partitionBy">partitionBy</a> + </li> + <li> + <a class="function" href="#WindowSpec.orderBy">orderBy</a> + </li> + <li> + <a class="function" href="#WindowSpec.rowsBetween">rowsBetween</a> + </li> + <li> + <a class="function" href="#WindowSpec.rangeBetween">rangeBetween</a> + </li> + </ul> + + </li> + <li> + <a class="class" href="#DataFrameReader">DataFrameReader</a> + <ul class="memberlist"> + <li> + <a class="function" href="#DataFrameReader.__init__">DataFrameReader</a> + </li> + <li> + <a class="function" href="#DataFrameReader.table">table</a> + </li> + </ul> + + </li> + <li> + <a class="class" href="#DataFrameWriter">DataFrameWriter</a> + <ul class="memberlist"> + <li> + <a class="function" href="#DataFrameWriter.__init__">DataFrameWriter</a> + </li> + <li> + <a class="function" href="#DataFrameWriter.copy">copy</a> + </li> + <li> + <a class="function" href="#DataFrameWriter.sql">sql</a> + </li> + <li> + <a class="function" href="#DataFrameWriter.mode">mode</a> + </li> + <li> + <a class="function" href="#DataFrameWriter.insertInto">insertInto</a> + </li> + <li> + <a class="function" href="#DataFrameWriter.saveAsTable">saveAsTable</a> + </li> + </ul> + + </li> + </ul> + + + <footer>Copyright (c) 2023 Toby Mao</footer> + + <a class="attribution" title="pdoc: Python API documentation generator" href="https://pdoc.dev" target="_blank"> + built with <span class="visually-hidden">pdoc</span><img + alt="pdoc logo" + src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20role%3D%22img%22%20aria-label%3D%22pdoc%20logo%22%20width%3D%22300%22%20height%3D%22150%22%20viewBox%3D%22-1%200%2060%2030%22%3E%3Ctitle%3Epdoc%3C/title%3E%3Cpath%20d%3D%22M29.621%2021.293c-.011-.273-.214-.475-.511-.481a.5.5%200%200%200-.489.503l-.044%201.393c-.097.551-.695%201.215-1.566%201.704-.577.428-1.306.486-2.193.182-1.426-.617-2.467-1.654-3.304-2.487l-.173-.172a3.43%203.43%200%200%200-.365-.306.49.49%200%200%200-.286-.196c-1.718-1.06-4.931-1.47-7.353.191l-.219.15c-1.707%201.187-3.413%202.131-4.328%201.03-.02-.027-.49-.685-.141-1.763.233-.721.546-2.408.772-4.076.042-.09.067-.187.046-.288.166-1.347.277-2.625.241-3.351%201.378-1.008%202.271-2.586%202.271-4.362%200-.976-.272-1.935-.788-2.774-.057-.094-.122-.18-.184-.268.033-.167.052-.339.052-.516%200-1.477-1.202-2.679-2.679-2.679-.791%200-1.496.352-1.987.9a6.3%206.3%200%200%200-1.001.029c-.492-.564-1.207-.929-2.012-.929-1.477%200-2.679%201.202-2.679%202.679A2.65%202.65%200%200%200%20.97%206.554c-.383.747-.595%201.572-.595%202.41%200%202.311%201.507%204.29%203.635%205.107-.037.699-.147%202.27-.423%203.294l-.137.461c-.622%202.042-2.515%208.257%201.727%2010.643%201.614.908%203.06%201.248%204.317%201.248%202.665%200%204.492-1.524%205.322-2.401%201.476-1.559%202.886-1.854%206.491.82%201.877%201.393%203.514%201.753%204.861%201.068%202.223-1.713%202.811-3.867%203.399-6.374.077-.846.056-1.469.054-1.537zm-4.835%204.313c-.054.305-.156.586-.242.629-.034-.007-.131-.022-.307-.157-.145-.111-.314-.478-.456-.908.221.121.432.25.675.355.115.039.219.051.33.081zm-2.251-1.238c-.05.33-.158.648-.252.694-.022.001-.125-.018-.307-.157-.217-.166-.488-.906-.639-1.573.358.344.754.693%201.198%201.036zm-3.887-2.337c-.006-.116-.018-.231-.041-.342.635.145%201.189.368%201.599.625.097.231.166.481.174.642-.03.049-.055.101-.067.158-.046.013-.128.026-.298.004-.278-.037-.901-.57-1.367-1.087zm-1.127-.497c.116.306.176.625.12.71-.019.014-.117.045-.345.016-.206-.027-.604-.332-.986-.695.41-.051.816-.056%201.211-.031zm-4.535%201.535c.209.22.379.47.358.598-.006.041-.088.138-.351.234-.144.055-.539-.063-.979-.259a11.66%2011.66%200%200%200%20.972-.573zm.983-.664c.359-.237.738-.418%201.126-.554.25.237.479.548.457.694-.006.042-.087.138-.351.235-.174.064-.694-.105-1.232-.375zm-3.381%201.794c-.022.145-.061.29-.149.401-.133.166-.358.248-.69.251h-.002c-.133%200-.306-.26-.45-.621.417.091.854.07%201.291-.031zm-2.066-8.077a4.78%204.78%200%200%201-.775-.584c.172-.115.505-.254.88-.378l-.105.962zm-.331%202.302a10.32%2010.32%200%200%201-.828-.502c.202-.143.576-.328.984-.49l-.156.992zm-.45%202.157l-.701-.403c.214-.115.536-.249.891-.376a11.57%2011.57%200%200%201-.19.779zm-.181%201.716c.064.398.194.702.298.893-.194-.051-.435-.162-.736-.398.061-.119.224-.3.438-.495zM8.87%204.141c0%20.152-.123.276-.276.276s-.275-.124-.275-.276.123-.276.276-.276.275.124.275.276zm-.735-.389a1.15%201.15%200%200%200-.314.783%201.16%201.16%200%200%200%201.162%201.162c.457%200%20.842-.27%201.032-.653.026.117.042.238.042.362a1.68%201.68%200%200%201-1.679%201.679%201.68%201.68%200%200%201-1.679-1.679c0-.843.626-1.535%201.436-1.654zM5.059%205.406A1.68%201.68%200%200%201%203.38%207.085a1.68%201.68%200%200%201-1.679-1.679c0-.037.009-.072.011-.109.21.3.541.508.935.508a1.16%201.16%200%200%200%201.162-1.162%201.14%201.14%200%200%200-.474-.912c.015%200%20.03-.005.045-.005.926.001%201.679.754%201.679%201.68zM3.198%204.141c0%20.152-.123.276-.276.276s-.275-.124-.275-.276.123-.276.276-.276.275.124.275.276zM1.375%208.964c0-.52.103-1.035.288-1.52.466.394%201.06.64%201.717.64%201.144%200%202.116-.725%202.499-1.738.383%201.012%201.355%201.738%202.499%201.738.867%200%201.631-.421%202.121-1.062.307.605.478%201.267.478%201.942%200%202.486-2.153%204.51-4.801%204.51s-4.801-2.023-4.801-4.51zm24.342%2019.349c-.985.498-2.267.168-3.813-.979-3.073-2.281-5.453-3.199-7.813-.705-1.315%201.391-4.163%203.365-8.423.97-3.174-1.786-2.239-6.266-1.261-9.479l.146-.492c.276-1.02.395-2.457.444-3.268a6.11%206.11%200%200%200%201.18.115%206.01%206.01%200%200%200%202.536-.562l-.006.175c-.802.215-1.848.612-2.021%201.25-.079.295.021.601.274.837.219.203.415.364.598.501-.667.304-1.243.698-1.311%201.179-.02.144-.022.507.393.787.213.144.395.26.564.365-1.285.521-1.361.96-1.381%201.126-.018.142-.011.496.427.746l.854.489c-.473.389-.971.914-.999%201.429-.018.278.095.532.316.713.675.556%201.231.721%201.653.721.059%200%20.104-.014.158-.02.207.707.641%201.64%201.513%201.64h.013c.8-.008%201.236-.345%201.462-.626.173-.216.268-.457.325-.692.424.195.93.374%201.372.374.151%200%20.294-.021.423-.068.732-.27.944-.704.993-1.021.009-.061.003-.119.002-.179.266.086.538.147.789.147.15%200%20.294-.021.423-.069.542-.2.797-.489.914-.754.237.147.478.258.704.288.106.014.205.021.296.021.356%200%20.595-.101.767-.229.438.435%201.094.992%201.656%201.067.106.014.205.021.296.021a1.56%201.56%200%200%200%20.323-.035c.17.575.453%201.289.866%201.605.358.273.665.362.914.362a.99.99%200%200%200%20.421-.093%201.03%201.03%200%200%200%20.245-.164c.168.428.39.846.68%201.068.358.273.665.362.913.362a.99.99%200%200%200%20.421-.093c.317-.148.512-.448.639-.762.251.157.495.257.726.257.127%200%20.25-.024.37-.071.427-.17.706-.617.841-1.314.022-.015.047-.022.068-.038.067-.051.133-.104.196-.159-.443%201.486-1.107%202.761-2.086%203.257zM8.66%209.925a.5.5%200%201%200-1%200c0%20.653-.818%201.205-1.787%201.205s-1.787-.552-1.787-1.205a.5.5%200%201%200-1%200c0%201.216%201.25%202.205%202.787%202.205s2.787-.989%202.787-2.205zm4.4%2015.965l-.208.097c-2.661%201.258-4.708%201.436-6.086.527-1.542-1.017-1.88-3.19-1.844-4.198a.4.4%200%200%200-.385-.414c-.242-.029-.406.164-.414.385-.046%201.249.367%203.686%202.202%204.896.708.467%201.547.7%202.51.7%201.248%200%202.706-.392%204.362-1.174l.185-.086a.4.4%200%200%200%20.205-.527c-.089-.204-.326-.291-.527-.206zM9.547%202.292c.093.077.205.114.317.114a.5.5%200%200%200%20.318-.886L8.817.397a.5.5%200%200%200-.703.068.5.5%200%200%200%20.069.703l1.364%201.124zm-7.661-.065c.086%200%20.173-.022.253-.068l1.523-.893a.5.5%200%200%200-.506-.863l-1.523.892a.5.5%200%200%200-.179.685c.094.158.261.247.432.247z%22%20transform%3D%22matrix%28-1%200%200%201%2058%200%29%22%20fill%3D%22%233bb300%22/%3E%3Cpath%20d%3D%22M.3%2021.86V10.18q0-.46.02-.68.04-.22.18-.5.28-.54%201.34-.54%201.06%200%201.42.28.38.26.44.78.76-1.04%202.38-1.04%201.64%200%203.1%201.54%201.46%201.54%201.46%203.58%200%202.04-1.46%203.58-1.44%201.54-3.08%201.54-1.64%200-2.38-.92v4.04q0%20.46-.04.68-.02.22-.18.5-.14.3-.5.42-.36.12-.98.12-.62%200-1-.12-.36-.12-.52-.4-.14-.28-.18-.5-.02-.22-.02-.68zm3.96-9.42q-.46.54-.46%201.18%200%20.64.46%201.18.48.52%201.2.52.74%200%201.24-.52.52-.52.52-1.18%200-.66-.48-1.18-.48-.54-1.26-.54-.76%200-1.22.54zm14.741-8.36q.16-.3.54-.42.38-.12%201-.12.64%200%201.02.12.38.12.52.42.16.3.18.54.04.22.04.68v11.94q0%20.46-.04.7-.02.22-.18.5-.3.54-1.7.54-1.38%200-1.54-.98-.84.96-2.34.96-1.8%200-3.28-1.56-1.48-1.58-1.48-3.66%200-2.1%201.48-3.68%201.5-1.58%203.28-1.58%201.48%200%202.3%201v-4.2q0-.46.02-.68.04-.24.18-.52zm-3.24%2010.86q.52.54%201.26.54.74%200%201.22-.54.5-.54.5-1.18%200-.66-.48-1.22-.46-.56-1.26-.56-.8%200-1.28.56-.48.54-.48%201.2%200%20.66.52%201.2zm7.833-1.2q0-2.4%201.68-3.96%201.68-1.56%203.84-1.56%202.16%200%203.82%201.56%201.66%201.54%201.66%203.94%200%201.66-.86%202.96-.86%201.28-2.1%201.9-1.22.6-2.54.6-1.32%200-2.56-.64-1.24-.66-2.1-1.92-.84-1.28-.84-2.88zm4.18%201.44q.64.48%201.3.48.66%200%201.32-.5.66-.5.66-1.48%200-.98-.62-1.46-.62-.48-1.34-.48-.72%200-1.34.5-.62.5-.62%201.48%200%20.96.64%201.46zm11.412-1.44q0%20.84.56%201.32.56.46%201.18.46.64%200%201.18-.36.56-.38.9-.38.6%200%201.46%201.06.46.58.46%201.04%200%20.76-1.1%201.42-1.14.8-2.8.8-1.86%200-3.58-1.34-.82-.64-1.34-1.7-.52-1.08-.52-2.36%200-1.3.52-2.34.52-1.06%201.34-1.7%201.66-1.32%203.54-1.32.76%200%201.48.22.72.2%201.06.4l.32.2q.36.24.56.38.52.4.52.92%200%20.5-.42%201.14-.72%201.1-1.38%201.1-.38%200-1.08-.44-.36-.34-1.04-.34-.66%200-1.24.48-.58.48-.58%201.34z%22%20fill%3D%22green%22/%3E%3C/svg%3E"/> + </a> +</div> + </nav> + <main class="pdoc"> + <section class="module-info"> + <a class="pdoc-button git-button" href="https://github.com/tobymao/sqlglot/tree/main/sqlglot/dataframe/sql/__init__.py">Edit on GitHub</a> + <h1 class="modulename"> +<a href="./../../sqlglot.html">sqlglot</a><wbr>.<a href="./../dataframe.html">dataframe</a><wbr>.sql </h1> + + + <input id="mod-sql-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> + + <label class="view-source-button" for="mod-sql-view-source"><span>View Source</span></label> + + <div class="pdoc-code codehilite"><pre><span></span><span id="L-1"><a href="#L-1"><span class="linenos"> 1</span></a><span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.column</span> <span class="kn">import</span> <span class="n">Column</span> +</span><span id="L-2"><a href="#L-2"><span class="linenos"> 2</span></a><span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.dataframe</span> <span class="kn">import</span> <span class="n">DataFrame</span><span class="p">,</span> <span class="n">DataFrameNaFunctions</span> +</span><span id="L-3"><a href="#L-3"><span class="linenos"> 3</span></a><span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.group</span> <span class="kn">import</span> <span class="n">GroupedData</span> +</span><span id="L-4"><a href="#L-4"><span class="linenos"> 4</span></a><span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.readwriter</span> <span class="kn">import</span> <span class="n">DataFrameReader</span><span class="p">,</span> <span class="n">DataFrameWriter</span> +</span><span id="L-5"><a href="#L-5"><span class="linenos"> 5</span></a><span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.session</span> <span class="kn">import</span> <span class="n">SparkSession</span> +</span><span id="L-6"><a href="#L-6"><span class="linenos"> 6</span></a><span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.window</span> <span class="kn">import</span> <span class="n">Window</span><span class="p">,</span> <span class="n">WindowSpec</span> +</span><span id="L-7"><a href="#L-7"><span class="linenos"> 7</span></a> +</span><span id="L-8"><a href="#L-8"><span class="linenos"> 8</span></a><span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="L-9"><a href="#L-9"><span class="linenos"> 9</span></a> <span class="s2">"SparkSession"</span><span class="p">,</span> +</span><span id="L-10"><a href="#L-10"><span class="linenos">10</span></a> <span class="s2">"DataFrame"</span><span class="p">,</span> +</span><span id="L-11"><a href="#L-11"><span class="linenos">11</span></a> <span class="s2">"GroupedData"</span><span class="p">,</span> +</span><span id="L-12"><a href="#L-12"><span class="linenos">12</span></a> <span class="s2">"Column"</span><span class="p">,</span> +</span><span id="L-13"><a href="#L-13"><span class="linenos">13</span></a> <span class="s2">"DataFrameNaFunctions"</span><span class="p">,</span> +</span><span id="L-14"><a href="#L-14"><span class="linenos">14</span></a> <span class="s2">"Window"</span><span class="p">,</span> +</span><span id="L-15"><a href="#L-15"><span class="linenos">15</span></a> <span class="s2">"WindowSpec"</span><span class="p">,</span> +</span><span id="L-16"><a href="#L-16"><span class="linenos">16</span></a> <span class="s2">"DataFrameReader"</span><span class="p">,</span> +</span><span id="L-17"><a href="#L-17"><span class="linenos">17</span></a> <span class="s2">"DataFrameWriter"</span><span class="p">,</span> +</span><span id="L-18"><a href="#L-18"><span class="linenos">18</span></a><span class="p">]</span> +</span></pre></div> + + + </section> + <section id="SparkSession"> + <input id="SparkSession-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr class"> + + <span class="def">class</span> + <span class="name">SparkSession</span>: + + <label class="view-source-button" for="SparkSession-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#SparkSession"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="SparkSession-20"><a href="#SparkSession-20"><span class="linenos"> 20</span></a><span class="k">class</span> <span class="nc">SparkSession</span><span class="p">:</span> +</span><span id="SparkSession-21"><a href="#SparkSession-21"><span class="linenos"> 21</span></a> <span class="n">known_ids</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">ClassVar</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Set</span><span class="p">[</span><span class="nb">str</span><span class="p">]]</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span> +</span><span id="SparkSession-22"><a href="#SparkSession-22"><span class="linenos"> 22</span></a> <span class="n">known_branch_ids</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">ClassVar</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Set</span><span class="p">[</span><span class="nb">str</span><span class="p">]]</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span> +</span><span id="SparkSession-23"><a href="#SparkSession-23"><span class="linenos"> 23</span></a> <span class="n">known_sequence_ids</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">ClassVar</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Set</span><span class="p">[</span><span class="nb">str</span><span class="p">]]</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span> +</span><span id="SparkSession-24"><a href="#SparkSession-24"><span class="linenos"> 24</span></a> <span class="n">name_to_sequence_id_mapping</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">ClassVar</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]]]</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="nb">list</span><span class="p">)</span> +</span><span id="SparkSession-25"><a href="#SparkSession-25"><span class="linenos"> 25</span></a> +</span><span id="SparkSession-26"><a href="#SparkSession-26"><span class="linenos"> 26</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> +</span><span id="SparkSession-27"><a href="#SparkSession-27"><span class="linenos"> 27</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">incrementing_id</span> <span class="o">=</span> <span class="mi">1</span> +</span><span id="SparkSession-28"><a href="#SparkSession-28"><span class="linenos"> 28</span></a> +</span><span id="SparkSession-29"><a href="#SparkSession-29"><span class="linenos"> 29</span></a> <span class="k">def</span> <span class="fm">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">SparkSession</span><span class="p">:</span> +</span><span id="SparkSession-30"><a href="#SparkSession-30"><span class="linenos"> 30</span></a> <span class="k">return</span> <span class="bp">self</span> +</span><span id="SparkSession-31"><a href="#SparkSession-31"><span class="linenos"> 31</span></a> +</span><span id="SparkSession-32"><a href="#SparkSession-32"><span class="linenos"> 32</span></a> <span class="k">def</span> <span class="fm">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">SparkSession</span><span class="p">:</span> +</span><span id="SparkSession-33"><a href="#SparkSession-33"><span class="linenos"> 33</span></a> <span class="k">return</span> <span class="bp">self</span> +</span><span id="SparkSession-34"><a href="#SparkSession-34"><span class="linenos"> 34</span></a> +</span><span id="SparkSession-35"><a href="#SparkSession-35"><span class="linenos"> 35</span></a> <span class="nd">@property</span> +</span><span id="SparkSession-36"><a href="#SparkSession-36"><span class="linenos"> 36</span></a> <span class="k">def</span> <span class="nf">read</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrameReader</span><span class="p">:</span> +</span><span id="SparkSession-37"><a href="#SparkSession-37"><span class="linenos"> 37</span></a> <span class="k">return</span> <span class="n">DataFrameReader</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> +</span><span id="SparkSession-38"><a href="#SparkSession-38"><span class="linenos"> 38</span></a> +</span><span id="SparkSession-39"><a href="#SparkSession-39"><span class="linenos"> 39</span></a> <span class="k">def</span> <span class="nf">table</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tableName</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="SparkSession-40"><a href="#SparkSession-40"><span class="linenos"> 40</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">read</span><span class="o">.</span><span class="n">table</span><span class="p">(</span><span class="n">tableName</span><span class="p">)</span> +</span><span id="SparkSession-41"><a href="#SparkSession-41"><span class="linenos"> 41</span></a> +</span><span id="SparkSession-42"><a href="#SparkSession-42"><span class="linenos"> 42</span></a> <span class="k">def</span> <span class="nf">createDataFrame</span><span class="p">(</span> +</span><span id="SparkSession-43"><a href="#SparkSession-43"><span class="linenos"> 43</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="SparkSession-44"><a href="#SparkSession-44"><span class="linenos"> 44</span></a> <span class="n">data</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Sequence</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">ColumnLiterals</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">ColumnLiterals</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">]],</span> +</span><span id="SparkSession-45"><a href="#SparkSession-45"><span class="linenos"> 45</span></a> <span class="n">schema</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">SchemaInput</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="SparkSession-46"><a href="#SparkSession-46"><span class="linenos"> 46</span></a> <span class="n">samplingRatio</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">float</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="SparkSession-47"><a href="#SparkSession-47"><span class="linenos"> 47</span></a> <span class="n">verifySchema</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> +</span><span id="SparkSession-48"><a href="#SparkSession-48"><span class="linenos"> 48</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="SparkSession-49"><a href="#SparkSession-49"><span class="linenos"> 49</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.dataframe</span> <span class="kn">import</span> <span class="n">DataFrame</span> +</span><span id="SparkSession-50"><a href="#SparkSession-50"><span class="linenos"> 50</span></a> +</span><span id="SparkSession-51"><a href="#SparkSession-51"><span class="linenos"> 51</span></a> <span class="k">if</span> <span class="n">samplingRatio</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">or</span> <span class="n">verifySchema</span><span class="p">:</span> +</span><span id="SparkSession-52"><a href="#SparkSession-52"><span class="linenos"> 52</span></a> <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">"Sampling Ratio and Verify Schema are not supported"</span><span class="p">)</span> +</span><span id="SparkSession-53"><a href="#SparkSession-53"><span class="linenos"> 53</span></a> <span class="k">if</span> <span class="n">schema</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="p">(</span> +</span><span id="SparkSession-54"><a href="#SparkSession-54"><span class="linenos"> 54</span></a> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">schema</span><span class="p">,</span> <span class="p">(</span><span class="n">StructType</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="nb">list</span><span class="p">))</span> +</span><span id="SparkSession-55"><a href="#SparkSession-55"><span class="linenos"> 55</span></a> <span class="ow">or</span> <span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">schema</span><span class="p">,</span> <span class="nb">list</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">schema</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">str</span><span class="p">))</span> +</span><span id="SparkSession-56"><a href="#SparkSession-56"><span class="linenos"> 56</span></a> <span class="p">):</span> +</span><span id="SparkSession-57"><a href="#SparkSession-57"><span class="linenos"> 57</span></a> <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">"Only schema of either list or string of list supported"</span><span class="p">)</span> +</span><span id="SparkSession-58"><a href="#SparkSession-58"><span class="linenos"> 58</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">data</span><span class="p">:</span> +</span><span id="SparkSession-59"><a href="#SparkSession-59"><span class="linenos"> 59</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"Must provide data to create into a DataFrame"</span><span class="p">)</span> +</span><span id="SparkSession-60"><a href="#SparkSession-60"><span class="linenos"> 60</span></a> +</span><span id="SparkSession-61"><a href="#SparkSession-61"><span class="linenos"> 61</span></a> <span class="n">column_mapping</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]]</span> +</span><span id="SparkSession-62"><a href="#SparkSession-62"><span class="linenos"> 62</span></a> <span class="k">if</span> <span class="n">schema</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> +</span><span id="SparkSession-63"><a href="#SparkSession-63"><span class="linenos"> 63</span></a> <span class="n">column_mapping</span> <span class="o">=</span> <span class="n">get_column_mapping_from_schema_input</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span> +</span><span id="SparkSession-64"><a href="#SparkSession-64"><span class="linenos"> 64</span></a> <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">dict</span><span class="p">):</span> +</span><span id="SparkSession-65"><a href="#SparkSession-65"><span class="linenos"> 65</span></a> <span class="n">column_mapping</span> <span class="o">=</span> <span class="p">{</span><span class="n">col_name</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span> <span class="kc">None</span> <span class="k">for</span> <span class="n">col_name</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">]}</span> +</span><span id="SparkSession-66"><a href="#SparkSession-66"><span class="linenos"> 66</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="SparkSession-67"><a href="#SparkSession-67"><span class="linenos"> 67</span></a> <span class="n">column_mapping</span> <span class="o">=</span> <span class="p">{</span><span class="sa">f</span><span class="s2">"_</span><span class="si">{</span><span class="n">i</span><span class="si">}</span><span class="s2">"</span><span class="p">:</span> <span class="kc">None</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)}</span> +</span><span id="SparkSession-68"><a href="#SparkSession-68"><span class="linenos"> 68</span></a> +</span><span id="SparkSession-69"><a href="#SparkSession-69"><span class="linenos"> 69</span></a> <span class="n">data_expressions</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="SparkSession-70"><a href="#SparkSession-70"><span class="linenos"> 70</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Tuple</span><span class="p">(</span> +</span><span id="SparkSession-71"><a href="#SparkSession-71"><span class="linenos"> 71</span></a> <span class="n">expressions</span><span class="o">=</span><span class="nb">list</span><span class="p">(</span> +</span><span id="SparkSession-72"><a href="#SparkSession-72"><span class="linenos"> 72</span></a> <span class="nb">map</span><span class="p">(</span> +</span><span id="SparkSession-73"><a href="#SparkSession-73"><span class="linenos"> 73</span></a> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">F</span><span class="o">.</span><span class="n">lit</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> +</span><span id="SparkSession-74"><a href="#SparkSession-74"><span class="linenos"> 74</span></a> <span class="n">row</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">row</span><span class="p">,</span> <span class="nb">dict</span><span class="p">)</span> <span class="k">else</span> <span class="n">row</span><span class="o">.</span><span class="n">values</span><span class="p">(),</span> +</span><span id="SparkSession-75"><a href="#SparkSession-75"><span class="linenos"> 75</span></a> <span class="p">)</span> +</span><span id="SparkSession-76"><a href="#SparkSession-76"><span class="linenos"> 76</span></a> <span class="p">)</span> +</span><span id="SparkSession-77"><a href="#SparkSession-77"><span class="linenos"> 77</span></a> <span class="p">)</span> +</span><span id="SparkSession-78"><a href="#SparkSession-78"><span class="linenos"> 78</span></a> <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">data</span> +</span><span id="SparkSession-79"><a href="#SparkSession-79"><span class="linenos"> 79</span></a> <span class="p">]</span> +</span><span id="SparkSession-80"><a href="#SparkSession-80"><span class="linenos"> 80</span></a> +</span><span id="SparkSession-81"><a href="#SparkSession-81"><span class="linenos"> 81</span></a> <span class="n">sel_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="SparkSession-82"><a href="#SparkSession-82"><span class="linenos"> 82</span></a> <span class="n">F</span><span class="o">.</span><span class="n">col</span><span class="p">(</span><span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">data_type</span><span class="p">)</span><span class="o">.</span><span class="n">alias</span><span class="p">(</span><span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> +</span><span id="SparkSession-83"><a href="#SparkSession-83"><span class="linenos"> 83</span></a> <span class="k">if</span> <span class="n">data_type</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> +</span><span id="SparkSession-84"><a href="#SparkSession-84"><span class="linenos"> 84</span></a> <span class="k">else</span> <span class="n">F</span><span class="o">.</span><span class="n">col</span><span class="p">(</span><span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> +</span><span id="SparkSession-85"><a href="#SparkSession-85"><span class="linenos"> 85</span></a> <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">data_type</span> <span class="ow">in</span> <span class="n">column_mapping</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> +</span><span id="SparkSession-86"><a href="#SparkSession-86"><span class="linenos"> 86</span></a> <span class="p">]</span> +</span><span id="SparkSession-87"><a href="#SparkSession-87"><span class="linenos"> 87</span></a> +</span><span id="SparkSession-88"><a href="#SparkSession-88"><span class="linenos"> 88</span></a> <span class="n">select_kwargs</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="SparkSession-89"><a href="#SparkSession-89"><span class="linenos"> 89</span></a> <span class="s2">"expressions"</span><span class="p">:</span> <span class="n">sel_columns</span><span class="p">,</span> +</span><span id="SparkSession-90"><a href="#SparkSession-90"><span class="linenos"> 90</span></a> <span class="s2">"from"</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">From</span><span class="p">(</span> +</span><span id="SparkSession-91"><a href="#SparkSession-91"><span class="linenos"> 91</span></a> <span class="n">expressions</span><span class="o">=</span><span class="p">[</span> +</span><span id="SparkSession-92"><a href="#SparkSession-92"><span class="linenos"> 92</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Values</span><span class="p">(</span> +</span><span id="SparkSession-93"><a href="#SparkSession-93"><span class="linenos"> 93</span></a> <span class="n">expressions</span><span class="o">=</span><span class="n">data_expressions</span><span class="p">,</span> +</span><span id="SparkSession-94"><a href="#SparkSession-94"><span class="linenos"> 94</span></a> <span class="n">alias</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">TableAlias</span><span class="p">(</span> +</span><span id="SparkSession-95"><a href="#SparkSession-95"><span class="linenos"> 95</span></a> <span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">to_identifier</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_auto_incrementing_name</span><span class="p">),</span> +</span><span id="SparkSession-96"><a href="#SparkSession-96"><span class="linenos"> 96</span></a> <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">to_identifier</span><span class="p">(</span><span class="n">col_name</span><span class="p">)</span> <span class="k">for</span> <span class="n">col_name</span> <span class="ow">in</span> <span class="n">column_mapping</span><span class="p">],</span> +</span><span id="SparkSession-97"><a href="#SparkSession-97"><span class="linenos"> 97</span></a> <span class="p">),</span> +</span><span id="SparkSession-98"><a href="#SparkSession-98"><span class="linenos"> 98</span></a> <span class="p">),</span> +</span><span id="SparkSession-99"><a href="#SparkSession-99"><span class="linenos"> 99</span></a> <span class="p">],</span> +</span><span id="SparkSession-100"><a href="#SparkSession-100"><span class="linenos">100</span></a> <span class="p">),</span> +</span><span id="SparkSession-101"><a href="#SparkSession-101"><span class="linenos">101</span></a> <span class="p">}</span> +</span><span id="SparkSession-102"><a href="#SparkSession-102"><span class="linenos">102</span></a> +</span><span id="SparkSession-103"><a href="#SparkSession-103"><span class="linenos">103</span></a> <span class="n">sel_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">(</span><span class="o">**</span><span class="n">select_kwargs</span><span class="p">)</span> +</span><span id="SparkSession-104"><a href="#SparkSession-104"><span class="linenos">104</span></a> <span class="k">return</span> <span class="n">DataFrame</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sel_expression</span><span class="p">)</span> +</span><span id="SparkSession-105"><a href="#SparkSession-105"><span class="linenos">105</span></a> +</span><span id="SparkSession-106"><a href="#SparkSession-106"><span class="linenos">106</span></a> <span class="k">def</span> <span class="nf">sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sqlQuery</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="SparkSession-107"><a href="#SparkSession-107"><span class="linenos">107</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">sqlglot</span><span class="o">.</span><span class="n">parse_one</span><span class="p">(</span><span class="n">sqlQuery</span><span class="p">,</span> <span class="n">read</span><span class="o">=</span><span class="s2">"spark"</span><span class="p">)</span> +</span><span id="SparkSession-108"><a href="#SparkSession-108"><span class="linenos">108</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">):</span> +</span><span id="SparkSession-109"><a href="#SparkSession-109"><span class="linenos">109</span></a> <span class="n">df</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">)</span> +</span><span id="SparkSession-110"><a href="#SparkSession-110"><span class="linenos">110</span></a> <span class="n">df</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">_convert_leaf_to_cte</span><span class="p">()</span> +</span><span id="SparkSession-111"><a href="#SparkSession-111"><span class="linenos">111</span></a> <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Create</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Insert</span><span class="p">)):</span> +</span><span id="SparkSession-112"><a href="#SparkSession-112"><span class="linenos">112</span></a> <span class="n">select_expression</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="SparkSession-113"><a href="#SparkSession-113"><span class="linenos">113</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Insert</span><span class="p">):</span> +</span><span id="SparkSession-114"><a href="#SparkSession-114"><span class="linenos">114</span></a> <span class="n">select_expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"with"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"with"</span><span class="p">))</span> +</span><span id="SparkSession-115"><a href="#SparkSession-115"><span class="linenos">115</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"with"</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> +</span><span id="SparkSession-116"><a href="#SparkSession-116"><span class="linenos">116</span></a> <span class="k">del</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"expression"</span><span class="p">]</span> +</span><span id="SparkSession-117"><a href="#SparkSession-117"><span class="linenos">117</span></a> <span class="n">df</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">select_expression</span><span class="p">,</span> <span class="n">output_expression_container</span><span class="o">=</span><span class="n">expression</span><span class="p">)</span> <span class="c1"># type: ignore</span> +</span><span id="SparkSession-118"><a href="#SparkSession-118"><span class="linenos">118</span></a> <span class="n">df</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">_convert_leaf_to_cte</span><span class="p">()</span> +</span><span id="SparkSession-119"><a href="#SparkSession-119"><span class="linenos">119</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="SparkSession-120"><a href="#SparkSession-120"><span class="linenos">120</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span> +</span><span id="SparkSession-121"><a href="#SparkSession-121"><span class="linenos">121</span></a> <span class="s2">"Unknown expression type provided in the SQL. Please create an issue with the SQL."</span> +</span><span id="SparkSession-122"><a href="#SparkSession-122"><span class="linenos">122</span></a> <span class="p">)</span> +</span><span id="SparkSession-123"><a href="#SparkSession-123"><span class="linenos">123</span></a> <span class="k">return</span> <span class="n">df</span> +</span><span id="SparkSession-124"><a href="#SparkSession-124"><span class="linenos">124</span></a> +</span><span id="SparkSession-125"><a href="#SparkSession-125"><span class="linenos">125</span></a> <span class="nd">@property</span> +</span><span id="SparkSession-126"><a href="#SparkSession-126"><span class="linenos">126</span></a> <span class="k">def</span> <span class="nf">_auto_incrementing_name</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="SparkSession-127"><a href="#SparkSession-127"><span class="linenos">127</span></a> <span class="n">name</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"a</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">incrementing_id</span><span class="si">}</span><span class="s2">"</span> +</span><span id="SparkSession-128"><a href="#SparkSession-128"><span class="linenos">128</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">incrementing_id</span> <span class="o">+=</span> <span class="mi">1</span> +</span><span id="SparkSession-129"><a href="#SparkSession-129"><span class="linenos">129</span></a> <span class="k">return</span> <span class="n">name</span> +</span><span id="SparkSession-130"><a href="#SparkSession-130"><span class="linenos">130</span></a> +</span><span id="SparkSession-131"><a href="#SparkSession-131"><span class="linenos">131</span></a> <span class="nd">@property</span> +</span><span id="SparkSession-132"><a href="#SparkSession-132"><span class="linenos">132</span></a> <span class="k">def</span> <span class="nf">_random_name</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="SparkSession-133"><a href="#SparkSession-133"><span class="linenos">133</span></a> <span class="k">return</span> <span class="s2">"r"</span> <span class="o">+</span> <span class="n">uuid</span><span class="o">.</span><span class="n">uuid4</span><span class="p">()</span><span class="o">.</span><span class="n">hex</span> +</span><span id="SparkSession-134"><a href="#SparkSession-134"><span class="linenos">134</span></a> +</span><span id="SparkSession-135"><a href="#SparkSession-135"><span class="linenos">135</span></a> <span class="nd">@property</span> +</span><span id="SparkSession-136"><a href="#SparkSession-136"><span class="linenos">136</span></a> <span class="k">def</span> <span class="nf">_random_branch_id</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="SparkSession-137"><a href="#SparkSession-137"><span class="linenos">137</span></a> <span class="nb">id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_random_id</span> +</span><span id="SparkSession-138"><a href="#SparkSession-138"><span class="linenos">138</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">known_branch_ids</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="nb">id</span><span class="p">)</span> +</span><span id="SparkSession-139"><a href="#SparkSession-139"><span class="linenos">139</span></a> <span class="k">return</span> <span class="nb">id</span> +</span><span id="SparkSession-140"><a href="#SparkSession-140"><span class="linenos">140</span></a> +</span><span id="SparkSession-141"><a href="#SparkSession-141"><span class="linenos">141</span></a> <span class="nd">@property</span> +</span><span id="SparkSession-142"><a href="#SparkSession-142"><span class="linenos">142</span></a> <span class="k">def</span> <span class="nf">_random_sequence_id</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> +</span><span id="SparkSession-143"><a href="#SparkSession-143"><span class="linenos">143</span></a> <span class="nb">id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_random_id</span> +</span><span id="SparkSession-144"><a href="#SparkSession-144"><span class="linenos">144</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">known_sequence_ids</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="nb">id</span><span class="p">)</span> +</span><span id="SparkSession-145"><a href="#SparkSession-145"><span class="linenos">145</span></a> <span class="k">return</span> <span class="nb">id</span> +</span><span id="SparkSession-146"><a href="#SparkSession-146"><span class="linenos">146</span></a> +</span><span id="SparkSession-147"><a href="#SparkSession-147"><span class="linenos">147</span></a> <span class="nd">@property</span> +</span><span id="SparkSession-148"><a href="#SparkSession-148"><span class="linenos">148</span></a> <span class="k">def</span> <span class="nf">_random_id</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="SparkSession-149"><a href="#SparkSession-149"><span class="linenos">149</span></a> <span class="nb">id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_random_name</span> +</span><span id="SparkSession-150"><a href="#SparkSession-150"><span class="linenos">150</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">known_ids</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="nb">id</span><span class="p">)</span> +</span><span id="SparkSession-151"><a href="#SparkSession-151"><span class="linenos">151</span></a> <span class="k">return</span> <span class="nb">id</span> +</span><span id="SparkSession-152"><a href="#SparkSession-152"><span class="linenos">152</span></a> +</span><span id="SparkSession-153"><a href="#SparkSession-153"><span class="linenos">153</span></a> <span class="nd">@property</span> +</span><span id="SparkSession-154"><a href="#SparkSession-154"><span class="linenos">154</span></a> <span class="k">def</span> <span class="nf">_join_hint_names</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Set</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> +</span><span id="SparkSession-155"><a href="#SparkSession-155"><span class="linenos">155</span></a> <span class="k">return</span> <span class="p">{</span><span class="s2">"BROADCAST"</span><span class="p">,</span> <span class="s2">"MERGE"</span><span class="p">,</span> <span class="s2">"SHUFFLE_HASH"</span><span class="p">,</span> <span class="s2">"SHUFFLE_REPLICATE_NL"</span><span class="p">}</span> +</span><span id="SparkSession-156"><a href="#SparkSession-156"><span class="linenos">156</span></a> +</span><span id="SparkSession-157"><a href="#SparkSession-157"><span class="linenos">157</span></a> <span class="k">def</span> <span class="nf">_add_alias_to_mapping</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">sequence_id</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span> +</span><span id="SparkSession-158"><a href="#SparkSession-158"><span class="linenos">158</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">name_to_sequence_id_mapping</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sequence_id</span><span class="p">)</span> +</span></pre></div> + + + + + <div id="SparkSession.__init__" class="classattr"> + <input id="SparkSession.__init__-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="name">SparkSession</span><span class="signature pdoc-code condensed">()</span> + + <label class="view-source-button" for="SparkSession.__init__-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#SparkSession.__init__"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="SparkSession.__init__-26"><a href="#SparkSession.__init__-26"><span class="linenos">26</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> +</span><span id="SparkSession.__init__-27"><a href="#SparkSession.__init__-27"><span class="linenos">27</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">incrementing_id</span> <span class="o">=</span> <span class="mi">1</span> +</span></pre></div> + + + + + </div> + <div id="SparkSession.table" class="classattr"> + <input id="SparkSession.table-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">table</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">tableName</span><span class="p">:</span> <span class="nb">str</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="SparkSession.table-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#SparkSession.table"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="SparkSession.table-39"><a href="#SparkSession.table-39"><span class="linenos">39</span></a> <span class="k">def</span> <span class="nf">table</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tableName</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="SparkSession.table-40"><a href="#SparkSession.table-40"><span class="linenos">40</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">read</span><span class="o">.</span><span class="n">table</span><span class="p">(</span><span class="n">tableName</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="SparkSession.createDataFrame" class="classattr"> + <input id="SparkSession.createDataFrame-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">createDataFrame</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">data</span><span class="p">:</span> <span class="n">Sequence</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700333898336'</span><span class="o">></span><span class="p">],</span> <span class="n">List</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700333898336'</span><span class="o">></span><span class="p">],</span> <span class="n">Tuple</span><span class="p">]]</span>,</span><span class="param"> <span class="n">schema</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700333867312'</span><span class="o">></span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">samplingRatio</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">float</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">verifySchema</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="SparkSession.createDataFrame-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#SparkSession.createDataFrame"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="SparkSession.createDataFrame-42"><a href="#SparkSession.createDataFrame-42"><span class="linenos"> 42</span></a> <span class="k">def</span> <span class="nf">createDataFrame</span><span class="p">(</span> +</span><span id="SparkSession.createDataFrame-43"><a href="#SparkSession.createDataFrame-43"><span class="linenos"> 43</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="SparkSession.createDataFrame-44"><a href="#SparkSession.createDataFrame-44"><span class="linenos"> 44</span></a> <span class="n">data</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Sequence</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">ColumnLiterals</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">ColumnLiterals</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">]],</span> +</span><span id="SparkSession.createDataFrame-45"><a href="#SparkSession.createDataFrame-45"><span class="linenos"> 45</span></a> <span class="n">schema</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">SchemaInput</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="SparkSession.createDataFrame-46"><a href="#SparkSession.createDataFrame-46"><span class="linenos"> 46</span></a> <span class="n">samplingRatio</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">float</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="SparkSession.createDataFrame-47"><a href="#SparkSession.createDataFrame-47"><span class="linenos"> 47</span></a> <span class="n">verifySchema</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> +</span><span id="SparkSession.createDataFrame-48"><a href="#SparkSession.createDataFrame-48"><span class="linenos"> 48</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="SparkSession.createDataFrame-49"><a href="#SparkSession.createDataFrame-49"><span class="linenos"> 49</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.dataframe</span> <span class="kn">import</span> <span class="n">DataFrame</span> +</span><span id="SparkSession.createDataFrame-50"><a href="#SparkSession.createDataFrame-50"><span class="linenos"> 50</span></a> +</span><span id="SparkSession.createDataFrame-51"><a href="#SparkSession.createDataFrame-51"><span class="linenos"> 51</span></a> <span class="k">if</span> <span class="n">samplingRatio</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">or</span> <span class="n">verifySchema</span><span class="p">:</span> +</span><span id="SparkSession.createDataFrame-52"><a href="#SparkSession.createDataFrame-52"><span class="linenos"> 52</span></a> <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">"Sampling Ratio and Verify Schema are not supported"</span><span class="p">)</span> +</span><span id="SparkSession.createDataFrame-53"><a href="#SparkSession.createDataFrame-53"><span class="linenos"> 53</span></a> <span class="k">if</span> <span class="n">schema</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="p">(</span> +</span><span id="SparkSession.createDataFrame-54"><a href="#SparkSession.createDataFrame-54"><span class="linenos"> 54</span></a> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">schema</span><span class="p">,</span> <span class="p">(</span><span class="n">StructType</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="nb">list</span><span class="p">))</span> +</span><span id="SparkSession.createDataFrame-55"><a href="#SparkSession.createDataFrame-55"><span class="linenos"> 55</span></a> <span class="ow">or</span> <span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">schema</span><span class="p">,</span> <span class="nb">list</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">schema</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">str</span><span class="p">))</span> +</span><span id="SparkSession.createDataFrame-56"><a href="#SparkSession.createDataFrame-56"><span class="linenos"> 56</span></a> <span class="p">):</span> +</span><span id="SparkSession.createDataFrame-57"><a href="#SparkSession.createDataFrame-57"><span class="linenos"> 57</span></a> <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">"Only schema of either list or string of list supported"</span><span class="p">)</span> +</span><span id="SparkSession.createDataFrame-58"><a href="#SparkSession.createDataFrame-58"><span class="linenos"> 58</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">data</span><span class="p">:</span> +</span><span id="SparkSession.createDataFrame-59"><a href="#SparkSession.createDataFrame-59"><span class="linenos"> 59</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"Must provide data to create into a DataFrame"</span><span class="p">)</span> +</span><span id="SparkSession.createDataFrame-60"><a href="#SparkSession.createDataFrame-60"><span class="linenos"> 60</span></a> +</span><span id="SparkSession.createDataFrame-61"><a href="#SparkSession.createDataFrame-61"><span class="linenos"> 61</span></a> <span class="n">column_mapping</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]]</span> +</span><span id="SparkSession.createDataFrame-62"><a href="#SparkSession.createDataFrame-62"><span class="linenos"> 62</span></a> <span class="k">if</span> <span class="n">schema</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> +</span><span id="SparkSession.createDataFrame-63"><a href="#SparkSession.createDataFrame-63"><span class="linenos"> 63</span></a> <span class="n">column_mapping</span> <span class="o">=</span> <span class="n">get_column_mapping_from_schema_input</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span> +</span><span id="SparkSession.createDataFrame-64"><a href="#SparkSession.createDataFrame-64"><span class="linenos"> 64</span></a> <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">dict</span><span class="p">):</span> +</span><span id="SparkSession.createDataFrame-65"><a href="#SparkSession.createDataFrame-65"><span class="linenos"> 65</span></a> <span class="n">column_mapping</span> <span class="o">=</span> <span class="p">{</span><span class="n">col_name</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span> <span class="kc">None</span> <span class="k">for</span> <span class="n">col_name</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">]}</span> +</span><span id="SparkSession.createDataFrame-66"><a href="#SparkSession.createDataFrame-66"><span class="linenos"> 66</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="SparkSession.createDataFrame-67"><a href="#SparkSession.createDataFrame-67"><span class="linenos"> 67</span></a> <span class="n">column_mapping</span> <span class="o">=</span> <span class="p">{</span><span class="sa">f</span><span class="s2">"_</span><span class="si">{</span><span class="n">i</span><span class="si">}</span><span class="s2">"</span><span class="p">:</span> <span class="kc">None</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)}</span> +</span><span id="SparkSession.createDataFrame-68"><a href="#SparkSession.createDataFrame-68"><span class="linenos"> 68</span></a> +</span><span id="SparkSession.createDataFrame-69"><a href="#SparkSession.createDataFrame-69"><span class="linenos"> 69</span></a> <span class="n">data_expressions</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="SparkSession.createDataFrame-70"><a href="#SparkSession.createDataFrame-70"><span class="linenos"> 70</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Tuple</span><span class="p">(</span> +</span><span id="SparkSession.createDataFrame-71"><a href="#SparkSession.createDataFrame-71"><span class="linenos"> 71</span></a> <span class="n">expressions</span><span class="o">=</span><span class="nb">list</span><span class="p">(</span> +</span><span id="SparkSession.createDataFrame-72"><a href="#SparkSession.createDataFrame-72"><span class="linenos"> 72</span></a> <span class="nb">map</span><span class="p">(</span> +</span><span id="SparkSession.createDataFrame-73"><a href="#SparkSession.createDataFrame-73"><span class="linenos"> 73</span></a> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">F</span><span class="o">.</span><span class="n">lit</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> +</span><span id="SparkSession.createDataFrame-74"><a href="#SparkSession.createDataFrame-74"><span class="linenos"> 74</span></a> <span class="n">row</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">row</span><span class="p">,</span> <span class="nb">dict</span><span class="p">)</span> <span class="k">else</span> <span class="n">row</span><span class="o">.</span><span class="n">values</span><span class="p">(),</span> +</span><span id="SparkSession.createDataFrame-75"><a href="#SparkSession.createDataFrame-75"><span class="linenos"> 75</span></a> <span class="p">)</span> +</span><span id="SparkSession.createDataFrame-76"><a href="#SparkSession.createDataFrame-76"><span class="linenos"> 76</span></a> <span class="p">)</span> +</span><span id="SparkSession.createDataFrame-77"><a href="#SparkSession.createDataFrame-77"><span class="linenos"> 77</span></a> <span class="p">)</span> +</span><span id="SparkSession.createDataFrame-78"><a href="#SparkSession.createDataFrame-78"><span class="linenos"> 78</span></a> <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">data</span> +</span><span id="SparkSession.createDataFrame-79"><a href="#SparkSession.createDataFrame-79"><span class="linenos"> 79</span></a> <span class="p">]</span> +</span><span id="SparkSession.createDataFrame-80"><a href="#SparkSession.createDataFrame-80"><span class="linenos"> 80</span></a> +</span><span id="SparkSession.createDataFrame-81"><a href="#SparkSession.createDataFrame-81"><span class="linenos"> 81</span></a> <span class="n">sel_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="SparkSession.createDataFrame-82"><a href="#SparkSession.createDataFrame-82"><span class="linenos"> 82</span></a> <span class="n">F</span><span class="o">.</span><span class="n">col</span><span class="p">(</span><span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">data_type</span><span class="p">)</span><span class="o">.</span><span class="n">alias</span><span class="p">(</span><span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> +</span><span id="SparkSession.createDataFrame-83"><a href="#SparkSession.createDataFrame-83"><span class="linenos"> 83</span></a> <span class="k">if</span> <span class="n">data_type</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> +</span><span id="SparkSession.createDataFrame-84"><a href="#SparkSession.createDataFrame-84"><span class="linenos"> 84</span></a> <span class="k">else</span> <span class="n">F</span><span class="o">.</span><span class="n">col</span><span class="p">(</span><span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> +</span><span id="SparkSession.createDataFrame-85"><a href="#SparkSession.createDataFrame-85"><span class="linenos"> 85</span></a> <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">data_type</span> <span class="ow">in</span> <span class="n">column_mapping</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> +</span><span id="SparkSession.createDataFrame-86"><a href="#SparkSession.createDataFrame-86"><span class="linenos"> 86</span></a> <span class="p">]</span> +</span><span id="SparkSession.createDataFrame-87"><a href="#SparkSession.createDataFrame-87"><span class="linenos"> 87</span></a> +</span><span id="SparkSession.createDataFrame-88"><a href="#SparkSession.createDataFrame-88"><span class="linenos"> 88</span></a> <span class="n">select_kwargs</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="SparkSession.createDataFrame-89"><a href="#SparkSession.createDataFrame-89"><span class="linenos"> 89</span></a> <span class="s2">"expressions"</span><span class="p">:</span> <span class="n">sel_columns</span><span class="p">,</span> +</span><span id="SparkSession.createDataFrame-90"><a href="#SparkSession.createDataFrame-90"><span class="linenos"> 90</span></a> <span class="s2">"from"</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">From</span><span class="p">(</span> +</span><span id="SparkSession.createDataFrame-91"><a href="#SparkSession.createDataFrame-91"><span class="linenos"> 91</span></a> <span class="n">expressions</span><span class="o">=</span><span class="p">[</span> +</span><span id="SparkSession.createDataFrame-92"><a href="#SparkSession.createDataFrame-92"><span class="linenos"> 92</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Values</span><span class="p">(</span> +</span><span id="SparkSession.createDataFrame-93"><a href="#SparkSession.createDataFrame-93"><span class="linenos"> 93</span></a> <span class="n">expressions</span><span class="o">=</span><span class="n">data_expressions</span><span class="p">,</span> +</span><span id="SparkSession.createDataFrame-94"><a href="#SparkSession.createDataFrame-94"><span class="linenos"> 94</span></a> <span class="n">alias</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">TableAlias</span><span class="p">(</span> +</span><span id="SparkSession.createDataFrame-95"><a href="#SparkSession.createDataFrame-95"><span class="linenos"> 95</span></a> <span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">to_identifier</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_auto_incrementing_name</span><span class="p">),</span> +</span><span id="SparkSession.createDataFrame-96"><a href="#SparkSession.createDataFrame-96"><span class="linenos"> 96</span></a> <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">to_identifier</span><span class="p">(</span><span class="n">col_name</span><span class="p">)</span> <span class="k">for</span> <span class="n">col_name</span> <span class="ow">in</span> <span class="n">column_mapping</span><span class="p">],</span> +</span><span id="SparkSession.createDataFrame-97"><a href="#SparkSession.createDataFrame-97"><span class="linenos"> 97</span></a> <span class="p">),</span> +</span><span id="SparkSession.createDataFrame-98"><a href="#SparkSession.createDataFrame-98"><span class="linenos"> 98</span></a> <span class="p">),</span> +</span><span id="SparkSession.createDataFrame-99"><a href="#SparkSession.createDataFrame-99"><span class="linenos"> 99</span></a> <span class="p">],</span> +</span><span id="SparkSession.createDataFrame-100"><a href="#SparkSession.createDataFrame-100"><span class="linenos">100</span></a> <span class="p">),</span> +</span><span id="SparkSession.createDataFrame-101"><a href="#SparkSession.createDataFrame-101"><span class="linenos">101</span></a> <span class="p">}</span> +</span><span id="SparkSession.createDataFrame-102"><a href="#SparkSession.createDataFrame-102"><span class="linenos">102</span></a> +</span><span id="SparkSession.createDataFrame-103"><a href="#SparkSession.createDataFrame-103"><span class="linenos">103</span></a> <span class="n">sel_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">(</span><span class="o">**</span><span class="n">select_kwargs</span><span class="p">)</span> +</span><span id="SparkSession.createDataFrame-104"><a href="#SparkSession.createDataFrame-104"><span class="linenos">104</span></a> <span class="k">return</span> <span class="n">DataFrame</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sel_expression</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="SparkSession.sql" class="classattr"> + <input id="SparkSession.sql-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">sql</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">sqlQuery</span><span class="p">:</span> <span class="nb">str</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="SparkSession.sql-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#SparkSession.sql"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="SparkSession.sql-106"><a href="#SparkSession.sql-106"><span class="linenos">106</span></a> <span class="k">def</span> <span class="nf">sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sqlQuery</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="SparkSession.sql-107"><a href="#SparkSession.sql-107"><span class="linenos">107</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">sqlglot</span><span class="o">.</span><span class="n">parse_one</span><span class="p">(</span><span class="n">sqlQuery</span><span class="p">,</span> <span class="n">read</span><span class="o">=</span><span class="s2">"spark"</span><span class="p">)</span> +</span><span id="SparkSession.sql-108"><a href="#SparkSession.sql-108"><span class="linenos">108</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">):</span> +</span><span id="SparkSession.sql-109"><a href="#SparkSession.sql-109"><span class="linenos">109</span></a> <span class="n">df</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">)</span> +</span><span id="SparkSession.sql-110"><a href="#SparkSession.sql-110"><span class="linenos">110</span></a> <span class="n">df</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">_convert_leaf_to_cte</span><span class="p">()</span> +</span><span id="SparkSession.sql-111"><a href="#SparkSession.sql-111"><span class="linenos">111</span></a> <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Create</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Insert</span><span class="p">)):</span> +</span><span id="SparkSession.sql-112"><a href="#SparkSession.sql-112"><span class="linenos">112</span></a> <span class="n">select_expression</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="SparkSession.sql-113"><a href="#SparkSession.sql-113"><span class="linenos">113</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Insert</span><span class="p">):</span> +</span><span id="SparkSession.sql-114"><a href="#SparkSession.sql-114"><span class="linenos">114</span></a> <span class="n">select_expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"with"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"with"</span><span class="p">))</span> +</span><span id="SparkSession.sql-115"><a href="#SparkSession.sql-115"><span class="linenos">115</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"with"</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> +</span><span id="SparkSession.sql-116"><a href="#SparkSession.sql-116"><span class="linenos">116</span></a> <span class="k">del</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"expression"</span><span class="p">]</span> +</span><span id="SparkSession.sql-117"><a href="#SparkSession.sql-117"><span class="linenos">117</span></a> <span class="n">df</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">select_expression</span><span class="p">,</span> <span class="n">output_expression_container</span><span class="o">=</span><span class="n">expression</span><span class="p">)</span> <span class="c1"># type: ignore</span> +</span><span id="SparkSession.sql-118"><a href="#SparkSession.sql-118"><span class="linenos">118</span></a> <span class="n">df</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">_convert_leaf_to_cte</span><span class="p">()</span> +</span><span id="SparkSession.sql-119"><a href="#SparkSession.sql-119"><span class="linenos">119</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="SparkSession.sql-120"><a href="#SparkSession.sql-120"><span class="linenos">120</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span> +</span><span id="SparkSession.sql-121"><a href="#SparkSession.sql-121"><span class="linenos">121</span></a> <span class="s2">"Unknown expression type provided in the SQL. Please create an issue with the SQL."</span> +</span><span id="SparkSession.sql-122"><a href="#SparkSession.sql-122"><span class="linenos">122</span></a> <span class="p">)</span> +</span><span id="SparkSession.sql-123"><a href="#SparkSession.sql-123"><span class="linenos">123</span></a> <span class="k">return</span> <span class="n">df</span> +</span></pre></div> + + + + + </div> + </section> + <section id="DataFrame"> + <input id="DataFrame-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr class"> + + <span class="def">class</span> + <span class="name">DataFrame</span>: + + <label class="view-source-button" for="DataFrame-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame-46"><a href="#DataFrame-46"><span class="linenos"> 46</span></a><span class="k">class</span> <span class="nc">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-47"><a href="#DataFrame-47"><span class="linenos"> 47</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span> +</span><span id="DataFrame-48"><a href="#DataFrame-48"><span class="linenos"> 48</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame-49"><a href="#DataFrame-49"><span class="linenos"> 49</span></a> <span class="n">spark</span><span class="p">:</span> <span class="n">SparkSession</span><span class="p">,</span> +</span><span id="DataFrame-50"><a href="#DataFrame-50"><span class="linenos"> 50</span></a> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">,</span> +</span><span id="DataFrame-51"><a href="#DataFrame-51"><span class="linenos"> 51</span></a> <span class="n">branch_id</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame-52"><a href="#DataFrame-52"><span class="linenos"> 52</span></a> <span class="n">sequence_id</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame-53"><a href="#DataFrame-53"><span class="linenos"> 53</span></a> <span class="n">last_op</span><span class="p">:</span> <span class="n">Operation</span> <span class="o">=</span> <span class="n">Operation</span><span class="o">.</span><span class="n">INIT</span><span class="p">,</span> +</span><span id="DataFrame-54"><a href="#DataFrame-54"><span class="linenos"> 54</span></a> <span class="n">pending_hints</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame-55"><a href="#DataFrame-55"><span class="linenos"> 55</span></a> <span class="n">output_expression_container</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">OutputExpressionContainer</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame-56"><a href="#DataFrame-56"><span class="linenos"> 56</span></a> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span> +</span><span id="DataFrame-57"><a href="#DataFrame-57"><span class="linenos"> 57</span></a> <span class="p">):</span> +</span><span id="DataFrame-58"><a href="#DataFrame-58"><span class="linenos"> 58</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">spark</span> <span class="o">=</span> <span class="n">spark</span> +</span><span id="DataFrame-59"><a href="#DataFrame-59"><span class="linenos"> 59</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span> <span class="o">=</span> <span class="n">expression</span> +</span><span id="DataFrame-60"><a href="#DataFrame-60"><span class="linenos"> 60</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">branch_id</span> <span class="o">=</span> <span class="n">branch_id</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">spark</span><span class="o">.</span><span class="n">_random_branch_id</span> +</span><span id="DataFrame-61"><a href="#DataFrame-61"><span class="linenos"> 61</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sequence_id</span> <span class="o">=</span> <span class="n">sequence_id</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">spark</span><span class="o">.</span><span class="n">_random_sequence_id</span> +</span><span id="DataFrame-62"><a href="#DataFrame-62"><span class="linenos"> 62</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">last_op</span> <span class="o">=</span> <span class="n">last_op</span> +</span><span id="DataFrame-63"><a href="#DataFrame-63"><span class="linenos"> 63</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">pending_hints</span> <span class="o">=</span> <span class="n">pending_hints</span> <span class="ow">or</span> <span class="p">[]</span> +</span><span id="DataFrame-64"><a href="#DataFrame-64"><span class="linenos"> 64</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">output_expression_container</span> <span class="o">=</span> <span class="n">output_expression_container</span> <span class="ow">or</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">()</span> +</span><span id="DataFrame-65"><a href="#DataFrame-65"><span class="linenos"> 65</span></a> +</span><span id="DataFrame-66"><a href="#DataFrame-66"><span class="linenos"> 66</span></a> <span class="k">def</span> <span class="fm">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">column_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="DataFrame-67"><a href="#DataFrame-67"><span class="linenos"> 67</span></a> <span class="k">return</span> <span class="bp">self</span><span class="p">[</span><span class="n">column_name</span><span class="p">]</span> +</span><span id="DataFrame-68"><a href="#DataFrame-68"><span class="linenos"> 68</span></a> +</span><span id="DataFrame-69"><a href="#DataFrame-69"><span class="linenos"> 69</span></a> <span class="k">def</span> <span class="fm">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">column_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="DataFrame-70"><a href="#DataFrame-70"><span class="linenos"> 70</span></a> <span class="n">column_name</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">branch_id</span><span class="si">}</span><span class="s2">.</span><span class="si">{</span><span class="n">column_name</span><span class="si">}</span><span class="s2">"</span> +</span><span id="DataFrame-71"><a href="#DataFrame-71"><span class="linenos"> 71</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">column_name</span><span class="p">)</span> +</span><span id="DataFrame-72"><a href="#DataFrame-72"><span class="linenos"> 72</span></a> +</span><span id="DataFrame-73"><a href="#DataFrame-73"><span class="linenos"> 73</span></a> <span class="k">def</span> <span class="nf">__copy__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> +</span><span id="DataFrame-74"><a href="#DataFrame-74"><span class="linenos"> 74</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-75"><a href="#DataFrame-75"><span class="linenos"> 75</span></a> +</span><span id="DataFrame-76"><a href="#DataFrame-76"><span class="linenos"> 76</span></a> <span class="nd">@property</span> +</span><span id="DataFrame-77"><a href="#DataFrame-77"><span class="linenos"> 77</span></a> <span class="k">def</span> <span class="nf">sparkSession</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> +</span><span id="DataFrame-78"><a href="#DataFrame-78"><span class="linenos"> 78</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">spark</span> +</span><span id="DataFrame-79"><a href="#DataFrame-79"><span class="linenos"> 79</span></a> +</span><span id="DataFrame-80"><a href="#DataFrame-80"><span class="linenos"> 80</span></a> <span class="nd">@property</span> +</span><span id="DataFrame-81"><a href="#DataFrame-81"><span class="linenos"> 81</span></a> <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> +</span><span id="DataFrame-82"><a href="#DataFrame-82"><span class="linenos"> 82</span></a> <span class="k">return</span> <span class="n">DataFrameWriter</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> +</span><span id="DataFrame-83"><a href="#DataFrame-83"><span class="linenos"> 83</span></a> +</span><span id="DataFrame-84"><a href="#DataFrame-84"><span class="linenos"> 84</span></a> <span class="nd">@property</span> +</span><span id="DataFrame-85"><a href="#DataFrame-85"><span class="linenos"> 85</span></a> <span class="k">def</span> <span class="nf">latest_cte_name</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="DataFrame-86"><a href="#DataFrame-86"><span class="linenos"> 86</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">ctes</span><span class="p">:</span> +</span><span id="DataFrame-87"><a href="#DataFrame-87"><span class="linenos"> 87</span></a> <span class="n">from_exp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"from"</span><span class="p">]</span> +</span><span id="DataFrame-88"><a href="#DataFrame-88"><span class="linenos"> 88</span></a> <span class="k">if</span> <span class="n">from_exp</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">:</span> +</span><span id="DataFrame-89"><a href="#DataFrame-89"><span class="linenos"> 89</span></a> <span class="k">return</span> <span class="n">from_exp</span><span class="o">.</span><span class="n">alias_or_name</span> +</span><span id="DataFrame-90"><a href="#DataFrame-90"><span class="linenos"> 90</span></a> <span class="n">table_alias</span> <span class="o">=</span> <span class="n">from_exp</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">TableAlias</span><span class="p">)</span> +</span><span id="DataFrame-91"><a href="#DataFrame-91"><span class="linenos"> 91</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">table_alias</span><span class="p">:</span> +</span><span id="DataFrame-92"><a href="#DataFrame-92"><span class="linenos"> 92</span></a> <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span> +</span><span id="DataFrame-93"><a href="#DataFrame-93"><span class="linenos"> 93</span></a> <span class="sa">f</span><span class="s2">"Could not find an alias name for this expression: </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="si">}</span><span class="s2">"</span> +</span><span id="DataFrame-94"><a href="#DataFrame-94"><span class="linenos"> 94</span></a> <span class="p">)</span> +</span><span id="DataFrame-95"><a href="#DataFrame-95"><span class="linenos"> 95</span></a> <span class="k">return</span> <span class="n">table_alias</span><span class="o">.</span><span class="n">alias_or_name</span> +</span><span id="DataFrame-96"><a href="#DataFrame-96"><span class="linenos"> 96</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">ctes</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">alias</span> +</span><span id="DataFrame-97"><a href="#DataFrame-97"><span class="linenos"> 97</span></a> +</span><span id="DataFrame-98"><a href="#DataFrame-98"><span class="linenos"> 98</span></a> <span class="nd">@property</span> +</span><span id="DataFrame-99"><a href="#DataFrame-99"><span class="linenos"> 99</span></a> <span class="k">def</span> <span class="nf">pending_join_hints</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> +</span><span id="DataFrame-100"><a href="#DataFrame-100"><span class="linenos">100</span></a> <span class="k">return</span> <span class="p">[</span><span class="n">hint</span> <span class="k">for</span> <span class="n">hint</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">pending_hints</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">hint</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">JoinHint</span><span class="p">)]</span> +</span><span id="DataFrame-101"><a href="#DataFrame-101"><span class="linenos">101</span></a> +</span><span id="DataFrame-102"><a href="#DataFrame-102"><span class="linenos">102</span></a> <span class="nd">@property</span> +</span><span id="DataFrame-103"><a href="#DataFrame-103"><span class="linenos">103</span></a> <span class="k">def</span> <span class="nf">pending_partition_hints</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> +</span><span id="DataFrame-104"><a href="#DataFrame-104"><span class="linenos">104</span></a> <span class="k">return</span> <span class="p">[</span><span class="n">hint</span> <span class="k">for</span> <span class="n">hint</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">pending_hints</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">hint</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Anonymous</span><span class="p">)]</span> +</span><span id="DataFrame-105"><a href="#DataFrame-105"><span class="linenos">105</span></a> +</span><span id="DataFrame-106"><a href="#DataFrame-106"><span class="linenos">106</span></a> <span class="nd">@property</span> +</span><span id="DataFrame-107"><a href="#DataFrame-107"><span class="linenos">107</span></a> <span class="k">def</span> <span class="nf">columns</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> +</span><span id="DataFrame-108"><a href="#DataFrame-108"><span class="linenos">108</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">named_selects</span> +</span><span id="DataFrame-109"><a href="#DataFrame-109"><span class="linenos">109</span></a> +</span><span id="DataFrame-110"><a href="#DataFrame-110"><span class="linenos">110</span></a> <span class="nd">@property</span> +</span><span id="DataFrame-111"><a href="#DataFrame-111"><span class="linenos">111</span></a> <span class="k">def</span> <span class="nf">na</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrameNaFunctions</span><span class="p">:</span> +</span><span id="DataFrame-112"><a href="#DataFrame-112"><span class="linenos">112</span></a> <span class="k">return</span> <span class="n">DataFrameNaFunctions</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> +</span><span id="DataFrame-113"><a href="#DataFrame-113"><span class="linenos">113</span></a> +</span><span id="DataFrame-114"><a href="#DataFrame-114"><span class="linenos">114</span></a> <span class="k">def</span> <span class="nf">_replace_cte_names_with_hashes</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">):</span> +</span><span id="DataFrame-115"><a href="#DataFrame-115"><span class="linenos">115</span></a> <span class="n">replacement_mapping</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="DataFrame-116"><a href="#DataFrame-116"><span class="linenos">116</span></a> <span class="k">for</span> <span class="n">cte</span> <span class="ow">in</span> <span class="n">expression</span><span class="o">.</span><span class="n">ctes</span><span class="p">:</span> +</span><span id="DataFrame-117"><a href="#DataFrame-117"><span class="linenos">117</span></a> <span class="n">old_name_id</span> <span class="o">=</span> <span class="n">cte</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"alias"</span><span class="p">]</span><span class="o">.</span><span class="n">this</span> +</span><span id="DataFrame-118"><a href="#DataFrame-118"><span class="linenos">118</span></a> <span class="n">new_hashed_id</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">to_identifier</span><span class="p">(</span> +</span><span id="DataFrame-119"><a href="#DataFrame-119"><span class="linenos">119</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_create_hash_from_expression</span><span class="p">(</span><span class="n">cte</span><span class="o">.</span><span class="n">this</span><span class="p">),</span> <span class="n">quoted</span><span class="o">=</span><span class="n">old_name_id</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"quoted"</span><span class="p">]</span> +</span><span id="DataFrame-120"><a href="#DataFrame-120"><span class="linenos">120</span></a> <span class="p">)</span> +</span><span id="DataFrame-121"><a href="#DataFrame-121"><span class="linenos">121</span></a> <span class="n">replacement_mapping</span><span class="p">[</span><span class="n">old_name_id</span><span class="p">]</span> <span class="o">=</span> <span class="n">new_hashed_id</span> +</span><span id="DataFrame-122"><a href="#DataFrame-122"><span class="linenos">122</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span><span class="n">replace_id_value</span><span class="p">,</span> <span class="n">replacement_mapping</span><span class="p">)</span> +</span><span id="DataFrame-123"><a href="#DataFrame-123"><span class="linenos">123</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="DataFrame-124"><a href="#DataFrame-124"><span class="linenos">124</span></a> +</span><span id="DataFrame-125"><a href="#DataFrame-125"><span class="linenos">125</span></a> <span class="k">def</span> <span class="nf">_create_cte_from_expression</span><span class="p">(</span> +</span><span id="DataFrame-126"><a href="#DataFrame-126"><span class="linenos">126</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame-127"><a href="#DataFrame-127"><span class="linenos">127</span></a> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">,</span> +</span><span id="DataFrame-128"><a href="#DataFrame-128"><span class="linenos">128</span></a> <span class="n">branch_id</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame-129"><a href="#DataFrame-129"><span class="linenos">129</span></a> <span class="n">sequence_id</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame-130"><a href="#DataFrame-130"><span class="linenos">130</span></a> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span> +</span><span id="DataFrame-131"><a href="#DataFrame-131"><span class="linenos">131</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">CTE</span><span class="p">,</span> <span class="nb">str</span><span class="p">]:</span> +</span><span id="DataFrame-132"><a href="#DataFrame-132"><span class="linenos">132</span></a> <span class="n">name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">spark</span><span class="o">.</span><span class="n">_random_name</span> +</span><span id="DataFrame-133"><a href="#DataFrame-133"><span class="linenos">133</span></a> <span class="n">expression_to_cte</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-134"><a href="#DataFrame-134"><span class="linenos">134</span></a> <span class="n">expression_to_cte</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"with"</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> +</span><span id="DataFrame-135"><a href="#DataFrame-135"><span class="linenos">135</span></a> <span class="n">cte</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">()</span><span class="o">.</span><span class="n">with_</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">as_</span><span class="o">=</span><span class="n">expression_to_cte</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span><span class="o">.</span><span class="n">ctes</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> +</span><span id="DataFrame-136"><a href="#DataFrame-136"><span class="linenos">136</span></a> <span class="n">cte</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"branch_id"</span><span class="p">,</span> <span class="n">branch_id</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">branch_id</span><span class="p">)</span> +</span><span id="DataFrame-137"><a href="#DataFrame-137"><span class="linenos">137</span></a> <span class="n">cte</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"sequence_id"</span><span class="p">,</span> <span class="n">sequence_id</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">sequence_id</span><span class="p">)</span> +</span><span id="DataFrame-138"><a href="#DataFrame-138"><span class="linenos">138</span></a> <span class="k">return</span> <span class="n">cte</span><span class="p">,</span> <span class="n">name</span> +</span><span id="DataFrame-139"><a href="#DataFrame-139"><span class="linenos">139</span></a> +</span><span id="DataFrame-140"><a href="#DataFrame-140"><span class="linenos">140</span></a> <span class="nd">@t</span><span class="o">.</span><span class="n">overload</span> +</span><span id="DataFrame-141"><a href="#DataFrame-141"><span class="linenos">141</span></a> <span class="k">def</span> <span class="nf">_ensure_list_of_columns</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cols</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Collection</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">])</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Column</span><span class="p">]:</span> +</span><span id="DataFrame-142"><a href="#DataFrame-142"><span class="linenos">142</span></a> <span class="o">...</span> +</span><span id="DataFrame-143"><a href="#DataFrame-143"><span class="linenos">143</span></a> +</span><span id="DataFrame-144"><a href="#DataFrame-144"><span class="linenos">144</span></a> <span class="nd">@t</span><span class="o">.</span><span class="n">overload</span> +</span><span id="DataFrame-145"><a href="#DataFrame-145"><span class="linenos">145</span></a> <span class="k">def</span> <span class="nf">_ensure_list_of_columns</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cols</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Column</span><span class="p">]:</span> +</span><span id="DataFrame-146"><a href="#DataFrame-146"><span class="linenos">146</span></a> <span class="o">...</span> +</span><span id="DataFrame-147"><a href="#DataFrame-147"><span class="linenos">147</span></a> +</span><span id="DataFrame-148"><a href="#DataFrame-148"><span class="linenos">148</span></a> <span class="k">def</span> <span class="nf">_ensure_list_of_columns</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cols</span><span class="p">):</span> +</span><span id="DataFrame-149"><a href="#DataFrame-149"><span class="linenos">149</span></a> <span class="k">return</span> <span class="n">Column</span><span class="o">.</span><span class="n">ensure_cols</span><span class="p">(</span><span class="n">ensure_list</span><span class="p">(</span><span class="n">cols</span><span class="p">))</span> +</span><span id="DataFrame-150"><a href="#DataFrame-150"><span class="linenos">150</span></a> +</span><span id="DataFrame-151"><a href="#DataFrame-151"><span class="linenos">151</span></a> <span class="k">def</span> <span class="nf">_ensure_and_normalize_cols</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cols</span><span class="p">):</span> +</span><span id="DataFrame-152"><a href="#DataFrame-152"><span class="linenos">152</span></a> <span class="n">cols</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_list_of_columns</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> +</span><span id="DataFrame-153"><a href="#DataFrame-153"><span class="linenos">153</span></a> <span class="n">normalize</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">spark</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">cols</span><span class="p">)</span> +</span><span id="DataFrame-154"><a href="#DataFrame-154"><span class="linenos">154</span></a> <span class="k">return</span> <span class="n">cols</span> +</span><span id="DataFrame-155"><a href="#DataFrame-155"><span class="linenos">155</span></a> +</span><span id="DataFrame-156"><a href="#DataFrame-156"><span class="linenos">156</span></a> <span class="k">def</span> <span class="nf">_ensure_and_normalize_col</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">col</span><span class="p">):</span> +</span><span id="DataFrame-157"><a href="#DataFrame-157"><span class="linenos">157</span></a> <span class="n">col</span> <span class="o">=</span> <span class="n">Column</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">col</span><span class="p">)</span> +</span><span id="DataFrame-158"><a href="#DataFrame-158"><span class="linenos">158</span></a> <span class="n">normalize</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">spark</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">col</span><span class="p">)</span> +</span><span id="DataFrame-159"><a href="#DataFrame-159"><span class="linenos">159</span></a> <span class="k">return</span> <span class="n">col</span> +</span><span id="DataFrame-160"><a href="#DataFrame-160"><span class="linenos">160</span></a> +</span><span id="DataFrame-161"><a href="#DataFrame-161"><span class="linenos">161</span></a> <span class="k">def</span> <span class="nf">_convert_leaf_to_cte</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sequence_id</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-162"><a href="#DataFrame-162"><span class="linenos">162</span></a> <span class="n">df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_resolve_pending_hints</span><span class="p">()</span> +</span><span id="DataFrame-163"><a href="#DataFrame-163"><span class="linenos">163</span></a> <span class="n">sequence_id</span> <span class="o">=</span> <span class="n">sequence_id</span> <span class="ow">or</span> <span class="n">df</span><span class="o">.</span><span class="n">sequence_id</span> +</span><span id="DataFrame-164"><a href="#DataFrame-164"><span class="linenos">164</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-165"><a href="#DataFrame-165"><span class="linenos">165</span></a> <span class="n">cte_expression</span><span class="p">,</span> <span class="n">cte_name</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">_create_cte_from_expression</span><span class="p">(</span> +</span><span id="DataFrame-166"><a href="#DataFrame-166"><span class="linenos">166</span></a> <span class="n">expression</span><span class="o">=</span><span class="n">expression</span><span class="p">,</span> <span class="n">sequence_id</span><span class="o">=</span><span class="n">sequence_id</span> +</span><span id="DataFrame-167"><a href="#DataFrame-167"><span class="linenos">167</span></a> <span class="p">)</span> +</span><span id="DataFrame-168"><a href="#DataFrame-168"><span class="linenos">168</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">_add_ctes_to_expression</span><span class="p">(</span> +</span><span id="DataFrame-169"><a href="#DataFrame-169"><span class="linenos">169</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">(),</span> <span class="n">expression</span><span class="o">.</span><span class="n">ctes</span> <span class="o">+</span> <span class="p">[</span><span class="n">cte_expression</span><span class="p">]</span> +</span><span id="DataFrame-170"><a href="#DataFrame-170"><span class="linenos">170</span></a> <span class="p">)</span> +</span><span id="DataFrame-171"><a href="#DataFrame-171"><span class="linenos">171</span></a> <span class="n">sel_columns</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">_get_outer_select_columns</span><span class="p">(</span><span class="n">cte_expression</span><span class="p">)</span> +</span><span id="DataFrame-172"><a href="#DataFrame-172"><span class="linenos">172</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">new_expression</span><span class="o">.</span><span class="n">from_</span><span class="p">(</span><span class="n">cte_name</span><span class="p">)</span><span class="o">.</span><span class="n">select</span><span class="p">(</span> +</span><span id="DataFrame-173"><a href="#DataFrame-173"><span class="linenos">173</span></a> <span class="o">*</span><span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">sel_columns</span><span class="p">]</span> +</span><span id="DataFrame-174"><a href="#DataFrame-174"><span class="linenos">174</span></a> <span class="p">)</span> +</span><span id="DataFrame-175"><a href="#DataFrame-175"><span class="linenos">175</span></a> <span class="k">return</span> <span class="n">df</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="n">new_expression</span><span class="p">,</span> <span class="n">sequence_id</span><span class="o">=</span><span class="n">sequence_id</span><span class="p">)</span> +</span><span id="DataFrame-176"><a href="#DataFrame-176"><span class="linenos">176</span></a> +</span><span id="DataFrame-177"><a href="#DataFrame-177"><span class="linenos">177</span></a> <span class="k">def</span> <span class="nf">_resolve_pending_hints</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-178"><a href="#DataFrame-178"><span class="linenos">178</span></a> <span class="n">df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-179"><a href="#DataFrame-179"><span class="linenos">179</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">pending_hints</span><span class="p">:</span> +</span><span id="DataFrame-180"><a href="#DataFrame-180"><span class="linenos">180</span></a> <span class="k">return</span> <span class="n">df</span> +</span><span id="DataFrame-181"><a href="#DataFrame-181"><span class="linenos">181</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">expression</span> +</span><span id="DataFrame-182"><a href="#DataFrame-182"><span class="linenos">182</span></a> <span class="n">hint_expression</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"hint"</span><span class="p">)</span> <span class="ow">or</span> <span class="n">exp</span><span class="o">.</span><span class="n">Hint</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="p">[])</span> +</span><span id="DataFrame-183"><a href="#DataFrame-183"><span class="linenos">183</span></a> <span class="k">for</span> <span class="n">hint</span> <span class="ow">in</span> <span class="n">df</span><span class="o">.</span><span class="n">pending_partition_hints</span><span class="p">:</span> +</span><span id="DataFrame-184"><a href="#DataFrame-184"><span class="linenos">184</span></a> <span class="n">hint_expression</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="n">hint</span><span class="p">)</span> +</span><span id="DataFrame-185"><a href="#DataFrame-185"><span class="linenos">185</span></a> <span class="n">df</span><span class="o">.</span><span class="n">pending_hints</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">hint</span><span class="p">)</span> +</span><span id="DataFrame-186"><a href="#DataFrame-186"><span class="linenos">186</span></a> +</span><span id="DataFrame-187"><a href="#DataFrame-187"><span class="linenos">187</span></a> <span class="n">join_aliases</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="DataFrame-188"><a href="#DataFrame-188"><span class="linenos">188</span></a> <span class="n">join_table</span><span class="o">.</span><span class="n">alias_or_name</span> +</span><span id="DataFrame-189"><a href="#DataFrame-189"><span class="linenos">189</span></a> <span class="k">for</span> <span class="n">join_table</span> <span class="ow">in</span> <span class="n">get_tables_from_expression_with_join</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame-190"><a href="#DataFrame-190"><span class="linenos">190</span></a> <span class="p">}</span> +</span><span id="DataFrame-191"><a href="#DataFrame-191"><span class="linenos">191</span></a> <span class="k">if</span> <span class="n">join_aliases</span><span class="p">:</span> +</span><span id="DataFrame-192"><a href="#DataFrame-192"><span class="linenos">192</span></a> <span class="k">for</span> <span class="n">hint</span> <span class="ow">in</span> <span class="n">df</span><span class="o">.</span><span class="n">pending_join_hints</span><span class="p">:</span> +</span><span id="DataFrame-193"><a href="#DataFrame-193"><span class="linenos">193</span></a> <span class="k">for</span> <span class="n">sequence_id_expression</span> <span class="ow">in</span> <span class="n">hint</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> +</span><span id="DataFrame-194"><a href="#DataFrame-194"><span class="linenos">194</span></a> <span class="n">sequence_id_or_name</span> <span class="o">=</span> <span class="n">sequence_id_expression</span><span class="o">.</span><span class="n">alias_or_name</span> +</span><span id="DataFrame-195"><a href="#DataFrame-195"><span class="linenos">195</span></a> <span class="n">sequence_ids_to_match</span> <span class="o">=</span> <span class="p">[</span><span class="n">sequence_id_or_name</span><span class="p">]</span> +</span><span id="DataFrame-196"><a href="#DataFrame-196"><span class="linenos">196</span></a> <span class="k">if</span> <span class="n">sequence_id_or_name</span> <span class="ow">in</span> <span class="n">df</span><span class="o">.</span><span class="n">spark</span><span class="o">.</span><span class="n">name_to_sequence_id_mapping</span><span class="p">:</span> +</span><span id="DataFrame-197"><a href="#DataFrame-197"><span class="linenos">197</span></a> <span class="n">sequence_ids_to_match</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">spark</span><span class="o">.</span><span class="n">name_to_sequence_id_mapping</span><span class="p">[</span> +</span><span id="DataFrame-198"><a href="#DataFrame-198"><span class="linenos">198</span></a> <span class="n">sequence_id_or_name</span> +</span><span id="DataFrame-199"><a href="#DataFrame-199"><span class="linenos">199</span></a> <span class="p">]</span> +</span><span id="DataFrame-200"><a href="#DataFrame-200"><span class="linenos">200</span></a> <span class="n">matching_ctes</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-201"><a href="#DataFrame-201"><span class="linenos">201</span></a> <span class="n">cte</span> +</span><span id="DataFrame-202"><a href="#DataFrame-202"><span class="linenos">202</span></a> <span class="k">for</span> <span class="n">cte</span> <span class="ow">in</span> <span class="nb">reversed</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">ctes</span><span class="p">)</span> +</span><span id="DataFrame-203"><a href="#DataFrame-203"><span class="linenos">203</span></a> <span class="k">if</span> <span class="n">cte</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"sequence_id"</span><span class="p">]</span> <span class="ow">in</span> <span class="n">sequence_ids_to_match</span> +</span><span id="DataFrame-204"><a href="#DataFrame-204"><span class="linenos">204</span></a> <span class="p">]</span> +</span><span id="DataFrame-205"><a href="#DataFrame-205"><span class="linenos">205</span></a> <span class="k">for</span> <span class="n">matching_cte</span> <span class="ow">in</span> <span class="n">matching_ctes</span><span class="p">:</span> +</span><span id="DataFrame-206"><a href="#DataFrame-206"><span class="linenos">206</span></a> <span class="k">if</span> <span class="n">matching_cte</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="ow">in</span> <span class="n">join_aliases</span><span class="p">:</span> +</span><span id="DataFrame-207"><a href="#DataFrame-207"><span class="linenos">207</span></a> <span class="n">sequence_id_expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"this"</span><span class="p">,</span> <span class="n">matching_cte</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"alias"</span><span class="p">]</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> +</span><span id="DataFrame-208"><a href="#DataFrame-208"><span class="linenos">208</span></a> <span class="n">df</span><span class="o">.</span><span class="n">pending_hints</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">hint</span><span class="p">)</span> +</span><span id="DataFrame-209"><a href="#DataFrame-209"><span class="linenos">209</span></a> <span class="k">break</span> +</span><span id="DataFrame-210"><a href="#DataFrame-210"><span class="linenos">210</span></a> <span class="n">hint_expression</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="n">hint</span><span class="p">)</span> +</span><span id="DataFrame-211"><a href="#DataFrame-211"><span class="linenos">211</span></a> <span class="k">if</span> <span class="n">hint_expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> +</span><span id="DataFrame-212"><a href="#DataFrame-212"><span class="linenos">212</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"hint"</span><span class="p">,</span> <span class="n">hint_expression</span><span class="p">)</span> +</span><span id="DataFrame-213"><a href="#DataFrame-213"><span class="linenos">213</span></a> <span class="k">return</span> <span class="n">df</span> +</span><span id="DataFrame-214"><a href="#DataFrame-214"><span class="linenos">214</span></a> +</span><span id="DataFrame-215"><a href="#DataFrame-215"><span class="linenos">215</span></a> <span class="k">def</span> <span class="nf">_hint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">hint_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">args</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Column</span><span class="p">])</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-216"><a href="#DataFrame-216"><span class="linenos">216</span></a> <span class="n">hint_name</span> <span class="o">=</span> <span class="n">hint_name</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> +</span><span id="DataFrame-217"><a href="#DataFrame-217"><span class="linenos">217</span></a> <span class="n">hint_expression</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="DataFrame-218"><a href="#DataFrame-218"><span class="linenos">218</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">JoinHint</span><span class="p">(</span> +</span><span id="DataFrame-219"><a href="#DataFrame-219"><span class="linenos">219</span></a> <span class="n">this</span><span class="o">=</span><span class="n">hint_name</span><span class="p">,</span> +</span><span id="DataFrame-220"><a href="#DataFrame-220"><span class="linenos">220</span></a> <span class="n">expressions</span><span class="o">=</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">to_table</span><span class="p">(</span><span class="n">parameter</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">)</span> <span class="k">for</span> <span class="n">parameter</span> <span class="ow">in</span> <span class="n">args</span><span class="p">],</span> +</span><span id="DataFrame-221"><a href="#DataFrame-221"><span class="linenos">221</span></a> <span class="p">)</span> +</span><span id="DataFrame-222"><a href="#DataFrame-222"><span class="linenos">222</span></a> <span class="k">if</span> <span class="n">hint_name</span> <span class="ow">in</span> <span class="n">JOIN_HINTS</span> +</span><span id="DataFrame-223"><a href="#DataFrame-223"><span class="linenos">223</span></a> <span class="k">else</span> <span class="n">exp</span><span class="o">.</span><span class="n">Anonymous</span><span class="p">(</span> +</span><span id="DataFrame-224"><a href="#DataFrame-224"><span class="linenos">224</span></a> <span class="n">this</span><span class="o">=</span><span class="n">hint_name</span><span class="p">,</span> <span class="n">expressions</span><span class="o">=</span><span class="p">[</span><span class="n">parameter</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">parameter</span> <span class="ow">in</span> <span class="n">args</span><span class="p">]</span> +</span><span id="DataFrame-225"><a href="#DataFrame-225"><span class="linenos">225</span></a> <span class="p">)</span> +</span><span id="DataFrame-226"><a href="#DataFrame-226"><span class="linenos">226</span></a> <span class="p">)</span> +</span><span id="DataFrame-227"><a href="#DataFrame-227"><span class="linenos">227</span></a> <span class="n">new_df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-228"><a href="#DataFrame-228"><span class="linenos">228</span></a> <span class="n">new_df</span><span class="o">.</span><span class="n">pending_hints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">hint_expression</span><span class="p">)</span> +</span><span id="DataFrame-229"><a href="#DataFrame-229"><span class="linenos">229</span></a> <span class="k">return</span> <span class="n">new_df</span> +</span><span id="DataFrame-230"><a href="#DataFrame-230"><span class="linenos">230</span></a> +</span><span id="DataFrame-231"><a href="#DataFrame-231"><span class="linenos">231</span></a> <span class="k">def</span> <span class="nf">_set_operation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">klass</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">,</span> <span class="n">distinct</span><span class="p">:</span> <span class="nb">bool</span><span class="p">):</span> +</span><span id="DataFrame-232"><a href="#DataFrame-232"><span class="linenos">232</span></a> <span class="n">other_df</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">_convert_leaf_to_cte</span><span class="p">()</span> +</span><span id="DataFrame-233"><a href="#DataFrame-233"><span class="linenos">233</span></a> <span class="n">base_expression</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-234"><a href="#DataFrame-234"><span class="linenos">234</span></a> <span class="n">base_expression</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_add_ctes_to_expression</span><span class="p">(</span><span class="n">base_expression</span><span class="p">,</span> <span class="n">other_df</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">ctes</span><span class="p">)</span> +</span><span id="DataFrame-235"><a href="#DataFrame-235"><span class="linenos">235</span></a> <span class="n">all_ctes</span> <span class="o">=</span> <span class="n">base_expression</span><span class="o">.</span><span class="n">ctes</span> +</span><span id="DataFrame-236"><a href="#DataFrame-236"><span class="linenos">236</span></a> <span class="n">other_df</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"with"</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> +</span><span id="DataFrame-237"><a href="#DataFrame-237"><span class="linenos">237</span></a> <span class="n">base_expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"with"</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> +</span><span id="DataFrame-238"><a href="#DataFrame-238"><span class="linenos">238</span></a> <span class="n">operation</span> <span class="o">=</span> <span class="n">klass</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">base_expression</span><span class="p">,</span> <span class="n">distinct</span><span class="o">=</span><span class="n">distinct</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">other_df</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame-239"><a href="#DataFrame-239"><span class="linenos">239</span></a> <span class="n">operation</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"with"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">With</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="n">all_ctes</span><span class="p">))</span> +</span><span id="DataFrame-240"><a href="#DataFrame-240"><span class="linenos">240</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="n">operation</span><span class="p">)</span><span class="o">.</span><span class="n">_convert_leaf_to_cte</span><span class="p">()</span> +</span><span id="DataFrame-241"><a href="#DataFrame-241"><span class="linenos">241</span></a> +</span><span id="DataFrame-242"><a href="#DataFrame-242"><span class="linenos">242</span></a> <span class="k">def</span> <span class="nf">_cache</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">storage_level</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span> +</span><span id="DataFrame-243"><a href="#DataFrame-243"><span class="linenos">243</span></a> <span class="n">df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_convert_leaf_to_cte</span><span class="p">()</span> +</span><span id="DataFrame-244"><a href="#DataFrame-244"><span class="linenos">244</span></a> <span class="n">df</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">ctes</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"cache_storage_level"</span><span class="p">,</span> <span class="n">storage_level</span><span class="p">)</span> +</span><span id="DataFrame-245"><a href="#DataFrame-245"><span class="linenos">245</span></a> <span class="k">return</span> <span class="n">df</span> +</span><span id="DataFrame-246"><a href="#DataFrame-246"><span class="linenos">246</span></a> +</span><span id="DataFrame-247"><a href="#DataFrame-247"><span class="linenos">247</span></a> <span class="nd">@classmethod</span> +</span><span id="DataFrame-248"><a href="#DataFrame-248"><span class="linenos">248</span></a> <span class="k">def</span> <span class="nf">_add_ctes_to_expression</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">,</span> <span class="n">ctes</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">CTE</span><span class="p">])</span> <span class="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">:</span> +</span><span id="DataFrame-249"><a href="#DataFrame-249"><span class="linenos">249</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-250"><a href="#DataFrame-250"><span class="linenos">250</span></a> <span class="n">with_expression</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"with"</span><span class="p">)</span> +</span><span id="DataFrame-251"><a href="#DataFrame-251"><span class="linenos">251</span></a> <span class="k">if</span> <span class="n">with_expression</span><span class="p">:</span> +</span><span id="DataFrame-252"><a href="#DataFrame-252"><span class="linenos">252</span></a> <span class="n">existing_ctes</span> <span class="o">=</span> <span class="n">with_expression</span><span class="o">.</span><span class="n">expressions</span> +</span><span id="DataFrame-253"><a href="#DataFrame-253"><span class="linenos">253</span></a> <span class="n">existsing_cte_names</span> <span class="o">=</span> <span class="p">{</span><span class="n">x</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">existing_ctes</span><span class="p">}</span> +</span><span id="DataFrame-254"><a href="#DataFrame-254"><span class="linenos">254</span></a> <span class="k">for</span> <span class="n">cte</span> <span class="ow">in</span> <span class="n">ctes</span><span class="p">:</span> +</span><span id="DataFrame-255"><a href="#DataFrame-255"><span class="linenos">255</span></a> <span class="k">if</span> <span class="n">cte</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">existsing_cte_names</span><span class="p">:</span> +</span><span id="DataFrame-256"><a href="#DataFrame-256"><span class="linenos">256</span></a> <span class="n">existing_ctes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cte</span><span class="p">)</span> +</span><span id="DataFrame-257"><a href="#DataFrame-257"><span class="linenos">257</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-258"><a href="#DataFrame-258"><span class="linenos">258</span></a> <span class="n">existing_ctes</span> <span class="o">=</span> <span class="n">ctes</span> +</span><span id="DataFrame-259"><a href="#DataFrame-259"><span class="linenos">259</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"with"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">With</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="n">existing_ctes</span><span class="p">))</span> +</span><span id="DataFrame-260"><a href="#DataFrame-260"><span class="linenos">260</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="DataFrame-261"><a href="#DataFrame-261"><span class="linenos">261</span></a> +</span><span id="DataFrame-262"><a href="#DataFrame-262"><span class="linenos">262</span></a> <span class="nd">@classmethod</span> +</span><span id="DataFrame-263"><a href="#DataFrame-263"><span class="linenos">263</span></a> <span class="k">def</span> <span class="nf">_get_outer_select_columns</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">item</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">,</span> <span class="n">DataFrame</span><span class="p">])</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Column</span><span class="p">]:</span> +</span><span id="DataFrame-264"><a href="#DataFrame-264"><span class="linenos">264</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">expression</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">DataFrame</span><span class="p">)</span> <span class="k">else</span> <span class="n">item</span> +</span><span id="DataFrame-265"><a href="#DataFrame-265"><span class="linenos">265</span></a> <span class="k">return</span> <span class="p">[</span><span class="n">Column</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">expression</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">)</span><span class="o">.</span><span class="n">expressions</span><span class="p">]</span> +</span><span id="DataFrame-266"><a href="#DataFrame-266"><span class="linenos">266</span></a> +</span><span id="DataFrame-267"><a href="#DataFrame-267"><span class="linenos">267</span></a> <span class="nd">@classmethod</span> +</span><span id="DataFrame-268"><a href="#DataFrame-268"><span class="linenos">268</span></a> <span class="k">def</span> <span class="nf">_create_hash_from_expression</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">):</span> +</span><span id="DataFrame-269"><a href="#DataFrame-269"><span class="linenos">269</span></a> <span class="n">value</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="s2">"spark"</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">"utf-8"</span><span class="p">)</span> +</span><span id="DataFrame-270"><a href="#DataFrame-270"><span class="linenos">270</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"t</span><span class="si">{</span><span class="n">zlib</span><span class="o">.</span><span class="n">crc32</span><span class="p">(</span><span class="n">value</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="p">[:</span><span class="mi">6</span><span class="p">]</span> +</span><span id="DataFrame-271"><a href="#DataFrame-271"><span class="linenos">271</span></a> +</span><span id="DataFrame-272"><a href="#DataFrame-272"><span class="linenos">272</span></a> <span class="k">def</span> <span class="nf">_get_select_expressions</span><span class="p">(</span> +</span><span id="DataFrame-273"><a href="#DataFrame-273"><span class="linenos">273</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame-274"><a href="#DataFrame-274"><span class="linenos">274</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Cache</span><span class="p">],</span> <span class="n">OutputExpressionContainer</span><span class="p">],</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">]]:</span> +</span><span id="DataFrame-275"><a href="#DataFrame-275"><span class="linenos">275</span></a> <span class="n">select_expressions</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span> +</span><span id="DataFrame-276"><a href="#DataFrame-276"><span class="linenos">276</span></a> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Cache</span><span class="p">],</span> <span class="n">OutputExpressionContainer</span><span class="p">],</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">]</span> +</span><span id="DataFrame-277"><a href="#DataFrame-277"><span class="linenos">277</span></a> <span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="DataFrame-278"><a href="#DataFrame-278"><span class="linenos">278</span></a> <span class="n">main_select_ctes</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">CTE</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="DataFrame-279"><a href="#DataFrame-279"><span class="linenos">279</span></a> <span class="k">for</span> <span class="n">cte</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">ctes</span><span class="p">:</span> +</span><span id="DataFrame-280"><a href="#DataFrame-280"><span class="linenos">280</span></a> <span class="n">cache_storage_level</span> <span class="o">=</span> <span class="n">cte</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"cache_storage_level"</span><span class="p">)</span> +</span><span id="DataFrame-281"><a href="#DataFrame-281"><span class="linenos">281</span></a> <span class="k">if</span> <span class="n">cache_storage_level</span><span class="p">:</span> +</span><span id="DataFrame-282"><a href="#DataFrame-282"><span class="linenos">282</span></a> <span class="n">select_expression</span> <span class="o">=</span> <span class="n">cte</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-283"><a href="#DataFrame-283"><span class="linenos">283</span></a> <span class="n">select_expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"with"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">With</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="n">copy</span><span class="p">(</span><span class="n">main_select_ctes</span><span class="p">)))</span> +</span><span id="DataFrame-284"><a href="#DataFrame-284"><span class="linenos">284</span></a> <span class="n">select_expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"cte_alias_name"</span><span class="p">,</span> <span class="n">cte</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">)</span> +</span><span id="DataFrame-285"><a href="#DataFrame-285"><span class="linenos">285</span></a> <span class="n">select_expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"cache_storage_level"</span><span class="p">,</span> <span class="n">cache_storage_level</span><span class="p">)</span> +</span><span id="DataFrame-286"><a href="#DataFrame-286"><span class="linenos">286</span></a> <span class="n">select_expressions</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">exp</span><span class="o">.</span><span class="n">Cache</span><span class="p">,</span> <span class="n">select_expression</span><span class="p">))</span> +</span><span id="DataFrame-287"><a href="#DataFrame-287"><span class="linenos">287</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-288"><a href="#DataFrame-288"><span class="linenos">288</span></a> <span class="n">main_select_ctes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cte</span><span class="p">)</span> +</span><span id="DataFrame-289"><a href="#DataFrame-289"><span class="linenos">289</span></a> <span class="n">main_select</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-290"><a href="#DataFrame-290"><span class="linenos">290</span></a> <span class="k">if</span> <span class="n">main_select_ctes</span><span class="p">:</span> +</span><span id="DataFrame-291"><a href="#DataFrame-291"><span class="linenos">291</span></a> <span class="n">main_select</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"with"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">With</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="n">main_select_ctes</span><span class="p">))</span> +</span><span id="DataFrame-292"><a href="#DataFrame-292"><span class="linenos">292</span></a> <span class="n">expression_select_pair</span> <span class="o">=</span> <span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">output_expression_container</span><span class="p">),</span> <span class="n">main_select</span><span class="p">)</span> +</span><span id="DataFrame-293"><a href="#DataFrame-293"><span class="linenos">293</span></a> <span class="n">select_expressions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">expression_select_pair</span><span class="p">)</span> <span class="c1"># type: ignore</span> +</span><span id="DataFrame-294"><a href="#DataFrame-294"><span class="linenos">294</span></a> <span class="k">return</span> <span class="n">select_expressions</span> +</span><span id="DataFrame-295"><a href="#DataFrame-295"><span class="linenos">295</span></a> +</span><span id="DataFrame-296"><a href="#DataFrame-296"><span class="linenos">296</span></a> <span class="k">def</span> <span class="nf">sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="s2">"spark"</span><span class="p">,</span> <span class="n">optimize</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> +</span><span id="DataFrame-297"><a href="#DataFrame-297"><span class="linenos">297</span></a> <span class="n">df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_resolve_pending_hints</span><span class="p">()</span> +</span><span id="DataFrame-298"><a href="#DataFrame-298"><span class="linenos">298</span></a> <span class="n">select_expressions</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">_get_select_expressions</span><span class="p">()</span> +</span><span id="DataFrame-299"><a href="#DataFrame-299"><span class="linenos">299</span></a> <span class="n">output_expressions</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cache</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Drop</span><span class="p">]]</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="DataFrame-300"><a href="#DataFrame-300"><span class="linenos">300</span></a> <span class="n">replacement_mapping</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="DataFrame-301"><a href="#DataFrame-301"><span class="linenos">301</span></a> <span class="k">for</span> <span class="n">expression_type</span><span class="p">,</span> <span class="n">select_expression</span> <span class="ow">in</span> <span class="n">select_expressions</span><span class="p">:</span> +</span><span id="DataFrame-302"><a href="#DataFrame-302"><span class="linenos">302</span></a> <span class="n">select_expression</span> <span class="o">=</span> <span class="n">select_expression</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span><span class="n">replace_id_value</span><span class="p">,</span> <span class="n">replacement_mapping</span><span class="p">)</span> +</span><span id="DataFrame-303"><a href="#DataFrame-303"><span class="linenos">303</span></a> <span class="k">if</span> <span class="n">optimize</span><span class="p">:</span> +</span><span id="DataFrame-304"><a href="#DataFrame-304"><span class="linenos">304</span></a> <span class="n">select_expression</span> <span class="o">=</span> <span class="n">optimize_func</span><span class="p">(</span><span class="n">select_expression</span><span class="p">)</span> +</span><span id="DataFrame-305"><a href="#DataFrame-305"><span class="linenos">305</span></a> <span class="n">select_expression</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">_replace_cte_names_with_hashes</span><span class="p">(</span><span class="n">select_expression</span><span class="p">)</span> +</span><span id="DataFrame-306"><a href="#DataFrame-306"><span class="linenos">306</span></a> <span class="n">expression</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cache</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Drop</span><span class="p">]</span> +</span><span id="DataFrame-307"><a href="#DataFrame-307"><span class="linenos">307</span></a> <span class="k">if</span> <span class="n">expression_type</span> <span class="o">==</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cache</span><span class="p">:</span> +</span><span id="DataFrame-308"><a href="#DataFrame-308"><span class="linenos">308</span></a> <span class="n">cache_table_name</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">_create_hash_from_expression</span><span class="p">(</span><span class="n">select_expression</span><span class="p">)</span> +</span><span id="DataFrame-309"><a href="#DataFrame-309"><span class="linenos">309</span></a> <span class="n">cache_table</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">to_table</span><span class="p">(</span><span class="n">cache_table_name</span><span class="p">)</span> +</span><span id="DataFrame-310"><a href="#DataFrame-310"><span class="linenos">310</span></a> <span class="n">original_alias_name</span> <span class="o">=</span> <span class="n">select_expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"cte_alias_name"</span><span class="p">]</span> +</span><span id="DataFrame-311"><a href="#DataFrame-311"><span class="linenos">311</span></a> +</span><span id="DataFrame-312"><a href="#DataFrame-312"><span class="linenos">312</span></a> <span class="n">replacement_mapping</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">to_identifier</span><span class="p">(</span><span class="n">original_alias_name</span><span class="p">)]</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">to_identifier</span><span class="p">(</span> <span class="c1"># type: ignore</span> +</span><span id="DataFrame-313"><a href="#DataFrame-313"><span class="linenos">313</span></a> <span class="n">cache_table_name</span> +</span><span id="DataFrame-314"><a href="#DataFrame-314"><span class="linenos">314</span></a> <span class="p">)</span> +</span><span id="DataFrame-315"><a href="#DataFrame-315"><span class="linenos">315</span></a> <span class="n">sqlglot</span><span class="o">.</span><span class="n">schema</span><span class="o">.</span><span class="n">add_table</span><span class="p">(</span> +</span><span id="DataFrame-316"><a href="#DataFrame-316"><span class="linenos">316</span></a> <span class="n">cache_table_name</span><span class="p">,</span> +</span><span id="DataFrame-317"><a href="#DataFrame-317"><span class="linenos">317</span></a> <span class="p">{</span> +</span><span id="DataFrame-318"><a href="#DataFrame-318"><span class="linenos">318</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">:</span> <span class="n">expression</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="s2">"spark"</span><span class="p">)</span> +</span><span id="DataFrame-319"><a href="#DataFrame-319"><span class="linenos">319</span></a> <span class="k">for</span> <span class="n">expression</span> <span class="ow">in</span> <span class="n">select_expression</span><span class="o">.</span><span class="n">expressions</span> +</span><span id="DataFrame-320"><a href="#DataFrame-320"><span class="linenos">320</span></a> <span class="p">},</span> +</span><span id="DataFrame-321"><a href="#DataFrame-321"><span class="linenos">321</span></a> <span class="p">)</span> +</span><span id="DataFrame-322"><a href="#DataFrame-322"><span class="linenos">322</span></a> <span class="n">cache_storage_level</span> <span class="o">=</span> <span class="n">select_expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"cache_storage_level"</span><span class="p">]</span> +</span><span id="DataFrame-323"><a href="#DataFrame-323"><span class="linenos">323</span></a> <span class="n">options</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-324"><a href="#DataFrame-324"><span class="linenos">324</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="s2">"storageLevel"</span><span class="p">),</span> +</span><span id="DataFrame-325"><a href="#DataFrame-325"><span class="linenos">325</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="n">cache_storage_level</span><span class="p">),</span> +</span><span id="DataFrame-326"><a href="#DataFrame-326"><span class="linenos">326</span></a> <span class="p">]</span> +</span><span id="DataFrame-327"><a href="#DataFrame-327"><span class="linenos">327</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cache</span><span class="p">(</span> +</span><span id="DataFrame-328"><a href="#DataFrame-328"><span class="linenos">328</span></a> <span class="n">this</span><span class="o">=</span><span class="n">cache_table</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">select_expression</span><span class="p">,</span> <span class="n">lazy</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="n">options</span> +</span><span id="DataFrame-329"><a href="#DataFrame-329"><span class="linenos">329</span></a> <span class="p">)</span> +</span><span id="DataFrame-330"><a href="#DataFrame-330"><span class="linenos">330</span></a> <span class="c1"># We will drop the "view" if it exists before running the cache table</span> +</span><span id="DataFrame-331"><a href="#DataFrame-331"><span class="linenos">331</span></a> <span class="n">output_expressions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Drop</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">cache_table</span><span class="p">,</span> <span class="n">exists</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">kind</span><span class="o">=</span><span class="s2">"VIEW"</span><span class="p">))</span> +</span><span id="DataFrame-332"><a href="#DataFrame-332"><span class="linenos">332</span></a> <span class="k">elif</span> <span class="n">expression_type</span> <span class="o">==</span> <span class="n">exp</span><span class="o">.</span><span class="n">Create</span><span class="p">:</span> +</span><span id="DataFrame-333"><a href="#DataFrame-333"><span class="linenos">333</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">output_expression_container</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-334"><a href="#DataFrame-334"><span class="linenos">334</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"expression"</span><span class="p">,</span> <span class="n">select_expression</span><span class="p">)</span> +</span><span id="DataFrame-335"><a href="#DataFrame-335"><span class="linenos">335</span></a> <span class="k">elif</span> <span class="n">expression_type</span> <span class="o">==</span> <span class="n">exp</span><span class="o">.</span><span class="n">Insert</span><span class="p">:</span> +</span><span id="DataFrame-336"><a href="#DataFrame-336"><span class="linenos">336</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">output_expression_container</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-337"><a href="#DataFrame-337"><span class="linenos">337</span></a> <span class="n">select_without_ctes</span> <span class="o">=</span> <span class="n">select_expression</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-338"><a href="#DataFrame-338"><span class="linenos">338</span></a> <span class="n">select_without_ctes</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"with"</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> +</span><span id="DataFrame-339"><a href="#DataFrame-339"><span class="linenos">339</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"expression"</span><span class="p">,</span> <span class="n">select_without_ctes</span><span class="p">)</span> +</span><span id="DataFrame-340"><a href="#DataFrame-340"><span class="linenos">340</span></a> <span class="k">if</span> <span class="n">select_expression</span><span class="o">.</span><span class="n">ctes</span><span class="p">:</span> +</span><span id="DataFrame-341"><a href="#DataFrame-341"><span class="linenos">341</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"with"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">With</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="n">select_expression</span><span class="o">.</span><span class="n">ctes</span><span class="p">))</span> +</span><span id="DataFrame-342"><a href="#DataFrame-342"><span class="linenos">342</span></a> <span class="k">elif</span> <span class="n">expression_type</span> <span class="o">==</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">:</span> +</span><span id="DataFrame-343"><a href="#DataFrame-343"><span class="linenos">343</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">select_expression</span> +</span><span id="DataFrame-344"><a href="#DataFrame-344"><span class="linenos">344</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-345"><a href="#DataFrame-345"><span class="linenos">345</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Invalid expression type: </span><span class="si">{</span><span class="n">expression_type</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="DataFrame-346"><a href="#DataFrame-346"><span class="linenos">346</span></a> <span class="n">output_expressions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame-347"><a href="#DataFrame-347"><span class="linenos">347</span></a> +</span><span id="DataFrame-348"><a href="#DataFrame-348"><span class="linenos">348</span></a> <span class="k">return</span> <span class="p">[</span> +</span><span id="DataFrame-349"><a href="#DataFrame-349"><span class="linenos">349</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="s2">"dialect"</span><span class="p">:</span> <span class="n">dialect</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">})</span> <span class="k">for</span> <span class="n">expression</span> <span class="ow">in</span> <span class="n">output_expressions</span> +</span><span id="DataFrame-350"><a href="#DataFrame-350"><span class="linenos">350</span></a> <span class="p">]</span> +</span><span id="DataFrame-351"><a href="#DataFrame-351"><span class="linenos">351</span></a> +</span><span id="DataFrame-352"><a href="#DataFrame-352"><span class="linenos">352</span></a> <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-353"><a href="#DataFrame-353"><span class="linenos">353</span></a> <span class="k">return</span> <span class="n">DataFrame</span><span class="p">(</span><span class="o">**</span><span class="n">object_to_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">))</span> +</span><span id="DataFrame-354"><a href="#DataFrame-354"><span class="linenos">354</span></a> +</span><span id="DataFrame-355"><a href="#DataFrame-355"><span class="linenos">355</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">SELECT</span><span class="p">)</span> +</span><span id="DataFrame-356"><a href="#DataFrame-356"><span class="linenos">356</span></a> <span class="k">def</span> <span class="nf">select</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="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-357"><a href="#DataFrame-357"><span class="linenos">357</span></a> <span class="n">cols</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> +</span><span id="DataFrame-358"><a href="#DataFrame-358"><span class="linenos">358</span></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">"append"</span><span class="p">]</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"append"</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> +</span><span id="DataFrame-359"><a href="#DataFrame-359"><span class="linenos">359</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"joins"</span><span class="p">):</span> +</span><span id="DataFrame-360"><a href="#DataFrame-360"><span class="linenos">360</span></a> <span class="n">ambiguous_cols</span> <span class="o">=</span> <span class="p">[</span><span class="n">col</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">cols</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">col</span><span class="o">.</span><span class="n">column_expression</span><span class="o">.</span><span class="n">table</span><span class="p">]</span> +</span><span id="DataFrame-361"><a href="#DataFrame-361"><span class="linenos">361</span></a> <span class="k">if</span> <span class="n">ambiguous_cols</span><span class="p">:</span> +</span><span id="DataFrame-362"><a href="#DataFrame-362"><span class="linenos">362</span></a> <span class="n">join_table_identifiers</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-363"><a href="#DataFrame-363"><span class="linenos">363</span></a> <span class="n">x</span><span class="o">.</span><span class="n">this</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">get_tables_from_expression_with_join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame-364"><a href="#DataFrame-364"><span class="linenos">364</span></a> <span class="p">]</span> +</span><span id="DataFrame-365"><a href="#DataFrame-365"><span class="linenos">365</span></a> <span class="n">cte_names_in_join</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">this</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">join_table_identifiers</span><span class="p">]</span> +</span><span id="DataFrame-366"><a href="#DataFrame-366"><span class="linenos">366</span></a> <span class="k">for</span> <span class="n">ambiguous_col</span> <span class="ow">in</span> <span class="n">ambiguous_cols</span><span class="p">:</span> +</span><span id="DataFrame-367"><a href="#DataFrame-367"><span class="linenos">367</span></a> <span class="n">ctes_with_column</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-368"><a href="#DataFrame-368"><span class="linenos">368</span></a> <span class="n">cte</span> +</span><span id="DataFrame-369"><a href="#DataFrame-369"><span class="linenos">369</span></a> <span class="k">for</span> <span class="n">cte</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">ctes</span> +</span><span id="DataFrame-370"><a href="#DataFrame-370"><span class="linenos">370</span></a> <span class="k">if</span> <span class="n">cte</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="ow">in</span> <span class="n">cte_names_in_join</span> +</span><span id="DataFrame-371"><a href="#DataFrame-371"><span class="linenos">371</span></a> <span class="ow">and</span> <span class="n">ambiguous_col</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="ow">in</span> <span class="n">cte</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">named_selects</span> +</span><span id="DataFrame-372"><a href="#DataFrame-372"><span class="linenos">372</span></a> <span class="p">]</span> +</span><span id="DataFrame-373"><a href="#DataFrame-373"><span class="linenos">373</span></a> <span class="c1"># If the select column does not specify a table and there is a join</span> +</span><span id="DataFrame-374"><a href="#DataFrame-374"><span class="linenos">374</span></a> <span class="c1"># then we assume they are referring to the left table</span> +</span><span id="DataFrame-375"><a href="#DataFrame-375"><span class="linenos">375</span></a> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ctes_with_column</span><span class="p">)</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> +</span><span id="DataFrame-376"><a href="#DataFrame-376"><span class="linenos">376</span></a> <span class="n">table_identifier</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"from"</span><span class="p">]</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"expressions"</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">this</span> +</span><span id="DataFrame-377"><a href="#DataFrame-377"><span class="linenos">377</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-378"><a href="#DataFrame-378"><span class="linenos">378</span></a> <span class="n">table_identifier</span> <span class="o">=</span> <span class="n">ctes_with_column</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"alias"</span><span class="p">]</span><span class="o">.</span><span class="n">this</span> +</span><span id="DataFrame-379"><a href="#DataFrame-379"><span class="linenos">379</span></a> <span class="n">ambiguous_col</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"table"</span><span class="p">,</span> <span class="n">table_identifier</span><span class="p">)</span> +</span><span id="DataFrame-380"><a href="#DataFrame-380"><span class="linenos">380</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">cols</span><span class="p">],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> +</span><span id="DataFrame-381"><a href="#DataFrame-381"><span class="linenos">381</span></a> <span class="n">qualify_columns</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">sqlglot</span><span class="o">.</span><span class="n">schema</span><span class="p">)</span> +</span><span id="DataFrame-382"><a href="#DataFrame-382"><span class="linenos">382</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="n">expression</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> +</span><span id="DataFrame-383"><a href="#DataFrame-383"><span class="linenos">383</span></a> +</span><span id="DataFrame-384"><a href="#DataFrame-384"><span class="linenos">384</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">NO_OP</span><span class="p">)</span> +</span><span id="DataFrame-385"><a href="#DataFrame-385"><span class="linenos">385</span></a> <span class="k">def</span> <span class="nf">alias</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-386"><a href="#DataFrame-386"><span class="linenos">386</span></a> <span class="n">new_sequence_id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">spark</span><span class="o">.</span><span class="n">_random_sequence_id</span> +</span><span id="DataFrame-387"><a href="#DataFrame-387"><span class="linenos">387</span></a> <span class="n">df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-388"><a href="#DataFrame-388"><span class="linenos">388</span></a> <span class="k">for</span> <span class="n">join_hint</span> <span class="ow">in</span> <span class="n">df</span><span class="o">.</span><span class="n">pending_join_hints</span><span class="p">:</span> +</span><span id="DataFrame-389"><a href="#DataFrame-389"><span class="linenos">389</span></a> <span class="k">for</span> <span class="n">expression</span> <span class="ow">in</span> <span class="n">join_hint</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> +</span><span id="DataFrame-390"><a href="#DataFrame-390"><span class="linenos">390</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">sequence_id</span><span class="p">:</span> +</span><span id="DataFrame-391"><a href="#DataFrame-391"><span class="linenos">391</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"this"</span><span class="p">,</span> <span class="n">Column</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">new_sequence_id</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame-392"><a href="#DataFrame-392"><span class="linenos">392</span></a> <span class="n">df</span><span class="o">.</span><span class="n">spark</span><span class="o">.</span><span class="n">_add_alias_to_mapping</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">new_sequence_id</span><span class="p">)</span> +</span><span id="DataFrame-393"><a href="#DataFrame-393"><span class="linenos">393</span></a> <span class="k">return</span> <span class="n">df</span><span class="o">.</span><span class="n">_convert_leaf_to_cte</span><span class="p">(</span><span class="n">sequence_id</span><span class="o">=</span><span class="n">new_sequence_id</span><span class="p">)</span> +</span><span id="DataFrame-394"><a href="#DataFrame-394"><span class="linenos">394</span></a> +</span><span id="DataFrame-395"><a href="#DataFrame-395"><span class="linenos">395</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">WHERE</span><span class="p">)</span> +</span><span id="DataFrame-396"><a href="#DataFrame-396"><span class="linenos">396</span></a> <span class="k">def</span> <span class="nf">where</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">column</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">Column</span><span class="p">,</span> <span class="nb">bool</span><span class="p">],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-397"><a href="#DataFrame-397"><span class="linenos">397</span></a> <span class="n">col</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_col</span><span class="p">(</span><span class="n">column</span><span class="p">)</span> +</span><span id="DataFrame-398"><a href="#DataFrame-398"><span class="linenos">398</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">col</span><span class="o">.</span><span class="n">expression</span><span class="p">))</span> +</span><span id="DataFrame-399"><a href="#DataFrame-399"><span class="linenos">399</span></a> +</span><span id="DataFrame-400"><a href="#DataFrame-400"><span class="linenos">400</span></a> <span class="nb">filter</span> <span class="o">=</span> <span class="n">where</span> +</span><span id="DataFrame-401"><a href="#DataFrame-401"><span class="linenos">401</span></a> +</span><span id="DataFrame-402"><a href="#DataFrame-402"><span class="linenos">402</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">GROUP_BY</span><span class="p">)</span> +</span><span id="DataFrame-403"><a href="#DataFrame-403"><span class="linenos">403</span></a> <span class="k">def</span> <span class="nf">groupBy</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="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">GroupedData</span><span class="p">:</span> +</span><span id="DataFrame-404"><a href="#DataFrame-404"><span class="linenos">404</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> +</span><span id="DataFrame-405"><a href="#DataFrame-405"><span class="linenos">405</span></a> <span class="k">return</span> <span class="n">GroupedData</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">columns</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">last_op</span><span class="p">)</span> +</span><span id="DataFrame-406"><a href="#DataFrame-406"><span class="linenos">406</span></a> +</span><span id="DataFrame-407"><a href="#DataFrame-407"><span class="linenos">407</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">SELECT</span><span class="p">)</span> +</span><span id="DataFrame-408"><a href="#DataFrame-408"><span class="linenos">408</span></a> <span class="k">def</span> <span class="nf">agg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">exprs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-409"><a href="#DataFrame-409"><span class="linenos">409</span></a> <span class="n">cols</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">exprs</span><span class="p">)</span> +</span><span id="DataFrame-410"><a href="#DataFrame-410"><span class="linenos">410</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">groupBy</span><span class="p">()</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="o">*</span><span class="n">cols</span><span class="p">)</span> +</span><span id="DataFrame-411"><a href="#DataFrame-411"><span class="linenos">411</span></a> +</span><span id="DataFrame-412"><a href="#DataFrame-412"><span class="linenos">412</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame-413"><a href="#DataFrame-413"><span class="linenos">413</span></a> <span class="k">def</span> <span class="nf">join</span><span class="p">(</span> +</span><span id="DataFrame-414"><a href="#DataFrame-414"><span class="linenos">414</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame-415"><a href="#DataFrame-415"><span class="linenos">415</span></a> <span class="n">other_df</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">,</span> +</span><span id="DataFrame-416"><a href="#DataFrame-416"><span class="linenos">416</span></a> <span class="n">on</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">],</span> <span class="n">Column</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Column</span><span class="p">]],</span> +</span><span id="DataFrame-417"><a href="#DataFrame-417"><span class="linenos">417</span></a> <span class="n">how</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"inner"</span><span class="p">,</span> +</span><span id="DataFrame-418"><a href="#DataFrame-418"><span class="linenos">418</span></a> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span> +</span><span id="DataFrame-419"><a href="#DataFrame-419"><span class="linenos">419</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-420"><a href="#DataFrame-420"><span class="linenos">420</span></a> <span class="n">other_df</span> <span class="o">=</span> <span class="n">other_df</span><span class="o">.</span><span class="n">_convert_leaf_to_cte</span><span class="p">()</span> +</span><span id="DataFrame-421"><a href="#DataFrame-421"><span class="linenos">421</span></a> <span class="n">pre_join_self_latest_cte_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">latest_cte_name</span> +</span><span id="DataFrame-422"><a href="#DataFrame-422"><span class="linenos">422</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">on</span><span class="p">)</span> +</span><span id="DataFrame-423"><a href="#DataFrame-423"><span class="linenos">423</span></a> <span class="n">join_type</span> <span class="o">=</span> <span class="n">how</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">"_"</span><span class="p">,</span> <span class="s2">" "</span><span class="p">)</span> +</span><span id="DataFrame-424"><a href="#DataFrame-424"><span class="linenos">424</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">columns</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">):</span> +</span><span id="DataFrame-425"><a href="#DataFrame-425"><span class="linenos">425</span></a> <span class="n">join_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-426"><a href="#DataFrame-426"><span class="linenos">426</span></a> <span class="n">Column</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">set_table_name</span><span class="p">(</span><span class="n">pre_join_self_latest_cte_name</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">columns</span> +</span><span id="DataFrame-427"><a href="#DataFrame-427"><span class="linenos">427</span></a> <span class="p">]</span> +</span><span id="DataFrame-428"><a href="#DataFrame-428"><span class="linenos">428</span></a> <span class="n">join_clause</span> <span class="o">=</span> <span class="n">functools</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span> +</span><span id="DataFrame-429"><a href="#DataFrame-429"><span class="linenos">429</span></a> <span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">x</span> <span class="o">&</span> <span class="n">y</span><span class="p">,</span> +</span><span id="DataFrame-430"><a href="#DataFrame-430"><span class="linenos">430</span></a> <span class="p">[</span> +</span><span id="DataFrame-431"><a href="#DataFrame-431"><span class="linenos">431</span></a> <span class="n">col</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span><span class="o">.</span><span class="n">set_table_name</span><span class="p">(</span><span class="n">pre_join_self_latest_cte_name</span><span class="p">)</span> +</span><span id="DataFrame-432"><a href="#DataFrame-432"><span class="linenos">432</span></a> <span class="o">==</span> <span class="n">col</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span><span class="o">.</span><span class="n">set_table_name</span><span class="p">(</span><span class="n">other_df</span><span class="o">.</span><span class="n">latest_cte_name</span><span class="p">)</span> +</span><span id="DataFrame-433"><a href="#DataFrame-433"><span class="linenos">433</span></a> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">columns</span> +</span><span id="DataFrame-434"><a href="#DataFrame-434"><span class="linenos">434</span></a> <span class="p">],</span> +</span><span id="DataFrame-435"><a href="#DataFrame-435"><span class="linenos">435</span></a> <span class="p">)</span> +</span><span id="DataFrame-436"><a href="#DataFrame-436"><span class="linenos">436</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-437"><a href="#DataFrame-437"><span class="linenos">437</span></a> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> +</span><span id="DataFrame-438"><a href="#DataFrame-438"><span class="linenos">438</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="n">functools</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">x</span> <span class="o">&</span> <span class="n">y</span><span class="p">,</span> <span class="n">columns</span><span class="p">)]</span> +</span><span id="DataFrame-439"><a href="#DataFrame-439"><span class="linenos">439</span></a> <span class="n">join_clause</span> <span class="o">=</span> <span class="n">columns</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> +</span><span id="DataFrame-440"><a href="#DataFrame-440"><span class="linenos">440</span></a> <span class="n">join_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-441"><a href="#DataFrame-441"><span class="linenos">441</span></a> <span class="n">Column</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">set_table_name</span><span class="p">(</span><span class="n">pre_join_self_latest_cte_name</span><span class="p">)</span> +</span><span id="DataFrame-442"><a href="#DataFrame-442"><span class="linenos">442</span></a> <span class="k">if</span> <span class="n">i</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span> +</span><span id="DataFrame-443"><a href="#DataFrame-443"><span class="linenos">443</span></a> <span class="k">else</span> <span class="n">Column</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">set_table_name</span><span class="p">(</span><span class="n">other_df</span><span class="o">.</span><span class="n">latest_cte_name</span><span class="p">)</span> +</span><span id="DataFrame-444"><a href="#DataFrame-444"><span class="linenos">444</span></a> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">join_clause</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">find_all</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">))</span> +</span><span id="DataFrame-445"><a href="#DataFrame-445"><span class="linenos">445</span></a> <span class="p">]</span> +</span><span id="DataFrame-446"><a href="#DataFrame-446"><span class="linenos">446</span></a> <span class="n">self_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-447"><a href="#DataFrame-447"><span class="linenos">447</span></a> <span class="n">column</span><span class="o">.</span><span class="n">set_table_name</span><span class="p">(</span><span class="n">pre_join_self_latest_cte_name</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="DataFrame-448"><a href="#DataFrame-448"><span class="linenos">448</span></a> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_outer_select_columns</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> +</span><span id="DataFrame-449"><a href="#DataFrame-449"><span class="linenos">449</span></a> <span class="p">]</span> +</span><span id="DataFrame-450"><a href="#DataFrame-450"><span class="linenos">450</span></a> <span class="n">other_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-451"><a href="#DataFrame-451"><span class="linenos">451</span></a> <span class="n">column</span><span class="o">.</span><span class="n">set_table_name</span><span class="p">(</span><span class="n">other_df</span><span class="o">.</span><span class="n">latest_cte_name</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="DataFrame-452"><a href="#DataFrame-452"><span class="linenos">452</span></a> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_outer_select_columns</span><span class="p">(</span><span class="n">other_df</span><span class="p">)</span> +</span><span id="DataFrame-453"><a href="#DataFrame-453"><span class="linenos">453</span></a> <span class="p">]</span> +</span><span id="DataFrame-454"><a href="#DataFrame-454"><span class="linenos">454</span></a> <span class="n">column_value_mapping</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="DataFrame-455"><a href="#DataFrame-455"><span class="linenos">455</span></a> <span class="n">column</span><span class="o">.</span><span class="n">alias_or_name</span> +</span><span id="DataFrame-456"><a href="#DataFrame-456"><span class="linenos">456</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">column</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Star</span><span class="p">)</span> +</span><span id="DataFrame-457"><a href="#DataFrame-457"><span class="linenos">457</span></a> <span class="k">else</span> <span class="n">column</span><span class="o">.</span><span class="n">sql</span><span class="p">():</span> <span class="n">column</span> +</span><span id="DataFrame-458"><a href="#DataFrame-458"><span class="linenos">458</span></a> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">other_columns</span> <span class="o">+</span> <span class="n">self_columns</span> <span class="o">+</span> <span class="n">join_columns</span> +</span><span id="DataFrame-459"><a href="#DataFrame-459"><span class="linenos">459</span></a> <span class="p">}</span> +</span><span id="DataFrame-460"><a href="#DataFrame-460"><span class="linenos">460</span></a> <span class="n">all_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-461"><a href="#DataFrame-461"><span class="linenos">461</span></a> <span class="n">column_value_mapping</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> +</span><span id="DataFrame-462"><a href="#DataFrame-462"><span class="linenos">462</span></a> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="p">{</span><span class="n">x</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">:</span> <span class="kc">None</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">join_columns</span> <span class="o">+</span> <span class="n">self_columns</span> <span class="o">+</span> <span class="n">other_columns</span><span class="p">}</span> +</span><span id="DataFrame-463"><a href="#DataFrame-463"><span class="linenos">463</span></a> <span class="p">]</span> +</span><span id="DataFrame-464"><a href="#DataFrame-464"><span class="linenos">464</span></a> <span class="n">new_df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span> +</span><span id="DataFrame-465"><a href="#DataFrame-465"><span class="linenos">465</span></a> <span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">join</span><span class="p">(</span> +</span><span id="DataFrame-466"><a href="#DataFrame-466"><span class="linenos">466</span></a> <span class="n">other_df</span><span class="o">.</span><span class="n">latest_cte_name</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="n">join_clause</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">join_type</span><span class="o">=</span><span class="n">join_type</span> +</span><span id="DataFrame-467"><a href="#DataFrame-467"><span class="linenos">467</span></a> <span class="p">)</span> +</span><span id="DataFrame-468"><a href="#DataFrame-468"><span class="linenos">468</span></a> <span class="p">)</span> +</span><span id="DataFrame-469"><a href="#DataFrame-469"><span class="linenos">469</span></a> <span class="n">new_df</span><span class="o">.</span><span class="n">expression</span> <span class="o">=</span> <span class="n">new_df</span><span class="o">.</span><span class="n">_add_ctes_to_expression</span><span class="p">(</span> +</span><span id="DataFrame-470"><a href="#DataFrame-470"><span class="linenos">470</span></a> <span class="n">new_df</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">other_df</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">ctes</span> +</span><span id="DataFrame-471"><a href="#DataFrame-471"><span class="linenos">471</span></a> <span class="p">)</span> +</span><span id="DataFrame-472"><a href="#DataFrame-472"><span class="linenos">472</span></a> <span class="n">new_df</span><span class="o">.</span><span class="n">pending_hints</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">other_df</span><span class="o">.</span><span class="n">pending_hints</span><span class="p">)</span> +</span><span id="DataFrame-473"><a href="#DataFrame-473"><span class="linenos">473</span></a> <span class="n">new_df</span> <span class="o">=</span> <span class="n">new_df</span><span class="o">.</span><span class="n">select</span><span class="o">.</span><span class="n">__wrapped__</span><span class="p">(</span><span class="n">new_df</span><span class="p">,</span> <span class="o">*</span><span class="n">all_columns</span><span class="p">)</span> +</span><span id="DataFrame-474"><a href="#DataFrame-474"><span class="linenos">474</span></a> <span class="k">return</span> <span class="n">new_df</span> +</span><span id="DataFrame-475"><a href="#DataFrame-475"><span class="linenos">475</span></a> +</span><span id="DataFrame-476"><a href="#DataFrame-476"><span class="linenos">476</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">ORDER_BY</span><span class="p">)</span> +</span><span id="DataFrame-477"><a href="#DataFrame-477"><span class="linenos">477</span></a> <span class="k">def</span> <span class="nf">orderBy</span><span class="p">(</span> +</span><span id="DataFrame-478"><a href="#DataFrame-478"><span class="linenos">478</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame-479"><a href="#DataFrame-479"><span class="linenos">479</span></a> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Column</span><span class="p">],</span> +</span><span id="DataFrame-480"><a href="#DataFrame-480"><span class="linenos">480</span></a> <span class="n">ascending</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Any</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Any</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame-481"><a href="#DataFrame-481"><span class="linenos">481</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-482"><a href="#DataFrame-482"><span class="linenos">482</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="DataFrame-483"><a href="#DataFrame-483"><span class="linenos">483</span></a><span class="sd"> This implementation lets any ordered columns take priority over whatever is provided in `ascending`. Spark</span> +</span><span id="DataFrame-484"><a href="#DataFrame-484"><span class="linenos">484</span></a><span class="sd"> has irregular behavior and can result in runtime errors. Users shouldn't be mixing the two anyways so this</span> +</span><span id="DataFrame-485"><a href="#DataFrame-485"><span class="linenos">485</span></a><span class="sd"> is unlikely to come up.</span> +</span><span id="DataFrame-486"><a href="#DataFrame-486"><span class="linenos">486</span></a><span class="sd"> """</span> +</span><span id="DataFrame-487"><a href="#DataFrame-487"><span class="linenos">487</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> +</span><span id="DataFrame-488"><a href="#DataFrame-488"><span class="linenos">488</span></a> <span class="n">pre_ordered_col_indexes</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-489"><a href="#DataFrame-489"><span class="linenos">489</span></a> <span class="n">x</span> +</span><span id="DataFrame-490"><a href="#DataFrame-490"><span class="linenos">490</span></a> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="p">[</span> +</span><span id="DataFrame-491"><a href="#DataFrame-491"><span class="linenos">491</span></a> <span class="n">i</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">col</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Ordered</span><span class="p">)</span> <span class="k">else</span> <span class="kc">None</span> +</span><span id="DataFrame-492"><a href="#DataFrame-492"><span class="linenos">492</span></a> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">col</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> +</span><span id="DataFrame-493"><a href="#DataFrame-493"><span class="linenos">493</span></a> <span class="p">]</span> +</span><span id="DataFrame-494"><a href="#DataFrame-494"><span class="linenos">494</span></a> <span class="k">if</span> <span class="n">x</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> +</span><span id="DataFrame-495"><a href="#DataFrame-495"><span class="linenos">495</span></a> <span class="p">]</span> +</span><span id="DataFrame-496"><a href="#DataFrame-496"><span class="linenos">496</span></a> <span class="k">if</span> <span class="n">ascending</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> +</span><span id="DataFrame-497"><a href="#DataFrame-497"><span class="linenos">497</span></a> <span class="n">ascending</span> <span class="o">=</span> <span class="p">[</span><span class="kc">True</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> +</span><span id="DataFrame-498"><a href="#DataFrame-498"><span class="linenos">498</span></a> <span class="k">elif</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">ascending</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span> +</span><span id="DataFrame-499"><a href="#DataFrame-499"><span class="linenos">499</span></a> <span class="n">ascending</span> <span class="o">=</span> <span class="p">[</span><span class="n">ascending</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> +</span><span id="DataFrame-500"><a href="#DataFrame-500"><span class="linenos">500</span></a> <span class="n">ascending</span> <span class="o">=</span> <span class="p">[</span><span class="nb">bool</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ascending</span><span class="p">)]</span> +</span><span id="DataFrame-501"><a href="#DataFrame-501"><span class="linenos">501</span></a> <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span> +</span><span id="DataFrame-502"><a href="#DataFrame-502"><span class="linenos">502</span></a> <span class="n">ascending</span> +</span><span id="DataFrame-503"><a href="#DataFrame-503"><span class="linenos">503</span></a> <span class="p">),</span> <span class="s2">"The length of items in ascending must equal the number of columns provided"</span> +</span><span id="DataFrame-504"><a href="#DataFrame-504"><span class="linenos">504</span></a> <span class="n">col_and_ascending</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">columns</span><span class="p">,</span> <span class="n">ascending</span><span class="p">))</span> +</span><span id="DataFrame-505"><a href="#DataFrame-505"><span class="linenos">505</span></a> <span class="n">order_by_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-506"><a href="#DataFrame-506"><span class="linenos">506</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Ordered</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">col</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">desc</span><span class="o">=</span><span class="ow">not</span> <span class="n">asc</span><span class="p">)</span> +</span><span id="DataFrame-507"><a href="#DataFrame-507"><span class="linenos">507</span></a> <span class="k">if</span> <span class="n">i</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">pre_ordered_col_indexes</span> +</span><span id="DataFrame-508"><a href="#DataFrame-508"><span class="linenos">508</span></a> <span class="k">else</span> <span class="n">columns</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">column_expression</span> +</span><span id="DataFrame-509"><a href="#DataFrame-509"><span class="linenos">509</span></a> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">col</span><span class="p">,</span> <span class="n">asc</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">col_and_ascending</span><span class="p">)</span> +</span><span id="DataFrame-510"><a href="#DataFrame-510"><span class="linenos">510</span></a> <span class="p">]</span> +</span><span id="DataFrame-511"><a href="#DataFrame-511"><span class="linenos">511</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">order_by</span><span class="p">(</span><span class="o">*</span><span class="n">order_by_columns</span><span class="p">))</span> +</span><span id="DataFrame-512"><a href="#DataFrame-512"><span class="linenos">512</span></a> +</span><span id="DataFrame-513"><a href="#DataFrame-513"><span class="linenos">513</span></a> <span class="n">sort</span> <span class="o">=</span> <span class="n">orderBy</span> +</span><span id="DataFrame-514"><a href="#DataFrame-514"><span class="linenos">514</span></a> +</span><span id="DataFrame-515"><a href="#DataFrame-515"><span class="linenos">515</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame-516"><a href="#DataFrame-516"><span class="linenos">516</span></a> <span class="k">def</span> <span class="nf">union</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-517"><a href="#DataFrame-517"><span class="linenos">517</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_set_operation</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Union</span><span class="p">,</span> <span class="n">other</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> +</span><span id="DataFrame-518"><a href="#DataFrame-518"><span class="linenos">518</span></a> +</span><span id="DataFrame-519"><a href="#DataFrame-519"><span class="linenos">519</span></a> <span class="n">unionAll</span> <span class="o">=</span> <span class="n">union</span> +</span><span id="DataFrame-520"><a href="#DataFrame-520"><span class="linenos">520</span></a> +</span><span id="DataFrame-521"><a href="#DataFrame-521"><span class="linenos">521</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame-522"><a href="#DataFrame-522"><span class="linenos">522</span></a> <span class="k">def</span> <span class="nf">unionByName</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">,</span> <span class="n">allowMissingColumns</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">):</span> +</span><span id="DataFrame-523"><a href="#DataFrame-523"><span class="linenos">523</span></a> <span class="n">l_columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">columns</span> +</span><span id="DataFrame-524"><a href="#DataFrame-524"><span class="linenos">524</span></a> <span class="n">r_columns</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">columns</span> +</span><span id="DataFrame-525"><a href="#DataFrame-525"><span class="linenos">525</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">allowMissingColumns</span><span class="p">:</span> +</span><span id="DataFrame-526"><a href="#DataFrame-526"><span class="linenos">526</span></a> <span class="n">l_expressions</span> <span class="o">=</span> <span class="n">l_columns</span> +</span><span id="DataFrame-527"><a href="#DataFrame-527"><span class="linenos">527</span></a> <span class="n">r_expressions</span> <span class="o">=</span> <span class="n">l_columns</span> +</span><span id="DataFrame-528"><a href="#DataFrame-528"><span class="linenos">528</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-529"><a href="#DataFrame-529"><span class="linenos">529</span></a> <span class="n">l_expressions</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="DataFrame-530"><a href="#DataFrame-530"><span class="linenos">530</span></a> <span class="n">r_expressions</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="DataFrame-531"><a href="#DataFrame-531"><span class="linenos">531</span></a> <span class="n">r_columns_unused</span> <span class="o">=</span> <span class="n">copy</span><span class="p">(</span><span class="n">r_columns</span><span class="p">)</span> +</span><span id="DataFrame-532"><a href="#DataFrame-532"><span class="linenos">532</span></a> <span class="k">for</span> <span class="n">l_column</span> <span class="ow">in</span> <span class="n">l_columns</span><span class="p">:</span> +</span><span id="DataFrame-533"><a href="#DataFrame-533"><span class="linenos">533</span></a> <span class="n">l_expressions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">l_column</span><span class="p">)</span> +</span><span id="DataFrame-534"><a href="#DataFrame-534"><span class="linenos">534</span></a> <span class="k">if</span> <span class="n">l_column</span> <span class="ow">in</span> <span class="n">r_columns</span><span class="p">:</span> +</span><span id="DataFrame-535"><a href="#DataFrame-535"><span class="linenos">535</span></a> <span class="n">r_expressions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">l_column</span><span class="p">)</span> +</span><span id="DataFrame-536"><a href="#DataFrame-536"><span class="linenos">536</span></a> <span class="n">r_columns_unused</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">l_column</span><span class="p">)</span> +</span><span id="DataFrame-537"><a href="#DataFrame-537"><span class="linenos">537</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-538"><a href="#DataFrame-538"><span class="linenos">538</span></a> <span class="n">r_expressions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">alias_</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Null</span><span class="p">(),</span> <span class="n">l_column</span><span class="p">))</span> +</span><span id="DataFrame-539"><a href="#DataFrame-539"><span class="linenos">539</span></a> <span class="k">for</span> <span class="n">r_column</span> <span class="ow">in</span> <span class="n">r_columns_unused</span><span class="p">:</span> +</span><span id="DataFrame-540"><a href="#DataFrame-540"><span class="linenos">540</span></a> <span class="n">l_expressions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">alias_</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Null</span><span class="p">(),</span> <span class="n">r_column</span><span class="p">))</span> +</span><span id="DataFrame-541"><a href="#DataFrame-541"><span class="linenos">541</span></a> <span class="n">r_expressions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">r_column</span><span class="p">)</span> +</span><span id="DataFrame-542"><a href="#DataFrame-542"><span class="linenos">542</span></a> <span class="n">r_df</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="DataFrame-543"><a href="#DataFrame-543"><span class="linenos">543</span></a> <span class="n">other</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span><span class="o">.</span><span class="n">_convert_leaf_to_cte</span><span class="p">()</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">_ensure_list_of_columns</span><span class="p">(</span><span class="n">r_expressions</span><span class="p">))</span> +</span><span id="DataFrame-544"><a href="#DataFrame-544"><span class="linenos">544</span></a> <span class="p">)</span> +</span><span id="DataFrame-545"><a href="#DataFrame-545"><span class="linenos">545</span></a> <span class="n">l_df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-546"><a href="#DataFrame-546"><span class="linenos">546</span></a> <span class="k">if</span> <span class="n">allowMissingColumns</span><span class="p">:</span> +</span><span id="DataFrame-547"><a href="#DataFrame-547"><span class="linenos">547</span></a> <span class="n">l_df</span> <span class="o">=</span> <span class="n">l_df</span><span class="o">.</span><span class="n">_convert_leaf_to_cte</span><span class="p">()</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">_ensure_list_of_columns</span><span class="p">(</span><span class="n">l_expressions</span><span class="p">))</span> +</span><span id="DataFrame-548"><a href="#DataFrame-548"><span class="linenos">548</span></a> <span class="k">return</span> <span class="n">l_df</span><span class="o">.</span><span class="n">_set_operation</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Union</span><span class="p">,</span> <span class="n">r_df</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> +</span><span id="DataFrame-549"><a href="#DataFrame-549"><span class="linenos">549</span></a> +</span><span id="DataFrame-550"><a href="#DataFrame-550"><span class="linenos">550</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame-551"><a href="#DataFrame-551"><span class="linenos">551</span></a> <span class="k">def</span> <span class="nf">intersect</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-552"><a href="#DataFrame-552"><span class="linenos">552</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_set_operation</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Intersect</span><span class="p">,</span> <span class="n">other</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span> +</span><span id="DataFrame-553"><a href="#DataFrame-553"><span class="linenos">553</span></a> +</span><span id="DataFrame-554"><a href="#DataFrame-554"><span class="linenos">554</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame-555"><a href="#DataFrame-555"><span class="linenos">555</span></a> <span class="k">def</span> <span class="nf">intersectAll</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-556"><a href="#DataFrame-556"><span class="linenos">556</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_set_operation</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Intersect</span><span class="p">,</span> <span class="n">other</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> +</span><span id="DataFrame-557"><a href="#DataFrame-557"><span class="linenos">557</span></a> +</span><span id="DataFrame-558"><a href="#DataFrame-558"><span class="linenos">558</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame-559"><a href="#DataFrame-559"><span class="linenos">559</span></a> <span class="k">def</span> <span class="nf">exceptAll</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-560"><a href="#DataFrame-560"><span class="linenos">560</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_set_operation</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Except</span><span class="p">,</span> <span class="n">other</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> +</span><span id="DataFrame-561"><a href="#DataFrame-561"><span class="linenos">561</span></a> +</span><span id="DataFrame-562"><a href="#DataFrame-562"><span class="linenos">562</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">SELECT</span><span class="p">)</span> +</span><span id="DataFrame-563"><a href="#DataFrame-563"><span class="linenos">563</span></a> <span class="k">def</span> <span class="nf">distinct</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-564"><a href="#DataFrame-564"><span class="linenos">564</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">distinct</span><span class="p">())</span> +</span><span id="DataFrame-565"><a href="#DataFrame-565"><span class="linenos">565</span></a> +</span><span id="DataFrame-566"><a href="#DataFrame-566"><span class="linenos">566</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">SELECT</span><span class="p">)</span> +</span><span id="DataFrame-567"><a href="#DataFrame-567"><span class="linenos">567</span></a> <span class="k">def</span> <span class="nf">dropDuplicates</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">subset</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span> +</span><span id="DataFrame-568"><a href="#DataFrame-568"><span class="linenos">568</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">subset</span><span class="p">:</span> +</span><span id="DataFrame-569"><a href="#DataFrame-569"><span class="linenos">569</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">distinct</span><span class="p">()</span> +</span><span id="DataFrame-570"><a href="#DataFrame-570"><span class="linenos">570</span></a> <span class="n">column_names</span> <span class="o">=</span> <span class="n">ensure_list</span><span class="p">(</span><span class="n">subset</span><span class="p">)</span> +</span><span id="DataFrame-571"><a href="#DataFrame-571"><span class="linenos">571</span></a> <span class="n">window</span> <span class="o">=</span> <span class="n">Window</span><span class="o">.</span><span class="n">partitionBy</span><span class="p">(</span><span class="o">*</span><span class="n">column_names</span><span class="p">)</span><span class="o">.</span><span class="n">orderBy</span><span class="p">(</span><span class="o">*</span><span class="n">column_names</span><span class="p">)</span> +</span><span id="DataFrame-572"><a href="#DataFrame-572"><span class="linenos">572</span></a> <span class="k">return</span> <span class="p">(</span> +</span><span id="DataFrame-573"><a href="#DataFrame-573"><span class="linenos">573</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-574"><a href="#DataFrame-574"><span class="linenos">574</span></a> <span class="o">.</span><span class="n">withColumn</span><span class="p">(</span><span class="s2">"row_num"</span><span class="p">,</span> <span class="n">F</span><span class="o">.</span><span class="n">row_number</span><span class="p">()</span><span class="o">.</span><span class="n">over</span><span class="p">(</span><span class="n">window</span><span class="p">))</span> +</span><span id="DataFrame-575"><a href="#DataFrame-575"><span class="linenos">575</span></a> <span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">col</span><span class="p">(</span><span class="s2">"row_num"</span><span class="p">)</span> <span class="o">==</span> <span class="n">F</span><span class="o">.</span><span class="n">lit</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span> +</span><span id="DataFrame-576"><a href="#DataFrame-576"><span class="linenos">576</span></a> <span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="s2">"row_num"</span><span class="p">)</span> +</span><span id="DataFrame-577"><a href="#DataFrame-577"><span class="linenos">577</span></a> <span class="p">)</span> +</span><span id="DataFrame-578"><a href="#DataFrame-578"><span class="linenos">578</span></a> +</span><span id="DataFrame-579"><a href="#DataFrame-579"><span class="linenos">579</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame-580"><a href="#DataFrame-580"><span class="linenos">580</span></a> <span class="k">def</span> <span class="nf">dropna</span><span class="p">(</span> +</span><span id="DataFrame-581"><a href="#DataFrame-581"><span class="linenos">581</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame-582"><a href="#DataFrame-582"><span class="linenos">582</span></a> <span class="n">how</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"any"</span><span class="p">,</span> +</span><span id="DataFrame-583"><a href="#DataFrame-583"><span class="linenos">583</span></a> <span class="n">thresh</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame-584"><a href="#DataFrame-584"><span class="linenos">584</span></a> <span class="n">subset</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="o">...</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame-585"><a href="#DataFrame-585"><span class="linenos">585</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-586"><a href="#DataFrame-586"><span class="linenos">586</span></a> <span class="n">minimum_non_null</span> <span class="o">=</span> <span class="n">thresh</span> <span class="ow">or</span> <span class="mi">0</span> <span class="c1"># will be determined later if thresh is null</span> +</span><span id="DataFrame-587"><a href="#DataFrame-587"><span class="linenos">587</span></a> <span class="n">new_df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-588"><a href="#DataFrame-588"><span class="linenos">588</span></a> <span class="n">all_columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_outer_select_columns</span><span class="p">(</span><span class="n">new_df</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame-589"><a href="#DataFrame-589"><span class="linenos">589</span></a> <span class="k">if</span> <span class="n">subset</span><span class="p">:</span> +</span><span id="DataFrame-590"><a href="#DataFrame-590"><span class="linenos">590</span></a> <span class="n">null_check_columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">subset</span><span class="p">)</span> +</span><span id="DataFrame-591"><a href="#DataFrame-591"><span class="linenos">591</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-592"><a href="#DataFrame-592"><span class="linenos">592</span></a> <span class="n">null_check_columns</span> <span class="o">=</span> <span class="n">all_columns</span> +</span><span id="DataFrame-593"><a href="#DataFrame-593"><span class="linenos">593</span></a> <span class="k">if</span> <span class="n">thresh</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> +</span><span id="DataFrame-594"><a href="#DataFrame-594"><span class="linenos">594</span></a> <span class="n">minimum_num_nulls</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">if</span> <span class="n">how</span> <span class="o">==</span> <span class="s2">"any"</span> <span class="k">else</span> <span class="nb">len</span><span class="p">(</span><span class="n">null_check_columns</span><span class="p">)</span> +</span><span id="DataFrame-595"><a href="#DataFrame-595"><span class="linenos">595</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-596"><a href="#DataFrame-596"><span class="linenos">596</span></a> <span class="n">minimum_num_nulls</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">null_check_columns</span><span class="p">)</span> <span class="o">-</span> <span class="n">minimum_non_null</span> <span class="o">+</span> <span class="mi">1</span> +</span><span id="DataFrame-597"><a href="#DataFrame-597"><span class="linenos">597</span></a> <span class="k">if</span> <span class="n">minimum_num_nulls</span> <span class="o">></span> <span class="nb">len</span><span class="p">(</span><span class="n">null_check_columns</span><span class="p">):</span> +</span><span id="DataFrame-598"><a href="#DataFrame-598"><span class="linenos">598</span></a> <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span> +</span><span id="DataFrame-599"><a href="#DataFrame-599"><span class="linenos">599</span></a> <span class="sa">f</span><span class="s2">"The minimum num nulls for dropna must be less than or equal to the number of columns. "</span> +</span><span id="DataFrame-600"><a href="#DataFrame-600"><span class="linenos">600</span></a> <span class="sa">f</span><span class="s2">"Minimum num nulls: </span><span class="si">{</span><span class="n">minimum_num_nulls</span><span class="si">}</span><span class="s2">, Num Columns: </span><span class="si">{</span><span class="nb">len</span><span class="p">(</span><span class="n">null_check_columns</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span> +</span><span id="DataFrame-601"><a href="#DataFrame-601"><span class="linenos">601</span></a> <span class="p">)</span> +</span><span id="DataFrame-602"><a href="#DataFrame-602"><span class="linenos">602</span></a> <span class="n">if_null_checks</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-603"><a href="#DataFrame-603"><span class="linenos">603</span></a> <span class="n">F</span><span class="o">.</span><span class="n">when</span><span class="p">(</span><span class="n">column</span><span class="o">.</span><span class="n">isNull</span><span class="p">(),</span> <span class="n">F</span><span class="o">.</span><span class="n">lit</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">otherwise</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">lit</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">null_check_columns</span> +</span><span id="DataFrame-604"><a href="#DataFrame-604"><span class="linenos">604</span></a> <span class="p">]</span> +</span><span id="DataFrame-605"><a href="#DataFrame-605"><span class="linenos">605</span></a> <span class="n">nulls_added_together</span> <span class="o">=</span> <span class="n">functools</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">,</span> <span class="n">if_null_checks</span><span class="p">)</span> +</span><span id="DataFrame-606"><a href="#DataFrame-606"><span class="linenos">606</span></a> <span class="n">num_nulls</span> <span class="o">=</span> <span class="n">nulls_added_together</span><span class="o">.</span><span class="n">alias</span><span class="p">(</span><span class="s2">"num_nulls"</span><span class="p">)</span> +</span><span id="DataFrame-607"><a href="#DataFrame-607"><span class="linenos">607</span></a> <span class="n">new_df</span> <span class="o">=</span> <span class="n">new_df</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">num_nulls</span><span class="p">,</span> <span class="n">append</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="DataFrame-608"><a href="#DataFrame-608"><span class="linenos">608</span></a> <span class="n">filtered_df</span> <span class="o">=</span> <span class="n">new_df</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">col</span><span class="p">(</span><span class="s2">"num_nulls"</span><span class="p">)</span> <span class="o"><</span> <span class="n">F</span><span class="o">.</span><span class="n">lit</span><span class="p">(</span><span class="n">minimum_num_nulls</span><span class="p">))</span> +</span><span id="DataFrame-609"><a href="#DataFrame-609"><span class="linenos">609</span></a> <span class="n">final_df</span> <span class="o">=</span> <span class="n">filtered_df</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="n">all_columns</span><span class="p">)</span> +</span><span id="DataFrame-610"><a href="#DataFrame-610"><span class="linenos">610</span></a> <span class="k">return</span> <span class="n">final_df</span> +</span><span id="DataFrame-611"><a href="#DataFrame-611"><span class="linenos">611</span></a> +</span><span id="DataFrame-612"><a href="#DataFrame-612"><span class="linenos">612</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame-613"><a href="#DataFrame-613"><span class="linenos">613</span></a> <span class="k">def</span> <span class="nf">fillna</span><span class="p">(</span> +</span><span id="DataFrame-614"><a href="#DataFrame-614"><span class="linenos">614</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame-615"><a href="#DataFrame-615"><span class="linenos">615</span></a> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnLiterals</span><span class="p">],</span> +</span><span id="DataFrame-616"><a href="#DataFrame-616"><span class="linenos">616</span></a> <span class="n">subset</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="o">...</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame-617"><a href="#DataFrame-617"><span class="linenos">617</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-618"><a href="#DataFrame-618"><span class="linenos">618</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="DataFrame-619"><a href="#DataFrame-619"><span class="linenos">619</span></a><span class="sd"> Functionality Difference: If you provide a value to replace a null and that type conflicts</span> +</span><span id="DataFrame-620"><a href="#DataFrame-620"><span class="linenos">620</span></a><span class="sd"> with the type of the column then PySpark will just ignore your replacement.</span> +</span><span id="DataFrame-621"><a href="#DataFrame-621"><span class="linenos">621</span></a><span class="sd"> This will try to cast them to be the same in some cases. So they won't always match.</span> +</span><span id="DataFrame-622"><a href="#DataFrame-622"><span class="linenos">622</span></a><span class="sd"> Best to not mix types so make sure replacement is the same type as the column</span> +</span><span id="DataFrame-623"><a href="#DataFrame-623"><span class="linenos">623</span></a> +</span><span id="DataFrame-624"><a href="#DataFrame-624"><span class="linenos">624</span></a><span class="sd"> Possibility for improvement: Use `typeof` function to get the type of the column</span> +</span><span id="DataFrame-625"><a href="#DataFrame-625"><span class="linenos">625</span></a><span class="sd"> and check if it matches the type of the value provided. If not then make it null.</span> +</span><span id="DataFrame-626"><a href="#DataFrame-626"><span class="linenos">626</span></a><span class="sd"> """</span> +</span><span id="DataFrame-627"><a href="#DataFrame-627"><span class="linenos">627</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.functions</span> <span class="kn">import</span> <span class="n">lit</span> +</span><span id="DataFrame-628"><a href="#DataFrame-628"><span class="linenos">628</span></a> +</span><span id="DataFrame-629"><a href="#DataFrame-629"><span class="linenos">629</span></a> <span class="n">values</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="DataFrame-630"><a href="#DataFrame-630"><span class="linenos">630</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="DataFrame-631"><a href="#DataFrame-631"><span class="linenos">631</span></a> <span class="n">new_df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-632"><a href="#DataFrame-632"><span class="linenos">632</span></a> <span class="n">all_columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_outer_select_columns</span><span class="p">(</span><span class="n">new_df</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame-633"><a href="#DataFrame-633"><span class="linenos">633</span></a> <span class="n">all_column_mapping</span> <span class="o">=</span> <span class="p">{</span><span class="n">column</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">:</span> <span class="n">column</span> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">all_columns</span><span class="p">}</span> +</span><span id="DataFrame-634"><a href="#DataFrame-634"><span class="linenos">634</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span> +</span><span id="DataFrame-635"><a href="#DataFrame-635"><span class="linenos">635</span></a> <span class="n">values</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">value</span><span class="o">.</span><span class="n">values</span><span class="p">())</span> +</span><span id="DataFrame-636"><a href="#DataFrame-636"><span class="linenos">636</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">value</span><span class="p">))</span> +</span><span id="DataFrame-637"><a href="#DataFrame-637"><span class="linenos">637</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">columns</span><span class="p">:</span> +</span><span id="DataFrame-638"><a href="#DataFrame-638"><span class="linenos">638</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">subset</span><span class="p">)</span> <span class="k">if</span> <span class="n">subset</span> <span class="k">else</span> <span class="n">all_columns</span> +</span><span id="DataFrame-639"><a href="#DataFrame-639"><span class="linenos">639</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">values</span><span class="p">:</span> +</span><span id="DataFrame-640"><a href="#DataFrame-640"><span class="linenos">640</span></a> <span class="n">values</span> <span class="o">=</span> <span class="p">[</span><span class="n">value</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> +</span><span id="DataFrame-641"><a href="#DataFrame-641"><span class="linenos">641</span></a> <span class="n">value_columns</span> <span class="o">=</span> <span class="p">[</span><span class="n">lit</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">values</span><span class="p">]</span> +</span><span id="DataFrame-642"><a href="#DataFrame-642"><span class="linenos">642</span></a> +</span><span id="DataFrame-643"><a href="#DataFrame-643"><span class="linenos">643</span></a> <span class="n">null_replacement_mapping</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="DataFrame-644"><a href="#DataFrame-644"><span class="linenos">644</span></a> <span class="n">column</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">:</span> <span class="p">(</span> +</span><span id="DataFrame-645"><a href="#DataFrame-645"><span class="linenos">645</span></a> <span class="n">F</span><span class="o">.</span><span class="n">when</span><span class="p">(</span><span class="n">column</span><span class="o">.</span><span class="n">isNull</span><span class="p">(),</span> <span class="n">value</span><span class="p">)</span><span class="o">.</span><span class="n">otherwise</span><span class="p">(</span><span class="n">column</span><span class="p">)</span><span class="o">.</span><span class="n">alias</span><span class="p">(</span><span class="n">column</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">)</span> +</span><span id="DataFrame-646"><a href="#DataFrame-646"><span class="linenos">646</span></a> <span class="p">)</span> +</span><span id="DataFrame-647"><a href="#DataFrame-647"><span class="linenos">647</span></a> <span class="k">for</span> <span class="n">column</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">columns</span><span class="p">,</span> <span class="n">value_columns</span><span class="p">)</span> +</span><span id="DataFrame-648"><a href="#DataFrame-648"><span class="linenos">648</span></a> <span class="p">}</span> +</span><span id="DataFrame-649"><a href="#DataFrame-649"><span class="linenos">649</span></a> <span class="n">null_replacement_mapping</span> <span class="o">=</span> <span class="p">{</span><span class="o">**</span><span class="n">all_column_mapping</span><span class="p">,</span> <span class="o">**</span><span class="n">null_replacement_mapping</span><span class="p">}</span> +</span><span id="DataFrame-650"><a href="#DataFrame-650"><span class="linenos">650</span></a> <span class="n">null_replacement_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-651"><a href="#DataFrame-651"><span class="linenos">651</span></a> <span class="n">null_replacement_mapping</span><span class="p">[</span><span class="n">column</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">]</span> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">all_columns</span> +</span><span id="DataFrame-652"><a href="#DataFrame-652"><span class="linenos">652</span></a> <span class="p">]</span> +</span><span id="DataFrame-653"><a href="#DataFrame-653"><span class="linenos">653</span></a> <span class="n">new_df</span> <span class="o">=</span> <span class="n">new_df</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="n">null_replacement_columns</span><span class="p">)</span> +</span><span id="DataFrame-654"><a href="#DataFrame-654"><span class="linenos">654</span></a> <span class="k">return</span> <span class="n">new_df</span> +</span><span id="DataFrame-655"><a href="#DataFrame-655"><span class="linenos">655</span></a> +</span><span id="DataFrame-656"><a href="#DataFrame-656"><span class="linenos">656</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame-657"><a href="#DataFrame-657"><span class="linenos">657</span></a> <span class="k">def</span> <span class="nf">replace</span><span class="p">(</span> +</span><span id="DataFrame-658"><a href="#DataFrame-658"><span class="linenos">658</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame-659"><a href="#DataFrame-659"><span class="linenos">659</span></a> <span class="n">to_replace</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">bool</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">],</span> +</span><span id="DataFrame-660"><a href="#DataFrame-660"><span class="linenos">660</span></a> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">bool</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame-661"><a href="#DataFrame-661"><span class="linenos">661</span></a> <span class="n">subset</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Collection</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">]</span> <span class="o">|</span> <span class="n">ColumnOrName</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame-662"><a href="#DataFrame-662"><span class="linenos">662</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-663"><a href="#DataFrame-663"><span class="linenos">663</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.functions</span> <span class="kn">import</span> <span class="n">lit</span> +</span><span id="DataFrame-664"><a href="#DataFrame-664"><span class="linenos">664</span></a> +</span><span id="DataFrame-665"><a href="#DataFrame-665"><span class="linenos">665</span></a> <span class="n">old_values</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="DataFrame-666"><a href="#DataFrame-666"><span class="linenos">666</span></a> <span class="n">new_df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-667"><a href="#DataFrame-667"><span class="linenos">667</span></a> <span class="n">all_columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_outer_select_columns</span><span class="p">(</span><span class="n">new_df</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame-668"><a href="#DataFrame-668"><span class="linenos">668</span></a> <span class="n">all_column_mapping</span> <span class="o">=</span> <span class="p">{</span><span class="n">column</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">:</span> <span class="n">column</span> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">all_columns</span><span class="p">}</span> +</span><span id="DataFrame-669"><a href="#DataFrame-669"><span class="linenos">669</span></a> +</span><span id="DataFrame-670"><a href="#DataFrame-670"><span class="linenos">670</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">subset</span><span class="p">)</span> <span class="k">if</span> <span class="n">subset</span> <span class="k">else</span> <span class="n">all_columns</span> +</span><span id="DataFrame-671"><a href="#DataFrame-671"><span class="linenos">671</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">to_replace</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span> +</span><span id="DataFrame-672"><a href="#DataFrame-672"><span class="linenos">672</span></a> <span class="n">old_values</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">to_replace</span><span class="p">)</span> +</span><span id="DataFrame-673"><a href="#DataFrame-673"><span class="linenos">673</span></a> <span class="n">new_values</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">to_replace</span><span class="o">.</span><span class="n">values</span><span class="p">())</span> +</span><span id="DataFrame-674"><a href="#DataFrame-674"><span class="linenos">674</span></a> <span class="k">elif</span> <span class="ow">not</span> <span class="n">old_values</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">to_replace</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span> +</span><span id="DataFrame-675"><a href="#DataFrame-675"><span class="linenos">675</span></a> <span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">list</span><span class="p">),</span> <span class="s2">"value must be a list since the replacements are a list"</span> +</span><span id="DataFrame-676"><a href="#DataFrame-676"><span class="linenos">676</span></a> <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">to_replace</span><span class="p">)</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span> +</span><span id="DataFrame-677"><a href="#DataFrame-677"><span class="linenos">677</span></a> <span class="n">value</span> +</span><span id="DataFrame-678"><a href="#DataFrame-678"><span class="linenos">678</span></a> <span class="p">),</span> <span class="s2">"the replacements and values must be the same length"</span> +</span><span id="DataFrame-679"><a href="#DataFrame-679"><span class="linenos">679</span></a> <span class="n">old_values</span> <span class="o">=</span> <span class="n">to_replace</span> +</span><span id="DataFrame-680"><a href="#DataFrame-680"><span class="linenos">680</span></a> <span class="n">new_values</span> <span class="o">=</span> <span class="n">value</span> +</span><span id="DataFrame-681"><a href="#DataFrame-681"><span class="linenos">681</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-682"><a href="#DataFrame-682"><span class="linenos">682</span></a> <span class="n">old_values</span> <span class="o">=</span> <span class="p">[</span><span class="n">to_replace</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> +</span><span id="DataFrame-683"><a href="#DataFrame-683"><span class="linenos">683</span></a> <span class="n">new_values</span> <span class="o">=</span> <span class="p">[</span><span class="n">value</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> +</span><span id="DataFrame-684"><a href="#DataFrame-684"><span class="linenos">684</span></a> <span class="n">old_values</span> <span class="o">=</span> <span class="p">[</span><span class="n">lit</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">old_values</span><span class="p">]</span> +</span><span id="DataFrame-685"><a href="#DataFrame-685"><span class="linenos">685</span></a> <span class="n">new_values</span> <span class="o">=</span> <span class="p">[</span><span class="n">lit</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">new_values</span><span class="p">]</span> +</span><span id="DataFrame-686"><a href="#DataFrame-686"><span class="linenos">686</span></a> +</span><span id="DataFrame-687"><a href="#DataFrame-687"><span class="linenos">687</span></a> <span class="n">replacement_mapping</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="DataFrame-688"><a href="#DataFrame-688"><span class="linenos">688</span></a> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">columns</span><span class="p">:</span> +</span><span id="DataFrame-689"><a href="#DataFrame-689"><span class="linenos">689</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span> +</span><span id="DataFrame-690"><a href="#DataFrame-690"><span class="linenos">690</span></a> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">old_value</span><span class="p">,</span> <span class="n">new_value</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">old_values</span><span class="p">,</span> <span class="n">new_values</span><span class="p">)):</span> +</span><span id="DataFrame-691"><a href="#DataFrame-691"><span class="linenos">691</span></a> <span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> +</span><span id="DataFrame-692"><a href="#DataFrame-692"><span class="linenos">692</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">when</span><span class="p">(</span><span class="n">column</span> <span class="o">==</span> <span class="n">old_value</span><span class="p">,</span> <span class="n">new_value</span><span class="p">)</span> +</span><span id="DataFrame-693"><a href="#DataFrame-693"><span class="linenos">693</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-694"><a href="#DataFrame-694"><span class="linenos">694</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">when</span><span class="p">(</span><span class="n">column</span> <span class="o">==</span> <span class="n">old_value</span><span class="p">,</span> <span class="n">new_value</span><span class="p">)</span> <span class="c1"># type: ignore</span> +</span><span id="DataFrame-695"><a href="#DataFrame-695"><span class="linenos">695</span></a> <span class="n">replacement_mapping</span><span class="p">[</span><span class="n">column</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">otherwise</span><span class="p">(</span><span class="n">column</span><span class="p">)</span><span class="o">.</span><span class="n">alias</span><span class="p">(</span> +</span><span id="DataFrame-696"><a href="#DataFrame-696"><span class="linenos">696</span></a> <span class="n">column</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">alias_or_name</span> +</span><span id="DataFrame-697"><a href="#DataFrame-697"><span class="linenos">697</span></a> <span class="p">)</span> +</span><span id="DataFrame-698"><a href="#DataFrame-698"><span class="linenos">698</span></a> +</span><span id="DataFrame-699"><a href="#DataFrame-699"><span class="linenos">699</span></a> <span class="n">replacement_mapping</span> <span class="o">=</span> <span class="p">{</span><span class="o">**</span><span class="n">all_column_mapping</span><span class="p">,</span> <span class="o">**</span><span class="n">replacement_mapping</span><span class="p">}</span> +</span><span id="DataFrame-700"><a href="#DataFrame-700"><span class="linenos">700</span></a> <span class="n">replacement_columns</span> <span class="o">=</span> <span class="p">[</span><span class="n">replacement_mapping</span><span class="p">[</span><span class="n">column</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">]</span> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">all_columns</span><span class="p">]</span> +</span><span id="DataFrame-701"><a href="#DataFrame-701"><span class="linenos">701</span></a> <span class="n">new_df</span> <span class="o">=</span> <span class="n">new_df</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="n">replacement_columns</span><span class="p">)</span> +</span><span id="DataFrame-702"><a href="#DataFrame-702"><span class="linenos">702</span></a> <span class="k">return</span> <span class="n">new_df</span> +</span><span id="DataFrame-703"><a href="#DataFrame-703"><span class="linenos">703</span></a> +</span><span id="DataFrame-704"><a href="#DataFrame-704"><span class="linenos">704</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">SELECT</span><span class="p">)</span> +</span><span id="DataFrame-705"><a href="#DataFrame-705"><span class="linenos">705</span></a> <span class="k">def</span> <span class="nf">withColumn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">colName</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">col</span><span class="p">:</span> <span class="n">Column</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-706"><a href="#DataFrame-706"><span class="linenos">706</span></a> <span class="n">col</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_col</span><span class="p">(</span><span class="n">col</span><span class="p">)</span> +</span><span id="DataFrame-707"><a href="#DataFrame-707"><span class="linenos">707</span></a> <span class="n">existing_col_names</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">named_selects</span> +</span><span id="DataFrame-708"><a href="#DataFrame-708"><span class="linenos">708</span></a> <span class="n">existing_col_index</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="DataFrame-709"><a href="#DataFrame-709"><span class="linenos">709</span></a> <span class="n">existing_col_names</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">colName</span><span class="p">)</span> <span class="k">if</span> <span class="n">colName</span> <span class="ow">in</span> <span class="n">existing_col_names</span> <span class="k">else</span> <span class="kc">None</span> +</span><span id="DataFrame-710"><a href="#DataFrame-710"><span class="linenos">710</span></a> <span class="p">)</span> +</span><span id="DataFrame-711"><a href="#DataFrame-711"><span class="linenos">711</span></a> <span class="k">if</span> <span class="n">existing_col_index</span><span class="p">:</span> +</span><span id="DataFrame-712"><a href="#DataFrame-712"><span class="linenos">712</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-713"><a href="#DataFrame-713"><span class="linenos">713</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">[</span><span class="n">existing_col_index</span><span class="p">]</span> <span class="o">=</span> <span class="n">col</span><span class="o">.</span><span class="n">expression</span> +</span><span id="DataFrame-714"><a href="#DataFrame-714"><span class="linenos">714</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame-715"><a href="#DataFrame-715"><span class="linenos">715</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">col</span><span class="o">.</span><span class="n">alias</span><span class="p">(</span><span class="n">colName</span><span class="p">),</span> <span class="n">append</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="DataFrame-716"><a href="#DataFrame-716"><span class="linenos">716</span></a> +</span><span id="DataFrame-717"><a href="#DataFrame-717"><span class="linenos">717</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">SELECT</span><span class="p">)</span> +</span><span id="DataFrame-718"><a href="#DataFrame-718"><span class="linenos">718</span></a> <span class="k">def</span> <span class="nf">withColumnRenamed</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">existing</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">new</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span> +</span><span id="DataFrame-719"><a href="#DataFrame-719"><span class="linenos">719</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-720"><a href="#DataFrame-720"><span class="linenos">720</span></a> <span class="n">existing_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-721"><a href="#DataFrame-721"><span class="linenos">721</span></a> <span class="n">expression</span> +</span><span id="DataFrame-722"><a href="#DataFrame-722"><span class="linenos">722</span></a> <span class="k">for</span> <span class="n">expression</span> <span class="ow">in</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> +</span><span id="DataFrame-723"><a href="#DataFrame-723"><span class="linenos">723</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="o">==</span> <span class="n">existing</span> +</span><span id="DataFrame-724"><a href="#DataFrame-724"><span class="linenos">724</span></a> <span class="p">]</span> +</span><span id="DataFrame-725"><a href="#DataFrame-725"><span class="linenos">725</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">existing_columns</span><span class="p">:</span> +</span><span id="DataFrame-726"><a href="#DataFrame-726"><span class="linenos">726</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"Tried to rename a column that doesn't exist"</span><span class="p">)</span> +</span><span id="DataFrame-727"><a href="#DataFrame-727"><span class="linenos">727</span></a> <span class="k">for</span> <span class="n">existing_column</span> <span class="ow">in</span> <span class="n">existing_columns</span><span class="p">:</span> +</span><span id="DataFrame-728"><a href="#DataFrame-728"><span class="linenos">728</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">existing_column</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">):</span> +</span><span id="DataFrame-729"><a href="#DataFrame-729"><span class="linenos">729</span></a> <span class="n">existing_column</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">alias_</span><span class="p">(</span><span class="n">existing_column</span><span class="o">.</span><span class="n">copy</span><span class="p">(),</span> <span class="n">new</span><span class="p">))</span> +</span><span id="DataFrame-730"><a href="#DataFrame-730"><span class="linenos">730</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-731"><a href="#DataFrame-731"><span class="linenos">731</span></a> <span class="n">existing_column</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"alias"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">to_identifier</span><span class="p">(</span><span class="n">new</span><span class="p">))</span> +</span><span id="DataFrame-732"><a href="#DataFrame-732"><span class="linenos">732</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame-733"><a href="#DataFrame-733"><span class="linenos">733</span></a> +</span><span id="DataFrame-734"><a href="#DataFrame-734"><span class="linenos">734</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">SELECT</span><span class="p">)</span> +</span><span id="DataFrame-735"><a href="#DataFrame-735"><span class="linenos">735</span></a> <span class="k">def</span> <span class="nf">drop</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">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Column</span><span class="p">])</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-736"><a href="#DataFrame-736"><span class="linenos">736</span></a> <span class="n">all_columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_outer_select_columns</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame-737"><a href="#DataFrame-737"><span class="linenos">737</span></a> <span class="n">drop_cols</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> +</span><span id="DataFrame-738"><a href="#DataFrame-738"><span class="linenos">738</span></a> <span class="n">new_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-739"><a href="#DataFrame-739"><span class="linenos">739</span></a> <span class="n">col</span> +</span><span id="DataFrame-740"><a href="#DataFrame-740"><span class="linenos">740</span></a> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">all_columns</span> +</span><span id="DataFrame-741"><a href="#DataFrame-741"><span class="linenos">741</span></a> <span class="k">if</span> <span class="n">col</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="n">drop_column</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="k">for</span> <span class="n">drop_column</span> <span class="ow">in</span> <span class="n">drop_cols</span><span class="p">]</span> +</span><span id="DataFrame-742"><a href="#DataFrame-742"><span class="linenos">742</span></a> <span class="p">]</span> +</span><span id="DataFrame-743"><a href="#DataFrame-743"><span class="linenos">743</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="n">new_columns</span><span class="p">,</span> <span class="n">append</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +</span><span id="DataFrame-744"><a href="#DataFrame-744"><span class="linenos">744</span></a> +</span><span id="DataFrame-745"><a href="#DataFrame-745"><span class="linenos">745</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">LIMIT</span><span class="p">)</span> +</span><span id="DataFrame-746"><a href="#DataFrame-746"><span class="linenos">746</span></a> <span class="k">def</span> <span class="nf">limit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">num</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-747"><a href="#DataFrame-747"><span class="linenos">747</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">limit</span><span class="p">(</span><span class="n">num</span><span class="p">))</span> +</span><span id="DataFrame-748"><a href="#DataFrame-748"><span class="linenos">748</span></a> +</span><span id="DataFrame-749"><a href="#DataFrame-749"><span class="linenos">749</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">NO_OP</span><span class="p">)</span> +</span><span id="DataFrame-750"><a href="#DataFrame-750"><span class="linenos">750</span></a> <span class="k">def</span> <span class="nf">hint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">*</span><span class="n">parameters</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">int</span><span class="p">]])</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-751"><a href="#DataFrame-751"><span class="linenos">751</span></a> <span class="n">parameter_list</span> <span class="o">=</span> <span class="n">ensure_list</span><span class="p">(</span><span class="n">parameters</span><span class="p">)</span> +</span><span id="DataFrame-752"><a href="#DataFrame-752"><span class="linenos">752</span></a> <span class="n">parameter_columns</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="DataFrame-753"><a href="#DataFrame-753"><span class="linenos">753</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_list_of_columns</span><span class="p">(</span><span class="n">parameter_list</span><span class="p">)</span> +</span><span id="DataFrame-754"><a href="#DataFrame-754"><span class="linenos">754</span></a> <span class="k">if</span> <span class="n">parameters</span> +</span><span id="DataFrame-755"><a href="#DataFrame-755"><span class="linenos">755</span></a> <span class="k">else</span> <span class="n">Column</span><span class="o">.</span><span class="n">ensure_cols</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">sequence_id</span><span class="p">])</span> +</span><span id="DataFrame-756"><a href="#DataFrame-756"><span class="linenos">756</span></a> <span class="p">)</span> +</span><span id="DataFrame-757"><a href="#DataFrame-757"><span class="linenos">757</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_hint</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">parameter_columns</span><span class="p">)</span> +</span><span id="DataFrame-758"><a href="#DataFrame-758"><span class="linenos">758</span></a> +</span><span id="DataFrame-759"><a href="#DataFrame-759"><span class="linenos">759</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">NO_OP</span><span class="p">)</span> +</span><span id="DataFrame-760"><a href="#DataFrame-760"><span class="linenos">760</span></a> <span class="k">def</span> <span class="nf">repartition</span><span class="p">(</span> +</span><span id="DataFrame-761"><a href="#DataFrame-761"><span class="linenos">761</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">numPartitions</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="n">ColumnOrName</span><span class="p">],</span> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">ColumnOrName</span> +</span><span id="DataFrame-762"><a href="#DataFrame-762"><span class="linenos">762</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-763"><a href="#DataFrame-763"><span class="linenos">763</span></a> <span class="n">num_partition_cols</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_list_of_columns</span><span class="p">(</span><span class="n">numPartitions</span><span class="p">)</span> +</span><span id="DataFrame-764"><a href="#DataFrame-764"><span class="linenos">764</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> +</span><span id="DataFrame-765"><a href="#DataFrame-765"><span class="linenos">765</span></a> <span class="n">args</span> <span class="o">=</span> <span class="n">num_partition_cols</span> <span class="o">+</span> <span class="n">columns</span> +</span><span id="DataFrame-766"><a href="#DataFrame-766"><span class="linenos">766</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_hint</span><span class="p">(</span><span class="s2">"repartition"</span><span class="p">,</span> <span class="n">args</span><span class="p">)</span> +</span><span id="DataFrame-767"><a href="#DataFrame-767"><span class="linenos">767</span></a> +</span><span id="DataFrame-768"><a href="#DataFrame-768"><span class="linenos">768</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">NO_OP</span><span class="p">)</span> +</span><span id="DataFrame-769"><a href="#DataFrame-769"><span class="linenos">769</span></a> <span class="k">def</span> <span class="nf">coalesce</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">numPartitions</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-770"><a href="#DataFrame-770"><span class="linenos">770</span></a> <span class="n">num_partitions</span> <span class="o">=</span> <span class="n">Column</span><span class="o">.</span><span class="n">ensure_cols</span><span class="p">([</span><span class="n">numPartitions</span><span class="p">])</span> +</span><span id="DataFrame-771"><a href="#DataFrame-771"><span class="linenos">771</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_hint</span><span class="p">(</span><span class="s2">"coalesce"</span><span class="p">,</span> <span class="n">num_partitions</span><span class="p">)</span> +</span><span id="DataFrame-772"><a href="#DataFrame-772"><span class="linenos">772</span></a> +</span><span id="DataFrame-773"><a href="#DataFrame-773"><span class="linenos">773</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">NO_OP</span><span class="p">)</span> +</span><span id="DataFrame-774"><a href="#DataFrame-774"><span class="linenos">774</span></a> <span class="k">def</span> <span class="nf">cache</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-775"><a href="#DataFrame-775"><span class="linenos">775</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="p">(</span><span class="n">storage_level</span><span class="o">=</span><span class="s2">"MEMORY_AND_DISK"</span><span class="p">)</span> +</span><span id="DataFrame-776"><a href="#DataFrame-776"><span class="linenos">776</span></a> +</span><span id="DataFrame-777"><a href="#DataFrame-777"><span class="linenos">777</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">NO_OP</span><span class="p">)</span> +</span><span id="DataFrame-778"><a href="#DataFrame-778"><span class="linenos">778</span></a> <span class="k">def</span> <span class="nf">persist</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">storageLevel</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"MEMORY_AND_DISK_SER"</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-779"><a href="#DataFrame-779"><span class="linenos">779</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="DataFrame-780"><a href="#DataFrame-780"><span class="linenos">780</span></a><span class="sd"> Storage Level Options: https://spark.apache.org/docs/3.0.0-preview/sql-ref-syntax-aux-cache-cache-table.html</span> +</span><span id="DataFrame-781"><a href="#DataFrame-781"><span class="linenos">781</span></a><span class="sd"> """</span> +</span><span id="DataFrame-782"><a href="#DataFrame-782"><span class="linenos">782</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="p">(</span><span class="n">storageLevel</span><span class="p">)</span> +</span></pre></div> + + + + + <div id="DataFrame.__init__" class="classattr"> + <input id="DataFrame.__init__-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="name">DataFrame</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="n">spark</span><span class="p">:</span> <span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700332957056'</span><span class="o">></span>,</span><span class="param"> <span class="n">expression</span><span class="p">:</span> <span class="n"><a href="../expressions.html#Select">sqlglot.expressions.Select</a></span>,</span><span class="param"> <span class="n">branch_id</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">sequence_id</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">last_op</span><span class="p">:</span> <span class="n">sqlglot</span><span class="o">.</span><span class="n">dataframe</span><span class="o">.</span><span class="n">sql</span><span class="o">.</span><span class="n">operations</span><span class="o">.</span><span class="n">Operation</span> <span class="o">=</span> <span class="o"><</span><span class="n">Operation</span><span class="o">.</span><span class="n">INIT</span><span class="p">:</span> <span class="o">-</span><span class="mi">1</span><span class="o">></span>,</span><span class="param"> <span class="n">pending_hints</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">List</span><span class="p">[</span><span class="n"><a href="../expressions.html#Expression">sqlglot.expressions.Expression</a></span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">output_expression_container</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700332981504'</span><span class="o">></span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="o">**</span><span class="n">kwargs</span></span>)</span> + + <label class="view-source-button" for="DataFrame.__init__-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.__init__"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.__init__-47"><a href="#DataFrame.__init__-47"><span class="linenos">47</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span> +</span><span id="DataFrame.__init__-48"><a href="#DataFrame.__init__-48"><span class="linenos">48</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame.__init__-49"><a href="#DataFrame.__init__-49"><span class="linenos">49</span></a> <span class="n">spark</span><span class="p">:</span> <span class="n">SparkSession</span><span class="p">,</span> +</span><span id="DataFrame.__init__-50"><a href="#DataFrame.__init__-50"><span class="linenos">50</span></a> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">,</span> +</span><span id="DataFrame.__init__-51"><a href="#DataFrame.__init__-51"><span class="linenos">51</span></a> <span class="n">branch_id</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame.__init__-52"><a href="#DataFrame.__init__-52"><span class="linenos">52</span></a> <span class="n">sequence_id</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame.__init__-53"><a href="#DataFrame.__init__-53"><span class="linenos">53</span></a> <span class="n">last_op</span><span class="p">:</span> <span class="n">Operation</span> <span class="o">=</span> <span class="n">Operation</span><span class="o">.</span><span class="n">INIT</span><span class="p">,</span> +</span><span id="DataFrame.__init__-54"><a href="#DataFrame.__init__-54"><span class="linenos">54</span></a> <span class="n">pending_hints</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame.__init__-55"><a href="#DataFrame.__init__-55"><span class="linenos">55</span></a> <span class="n">output_expression_container</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">OutputExpressionContainer</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame.__init__-56"><a href="#DataFrame.__init__-56"><span class="linenos">56</span></a> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span> +</span><span id="DataFrame.__init__-57"><a href="#DataFrame.__init__-57"><span class="linenos">57</span></a> <span class="p">):</span> +</span><span id="DataFrame.__init__-58"><a href="#DataFrame.__init__-58"><span class="linenos">58</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">spark</span> <span class="o">=</span> <span class="n">spark</span> +</span><span id="DataFrame.__init__-59"><a href="#DataFrame.__init__-59"><span class="linenos">59</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span> <span class="o">=</span> <span class="n">expression</span> +</span><span id="DataFrame.__init__-60"><a href="#DataFrame.__init__-60"><span class="linenos">60</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">branch_id</span> <span class="o">=</span> <span class="n">branch_id</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">spark</span><span class="o">.</span><span class="n">_random_branch_id</span> +</span><span id="DataFrame.__init__-61"><a href="#DataFrame.__init__-61"><span class="linenos">61</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sequence_id</span> <span class="o">=</span> <span class="n">sequence_id</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">spark</span><span class="o">.</span><span class="n">_random_sequence_id</span> +</span><span id="DataFrame.__init__-62"><a href="#DataFrame.__init__-62"><span class="linenos">62</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">last_op</span> <span class="o">=</span> <span class="n">last_op</span> +</span><span id="DataFrame.__init__-63"><a href="#DataFrame.__init__-63"><span class="linenos">63</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">pending_hints</span> <span class="o">=</span> <span class="n">pending_hints</span> <span class="ow">or</span> <span class="p">[]</span> +</span><span id="DataFrame.__init__-64"><a href="#DataFrame.__init__-64"><span class="linenos">64</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">output_expression_container</span> <span class="o">=</span> <span class="n">output_expression_container</span> <span class="ow">or</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">()</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.sql" class="classattr"> + <input id="DataFrame.sql-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">sql</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">dialect</span><span class="o">=</span><span class="s1">'spark'</span>, </span><span class="param"><span class="n">optimize</span><span class="o">=</span><span class="kc">True</span>, </span><span class="param"><span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span>:</span></span> + + <label class="view-source-button" for="DataFrame.sql-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.sql"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.sql-296"><a href="#DataFrame.sql-296"><span class="linenos">296</span></a> <span class="k">def</span> <span class="nf">sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="s2">"spark"</span><span class="p">,</span> <span class="n">optimize</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> +</span><span id="DataFrame.sql-297"><a href="#DataFrame.sql-297"><span class="linenos">297</span></a> <span class="n">df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_resolve_pending_hints</span><span class="p">()</span> +</span><span id="DataFrame.sql-298"><a href="#DataFrame.sql-298"><span class="linenos">298</span></a> <span class="n">select_expressions</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">_get_select_expressions</span><span class="p">()</span> +</span><span id="DataFrame.sql-299"><a href="#DataFrame.sql-299"><span class="linenos">299</span></a> <span class="n">output_expressions</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cache</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Drop</span><span class="p">]]</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="DataFrame.sql-300"><a href="#DataFrame.sql-300"><span class="linenos">300</span></a> <span class="n">replacement_mapping</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="DataFrame.sql-301"><a href="#DataFrame.sql-301"><span class="linenos">301</span></a> <span class="k">for</span> <span class="n">expression_type</span><span class="p">,</span> <span class="n">select_expression</span> <span class="ow">in</span> <span class="n">select_expressions</span><span class="p">:</span> +</span><span id="DataFrame.sql-302"><a href="#DataFrame.sql-302"><span class="linenos">302</span></a> <span class="n">select_expression</span> <span class="o">=</span> <span class="n">select_expression</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span><span class="n">replace_id_value</span><span class="p">,</span> <span class="n">replacement_mapping</span><span class="p">)</span> +</span><span id="DataFrame.sql-303"><a href="#DataFrame.sql-303"><span class="linenos">303</span></a> <span class="k">if</span> <span class="n">optimize</span><span class="p">:</span> +</span><span id="DataFrame.sql-304"><a href="#DataFrame.sql-304"><span class="linenos">304</span></a> <span class="n">select_expression</span> <span class="o">=</span> <span class="n">optimize_func</span><span class="p">(</span><span class="n">select_expression</span><span class="p">)</span> +</span><span id="DataFrame.sql-305"><a href="#DataFrame.sql-305"><span class="linenos">305</span></a> <span class="n">select_expression</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">_replace_cte_names_with_hashes</span><span class="p">(</span><span class="n">select_expression</span><span class="p">)</span> +</span><span id="DataFrame.sql-306"><a href="#DataFrame.sql-306"><span class="linenos">306</span></a> <span class="n">expression</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cache</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Drop</span><span class="p">]</span> +</span><span id="DataFrame.sql-307"><a href="#DataFrame.sql-307"><span class="linenos">307</span></a> <span class="k">if</span> <span class="n">expression_type</span> <span class="o">==</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cache</span><span class="p">:</span> +</span><span id="DataFrame.sql-308"><a href="#DataFrame.sql-308"><span class="linenos">308</span></a> <span class="n">cache_table_name</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">_create_hash_from_expression</span><span class="p">(</span><span class="n">select_expression</span><span class="p">)</span> +</span><span id="DataFrame.sql-309"><a href="#DataFrame.sql-309"><span class="linenos">309</span></a> <span class="n">cache_table</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">to_table</span><span class="p">(</span><span class="n">cache_table_name</span><span class="p">)</span> +</span><span id="DataFrame.sql-310"><a href="#DataFrame.sql-310"><span class="linenos">310</span></a> <span class="n">original_alias_name</span> <span class="o">=</span> <span class="n">select_expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"cte_alias_name"</span><span class="p">]</span> +</span><span id="DataFrame.sql-311"><a href="#DataFrame.sql-311"><span class="linenos">311</span></a> +</span><span id="DataFrame.sql-312"><a href="#DataFrame.sql-312"><span class="linenos">312</span></a> <span class="n">replacement_mapping</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">to_identifier</span><span class="p">(</span><span class="n">original_alias_name</span><span class="p">)]</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">to_identifier</span><span class="p">(</span> <span class="c1"># type: ignore</span> +</span><span id="DataFrame.sql-313"><a href="#DataFrame.sql-313"><span class="linenos">313</span></a> <span class="n">cache_table_name</span> +</span><span id="DataFrame.sql-314"><a href="#DataFrame.sql-314"><span class="linenos">314</span></a> <span class="p">)</span> +</span><span id="DataFrame.sql-315"><a href="#DataFrame.sql-315"><span class="linenos">315</span></a> <span class="n">sqlglot</span><span class="o">.</span><span class="n">schema</span><span class="o">.</span><span class="n">add_table</span><span class="p">(</span> +</span><span id="DataFrame.sql-316"><a href="#DataFrame.sql-316"><span class="linenos">316</span></a> <span class="n">cache_table_name</span><span class="p">,</span> +</span><span id="DataFrame.sql-317"><a href="#DataFrame.sql-317"><span class="linenos">317</span></a> <span class="p">{</span> +</span><span id="DataFrame.sql-318"><a href="#DataFrame.sql-318"><span class="linenos">318</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">:</span> <span class="n">expression</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="s2">"spark"</span><span class="p">)</span> +</span><span id="DataFrame.sql-319"><a href="#DataFrame.sql-319"><span class="linenos">319</span></a> <span class="k">for</span> <span class="n">expression</span> <span class="ow">in</span> <span class="n">select_expression</span><span class="o">.</span><span class="n">expressions</span> +</span><span id="DataFrame.sql-320"><a href="#DataFrame.sql-320"><span class="linenos">320</span></a> <span class="p">},</span> +</span><span id="DataFrame.sql-321"><a href="#DataFrame.sql-321"><span class="linenos">321</span></a> <span class="p">)</span> +</span><span id="DataFrame.sql-322"><a href="#DataFrame.sql-322"><span class="linenos">322</span></a> <span class="n">cache_storage_level</span> <span class="o">=</span> <span class="n">select_expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"cache_storage_level"</span><span class="p">]</span> +</span><span id="DataFrame.sql-323"><a href="#DataFrame.sql-323"><span class="linenos">323</span></a> <span class="n">options</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.sql-324"><a href="#DataFrame.sql-324"><span class="linenos">324</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="s2">"storageLevel"</span><span class="p">),</span> +</span><span id="DataFrame.sql-325"><a href="#DataFrame.sql-325"><span class="linenos">325</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="n">cache_storage_level</span><span class="p">),</span> +</span><span id="DataFrame.sql-326"><a href="#DataFrame.sql-326"><span class="linenos">326</span></a> <span class="p">]</span> +</span><span id="DataFrame.sql-327"><a href="#DataFrame.sql-327"><span class="linenos">327</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cache</span><span class="p">(</span> +</span><span id="DataFrame.sql-328"><a href="#DataFrame.sql-328"><span class="linenos">328</span></a> <span class="n">this</span><span class="o">=</span><span class="n">cache_table</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">select_expression</span><span class="p">,</span> <span class="n">lazy</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="n">options</span> +</span><span id="DataFrame.sql-329"><a href="#DataFrame.sql-329"><span class="linenos">329</span></a> <span class="p">)</span> +</span><span id="DataFrame.sql-330"><a href="#DataFrame.sql-330"><span class="linenos">330</span></a> <span class="c1"># We will drop the "view" if it exists before running the cache table</span> +</span><span id="DataFrame.sql-331"><a href="#DataFrame.sql-331"><span class="linenos">331</span></a> <span class="n">output_expressions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Drop</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">cache_table</span><span class="p">,</span> <span class="n">exists</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">kind</span><span class="o">=</span><span class="s2">"VIEW"</span><span class="p">))</span> +</span><span id="DataFrame.sql-332"><a href="#DataFrame.sql-332"><span class="linenos">332</span></a> <span class="k">elif</span> <span class="n">expression_type</span> <span class="o">==</span> <span class="n">exp</span><span class="o">.</span><span class="n">Create</span><span class="p">:</span> +</span><span id="DataFrame.sql-333"><a href="#DataFrame.sql-333"><span class="linenos">333</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">output_expression_container</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame.sql-334"><a href="#DataFrame.sql-334"><span class="linenos">334</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"expression"</span><span class="p">,</span> <span class="n">select_expression</span><span class="p">)</span> +</span><span id="DataFrame.sql-335"><a href="#DataFrame.sql-335"><span class="linenos">335</span></a> <span class="k">elif</span> <span class="n">expression_type</span> <span class="o">==</span> <span class="n">exp</span><span class="o">.</span><span class="n">Insert</span><span class="p">:</span> +</span><span id="DataFrame.sql-336"><a href="#DataFrame.sql-336"><span class="linenos">336</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">output_expression_container</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame.sql-337"><a href="#DataFrame.sql-337"><span class="linenos">337</span></a> <span class="n">select_without_ctes</span> <span class="o">=</span> <span class="n">select_expression</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame.sql-338"><a href="#DataFrame.sql-338"><span class="linenos">338</span></a> <span class="n">select_without_ctes</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"with"</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> +</span><span id="DataFrame.sql-339"><a href="#DataFrame.sql-339"><span class="linenos">339</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"expression"</span><span class="p">,</span> <span class="n">select_without_ctes</span><span class="p">)</span> +</span><span id="DataFrame.sql-340"><a href="#DataFrame.sql-340"><span class="linenos">340</span></a> <span class="k">if</span> <span class="n">select_expression</span><span class="o">.</span><span class="n">ctes</span><span class="p">:</span> +</span><span id="DataFrame.sql-341"><a href="#DataFrame.sql-341"><span class="linenos">341</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"with"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">With</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="n">select_expression</span><span class="o">.</span><span class="n">ctes</span><span class="p">))</span> +</span><span id="DataFrame.sql-342"><a href="#DataFrame.sql-342"><span class="linenos">342</span></a> <span class="k">elif</span> <span class="n">expression_type</span> <span class="o">==</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">:</span> +</span><span id="DataFrame.sql-343"><a href="#DataFrame.sql-343"><span class="linenos">343</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">select_expression</span> +</span><span id="DataFrame.sql-344"><a href="#DataFrame.sql-344"><span class="linenos">344</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.sql-345"><a href="#DataFrame.sql-345"><span class="linenos">345</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Invalid expression type: </span><span class="si">{</span><span class="n">expression_type</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="DataFrame.sql-346"><a href="#DataFrame.sql-346"><span class="linenos">346</span></a> <span class="n">output_expressions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame.sql-347"><a href="#DataFrame.sql-347"><span class="linenos">347</span></a> +</span><span id="DataFrame.sql-348"><a href="#DataFrame.sql-348"><span class="linenos">348</span></a> <span class="k">return</span> <span class="p">[</span> +</span><span id="DataFrame.sql-349"><a href="#DataFrame.sql-349"><span class="linenos">349</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="s2">"dialect"</span><span class="p">:</span> <span class="n">dialect</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">})</span> <span class="k">for</span> <span class="n">expression</span> <span class="ow">in</span> <span class="n">output_expressions</span> +</span><span id="DataFrame.sql-350"><a href="#DataFrame.sql-350"><span class="linenos">350</span></a> <span class="p">]</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.copy" class="classattr"> + <input id="DataFrame.copy-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">copy</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.copy-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.copy"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.copy-352"><a href="#DataFrame.copy-352"><span class="linenos">352</span></a> <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.copy-353"><a href="#DataFrame.copy-353"><span class="linenos">353</span></a> <span class="k">return</span> <span class="n">DataFrame</span><span class="p">(</span><span class="o">**</span><span class="n">object_to_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">))</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.select" class="classattr"> + <input id="DataFrame.select-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.SELECT)</div> + + <span class="def">def</span> + <span class="name">select</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="o">*</span><span class="n">cols</span>, </span><span class="param"><span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.select-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.select"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.select-355"><a href="#DataFrame.select-355"><span class="linenos">355</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">SELECT</span><span class="p">)</span> +</span><span id="DataFrame.select-356"><a href="#DataFrame.select-356"><span class="linenos">356</span></a> <span class="k">def</span> <span class="nf">select</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="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.select-357"><a href="#DataFrame.select-357"><span class="linenos">357</span></a> <span class="n">cols</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> +</span><span id="DataFrame.select-358"><a href="#DataFrame.select-358"><span class="linenos">358</span></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">"append"</span><span class="p">]</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"append"</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> +</span><span id="DataFrame.select-359"><a href="#DataFrame.select-359"><span class="linenos">359</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"joins"</span><span class="p">):</span> +</span><span id="DataFrame.select-360"><a href="#DataFrame.select-360"><span class="linenos">360</span></a> <span class="n">ambiguous_cols</span> <span class="o">=</span> <span class="p">[</span><span class="n">col</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">cols</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">col</span><span class="o">.</span><span class="n">column_expression</span><span class="o">.</span><span class="n">table</span><span class="p">]</span> +</span><span id="DataFrame.select-361"><a href="#DataFrame.select-361"><span class="linenos">361</span></a> <span class="k">if</span> <span class="n">ambiguous_cols</span><span class="p">:</span> +</span><span id="DataFrame.select-362"><a href="#DataFrame.select-362"><span class="linenos">362</span></a> <span class="n">join_table_identifiers</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.select-363"><a href="#DataFrame.select-363"><span class="linenos">363</span></a> <span class="n">x</span><span class="o">.</span><span class="n">this</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">get_tables_from_expression_with_join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame.select-364"><a href="#DataFrame.select-364"><span class="linenos">364</span></a> <span class="p">]</span> +</span><span id="DataFrame.select-365"><a href="#DataFrame.select-365"><span class="linenos">365</span></a> <span class="n">cte_names_in_join</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">this</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">join_table_identifiers</span><span class="p">]</span> +</span><span id="DataFrame.select-366"><a href="#DataFrame.select-366"><span class="linenos">366</span></a> <span class="k">for</span> <span class="n">ambiguous_col</span> <span class="ow">in</span> <span class="n">ambiguous_cols</span><span class="p">:</span> +</span><span id="DataFrame.select-367"><a href="#DataFrame.select-367"><span class="linenos">367</span></a> <span class="n">ctes_with_column</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.select-368"><a href="#DataFrame.select-368"><span class="linenos">368</span></a> <span class="n">cte</span> +</span><span id="DataFrame.select-369"><a href="#DataFrame.select-369"><span class="linenos">369</span></a> <span class="k">for</span> <span class="n">cte</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">ctes</span> +</span><span id="DataFrame.select-370"><a href="#DataFrame.select-370"><span class="linenos">370</span></a> <span class="k">if</span> <span class="n">cte</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="ow">in</span> <span class="n">cte_names_in_join</span> +</span><span id="DataFrame.select-371"><a href="#DataFrame.select-371"><span class="linenos">371</span></a> <span class="ow">and</span> <span class="n">ambiguous_col</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="ow">in</span> <span class="n">cte</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">named_selects</span> +</span><span id="DataFrame.select-372"><a href="#DataFrame.select-372"><span class="linenos">372</span></a> <span class="p">]</span> +</span><span id="DataFrame.select-373"><a href="#DataFrame.select-373"><span class="linenos">373</span></a> <span class="c1"># If the select column does not specify a table and there is a join</span> +</span><span id="DataFrame.select-374"><a href="#DataFrame.select-374"><span class="linenos">374</span></a> <span class="c1"># then we assume they are referring to the left table</span> +</span><span id="DataFrame.select-375"><a href="#DataFrame.select-375"><span class="linenos">375</span></a> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ctes_with_column</span><span class="p">)</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> +</span><span id="DataFrame.select-376"><a href="#DataFrame.select-376"><span class="linenos">376</span></a> <span class="n">table_identifier</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"from"</span><span class="p">]</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"expressions"</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">this</span> +</span><span id="DataFrame.select-377"><a href="#DataFrame.select-377"><span class="linenos">377</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.select-378"><a href="#DataFrame.select-378"><span class="linenos">378</span></a> <span class="n">table_identifier</span> <span class="o">=</span> <span class="n">ctes_with_column</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"alias"</span><span class="p">]</span><span class="o">.</span><span class="n">this</span> +</span><span id="DataFrame.select-379"><a href="#DataFrame.select-379"><span class="linenos">379</span></a> <span class="n">ambiguous_col</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"table"</span><span class="p">,</span> <span class="n">table_identifier</span><span class="p">)</span> +</span><span id="DataFrame.select-380"><a href="#DataFrame.select-380"><span class="linenos">380</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">cols</span><span class="p">],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> +</span><span id="DataFrame.select-381"><a href="#DataFrame.select-381"><span class="linenos">381</span></a> <span class="n">qualify_columns</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">sqlglot</span><span class="o">.</span><span class="n">schema</span><span class="p">)</span> +</span><span id="DataFrame.select-382"><a href="#DataFrame.select-382"><span class="linenos">382</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="n">expression</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.alias" class="classattr"> + <input id="DataFrame.alias-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.NO_OP)</div> + + <span class="def">def</span> + <span class="name">alias</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">name</span><span class="p">:</span> <span class="nb">str</span>, </span><span class="param"><span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.alias-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.alias"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.alias-384"><a href="#DataFrame.alias-384"><span class="linenos">384</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">NO_OP</span><span class="p">)</span> +</span><span id="DataFrame.alias-385"><a href="#DataFrame.alias-385"><span class="linenos">385</span></a> <span class="k">def</span> <span class="nf">alias</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.alias-386"><a href="#DataFrame.alias-386"><span class="linenos">386</span></a> <span class="n">new_sequence_id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">spark</span><span class="o">.</span><span class="n">_random_sequence_id</span> +</span><span id="DataFrame.alias-387"><a href="#DataFrame.alias-387"><span class="linenos">387</span></a> <span class="n">df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame.alias-388"><a href="#DataFrame.alias-388"><span class="linenos">388</span></a> <span class="k">for</span> <span class="n">join_hint</span> <span class="ow">in</span> <span class="n">df</span><span class="o">.</span><span class="n">pending_join_hints</span><span class="p">:</span> +</span><span id="DataFrame.alias-389"><a href="#DataFrame.alias-389"><span class="linenos">389</span></a> <span class="k">for</span> <span class="n">expression</span> <span class="ow">in</span> <span class="n">join_hint</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> +</span><span id="DataFrame.alias-390"><a href="#DataFrame.alias-390"><span class="linenos">390</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">sequence_id</span><span class="p">:</span> +</span><span id="DataFrame.alias-391"><a href="#DataFrame.alias-391"><span class="linenos">391</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"this"</span><span class="p">,</span> <span class="n">Column</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">new_sequence_id</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame.alias-392"><a href="#DataFrame.alias-392"><span class="linenos">392</span></a> <span class="n">df</span><span class="o">.</span><span class="n">spark</span><span class="o">.</span><span class="n">_add_alias_to_mapping</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">new_sequence_id</span><span class="p">)</span> +</span><span id="DataFrame.alias-393"><a href="#DataFrame.alias-393"><span class="linenos">393</span></a> <span class="k">return</span> <span class="n">df</span><span class="o">.</span><span class="n">_convert_leaf_to_cte</span><span class="p">(</span><span class="n">sequence_id</span><span class="o">=</span><span class="n">new_sequence_id</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.where" class="classattr"> + <input id="DataFrame.where-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.WHERE)</div> + + <span class="def">def</span> + <span class="name">where</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">column</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span><span class="p">,</span> <span class="nb">bool</span><span class="p">]</span>,</span><span class="param"> <span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.where-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.where"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.where-395"><a href="#DataFrame.where-395"><span class="linenos">395</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">WHERE</span><span class="p">)</span> +</span><span id="DataFrame.where-396"><a href="#DataFrame.where-396"><span class="linenos">396</span></a> <span class="k">def</span> <span class="nf">where</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">column</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">Column</span><span class="p">,</span> <span class="nb">bool</span><span class="p">],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.where-397"><a href="#DataFrame.where-397"><span class="linenos">397</span></a> <span class="n">col</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_col</span><span class="p">(</span><span class="n">column</span><span class="p">)</span> +</span><span id="DataFrame.where-398"><a href="#DataFrame.where-398"><span class="linenos">398</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">col</span><span class="o">.</span><span class="n">expression</span><span class="p">))</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.filter" class="classattr"> + <input id="DataFrame.filter-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.WHERE)</div> + + <span class="def">def</span> + <span class="name">filter</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">column</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span><span class="p">,</span> <span class="nb">bool</span><span class="p">]</span>,</span><span class="param"> <span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.filter-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.filter"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.filter-395"><a href="#DataFrame.filter-395"><span class="linenos">395</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">WHERE</span><span class="p">)</span> +</span><span id="DataFrame.filter-396"><a href="#DataFrame.filter-396"><span class="linenos">396</span></a> <span class="k">def</span> <span class="nf">where</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">column</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">Column</span><span class="p">,</span> <span class="nb">bool</span><span class="p">],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.filter-397"><a href="#DataFrame.filter-397"><span class="linenos">397</span></a> <span class="n">col</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_col</span><span class="p">(</span><span class="n">column</span><span class="p">)</span> +</span><span id="DataFrame.filter-398"><a href="#DataFrame.filter-398"><span class="linenos">398</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">col</span><span class="o">.</span><span class="n">expression</span><span class="p">))</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.groupBy" class="classattr"> + <input id="DataFrame.groupBy-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.GROUP_BY)</div> + + <span class="def">def</span> + <span class="name">groupBy</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="o">*</span><span class="n">cols</span>, </span><span class="param"><span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="n"><a href="#GroupedData">sqlglot.dataframe.sql.GroupedData</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.groupBy-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.groupBy"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.groupBy-402"><a href="#DataFrame.groupBy-402"><span class="linenos">402</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">GROUP_BY</span><span class="p">)</span> +</span><span id="DataFrame.groupBy-403"><a href="#DataFrame.groupBy-403"><span class="linenos">403</span></a> <span class="k">def</span> <span class="nf">groupBy</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="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">GroupedData</span><span class="p">:</span> +</span><span id="DataFrame.groupBy-404"><a href="#DataFrame.groupBy-404"><span class="linenos">404</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> +</span><span id="DataFrame.groupBy-405"><a href="#DataFrame.groupBy-405"><span class="linenos">405</span></a> <span class="k">return</span> <span class="n">GroupedData</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">columns</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">last_op</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.agg" class="classattr"> + <input id="DataFrame.agg-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.SELECT)</div> + + <span class="def">def</span> + <span class="name">agg</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="o">*</span><span class="n">exprs</span>, </span><span class="param"><span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.agg-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.agg"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.agg-407"><a href="#DataFrame.agg-407"><span class="linenos">407</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">SELECT</span><span class="p">)</span> +</span><span id="DataFrame.agg-408"><a href="#DataFrame.agg-408"><span class="linenos">408</span></a> <span class="k">def</span> <span class="nf">agg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">exprs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.agg-409"><a href="#DataFrame.agg-409"><span class="linenos">409</span></a> <span class="n">cols</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">exprs</span><span class="p">)</span> +</span><span id="DataFrame.agg-410"><a href="#DataFrame.agg-410"><span class="linenos">410</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">groupBy</span><span class="p">()</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="o">*</span><span class="n">cols</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.join" class="classattr"> + <input id="DataFrame.join-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.FROM)</div> + + <span class="def">def</span> + <span class="name">join</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">other_df</span><span class="p">:</span> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>,</span><span class="param"> <span class="n">on</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">],</span> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span><span class="p">]]</span>,</span><span class="param"> <span class="n">how</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s1">'inner'</span>,</span><span class="param"> <span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.join-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.join"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.join-412"><a href="#DataFrame.join-412"><span class="linenos">412</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame.join-413"><a href="#DataFrame.join-413"><span class="linenos">413</span></a> <span class="k">def</span> <span class="nf">join</span><span class="p">(</span> +</span><span id="DataFrame.join-414"><a href="#DataFrame.join-414"><span class="linenos">414</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame.join-415"><a href="#DataFrame.join-415"><span class="linenos">415</span></a> <span class="n">other_df</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">,</span> +</span><span id="DataFrame.join-416"><a href="#DataFrame.join-416"><span class="linenos">416</span></a> <span class="n">on</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">],</span> <span class="n">Column</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Column</span><span class="p">]],</span> +</span><span id="DataFrame.join-417"><a href="#DataFrame.join-417"><span class="linenos">417</span></a> <span class="n">how</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"inner"</span><span class="p">,</span> +</span><span id="DataFrame.join-418"><a href="#DataFrame.join-418"><span class="linenos">418</span></a> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span> +</span><span id="DataFrame.join-419"><a href="#DataFrame.join-419"><span class="linenos">419</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.join-420"><a href="#DataFrame.join-420"><span class="linenos">420</span></a> <span class="n">other_df</span> <span class="o">=</span> <span class="n">other_df</span><span class="o">.</span><span class="n">_convert_leaf_to_cte</span><span class="p">()</span> +</span><span id="DataFrame.join-421"><a href="#DataFrame.join-421"><span class="linenos">421</span></a> <span class="n">pre_join_self_latest_cte_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">latest_cte_name</span> +</span><span id="DataFrame.join-422"><a href="#DataFrame.join-422"><span class="linenos">422</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">on</span><span class="p">)</span> +</span><span id="DataFrame.join-423"><a href="#DataFrame.join-423"><span class="linenos">423</span></a> <span class="n">join_type</span> <span class="o">=</span> <span class="n">how</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">"_"</span><span class="p">,</span> <span class="s2">" "</span><span class="p">)</span> +</span><span id="DataFrame.join-424"><a href="#DataFrame.join-424"><span class="linenos">424</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">columns</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">):</span> +</span><span id="DataFrame.join-425"><a href="#DataFrame.join-425"><span class="linenos">425</span></a> <span class="n">join_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.join-426"><a href="#DataFrame.join-426"><span class="linenos">426</span></a> <span class="n">Column</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">set_table_name</span><span class="p">(</span><span class="n">pre_join_self_latest_cte_name</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">columns</span> +</span><span id="DataFrame.join-427"><a href="#DataFrame.join-427"><span class="linenos">427</span></a> <span class="p">]</span> +</span><span id="DataFrame.join-428"><a href="#DataFrame.join-428"><span class="linenos">428</span></a> <span class="n">join_clause</span> <span class="o">=</span> <span class="n">functools</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span> +</span><span id="DataFrame.join-429"><a href="#DataFrame.join-429"><span class="linenos">429</span></a> <span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">x</span> <span class="o">&</span> <span class="n">y</span><span class="p">,</span> +</span><span id="DataFrame.join-430"><a href="#DataFrame.join-430"><span class="linenos">430</span></a> <span class="p">[</span> +</span><span id="DataFrame.join-431"><a href="#DataFrame.join-431"><span class="linenos">431</span></a> <span class="n">col</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span><span class="o">.</span><span class="n">set_table_name</span><span class="p">(</span><span class="n">pre_join_self_latest_cte_name</span><span class="p">)</span> +</span><span id="DataFrame.join-432"><a href="#DataFrame.join-432"><span class="linenos">432</span></a> <span class="o">==</span> <span class="n">col</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span><span class="o">.</span><span class="n">set_table_name</span><span class="p">(</span><span class="n">other_df</span><span class="o">.</span><span class="n">latest_cte_name</span><span class="p">)</span> +</span><span id="DataFrame.join-433"><a href="#DataFrame.join-433"><span class="linenos">433</span></a> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">columns</span> +</span><span id="DataFrame.join-434"><a href="#DataFrame.join-434"><span class="linenos">434</span></a> <span class="p">],</span> +</span><span id="DataFrame.join-435"><a href="#DataFrame.join-435"><span class="linenos">435</span></a> <span class="p">)</span> +</span><span id="DataFrame.join-436"><a href="#DataFrame.join-436"><span class="linenos">436</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.join-437"><a href="#DataFrame.join-437"><span class="linenos">437</span></a> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> +</span><span id="DataFrame.join-438"><a href="#DataFrame.join-438"><span class="linenos">438</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="n">functools</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">x</span> <span class="o">&</span> <span class="n">y</span><span class="p">,</span> <span class="n">columns</span><span class="p">)]</span> +</span><span id="DataFrame.join-439"><a href="#DataFrame.join-439"><span class="linenos">439</span></a> <span class="n">join_clause</span> <span class="o">=</span> <span class="n">columns</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> +</span><span id="DataFrame.join-440"><a href="#DataFrame.join-440"><span class="linenos">440</span></a> <span class="n">join_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.join-441"><a href="#DataFrame.join-441"><span class="linenos">441</span></a> <span class="n">Column</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">set_table_name</span><span class="p">(</span><span class="n">pre_join_self_latest_cte_name</span><span class="p">)</span> +</span><span id="DataFrame.join-442"><a href="#DataFrame.join-442"><span class="linenos">442</span></a> <span class="k">if</span> <span class="n">i</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span> +</span><span id="DataFrame.join-443"><a href="#DataFrame.join-443"><span class="linenos">443</span></a> <span class="k">else</span> <span class="n">Column</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">set_table_name</span><span class="p">(</span><span class="n">other_df</span><span class="o">.</span><span class="n">latest_cte_name</span><span class="p">)</span> +</span><span id="DataFrame.join-444"><a href="#DataFrame.join-444"><span class="linenos">444</span></a> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">join_clause</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">find_all</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">))</span> +</span><span id="DataFrame.join-445"><a href="#DataFrame.join-445"><span class="linenos">445</span></a> <span class="p">]</span> +</span><span id="DataFrame.join-446"><a href="#DataFrame.join-446"><span class="linenos">446</span></a> <span class="n">self_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.join-447"><a href="#DataFrame.join-447"><span class="linenos">447</span></a> <span class="n">column</span><span class="o">.</span><span class="n">set_table_name</span><span class="p">(</span><span class="n">pre_join_self_latest_cte_name</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="DataFrame.join-448"><a href="#DataFrame.join-448"><span class="linenos">448</span></a> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_outer_select_columns</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> +</span><span id="DataFrame.join-449"><a href="#DataFrame.join-449"><span class="linenos">449</span></a> <span class="p">]</span> +</span><span id="DataFrame.join-450"><a href="#DataFrame.join-450"><span class="linenos">450</span></a> <span class="n">other_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.join-451"><a href="#DataFrame.join-451"><span class="linenos">451</span></a> <span class="n">column</span><span class="o">.</span><span class="n">set_table_name</span><span class="p">(</span><span class="n">other_df</span><span class="o">.</span><span class="n">latest_cte_name</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="DataFrame.join-452"><a href="#DataFrame.join-452"><span class="linenos">452</span></a> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_outer_select_columns</span><span class="p">(</span><span class="n">other_df</span><span class="p">)</span> +</span><span id="DataFrame.join-453"><a href="#DataFrame.join-453"><span class="linenos">453</span></a> <span class="p">]</span> +</span><span id="DataFrame.join-454"><a href="#DataFrame.join-454"><span class="linenos">454</span></a> <span class="n">column_value_mapping</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="DataFrame.join-455"><a href="#DataFrame.join-455"><span class="linenos">455</span></a> <span class="n">column</span><span class="o">.</span><span class="n">alias_or_name</span> +</span><span id="DataFrame.join-456"><a href="#DataFrame.join-456"><span class="linenos">456</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">column</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Star</span><span class="p">)</span> +</span><span id="DataFrame.join-457"><a href="#DataFrame.join-457"><span class="linenos">457</span></a> <span class="k">else</span> <span class="n">column</span><span class="o">.</span><span class="n">sql</span><span class="p">():</span> <span class="n">column</span> +</span><span id="DataFrame.join-458"><a href="#DataFrame.join-458"><span class="linenos">458</span></a> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">other_columns</span> <span class="o">+</span> <span class="n">self_columns</span> <span class="o">+</span> <span class="n">join_columns</span> +</span><span id="DataFrame.join-459"><a href="#DataFrame.join-459"><span class="linenos">459</span></a> <span class="p">}</span> +</span><span id="DataFrame.join-460"><a href="#DataFrame.join-460"><span class="linenos">460</span></a> <span class="n">all_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.join-461"><a href="#DataFrame.join-461"><span class="linenos">461</span></a> <span class="n">column_value_mapping</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> +</span><span id="DataFrame.join-462"><a href="#DataFrame.join-462"><span class="linenos">462</span></a> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="p">{</span><span class="n">x</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">:</span> <span class="kc">None</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">join_columns</span> <span class="o">+</span> <span class="n">self_columns</span> <span class="o">+</span> <span class="n">other_columns</span><span class="p">}</span> +</span><span id="DataFrame.join-463"><a href="#DataFrame.join-463"><span class="linenos">463</span></a> <span class="p">]</span> +</span><span id="DataFrame.join-464"><a href="#DataFrame.join-464"><span class="linenos">464</span></a> <span class="n">new_df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span> +</span><span id="DataFrame.join-465"><a href="#DataFrame.join-465"><span class="linenos">465</span></a> <span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">join</span><span class="p">(</span> +</span><span id="DataFrame.join-466"><a href="#DataFrame.join-466"><span class="linenos">466</span></a> <span class="n">other_df</span><span class="o">.</span><span class="n">latest_cte_name</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="n">join_clause</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">join_type</span><span class="o">=</span><span class="n">join_type</span> +</span><span id="DataFrame.join-467"><a href="#DataFrame.join-467"><span class="linenos">467</span></a> <span class="p">)</span> +</span><span id="DataFrame.join-468"><a href="#DataFrame.join-468"><span class="linenos">468</span></a> <span class="p">)</span> +</span><span id="DataFrame.join-469"><a href="#DataFrame.join-469"><span class="linenos">469</span></a> <span class="n">new_df</span><span class="o">.</span><span class="n">expression</span> <span class="o">=</span> <span class="n">new_df</span><span class="o">.</span><span class="n">_add_ctes_to_expression</span><span class="p">(</span> +</span><span id="DataFrame.join-470"><a href="#DataFrame.join-470"><span class="linenos">470</span></a> <span class="n">new_df</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">other_df</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">ctes</span> +</span><span id="DataFrame.join-471"><a href="#DataFrame.join-471"><span class="linenos">471</span></a> <span class="p">)</span> +</span><span id="DataFrame.join-472"><a href="#DataFrame.join-472"><span class="linenos">472</span></a> <span class="n">new_df</span><span class="o">.</span><span class="n">pending_hints</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">other_df</span><span class="o">.</span><span class="n">pending_hints</span><span class="p">)</span> +</span><span id="DataFrame.join-473"><a href="#DataFrame.join-473"><span class="linenos">473</span></a> <span class="n">new_df</span> <span class="o">=</span> <span class="n">new_df</span><span class="o">.</span><span class="n">select</span><span class="o">.</span><span class="n">__wrapped__</span><span class="p">(</span><span class="n">new_df</span><span class="p">,</span> <span class="o">*</span><span class="n">all_columns</span><span class="p">)</span> +</span><span id="DataFrame.join-474"><a href="#DataFrame.join-474"><span class="linenos">474</span></a> <span class="k">return</span> <span class="n">new_df</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.orderBy" class="classattr"> + <input id="DataFrame.orderBy-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.ORDER_BY)</div> + + <span class="def">def</span> + <span class="name">orderBy</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span><span class="p">]</span>,</span><span class="param"> <span class="n">ascending</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="n">Any</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">Any</span><span class="p">],</span> <span class="n">NoneType</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.orderBy-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.orderBy"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.orderBy-476"><a href="#DataFrame.orderBy-476"><span class="linenos">476</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">ORDER_BY</span><span class="p">)</span> +</span><span id="DataFrame.orderBy-477"><a href="#DataFrame.orderBy-477"><span class="linenos">477</span></a> <span class="k">def</span> <span class="nf">orderBy</span><span class="p">(</span> +</span><span id="DataFrame.orderBy-478"><a href="#DataFrame.orderBy-478"><span class="linenos">478</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame.orderBy-479"><a href="#DataFrame.orderBy-479"><span class="linenos">479</span></a> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Column</span><span class="p">],</span> +</span><span id="DataFrame.orderBy-480"><a href="#DataFrame.orderBy-480"><span class="linenos">480</span></a> <span class="n">ascending</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Any</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Any</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame.orderBy-481"><a href="#DataFrame.orderBy-481"><span class="linenos">481</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.orderBy-482"><a href="#DataFrame.orderBy-482"><span class="linenos">482</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="DataFrame.orderBy-483"><a href="#DataFrame.orderBy-483"><span class="linenos">483</span></a><span class="sd"> This implementation lets any ordered columns take priority over whatever is provided in `ascending`. Spark</span> +</span><span id="DataFrame.orderBy-484"><a href="#DataFrame.orderBy-484"><span class="linenos">484</span></a><span class="sd"> has irregular behavior and can result in runtime errors. Users shouldn't be mixing the two anyways so this</span> +</span><span id="DataFrame.orderBy-485"><a href="#DataFrame.orderBy-485"><span class="linenos">485</span></a><span class="sd"> is unlikely to come up.</span> +</span><span id="DataFrame.orderBy-486"><a href="#DataFrame.orderBy-486"><span class="linenos">486</span></a><span class="sd"> """</span> +</span><span id="DataFrame.orderBy-487"><a href="#DataFrame.orderBy-487"><span class="linenos">487</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> +</span><span id="DataFrame.orderBy-488"><a href="#DataFrame.orderBy-488"><span class="linenos">488</span></a> <span class="n">pre_ordered_col_indexes</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.orderBy-489"><a href="#DataFrame.orderBy-489"><span class="linenos">489</span></a> <span class="n">x</span> +</span><span id="DataFrame.orderBy-490"><a href="#DataFrame.orderBy-490"><span class="linenos">490</span></a> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="p">[</span> +</span><span id="DataFrame.orderBy-491"><a href="#DataFrame.orderBy-491"><span class="linenos">491</span></a> <span class="n">i</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">col</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Ordered</span><span class="p">)</span> <span class="k">else</span> <span class="kc">None</span> +</span><span id="DataFrame.orderBy-492"><a href="#DataFrame.orderBy-492"><span class="linenos">492</span></a> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">col</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> +</span><span id="DataFrame.orderBy-493"><a href="#DataFrame.orderBy-493"><span class="linenos">493</span></a> <span class="p">]</span> +</span><span id="DataFrame.orderBy-494"><a href="#DataFrame.orderBy-494"><span class="linenos">494</span></a> <span class="k">if</span> <span class="n">x</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> +</span><span id="DataFrame.orderBy-495"><a href="#DataFrame.orderBy-495"><span class="linenos">495</span></a> <span class="p">]</span> +</span><span id="DataFrame.orderBy-496"><a href="#DataFrame.orderBy-496"><span class="linenos">496</span></a> <span class="k">if</span> <span class="n">ascending</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> +</span><span id="DataFrame.orderBy-497"><a href="#DataFrame.orderBy-497"><span class="linenos">497</span></a> <span class="n">ascending</span> <span class="o">=</span> <span class="p">[</span><span class="kc">True</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> +</span><span id="DataFrame.orderBy-498"><a href="#DataFrame.orderBy-498"><span class="linenos">498</span></a> <span class="k">elif</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">ascending</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span> +</span><span id="DataFrame.orderBy-499"><a href="#DataFrame.orderBy-499"><span class="linenos">499</span></a> <span class="n">ascending</span> <span class="o">=</span> <span class="p">[</span><span class="n">ascending</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> +</span><span id="DataFrame.orderBy-500"><a href="#DataFrame.orderBy-500"><span class="linenos">500</span></a> <span class="n">ascending</span> <span class="o">=</span> <span class="p">[</span><span class="nb">bool</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ascending</span><span class="p">)]</span> +</span><span id="DataFrame.orderBy-501"><a href="#DataFrame.orderBy-501"><span class="linenos">501</span></a> <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span> +</span><span id="DataFrame.orderBy-502"><a href="#DataFrame.orderBy-502"><span class="linenos">502</span></a> <span class="n">ascending</span> +</span><span id="DataFrame.orderBy-503"><a href="#DataFrame.orderBy-503"><span class="linenos">503</span></a> <span class="p">),</span> <span class="s2">"The length of items in ascending must equal the number of columns provided"</span> +</span><span id="DataFrame.orderBy-504"><a href="#DataFrame.orderBy-504"><span class="linenos">504</span></a> <span class="n">col_and_ascending</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">columns</span><span class="p">,</span> <span class="n">ascending</span><span class="p">))</span> +</span><span id="DataFrame.orderBy-505"><a href="#DataFrame.orderBy-505"><span class="linenos">505</span></a> <span class="n">order_by_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.orderBy-506"><a href="#DataFrame.orderBy-506"><span class="linenos">506</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Ordered</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">col</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">desc</span><span class="o">=</span><span class="ow">not</span> <span class="n">asc</span><span class="p">)</span> +</span><span id="DataFrame.orderBy-507"><a href="#DataFrame.orderBy-507"><span class="linenos">507</span></a> <span class="k">if</span> <span class="n">i</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">pre_ordered_col_indexes</span> +</span><span id="DataFrame.orderBy-508"><a href="#DataFrame.orderBy-508"><span class="linenos">508</span></a> <span class="k">else</span> <span class="n">columns</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">column_expression</span> +</span><span id="DataFrame.orderBy-509"><a href="#DataFrame.orderBy-509"><span class="linenos">509</span></a> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">col</span><span class="p">,</span> <span class="n">asc</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">col_and_ascending</span><span class="p">)</span> +</span><span id="DataFrame.orderBy-510"><a href="#DataFrame.orderBy-510"><span class="linenos">510</span></a> <span class="p">]</span> +</span><span id="DataFrame.orderBy-511"><a href="#DataFrame.orderBy-511"><span class="linenos">511</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">order_by</span><span class="p">(</span><span class="o">*</span><span class="n">order_by_columns</span><span class="p">))</span> +</span></pre></div> + + + <div class="docstring"><p>This implementation lets any ordered columns take priority over whatever is provided in <code>ascending</code>. Spark +has irregular behavior and can result in runtime errors. Users shouldn't be mixing the two anyways so this +is unlikely to come up.</p> +</div> + + + </div> + <div id="DataFrame.sort" class="classattr"> + <input id="DataFrame.sort-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.ORDER_BY)</div> + + <span class="def">def</span> + <span class="name">sort</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span><span class="p">]</span>,</span><span class="param"> <span class="n">ascending</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="n">Any</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">Any</span><span class="p">],</span> <span class="n">NoneType</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.sort-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.sort"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.sort-476"><a href="#DataFrame.sort-476"><span class="linenos">476</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">ORDER_BY</span><span class="p">)</span> +</span><span id="DataFrame.sort-477"><a href="#DataFrame.sort-477"><span class="linenos">477</span></a> <span class="k">def</span> <span class="nf">orderBy</span><span class="p">(</span> +</span><span id="DataFrame.sort-478"><a href="#DataFrame.sort-478"><span class="linenos">478</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame.sort-479"><a href="#DataFrame.sort-479"><span class="linenos">479</span></a> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Column</span><span class="p">],</span> +</span><span id="DataFrame.sort-480"><a href="#DataFrame.sort-480"><span class="linenos">480</span></a> <span class="n">ascending</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Any</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Any</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame.sort-481"><a href="#DataFrame.sort-481"><span class="linenos">481</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.sort-482"><a href="#DataFrame.sort-482"><span class="linenos">482</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="DataFrame.sort-483"><a href="#DataFrame.sort-483"><span class="linenos">483</span></a><span class="sd"> This implementation lets any ordered columns take priority over whatever is provided in `ascending`. Spark</span> +</span><span id="DataFrame.sort-484"><a href="#DataFrame.sort-484"><span class="linenos">484</span></a><span class="sd"> has irregular behavior and can result in runtime errors. Users shouldn't be mixing the two anyways so this</span> +</span><span id="DataFrame.sort-485"><a href="#DataFrame.sort-485"><span class="linenos">485</span></a><span class="sd"> is unlikely to come up.</span> +</span><span id="DataFrame.sort-486"><a href="#DataFrame.sort-486"><span class="linenos">486</span></a><span class="sd"> """</span> +</span><span id="DataFrame.sort-487"><a href="#DataFrame.sort-487"><span class="linenos">487</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> +</span><span id="DataFrame.sort-488"><a href="#DataFrame.sort-488"><span class="linenos">488</span></a> <span class="n">pre_ordered_col_indexes</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.sort-489"><a href="#DataFrame.sort-489"><span class="linenos">489</span></a> <span class="n">x</span> +</span><span id="DataFrame.sort-490"><a href="#DataFrame.sort-490"><span class="linenos">490</span></a> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="p">[</span> +</span><span id="DataFrame.sort-491"><a href="#DataFrame.sort-491"><span class="linenos">491</span></a> <span class="n">i</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">col</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Ordered</span><span class="p">)</span> <span class="k">else</span> <span class="kc">None</span> +</span><span id="DataFrame.sort-492"><a href="#DataFrame.sort-492"><span class="linenos">492</span></a> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">col</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> +</span><span id="DataFrame.sort-493"><a href="#DataFrame.sort-493"><span class="linenos">493</span></a> <span class="p">]</span> +</span><span id="DataFrame.sort-494"><a href="#DataFrame.sort-494"><span class="linenos">494</span></a> <span class="k">if</span> <span class="n">x</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> +</span><span id="DataFrame.sort-495"><a href="#DataFrame.sort-495"><span class="linenos">495</span></a> <span class="p">]</span> +</span><span id="DataFrame.sort-496"><a href="#DataFrame.sort-496"><span class="linenos">496</span></a> <span class="k">if</span> <span class="n">ascending</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> +</span><span id="DataFrame.sort-497"><a href="#DataFrame.sort-497"><span class="linenos">497</span></a> <span class="n">ascending</span> <span class="o">=</span> <span class="p">[</span><span class="kc">True</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> +</span><span id="DataFrame.sort-498"><a href="#DataFrame.sort-498"><span class="linenos">498</span></a> <span class="k">elif</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">ascending</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span> +</span><span id="DataFrame.sort-499"><a href="#DataFrame.sort-499"><span class="linenos">499</span></a> <span class="n">ascending</span> <span class="o">=</span> <span class="p">[</span><span class="n">ascending</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> +</span><span id="DataFrame.sort-500"><a href="#DataFrame.sort-500"><span class="linenos">500</span></a> <span class="n">ascending</span> <span class="o">=</span> <span class="p">[</span><span class="nb">bool</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ascending</span><span class="p">)]</span> +</span><span id="DataFrame.sort-501"><a href="#DataFrame.sort-501"><span class="linenos">501</span></a> <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span> +</span><span id="DataFrame.sort-502"><a href="#DataFrame.sort-502"><span class="linenos">502</span></a> <span class="n">ascending</span> +</span><span id="DataFrame.sort-503"><a href="#DataFrame.sort-503"><span class="linenos">503</span></a> <span class="p">),</span> <span class="s2">"The length of items in ascending must equal the number of columns provided"</span> +</span><span id="DataFrame.sort-504"><a href="#DataFrame.sort-504"><span class="linenos">504</span></a> <span class="n">col_and_ascending</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">columns</span><span class="p">,</span> <span class="n">ascending</span><span class="p">))</span> +</span><span id="DataFrame.sort-505"><a href="#DataFrame.sort-505"><span class="linenos">505</span></a> <span class="n">order_by_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.sort-506"><a href="#DataFrame.sort-506"><span class="linenos">506</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Ordered</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">col</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">desc</span><span class="o">=</span><span class="ow">not</span> <span class="n">asc</span><span class="p">)</span> +</span><span id="DataFrame.sort-507"><a href="#DataFrame.sort-507"><span class="linenos">507</span></a> <span class="k">if</span> <span class="n">i</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">pre_ordered_col_indexes</span> +</span><span id="DataFrame.sort-508"><a href="#DataFrame.sort-508"><span class="linenos">508</span></a> <span class="k">else</span> <span class="n">columns</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">column_expression</span> +</span><span id="DataFrame.sort-509"><a href="#DataFrame.sort-509"><span class="linenos">509</span></a> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">col</span><span class="p">,</span> <span class="n">asc</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">col_and_ascending</span><span class="p">)</span> +</span><span id="DataFrame.sort-510"><a href="#DataFrame.sort-510"><span class="linenos">510</span></a> <span class="p">]</span> +</span><span id="DataFrame.sort-511"><a href="#DataFrame.sort-511"><span class="linenos">511</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">order_by</span><span class="p">(</span><span class="o">*</span><span class="n">order_by_columns</span><span class="p">))</span> +</span></pre></div> + + + <div class="docstring"><p>This implementation lets any ordered columns take priority over whatever is provided in <code>ascending</code>. Spark +has irregular behavior and can result in runtime errors. Users shouldn't be mixing the two anyways so this +is unlikely to come up.</p> +</div> + + + </div> + <div id="DataFrame.union" class="classattr"> + <input id="DataFrame.union-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.FROM)</div> + + <span class="def">def</span> + <span class="name">union</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">other</span><span class="p">:</span> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.union-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.union"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.union-515"><a href="#DataFrame.union-515"><span class="linenos">515</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame.union-516"><a href="#DataFrame.union-516"><span class="linenos">516</span></a> <span class="k">def</span> <span class="nf">union</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.union-517"><a href="#DataFrame.union-517"><span class="linenos">517</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_set_operation</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Union</span><span class="p">,</span> <span class="n">other</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.unionAll" class="classattr"> + <input id="DataFrame.unionAll-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.FROM)</div> + + <span class="def">def</span> + <span class="name">unionAll</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">other</span><span class="p">:</span> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.unionAll-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.unionAll"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.unionAll-515"><a href="#DataFrame.unionAll-515"><span class="linenos">515</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame.unionAll-516"><a href="#DataFrame.unionAll-516"><span class="linenos">516</span></a> <span class="k">def</span> <span class="nf">union</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.unionAll-517"><a href="#DataFrame.unionAll-517"><span class="linenos">517</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_set_operation</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Union</span><span class="p">,</span> <span class="n">other</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.unionByName" class="classattr"> + <input id="DataFrame.unionByName-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.FROM)</div> + + <span class="def">def</span> + <span class="name">unionByName</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">other</span><span class="p">:</span> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>,</span><span class="param"> <span class="n">allowMissingColumns</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span></span><span class="return-annotation">):</span></span> + + <label class="view-source-button" for="DataFrame.unionByName-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.unionByName"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.unionByName-521"><a href="#DataFrame.unionByName-521"><span class="linenos">521</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame.unionByName-522"><a href="#DataFrame.unionByName-522"><span class="linenos">522</span></a> <span class="k">def</span> <span class="nf">unionByName</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">,</span> <span class="n">allowMissingColumns</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">):</span> +</span><span id="DataFrame.unionByName-523"><a href="#DataFrame.unionByName-523"><span class="linenos">523</span></a> <span class="n">l_columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">columns</span> +</span><span id="DataFrame.unionByName-524"><a href="#DataFrame.unionByName-524"><span class="linenos">524</span></a> <span class="n">r_columns</span> <span class="o">=</span> <span class="n">other</span><span class="o">.</span><span class="n">columns</span> +</span><span id="DataFrame.unionByName-525"><a href="#DataFrame.unionByName-525"><span class="linenos">525</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">allowMissingColumns</span><span class="p">:</span> +</span><span id="DataFrame.unionByName-526"><a href="#DataFrame.unionByName-526"><span class="linenos">526</span></a> <span class="n">l_expressions</span> <span class="o">=</span> <span class="n">l_columns</span> +</span><span id="DataFrame.unionByName-527"><a href="#DataFrame.unionByName-527"><span class="linenos">527</span></a> <span class="n">r_expressions</span> <span class="o">=</span> <span class="n">l_columns</span> +</span><span id="DataFrame.unionByName-528"><a href="#DataFrame.unionByName-528"><span class="linenos">528</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.unionByName-529"><a href="#DataFrame.unionByName-529"><span class="linenos">529</span></a> <span class="n">l_expressions</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="DataFrame.unionByName-530"><a href="#DataFrame.unionByName-530"><span class="linenos">530</span></a> <span class="n">r_expressions</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="DataFrame.unionByName-531"><a href="#DataFrame.unionByName-531"><span class="linenos">531</span></a> <span class="n">r_columns_unused</span> <span class="o">=</span> <span class="n">copy</span><span class="p">(</span><span class="n">r_columns</span><span class="p">)</span> +</span><span id="DataFrame.unionByName-532"><a href="#DataFrame.unionByName-532"><span class="linenos">532</span></a> <span class="k">for</span> <span class="n">l_column</span> <span class="ow">in</span> <span class="n">l_columns</span><span class="p">:</span> +</span><span id="DataFrame.unionByName-533"><a href="#DataFrame.unionByName-533"><span class="linenos">533</span></a> <span class="n">l_expressions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">l_column</span><span class="p">)</span> +</span><span id="DataFrame.unionByName-534"><a href="#DataFrame.unionByName-534"><span class="linenos">534</span></a> <span class="k">if</span> <span class="n">l_column</span> <span class="ow">in</span> <span class="n">r_columns</span><span class="p">:</span> +</span><span id="DataFrame.unionByName-535"><a href="#DataFrame.unionByName-535"><span class="linenos">535</span></a> <span class="n">r_expressions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">l_column</span><span class="p">)</span> +</span><span id="DataFrame.unionByName-536"><a href="#DataFrame.unionByName-536"><span class="linenos">536</span></a> <span class="n">r_columns_unused</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">l_column</span><span class="p">)</span> +</span><span id="DataFrame.unionByName-537"><a href="#DataFrame.unionByName-537"><span class="linenos">537</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.unionByName-538"><a href="#DataFrame.unionByName-538"><span class="linenos">538</span></a> <span class="n">r_expressions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">alias_</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Null</span><span class="p">(),</span> <span class="n">l_column</span><span class="p">))</span> +</span><span id="DataFrame.unionByName-539"><a href="#DataFrame.unionByName-539"><span class="linenos">539</span></a> <span class="k">for</span> <span class="n">r_column</span> <span class="ow">in</span> <span class="n">r_columns_unused</span><span class="p">:</span> +</span><span id="DataFrame.unionByName-540"><a href="#DataFrame.unionByName-540"><span class="linenos">540</span></a> <span class="n">l_expressions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">alias_</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Null</span><span class="p">(),</span> <span class="n">r_column</span><span class="p">))</span> +</span><span id="DataFrame.unionByName-541"><a href="#DataFrame.unionByName-541"><span class="linenos">541</span></a> <span class="n">r_expressions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">r_column</span><span class="p">)</span> +</span><span id="DataFrame.unionByName-542"><a href="#DataFrame.unionByName-542"><span class="linenos">542</span></a> <span class="n">r_df</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="DataFrame.unionByName-543"><a href="#DataFrame.unionByName-543"><span class="linenos">543</span></a> <span class="n">other</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span><span class="o">.</span><span class="n">_convert_leaf_to_cte</span><span class="p">()</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">_ensure_list_of_columns</span><span class="p">(</span><span class="n">r_expressions</span><span class="p">))</span> +</span><span id="DataFrame.unionByName-544"><a href="#DataFrame.unionByName-544"><span class="linenos">544</span></a> <span class="p">)</span> +</span><span id="DataFrame.unionByName-545"><a href="#DataFrame.unionByName-545"><span class="linenos">545</span></a> <span class="n">l_df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame.unionByName-546"><a href="#DataFrame.unionByName-546"><span class="linenos">546</span></a> <span class="k">if</span> <span class="n">allowMissingColumns</span><span class="p">:</span> +</span><span id="DataFrame.unionByName-547"><a href="#DataFrame.unionByName-547"><span class="linenos">547</span></a> <span class="n">l_df</span> <span class="o">=</span> <span class="n">l_df</span><span class="o">.</span><span class="n">_convert_leaf_to_cte</span><span class="p">()</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">_ensure_list_of_columns</span><span class="p">(</span><span class="n">l_expressions</span><span class="p">))</span> +</span><span id="DataFrame.unionByName-548"><a href="#DataFrame.unionByName-548"><span class="linenos">548</span></a> <span class="k">return</span> <span class="n">l_df</span><span class="o">.</span><span class="n">_set_operation</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Union</span><span class="p">,</span> <span class="n">r_df</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.intersect" class="classattr"> + <input id="DataFrame.intersect-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.FROM)</div> + + <span class="def">def</span> + <span class="name">intersect</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">other</span><span class="p">:</span> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.intersect-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.intersect"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.intersect-550"><a href="#DataFrame.intersect-550"><span class="linenos">550</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame.intersect-551"><a href="#DataFrame.intersect-551"><span class="linenos">551</span></a> <span class="k">def</span> <span class="nf">intersect</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.intersect-552"><a href="#DataFrame.intersect-552"><span class="linenos">552</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_set_operation</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Intersect</span><span class="p">,</span> <span class="n">other</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.intersectAll" class="classattr"> + <input id="DataFrame.intersectAll-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.FROM)</div> + + <span class="def">def</span> + <span class="name">intersectAll</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">other</span><span class="p">:</span> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.intersectAll-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.intersectAll"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.intersectAll-554"><a href="#DataFrame.intersectAll-554"><span class="linenos">554</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame.intersectAll-555"><a href="#DataFrame.intersectAll-555"><span class="linenos">555</span></a> <span class="k">def</span> <span class="nf">intersectAll</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.intersectAll-556"><a href="#DataFrame.intersectAll-556"><span class="linenos">556</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_set_operation</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Intersect</span><span class="p">,</span> <span class="n">other</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.exceptAll" class="classattr"> + <input id="DataFrame.exceptAll-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.FROM)</div> + + <span class="def">def</span> + <span class="name">exceptAll</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">other</span><span class="p">:</span> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.exceptAll-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.exceptAll"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.exceptAll-558"><a href="#DataFrame.exceptAll-558"><span class="linenos">558</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame.exceptAll-559"><a href="#DataFrame.exceptAll-559"><span class="linenos">559</span></a> <span class="k">def</span> <span class="nf">exceptAll</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.exceptAll-560"><a href="#DataFrame.exceptAll-560"><span class="linenos">560</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_set_operation</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Except</span><span class="p">,</span> <span class="n">other</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.distinct" class="classattr"> + <input id="DataFrame.distinct-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.SELECT)</div> + + <span class="def">def</span> + <span class="name">distinct</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.distinct-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.distinct"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.distinct-562"><a href="#DataFrame.distinct-562"><span class="linenos">562</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">SELECT</span><span class="p">)</span> +</span><span id="DataFrame.distinct-563"><a href="#DataFrame.distinct-563"><span class="linenos">563</span></a> <span class="k">def</span> <span class="nf">distinct</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.distinct-564"><a href="#DataFrame.distinct-564"><span class="linenos">564</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">distinct</span><span class="p">())</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.dropDuplicates" class="classattr"> + <input id="DataFrame.dropDuplicates-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.SELECT)</div> + + <span class="def">def</span> + <span class="name">dropDuplicates</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">subset</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span></span><span class="return-annotation">):</span></span> + + <label class="view-source-button" for="DataFrame.dropDuplicates-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.dropDuplicates"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.dropDuplicates-566"><a href="#DataFrame.dropDuplicates-566"><span class="linenos">566</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">SELECT</span><span class="p">)</span> +</span><span id="DataFrame.dropDuplicates-567"><a href="#DataFrame.dropDuplicates-567"><span class="linenos">567</span></a> <span class="k">def</span> <span class="nf">dropDuplicates</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">subset</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span> +</span><span id="DataFrame.dropDuplicates-568"><a href="#DataFrame.dropDuplicates-568"><span class="linenos">568</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">subset</span><span class="p">:</span> +</span><span id="DataFrame.dropDuplicates-569"><a href="#DataFrame.dropDuplicates-569"><span class="linenos">569</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">distinct</span><span class="p">()</span> +</span><span id="DataFrame.dropDuplicates-570"><a href="#DataFrame.dropDuplicates-570"><span class="linenos">570</span></a> <span class="n">column_names</span> <span class="o">=</span> <span class="n">ensure_list</span><span class="p">(</span><span class="n">subset</span><span class="p">)</span> +</span><span id="DataFrame.dropDuplicates-571"><a href="#DataFrame.dropDuplicates-571"><span class="linenos">571</span></a> <span class="n">window</span> <span class="o">=</span> <span class="n">Window</span><span class="o">.</span><span class="n">partitionBy</span><span class="p">(</span><span class="o">*</span><span class="n">column_names</span><span class="p">)</span><span class="o">.</span><span class="n">orderBy</span><span class="p">(</span><span class="o">*</span><span class="n">column_names</span><span class="p">)</span> +</span><span id="DataFrame.dropDuplicates-572"><a href="#DataFrame.dropDuplicates-572"><span class="linenos">572</span></a> <span class="k">return</span> <span class="p">(</span> +</span><span id="DataFrame.dropDuplicates-573"><a href="#DataFrame.dropDuplicates-573"><span class="linenos">573</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame.dropDuplicates-574"><a href="#DataFrame.dropDuplicates-574"><span class="linenos">574</span></a> <span class="o">.</span><span class="n">withColumn</span><span class="p">(</span><span class="s2">"row_num"</span><span class="p">,</span> <span class="n">F</span><span class="o">.</span><span class="n">row_number</span><span class="p">()</span><span class="o">.</span><span class="n">over</span><span class="p">(</span><span class="n">window</span><span class="p">))</span> +</span><span id="DataFrame.dropDuplicates-575"><a href="#DataFrame.dropDuplicates-575"><span class="linenos">575</span></a> <span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">col</span><span class="p">(</span><span class="s2">"row_num"</span><span class="p">)</span> <span class="o">==</span> <span class="n">F</span><span class="o">.</span><span class="n">lit</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span> +</span><span id="DataFrame.dropDuplicates-576"><a href="#DataFrame.dropDuplicates-576"><span class="linenos">576</span></a> <span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="s2">"row_num"</span><span class="p">)</span> +</span><span id="DataFrame.dropDuplicates-577"><a href="#DataFrame.dropDuplicates-577"><span class="linenos">577</span></a> <span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.dropna" class="classattr"> + <input id="DataFrame.dropna-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.FROM)</div> + + <span class="def">def</span> + <span class="name">dropna</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">how</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s1">'any'</span>,</span><span class="param"> <span class="n">thresh</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">subset</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="o">...</span><span class="p">],</span> <span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">],</span> <span class="n">NoneType</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.dropna-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.dropna"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.dropna-579"><a href="#DataFrame.dropna-579"><span class="linenos">579</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame.dropna-580"><a href="#DataFrame.dropna-580"><span class="linenos">580</span></a> <span class="k">def</span> <span class="nf">dropna</span><span class="p">(</span> +</span><span id="DataFrame.dropna-581"><a href="#DataFrame.dropna-581"><span class="linenos">581</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame.dropna-582"><a href="#DataFrame.dropna-582"><span class="linenos">582</span></a> <span class="n">how</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"any"</span><span class="p">,</span> +</span><span id="DataFrame.dropna-583"><a href="#DataFrame.dropna-583"><span class="linenos">583</span></a> <span class="n">thresh</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame.dropna-584"><a href="#DataFrame.dropna-584"><span class="linenos">584</span></a> <span class="n">subset</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="o">...</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame.dropna-585"><a href="#DataFrame.dropna-585"><span class="linenos">585</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.dropna-586"><a href="#DataFrame.dropna-586"><span class="linenos">586</span></a> <span class="n">minimum_non_null</span> <span class="o">=</span> <span class="n">thresh</span> <span class="ow">or</span> <span class="mi">0</span> <span class="c1"># will be determined later if thresh is null</span> +</span><span id="DataFrame.dropna-587"><a href="#DataFrame.dropna-587"><span class="linenos">587</span></a> <span class="n">new_df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame.dropna-588"><a href="#DataFrame.dropna-588"><span class="linenos">588</span></a> <span class="n">all_columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_outer_select_columns</span><span class="p">(</span><span class="n">new_df</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame.dropna-589"><a href="#DataFrame.dropna-589"><span class="linenos">589</span></a> <span class="k">if</span> <span class="n">subset</span><span class="p">:</span> +</span><span id="DataFrame.dropna-590"><a href="#DataFrame.dropna-590"><span class="linenos">590</span></a> <span class="n">null_check_columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">subset</span><span class="p">)</span> +</span><span id="DataFrame.dropna-591"><a href="#DataFrame.dropna-591"><span class="linenos">591</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.dropna-592"><a href="#DataFrame.dropna-592"><span class="linenos">592</span></a> <span class="n">null_check_columns</span> <span class="o">=</span> <span class="n">all_columns</span> +</span><span id="DataFrame.dropna-593"><a href="#DataFrame.dropna-593"><span class="linenos">593</span></a> <span class="k">if</span> <span class="n">thresh</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> +</span><span id="DataFrame.dropna-594"><a href="#DataFrame.dropna-594"><span class="linenos">594</span></a> <span class="n">minimum_num_nulls</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">if</span> <span class="n">how</span> <span class="o">==</span> <span class="s2">"any"</span> <span class="k">else</span> <span class="nb">len</span><span class="p">(</span><span class="n">null_check_columns</span><span class="p">)</span> +</span><span id="DataFrame.dropna-595"><a href="#DataFrame.dropna-595"><span class="linenos">595</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.dropna-596"><a href="#DataFrame.dropna-596"><span class="linenos">596</span></a> <span class="n">minimum_num_nulls</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">null_check_columns</span><span class="p">)</span> <span class="o">-</span> <span class="n">minimum_non_null</span> <span class="o">+</span> <span class="mi">1</span> +</span><span id="DataFrame.dropna-597"><a href="#DataFrame.dropna-597"><span class="linenos">597</span></a> <span class="k">if</span> <span class="n">minimum_num_nulls</span> <span class="o">></span> <span class="nb">len</span><span class="p">(</span><span class="n">null_check_columns</span><span class="p">):</span> +</span><span id="DataFrame.dropna-598"><a href="#DataFrame.dropna-598"><span class="linenos">598</span></a> <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span> +</span><span id="DataFrame.dropna-599"><a href="#DataFrame.dropna-599"><span class="linenos">599</span></a> <span class="sa">f</span><span class="s2">"The minimum num nulls for dropna must be less than or equal to the number of columns. "</span> +</span><span id="DataFrame.dropna-600"><a href="#DataFrame.dropna-600"><span class="linenos">600</span></a> <span class="sa">f</span><span class="s2">"Minimum num nulls: </span><span class="si">{</span><span class="n">minimum_num_nulls</span><span class="si">}</span><span class="s2">, Num Columns: </span><span class="si">{</span><span class="nb">len</span><span class="p">(</span><span class="n">null_check_columns</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span> +</span><span id="DataFrame.dropna-601"><a href="#DataFrame.dropna-601"><span class="linenos">601</span></a> <span class="p">)</span> +</span><span id="DataFrame.dropna-602"><a href="#DataFrame.dropna-602"><span class="linenos">602</span></a> <span class="n">if_null_checks</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.dropna-603"><a href="#DataFrame.dropna-603"><span class="linenos">603</span></a> <span class="n">F</span><span class="o">.</span><span class="n">when</span><span class="p">(</span><span class="n">column</span><span class="o">.</span><span class="n">isNull</span><span class="p">(),</span> <span class="n">F</span><span class="o">.</span><span class="n">lit</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">otherwise</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">lit</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">null_check_columns</span> +</span><span id="DataFrame.dropna-604"><a href="#DataFrame.dropna-604"><span class="linenos">604</span></a> <span class="p">]</span> +</span><span id="DataFrame.dropna-605"><a href="#DataFrame.dropna-605"><span class="linenos">605</span></a> <span class="n">nulls_added_together</span> <span class="o">=</span> <span class="n">functools</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">,</span> <span class="n">if_null_checks</span><span class="p">)</span> +</span><span id="DataFrame.dropna-606"><a href="#DataFrame.dropna-606"><span class="linenos">606</span></a> <span class="n">num_nulls</span> <span class="o">=</span> <span class="n">nulls_added_together</span><span class="o">.</span><span class="n">alias</span><span class="p">(</span><span class="s2">"num_nulls"</span><span class="p">)</span> +</span><span id="DataFrame.dropna-607"><a href="#DataFrame.dropna-607"><span class="linenos">607</span></a> <span class="n">new_df</span> <span class="o">=</span> <span class="n">new_df</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">num_nulls</span><span class="p">,</span> <span class="n">append</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="DataFrame.dropna-608"><a href="#DataFrame.dropna-608"><span class="linenos">608</span></a> <span class="n">filtered_df</span> <span class="o">=</span> <span class="n">new_df</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">col</span><span class="p">(</span><span class="s2">"num_nulls"</span><span class="p">)</span> <span class="o"><</span> <span class="n">F</span><span class="o">.</span><span class="n">lit</span><span class="p">(</span><span class="n">minimum_num_nulls</span><span class="p">))</span> +</span><span id="DataFrame.dropna-609"><a href="#DataFrame.dropna-609"><span class="linenos">609</span></a> <span class="n">final_df</span> <span class="o">=</span> <span class="n">filtered_df</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="n">all_columns</span><span class="p">)</span> +</span><span id="DataFrame.dropna-610"><a href="#DataFrame.dropna-610"><span class="linenos">610</span></a> <span class="k">return</span> <span class="n">final_df</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.fillna" class="classattr"> + <input id="DataFrame.fillna-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.FROM)</div> + + <span class="def">def</span> + <span class="name">fillna</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">value</span><span class="p">:</span> <span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700331804992'</span><span class="o">></span>,</span><span class="param"> <span class="n">subset</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="o">...</span><span class="p">],</span> <span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">],</span> <span class="n">NoneType</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.fillna-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.fillna"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.fillna-612"><a href="#DataFrame.fillna-612"><span class="linenos">612</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame.fillna-613"><a href="#DataFrame.fillna-613"><span class="linenos">613</span></a> <span class="k">def</span> <span class="nf">fillna</span><span class="p">(</span> +</span><span id="DataFrame.fillna-614"><a href="#DataFrame.fillna-614"><span class="linenos">614</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame.fillna-615"><a href="#DataFrame.fillna-615"><span class="linenos">615</span></a> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnLiterals</span><span class="p">],</span> +</span><span id="DataFrame.fillna-616"><a href="#DataFrame.fillna-616"><span class="linenos">616</span></a> <span class="n">subset</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="o">...</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame.fillna-617"><a href="#DataFrame.fillna-617"><span class="linenos">617</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.fillna-618"><a href="#DataFrame.fillna-618"><span class="linenos">618</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="DataFrame.fillna-619"><a href="#DataFrame.fillna-619"><span class="linenos">619</span></a><span class="sd"> Functionality Difference: If you provide a value to replace a null and that type conflicts</span> +</span><span id="DataFrame.fillna-620"><a href="#DataFrame.fillna-620"><span class="linenos">620</span></a><span class="sd"> with the type of the column then PySpark will just ignore your replacement.</span> +</span><span id="DataFrame.fillna-621"><a href="#DataFrame.fillna-621"><span class="linenos">621</span></a><span class="sd"> This will try to cast them to be the same in some cases. So they won't always match.</span> +</span><span id="DataFrame.fillna-622"><a href="#DataFrame.fillna-622"><span class="linenos">622</span></a><span class="sd"> Best to not mix types so make sure replacement is the same type as the column</span> +</span><span id="DataFrame.fillna-623"><a href="#DataFrame.fillna-623"><span class="linenos">623</span></a> +</span><span id="DataFrame.fillna-624"><a href="#DataFrame.fillna-624"><span class="linenos">624</span></a><span class="sd"> Possibility for improvement: Use `typeof` function to get the type of the column</span> +</span><span id="DataFrame.fillna-625"><a href="#DataFrame.fillna-625"><span class="linenos">625</span></a><span class="sd"> and check if it matches the type of the value provided. If not then make it null.</span> +</span><span id="DataFrame.fillna-626"><a href="#DataFrame.fillna-626"><span class="linenos">626</span></a><span class="sd"> """</span> +</span><span id="DataFrame.fillna-627"><a href="#DataFrame.fillna-627"><span class="linenos">627</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.functions</span> <span class="kn">import</span> <span class="n">lit</span> +</span><span id="DataFrame.fillna-628"><a href="#DataFrame.fillna-628"><span class="linenos">628</span></a> +</span><span id="DataFrame.fillna-629"><a href="#DataFrame.fillna-629"><span class="linenos">629</span></a> <span class="n">values</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="DataFrame.fillna-630"><a href="#DataFrame.fillna-630"><span class="linenos">630</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="DataFrame.fillna-631"><a href="#DataFrame.fillna-631"><span class="linenos">631</span></a> <span class="n">new_df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame.fillna-632"><a href="#DataFrame.fillna-632"><span class="linenos">632</span></a> <span class="n">all_columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_outer_select_columns</span><span class="p">(</span><span class="n">new_df</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame.fillna-633"><a href="#DataFrame.fillna-633"><span class="linenos">633</span></a> <span class="n">all_column_mapping</span> <span class="o">=</span> <span class="p">{</span><span class="n">column</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">:</span> <span class="n">column</span> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">all_columns</span><span class="p">}</span> +</span><span id="DataFrame.fillna-634"><a href="#DataFrame.fillna-634"><span class="linenos">634</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span> +</span><span id="DataFrame.fillna-635"><a href="#DataFrame.fillna-635"><span class="linenos">635</span></a> <span class="n">values</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">value</span><span class="o">.</span><span class="n">values</span><span class="p">())</span> +</span><span id="DataFrame.fillna-636"><a href="#DataFrame.fillna-636"><span class="linenos">636</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">value</span><span class="p">))</span> +</span><span id="DataFrame.fillna-637"><a href="#DataFrame.fillna-637"><span class="linenos">637</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">columns</span><span class="p">:</span> +</span><span id="DataFrame.fillna-638"><a href="#DataFrame.fillna-638"><span class="linenos">638</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">subset</span><span class="p">)</span> <span class="k">if</span> <span class="n">subset</span> <span class="k">else</span> <span class="n">all_columns</span> +</span><span id="DataFrame.fillna-639"><a href="#DataFrame.fillna-639"><span class="linenos">639</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">values</span><span class="p">:</span> +</span><span id="DataFrame.fillna-640"><a href="#DataFrame.fillna-640"><span class="linenos">640</span></a> <span class="n">values</span> <span class="o">=</span> <span class="p">[</span><span class="n">value</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> +</span><span id="DataFrame.fillna-641"><a href="#DataFrame.fillna-641"><span class="linenos">641</span></a> <span class="n">value_columns</span> <span class="o">=</span> <span class="p">[</span><span class="n">lit</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">values</span><span class="p">]</span> +</span><span id="DataFrame.fillna-642"><a href="#DataFrame.fillna-642"><span class="linenos">642</span></a> +</span><span id="DataFrame.fillna-643"><a href="#DataFrame.fillna-643"><span class="linenos">643</span></a> <span class="n">null_replacement_mapping</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="DataFrame.fillna-644"><a href="#DataFrame.fillna-644"><span class="linenos">644</span></a> <span class="n">column</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">:</span> <span class="p">(</span> +</span><span id="DataFrame.fillna-645"><a href="#DataFrame.fillna-645"><span class="linenos">645</span></a> <span class="n">F</span><span class="o">.</span><span class="n">when</span><span class="p">(</span><span class="n">column</span><span class="o">.</span><span class="n">isNull</span><span class="p">(),</span> <span class="n">value</span><span class="p">)</span><span class="o">.</span><span class="n">otherwise</span><span class="p">(</span><span class="n">column</span><span class="p">)</span><span class="o">.</span><span class="n">alias</span><span class="p">(</span><span class="n">column</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">)</span> +</span><span id="DataFrame.fillna-646"><a href="#DataFrame.fillna-646"><span class="linenos">646</span></a> <span class="p">)</span> +</span><span id="DataFrame.fillna-647"><a href="#DataFrame.fillna-647"><span class="linenos">647</span></a> <span class="k">for</span> <span class="n">column</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">columns</span><span class="p">,</span> <span class="n">value_columns</span><span class="p">)</span> +</span><span id="DataFrame.fillna-648"><a href="#DataFrame.fillna-648"><span class="linenos">648</span></a> <span class="p">}</span> +</span><span id="DataFrame.fillna-649"><a href="#DataFrame.fillna-649"><span class="linenos">649</span></a> <span class="n">null_replacement_mapping</span> <span class="o">=</span> <span class="p">{</span><span class="o">**</span><span class="n">all_column_mapping</span><span class="p">,</span> <span class="o">**</span><span class="n">null_replacement_mapping</span><span class="p">}</span> +</span><span id="DataFrame.fillna-650"><a href="#DataFrame.fillna-650"><span class="linenos">650</span></a> <span class="n">null_replacement_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.fillna-651"><a href="#DataFrame.fillna-651"><span class="linenos">651</span></a> <span class="n">null_replacement_mapping</span><span class="p">[</span><span class="n">column</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">]</span> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">all_columns</span> +</span><span id="DataFrame.fillna-652"><a href="#DataFrame.fillna-652"><span class="linenos">652</span></a> <span class="p">]</span> +</span><span id="DataFrame.fillna-653"><a href="#DataFrame.fillna-653"><span class="linenos">653</span></a> <span class="n">new_df</span> <span class="o">=</span> <span class="n">new_df</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="n">null_replacement_columns</span><span class="p">)</span> +</span><span id="DataFrame.fillna-654"><a href="#DataFrame.fillna-654"><span class="linenos">654</span></a> <span class="k">return</span> <span class="n">new_df</span> +</span></pre></div> + + + <div class="docstring"><p>Functionality Difference: If you provide a value to replace a null and that type conflicts +with the type of the column then PySpark will just ignore your replacement. +This will try to cast them to be the same in some cases. So they won't always match. +Best to not mix types so make sure replacement is the same type as the column</p> + +<p>Possibility for improvement: Use <code>typeof</code> function to get the type of the column +and check if it matches the type of the value provided. If not then make it null.</p> +</div> + + + </div> + <div id="DataFrame.replace" class="classattr"> + <input id="DataFrame.replace-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.FROM)</div> + + <span class="def">def</span> + <span class="name">replace</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">to_replace</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">bool</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="n">List</span><span class="p">,</span> <span class="n">Dict</span><span class="p">]</span>,</span><span class="param"> <span class="n">value</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">bool</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="n">List</span><span class="p">,</span> <span class="n">NoneType</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">subset</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="n">Collection</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700331990208'</span><span class="o">></span><span class="p">],</span> <span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700331990208'</span><span class="o">></span><span class="p">,</span> <span class="n">NoneType</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.replace-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.replace"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.replace-656"><a href="#DataFrame.replace-656"><span class="linenos">656</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">FROM</span><span class="p">)</span> +</span><span id="DataFrame.replace-657"><a href="#DataFrame.replace-657"><span class="linenos">657</span></a> <span class="k">def</span> <span class="nf">replace</span><span class="p">(</span> +</span><span id="DataFrame.replace-658"><a href="#DataFrame.replace-658"><span class="linenos">658</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame.replace-659"><a href="#DataFrame.replace-659"><span class="linenos">659</span></a> <span class="n">to_replace</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">bool</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">],</span> +</span><span id="DataFrame.replace-660"><a href="#DataFrame.replace-660"><span class="linenos">660</span></a> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">bool</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame.replace-661"><a href="#DataFrame.replace-661"><span class="linenos">661</span></a> <span class="n">subset</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Collection</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">]</span> <span class="o">|</span> <span class="n">ColumnOrName</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrame.replace-662"><a href="#DataFrame.replace-662"><span class="linenos">662</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.replace-663"><a href="#DataFrame.replace-663"><span class="linenos">663</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.functions</span> <span class="kn">import</span> <span class="n">lit</span> +</span><span id="DataFrame.replace-664"><a href="#DataFrame.replace-664"><span class="linenos">664</span></a> +</span><span id="DataFrame.replace-665"><a href="#DataFrame.replace-665"><span class="linenos">665</span></a> <span class="n">old_values</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="DataFrame.replace-666"><a href="#DataFrame.replace-666"><span class="linenos">666</span></a> <span class="n">new_df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame.replace-667"><a href="#DataFrame.replace-667"><span class="linenos">667</span></a> <span class="n">all_columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_outer_select_columns</span><span class="p">(</span><span class="n">new_df</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame.replace-668"><a href="#DataFrame.replace-668"><span class="linenos">668</span></a> <span class="n">all_column_mapping</span> <span class="o">=</span> <span class="p">{</span><span class="n">column</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">:</span> <span class="n">column</span> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">all_columns</span><span class="p">}</span> +</span><span id="DataFrame.replace-669"><a href="#DataFrame.replace-669"><span class="linenos">669</span></a> +</span><span id="DataFrame.replace-670"><a href="#DataFrame.replace-670"><span class="linenos">670</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">subset</span><span class="p">)</span> <span class="k">if</span> <span class="n">subset</span> <span class="k">else</span> <span class="n">all_columns</span> +</span><span id="DataFrame.replace-671"><a href="#DataFrame.replace-671"><span class="linenos">671</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">to_replace</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span> +</span><span id="DataFrame.replace-672"><a href="#DataFrame.replace-672"><span class="linenos">672</span></a> <span class="n">old_values</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">to_replace</span><span class="p">)</span> +</span><span id="DataFrame.replace-673"><a href="#DataFrame.replace-673"><span class="linenos">673</span></a> <span class="n">new_values</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">to_replace</span><span class="o">.</span><span class="n">values</span><span class="p">())</span> +</span><span id="DataFrame.replace-674"><a href="#DataFrame.replace-674"><span class="linenos">674</span></a> <span class="k">elif</span> <span class="ow">not</span> <span class="n">old_values</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">to_replace</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span> +</span><span id="DataFrame.replace-675"><a href="#DataFrame.replace-675"><span class="linenos">675</span></a> <span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">list</span><span class="p">),</span> <span class="s2">"value must be a list since the replacements are a list"</span> +</span><span id="DataFrame.replace-676"><a href="#DataFrame.replace-676"><span class="linenos">676</span></a> <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">to_replace</span><span class="p">)</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span> +</span><span id="DataFrame.replace-677"><a href="#DataFrame.replace-677"><span class="linenos">677</span></a> <span class="n">value</span> +</span><span id="DataFrame.replace-678"><a href="#DataFrame.replace-678"><span class="linenos">678</span></a> <span class="p">),</span> <span class="s2">"the replacements and values must be the same length"</span> +</span><span id="DataFrame.replace-679"><a href="#DataFrame.replace-679"><span class="linenos">679</span></a> <span class="n">old_values</span> <span class="o">=</span> <span class="n">to_replace</span> +</span><span id="DataFrame.replace-680"><a href="#DataFrame.replace-680"><span class="linenos">680</span></a> <span class="n">new_values</span> <span class="o">=</span> <span class="n">value</span> +</span><span id="DataFrame.replace-681"><a href="#DataFrame.replace-681"><span class="linenos">681</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.replace-682"><a href="#DataFrame.replace-682"><span class="linenos">682</span></a> <span class="n">old_values</span> <span class="o">=</span> <span class="p">[</span><span class="n">to_replace</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> +</span><span id="DataFrame.replace-683"><a href="#DataFrame.replace-683"><span class="linenos">683</span></a> <span class="n">new_values</span> <span class="o">=</span> <span class="p">[</span><span class="n">value</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> +</span><span id="DataFrame.replace-684"><a href="#DataFrame.replace-684"><span class="linenos">684</span></a> <span class="n">old_values</span> <span class="o">=</span> <span class="p">[</span><span class="n">lit</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">old_values</span><span class="p">]</span> +</span><span id="DataFrame.replace-685"><a href="#DataFrame.replace-685"><span class="linenos">685</span></a> <span class="n">new_values</span> <span class="o">=</span> <span class="p">[</span><span class="n">lit</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">new_values</span><span class="p">]</span> +</span><span id="DataFrame.replace-686"><a href="#DataFrame.replace-686"><span class="linenos">686</span></a> +</span><span id="DataFrame.replace-687"><a href="#DataFrame.replace-687"><span class="linenos">687</span></a> <span class="n">replacement_mapping</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="DataFrame.replace-688"><a href="#DataFrame.replace-688"><span class="linenos">688</span></a> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">columns</span><span class="p">:</span> +</span><span id="DataFrame.replace-689"><a href="#DataFrame.replace-689"><span class="linenos">689</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span> +</span><span id="DataFrame.replace-690"><a href="#DataFrame.replace-690"><span class="linenos">690</span></a> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">old_value</span><span class="p">,</span> <span class="n">new_value</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">old_values</span><span class="p">,</span> <span class="n">new_values</span><span class="p">)):</span> +</span><span id="DataFrame.replace-691"><a href="#DataFrame.replace-691"><span class="linenos">691</span></a> <span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> +</span><span id="DataFrame.replace-692"><a href="#DataFrame.replace-692"><span class="linenos">692</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">when</span><span class="p">(</span><span class="n">column</span> <span class="o">==</span> <span class="n">old_value</span><span class="p">,</span> <span class="n">new_value</span><span class="p">)</span> +</span><span id="DataFrame.replace-693"><a href="#DataFrame.replace-693"><span class="linenos">693</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.replace-694"><a href="#DataFrame.replace-694"><span class="linenos">694</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">when</span><span class="p">(</span><span class="n">column</span> <span class="o">==</span> <span class="n">old_value</span><span class="p">,</span> <span class="n">new_value</span><span class="p">)</span> <span class="c1"># type: ignore</span> +</span><span id="DataFrame.replace-695"><a href="#DataFrame.replace-695"><span class="linenos">695</span></a> <span class="n">replacement_mapping</span><span class="p">[</span><span class="n">column</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">otherwise</span><span class="p">(</span><span class="n">column</span><span class="p">)</span><span class="o">.</span><span class="n">alias</span><span class="p">(</span> +</span><span id="DataFrame.replace-696"><a href="#DataFrame.replace-696"><span class="linenos">696</span></a> <span class="n">column</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">alias_or_name</span> +</span><span id="DataFrame.replace-697"><a href="#DataFrame.replace-697"><span class="linenos">697</span></a> <span class="p">)</span> +</span><span id="DataFrame.replace-698"><a href="#DataFrame.replace-698"><span class="linenos">698</span></a> +</span><span id="DataFrame.replace-699"><a href="#DataFrame.replace-699"><span class="linenos">699</span></a> <span class="n">replacement_mapping</span> <span class="o">=</span> <span class="p">{</span><span class="o">**</span><span class="n">all_column_mapping</span><span class="p">,</span> <span class="o">**</span><span class="n">replacement_mapping</span><span class="p">}</span> +</span><span id="DataFrame.replace-700"><a href="#DataFrame.replace-700"><span class="linenos">700</span></a> <span class="n">replacement_columns</span> <span class="o">=</span> <span class="p">[</span><span class="n">replacement_mapping</span><span class="p">[</span><span class="n">column</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">]</span> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">all_columns</span><span class="p">]</span> +</span><span id="DataFrame.replace-701"><a href="#DataFrame.replace-701"><span class="linenos">701</span></a> <span class="n">new_df</span> <span class="o">=</span> <span class="n">new_df</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="n">replacement_columns</span><span class="p">)</span> +</span><span id="DataFrame.replace-702"><a href="#DataFrame.replace-702"><span class="linenos">702</span></a> <span class="k">return</span> <span class="n">new_df</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.withColumn" class="classattr"> + <input id="DataFrame.withColumn-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.SELECT)</div> + + <span class="def">def</span> + <span class="name">withColumn</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">colName</span><span class="p">:</span> <span class="nb">str</span>,</span><span class="param"> <span class="n">col</span><span class="p">:</span> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.withColumn-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.withColumn"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.withColumn-704"><a href="#DataFrame.withColumn-704"><span class="linenos">704</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">SELECT</span><span class="p">)</span> +</span><span id="DataFrame.withColumn-705"><a href="#DataFrame.withColumn-705"><span class="linenos">705</span></a> <span class="k">def</span> <span class="nf">withColumn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">colName</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">col</span><span class="p">:</span> <span class="n">Column</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.withColumn-706"><a href="#DataFrame.withColumn-706"><span class="linenos">706</span></a> <span class="n">col</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_col</span><span class="p">(</span><span class="n">col</span><span class="p">)</span> +</span><span id="DataFrame.withColumn-707"><a href="#DataFrame.withColumn-707"><span class="linenos">707</span></a> <span class="n">existing_col_names</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">named_selects</span> +</span><span id="DataFrame.withColumn-708"><a href="#DataFrame.withColumn-708"><span class="linenos">708</span></a> <span class="n">existing_col_index</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="DataFrame.withColumn-709"><a href="#DataFrame.withColumn-709"><span class="linenos">709</span></a> <span class="n">existing_col_names</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">colName</span><span class="p">)</span> <span class="k">if</span> <span class="n">colName</span> <span class="ow">in</span> <span class="n">existing_col_names</span> <span class="k">else</span> <span class="kc">None</span> +</span><span id="DataFrame.withColumn-710"><a href="#DataFrame.withColumn-710"><span class="linenos">710</span></a> <span class="p">)</span> +</span><span id="DataFrame.withColumn-711"><a href="#DataFrame.withColumn-711"><span class="linenos">711</span></a> <span class="k">if</span> <span class="n">existing_col_index</span><span class="p">:</span> +</span><span id="DataFrame.withColumn-712"><a href="#DataFrame.withColumn-712"><span class="linenos">712</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame.withColumn-713"><a href="#DataFrame.withColumn-713"><span class="linenos">713</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">[</span><span class="n">existing_col_index</span><span class="p">]</span> <span class="o">=</span> <span class="n">col</span><span class="o">.</span><span class="n">expression</span> +</span><span id="DataFrame.withColumn-714"><a href="#DataFrame.withColumn-714"><span class="linenos">714</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame.withColumn-715"><a href="#DataFrame.withColumn-715"><span class="linenos">715</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">col</span><span class="o">.</span><span class="n">alias</span><span class="p">(</span><span class="n">colName</span><span class="p">),</span> <span class="n">append</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.withColumnRenamed" class="classattr"> + <input id="DataFrame.withColumnRenamed-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.SELECT)</div> + + <span class="def">def</span> + <span class="name">withColumnRenamed</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">existing</span><span class="p">:</span> <span class="nb">str</span>, </span><span class="param"><span class="n">new</span><span class="p">:</span> <span class="nb">str</span></span><span class="return-annotation">):</span></span> + + <label class="view-source-button" for="DataFrame.withColumnRenamed-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.withColumnRenamed"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.withColumnRenamed-717"><a href="#DataFrame.withColumnRenamed-717"><span class="linenos">717</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">SELECT</span><span class="p">)</span> +</span><span id="DataFrame.withColumnRenamed-718"><a href="#DataFrame.withColumnRenamed-718"><span class="linenos">718</span></a> <span class="k">def</span> <span class="nf">withColumnRenamed</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">existing</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">new</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span> +</span><span id="DataFrame.withColumnRenamed-719"><a href="#DataFrame.withColumnRenamed-719"><span class="linenos">719</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame.withColumnRenamed-720"><a href="#DataFrame.withColumnRenamed-720"><span class="linenos">720</span></a> <span class="n">existing_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.withColumnRenamed-721"><a href="#DataFrame.withColumnRenamed-721"><span class="linenos">721</span></a> <span class="n">expression</span> +</span><span id="DataFrame.withColumnRenamed-722"><a href="#DataFrame.withColumnRenamed-722"><span class="linenos">722</span></a> <span class="k">for</span> <span class="n">expression</span> <span class="ow">in</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> +</span><span id="DataFrame.withColumnRenamed-723"><a href="#DataFrame.withColumnRenamed-723"><span class="linenos">723</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="o">==</span> <span class="n">existing</span> +</span><span id="DataFrame.withColumnRenamed-724"><a href="#DataFrame.withColumnRenamed-724"><span class="linenos">724</span></a> <span class="p">]</span> +</span><span id="DataFrame.withColumnRenamed-725"><a href="#DataFrame.withColumnRenamed-725"><span class="linenos">725</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">existing_columns</span><span class="p">:</span> +</span><span id="DataFrame.withColumnRenamed-726"><a href="#DataFrame.withColumnRenamed-726"><span class="linenos">726</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"Tried to rename a column that doesn't exist"</span><span class="p">)</span> +</span><span id="DataFrame.withColumnRenamed-727"><a href="#DataFrame.withColumnRenamed-727"><span class="linenos">727</span></a> <span class="k">for</span> <span class="n">existing_column</span> <span class="ow">in</span> <span class="n">existing_columns</span><span class="p">:</span> +</span><span id="DataFrame.withColumnRenamed-728"><a href="#DataFrame.withColumnRenamed-728"><span class="linenos">728</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">existing_column</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">):</span> +</span><span id="DataFrame.withColumnRenamed-729"><a href="#DataFrame.withColumnRenamed-729"><span class="linenos">729</span></a> <span class="n">existing_column</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">alias_</span><span class="p">(</span><span class="n">existing_column</span><span class="o">.</span><span class="n">copy</span><span class="p">(),</span> <span class="n">new</span><span class="p">))</span> +</span><span id="DataFrame.withColumnRenamed-730"><a href="#DataFrame.withColumnRenamed-730"><span class="linenos">730</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.withColumnRenamed-731"><a href="#DataFrame.withColumnRenamed-731"><span class="linenos">731</span></a> <span class="n">existing_column</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"alias"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">to_identifier</span><span class="p">(</span><span class="n">new</span><span class="p">))</span> +</span><span id="DataFrame.withColumnRenamed-732"><a href="#DataFrame.withColumnRenamed-732"><span class="linenos">732</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="n">expression</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.drop" class="classattr"> + <input id="DataFrame.drop-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.SELECT)</div> + + <span class="def">def</span> + <span class="name">drop</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span><span class="p">]</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.drop-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.drop"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.drop-734"><a href="#DataFrame.drop-734"><span class="linenos">734</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">SELECT</span><span class="p">)</span> +</span><span id="DataFrame.drop-735"><a href="#DataFrame.drop-735"><span class="linenos">735</span></a> <span class="k">def</span> <span class="nf">drop</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">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Column</span><span class="p">])</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.drop-736"><a href="#DataFrame.drop-736"><span class="linenos">736</span></a> <span class="n">all_columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_outer_select_columns</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="DataFrame.drop-737"><a href="#DataFrame.drop-737"><span class="linenos">737</span></a> <span class="n">drop_cols</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> +</span><span id="DataFrame.drop-738"><a href="#DataFrame.drop-738"><span class="linenos">738</span></a> <span class="n">new_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.drop-739"><a href="#DataFrame.drop-739"><span class="linenos">739</span></a> <span class="n">col</span> +</span><span id="DataFrame.drop-740"><a href="#DataFrame.drop-740"><span class="linenos">740</span></a> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">all_columns</span> +</span><span id="DataFrame.drop-741"><a href="#DataFrame.drop-741"><span class="linenos">741</span></a> <span class="k">if</span> <span class="n">col</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="n">drop_column</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="k">for</span> <span class="n">drop_column</span> <span class="ow">in</span> <span class="n">drop_cols</span><span class="p">]</span> +</span><span id="DataFrame.drop-742"><a href="#DataFrame.drop-742"><span class="linenos">742</span></a> <span class="p">]</span> +</span><span id="DataFrame.drop-743"><a href="#DataFrame.drop-743"><span class="linenos">743</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="n">new_columns</span><span class="p">,</span> <span class="n">append</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.limit" class="classattr"> + <input id="DataFrame.limit-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.LIMIT)</div> + + <span class="def">def</span> + <span class="name">limit</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">num</span><span class="p">:</span> <span class="nb">int</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.limit-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.limit"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.limit-745"><a href="#DataFrame.limit-745"><span class="linenos">745</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">LIMIT</span><span class="p">)</span> +</span><span id="DataFrame.limit-746"><a href="#DataFrame.limit-746"><span class="linenos">746</span></a> <span class="k">def</span> <span class="nf">limit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">num</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.limit-747"><a href="#DataFrame.limit-747"><span class="linenos">747</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">limit</span><span class="p">(</span><span class="n">num</span><span class="p">))</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.hint" class="classattr"> + <input id="DataFrame.hint-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.NO_OP)</div> + + <span class="def">def</span> + <span class="name">hint</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span>,</span><span class="param"> <span class="o">*</span><span class="n">parameters</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="n">NoneType</span><span class="p">]</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.hint-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.hint"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.hint-749"><a href="#DataFrame.hint-749"><span class="linenos">749</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">NO_OP</span><span class="p">)</span> +</span><span id="DataFrame.hint-750"><a href="#DataFrame.hint-750"><span class="linenos">750</span></a> <span class="k">def</span> <span class="nf">hint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">*</span><span class="n">parameters</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">int</span><span class="p">]])</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.hint-751"><a href="#DataFrame.hint-751"><span class="linenos">751</span></a> <span class="n">parameter_list</span> <span class="o">=</span> <span class="n">ensure_list</span><span class="p">(</span><span class="n">parameters</span><span class="p">)</span> +</span><span id="DataFrame.hint-752"><a href="#DataFrame.hint-752"><span class="linenos">752</span></a> <span class="n">parameter_columns</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="DataFrame.hint-753"><a href="#DataFrame.hint-753"><span class="linenos">753</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_list_of_columns</span><span class="p">(</span><span class="n">parameter_list</span><span class="p">)</span> +</span><span id="DataFrame.hint-754"><a href="#DataFrame.hint-754"><span class="linenos">754</span></a> <span class="k">if</span> <span class="n">parameters</span> +</span><span id="DataFrame.hint-755"><a href="#DataFrame.hint-755"><span class="linenos">755</span></a> <span class="k">else</span> <span class="n">Column</span><span class="o">.</span><span class="n">ensure_cols</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">sequence_id</span><span class="p">])</span> +</span><span id="DataFrame.hint-756"><a href="#DataFrame.hint-756"><span class="linenos">756</span></a> <span class="p">)</span> +</span><span id="DataFrame.hint-757"><a href="#DataFrame.hint-757"><span class="linenos">757</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_hint</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">parameter_columns</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.repartition" class="classattr"> + <input id="DataFrame.repartition-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.NO_OP)</div> + + <span class="def">def</span> + <span class="name">repartition</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">numPartitions</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700332136032'</span><span class="o">></span><span class="p">]</span>,</span><span class="param"> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700332245248'</span><span class="o">></span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.repartition-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.repartition"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.repartition-759"><a href="#DataFrame.repartition-759"><span class="linenos">759</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">NO_OP</span><span class="p">)</span> +</span><span id="DataFrame.repartition-760"><a href="#DataFrame.repartition-760"><span class="linenos">760</span></a> <span class="k">def</span> <span class="nf">repartition</span><span class="p">(</span> +</span><span id="DataFrame.repartition-761"><a href="#DataFrame.repartition-761"><span class="linenos">761</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">numPartitions</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="n">ColumnOrName</span><span class="p">],</span> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">ColumnOrName</span> +</span><span id="DataFrame.repartition-762"><a href="#DataFrame.repartition-762"><span class="linenos">762</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.repartition-763"><a href="#DataFrame.repartition-763"><span class="linenos">763</span></a> <span class="n">num_partition_cols</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_list_of_columns</span><span class="p">(</span><span class="n">numPartitions</span><span class="p">)</span> +</span><span id="DataFrame.repartition-764"><a href="#DataFrame.repartition-764"><span class="linenos">764</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> +</span><span id="DataFrame.repartition-765"><a href="#DataFrame.repartition-765"><span class="linenos">765</span></a> <span class="n">args</span> <span class="o">=</span> <span class="n">num_partition_cols</span> <span class="o">+</span> <span class="n">columns</span> +</span><span id="DataFrame.repartition-766"><a href="#DataFrame.repartition-766"><span class="linenos">766</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_hint</span><span class="p">(</span><span class="s2">"repartition"</span><span class="p">,</span> <span class="n">args</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.coalesce" class="classattr"> + <input id="DataFrame.coalesce-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.NO_OP)</div> + + <span class="def">def</span> + <span class="name">coalesce</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">numPartitions</span><span class="p">:</span> <span class="nb">int</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.coalesce-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.coalesce"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.coalesce-768"><a href="#DataFrame.coalesce-768"><span class="linenos">768</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">NO_OP</span><span class="p">)</span> +</span><span id="DataFrame.coalesce-769"><a href="#DataFrame.coalesce-769"><span class="linenos">769</span></a> <span class="k">def</span> <span class="nf">coalesce</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">numPartitions</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.coalesce-770"><a href="#DataFrame.coalesce-770"><span class="linenos">770</span></a> <span class="n">num_partitions</span> <span class="o">=</span> <span class="n">Column</span><span class="o">.</span><span class="n">ensure_cols</span><span class="p">([</span><span class="n">numPartitions</span><span class="p">])</span> +</span><span id="DataFrame.coalesce-771"><a href="#DataFrame.coalesce-771"><span class="linenos">771</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_hint</span><span class="p">(</span><span class="s2">"coalesce"</span><span class="p">,</span> <span class="n">num_partitions</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.cache" class="classattr"> + <input id="DataFrame.cache-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.NO_OP)</div> + + <span class="def">def</span> + <span class="name">cache</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.cache-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.cache"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.cache-773"><a href="#DataFrame.cache-773"><span class="linenos">773</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">NO_OP</span><span class="p">)</span> +</span><span id="DataFrame.cache-774"><a href="#DataFrame.cache-774"><span class="linenos">774</span></a> <span class="k">def</span> <span class="nf">cache</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.cache-775"><a href="#DataFrame.cache-775"><span class="linenos">775</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="p">(</span><span class="n">storage_level</span><span class="o">=</span><span class="s2">"MEMORY_AND_DISK"</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrame.persist" class="classattr"> + <input id="DataFrame.persist-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.NO_OP)</div> + + <span class="def">def</span> + <span class="name">persist</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">storageLevel</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s1">'MEMORY_AND_DISK_SER'</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrame.persist-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrame.persist"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.persist-777"><a href="#DataFrame.persist-777"><span class="linenos">777</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">NO_OP</span><span class="p">)</span> +</span><span id="DataFrame.persist-778"><a href="#DataFrame.persist-778"><span class="linenos">778</span></a> <span class="k">def</span> <span class="nf">persist</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">storageLevel</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"MEMORY_AND_DISK_SER"</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.persist-779"><a href="#DataFrame.persist-779"><span class="linenos">779</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="DataFrame.persist-780"><a href="#DataFrame.persist-780"><span class="linenos">780</span></a><span class="sd"> Storage Level Options: https://spark.apache.org/docs/3.0.0-preview/sql-ref-syntax-aux-cache-cache-table.html</span> +</span><span id="DataFrame.persist-781"><a href="#DataFrame.persist-781"><span class="linenos">781</span></a><span class="sd"> """</span> +</span><span id="DataFrame.persist-782"><a href="#DataFrame.persist-782"><span class="linenos">782</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="p">(</span><span class="n">storageLevel</span><span class="p">)</span> +</span></pre></div> + + + <div class="docstring"><p>Storage Level Options: <a href="https://spark.apache.org/docs/3.0.0-preview/sql-ref-syntax-aux-cache-cache-table.html">https://spark.apache.org/docs/3.0.0-preview/sql-ref-syntax-aux-cache-cache-table.html</a></p> +</div> + + + </div> + </section> + <section id="GroupedData"> + <input id="GroupedData-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr class"> + + <span class="def">class</span> + <span class="name">GroupedData</span>: + + <label class="view-source-button" for="GroupedData-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#GroupedData"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="GroupedData-14"><a href="#GroupedData-14"><span class="linenos">14</span></a><span class="k">class</span> <span class="nc">GroupedData</span><span class="p">:</span> +</span><span id="GroupedData-15"><a href="#GroupedData-15"><span class="linenos">15</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">df</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">,</span> <span class="n">group_by_cols</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Column</span><span class="p">],</span> <span class="n">last_op</span><span class="p">:</span> <span class="n">Operation</span><span class="p">):</span> +</span><span id="GroupedData-16"><a href="#GroupedData-16"><span class="linenos">16</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_df</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="GroupedData-17"><a href="#GroupedData-17"><span class="linenos">17</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">spark</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">spark</span> +</span><span id="GroupedData-18"><a href="#GroupedData-18"><span class="linenos">18</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">last_op</span> <span class="o">=</span> <span class="n">last_op</span> +</span><span id="GroupedData-19"><a href="#GroupedData-19"><span class="linenos">19</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">group_by_cols</span> <span class="o">=</span> <span class="n">group_by_cols</span> +</span><span id="GroupedData-20"><a href="#GroupedData-20"><span class="linenos">20</span></a> +</span><span id="GroupedData-21"><a href="#GroupedData-21"><span class="linenos">21</span></a> <span class="k">def</span> <span class="nf">_get_function_applied_columns</span><span class="p">(</span> +</span><span id="GroupedData-22"><a href="#GroupedData-22"><span class="linenos">22</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">func_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">cols</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="o">...</span><span class="p">]</span> +</span><span id="GroupedData-23"><a href="#GroupedData-23"><span class="linenos">23</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Column</span><span class="p">]:</span> +</span><span id="GroupedData-24"><a href="#GroupedData-24"><span class="linenos">24</span></a> <span class="n">func_name</span> <span class="o">=</span> <span class="n">func_name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> +</span><span id="GroupedData-25"><a href="#GroupedData-25"><span class="linenos">25</span></a> <span class="k">return</span> <span class="p">[</span><span class="nb">getattr</span><span class="p">(</span><span class="n">F</span><span class="p">,</span> <span class="n">func_name</span><span class="p">)(</span><span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">alias</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">func_name</span><span class="si">}</span><span class="s2">(</span><span class="si">{</span><span class="n">name</span><span class="si">}</span><span class="s2">)"</span><span class="p">)</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">cols</span><span class="p">]</span> +</span><span id="GroupedData-26"><a href="#GroupedData-26"><span class="linenos">26</span></a> +</span><span id="GroupedData-27"><a href="#GroupedData-27"><span class="linenos">27</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">SELECT</span><span class="p">)</span> +</span><span id="GroupedData-28"><a href="#GroupedData-28"><span class="linenos">28</span></a> <span class="k">def</span> <span class="nf">agg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">exprs</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">Column</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]])</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="GroupedData-29"><a href="#GroupedData-29"><span class="linenos">29</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="GroupedData-30"><a href="#GroupedData-30"><span class="linenos">30</span></a> <span class="p">[</span><span class="n">Column</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">agg_func</span><span class="si">}</span><span class="s2">(</span><span class="si">{</span><span class="n">column_name</span><span class="si">}</span><span class="s2">)"</span><span class="p">)</span> <span class="k">for</span> <span class="n">column_name</span><span class="p">,</span> <span class="n">agg_func</span> <span class="ow">in</span> <span class="n">exprs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()]</span> +</span><span id="GroupedData-31"><a href="#GroupedData-31"><span class="linenos">31</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">exprs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">dict</span><span class="p">)</span> +</span><span id="GroupedData-32"><a href="#GroupedData-32"><span class="linenos">32</span></a> <span class="k">else</span> <span class="n">exprs</span> +</span><span id="GroupedData-33"><a href="#GroupedData-33"><span class="linenos">33</span></a> <span class="p">)</span> +</span><span id="GroupedData-34"><a href="#GroupedData-34"><span class="linenos">34</span></a> <span class="n">cols</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_df</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> +</span><span id="GroupedData-35"><a href="#GroupedData-35"><span class="linenos">35</span></a> +</span><span id="GroupedData-36"><a href="#GroupedData-36"><span class="linenos">36</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_df</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">group_by</span><span class="p">(</span> +</span><span id="GroupedData-37"><a href="#GroupedData-37"><span class="linenos">37</span></a> <span class="o">*</span><span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">group_by_cols</span><span class="p">]</span> +</span><span id="GroupedData-38"><a href="#GroupedData-38"><span class="linenos">38</span></a> <span class="p">)</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">group_by_cols</span> <span class="o">+</span> <span class="n">cols</span><span class="p">],</span> <span class="n">append</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +</span><span id="GroupedData-39"><a href="#GroupedData-39"><span class="linenos">39</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_df</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="n">expression</span><span class="p">)</span> +</span><span id="GroupedData-40"><a href="#GroupedData-40"><span class="linenos">40</span></a> +</span><span id="GroupedData-41"><a href="#GroupedData-41"><span class="linenos">41</span></a> <span class="k">def</span> <span class="nf">count</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="GroupedData-42"><a href="#GroupedData-42"><span class="linenos">42</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s2">"*"</span><span class="p">)</span><span class="o">.</span><span class="n">alias</span><span class="p">(</span><span class="s2">"count"</span><span class="p">))</span> +</span><span id="GroupedData-43"><a href="#GroupedData-43"><span class="linenos">43</span></a> +</span><span id="GroupedData-44"><a href="#GroupedData-44"><span class="linenos">44</span></a> <span class="k">def</span> <span class="nf">mean</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="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="GroupedData-45"><a href="#GroupedData-45"><span class="linenos">45</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">avg</span><span class="p">(</span><span class="o">*</span><span class="n">cols</span><span class="p">)</span> +</span><span id="GroupedData-46"><a href="#GroupedData-46"><span class="linenos">46</span></a> +</span><span id="GroupedData-47"><a href="#GroupedData-47"><span class="linenos">47</span></a> <span class="k">def</span> <span class="nf">avg</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="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="GroupedData-48"><a href="#GroupedData-48"><span class="linenos">48</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">_get_function_applied_columns</span><span class="p">(</span><span class="s2">"avg"</span><span class="p">,</span> <span class="n">cols</span><span class="p">))</span> +</span><span id="GroupedData-49"><a href="#GroupedData-49"><span class="linenos">49</span></a> +</span><span id="GroupedData-50"><a href="#GroupedData-50"><span class="linenos">50</span></a> <span class="k">def</span> <span class="nf">max</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="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="GroupedData-51"><a href="#GroupedData-51"><span class="linenos">51</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">_get_function_applied_columns</span><span class="p">(</span><span class="s2">"max"</span><span class="p">,</span> <span class="n">cols</span><span class="p">))</span> +</span><span id="GroupedData-52"><a href="#GroupedData-52"><span class="linenos">52</span></a> +</span><span id="GroupedData-53"><a href="#GroupedData-53"><span class="linenos">53</span></a> <span class="k">def</span> <span class="nf">min</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="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="GroupedData-54"><a href="#GroupedData-54"><span class="linenos">54</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">_get_function_applied_columns</span><span class="p">(</span><span class="s2">"min"</span><span class="p">,</span> <span class="n">cols</span><span class="p">))</span> +</span><span id="GroupedData-55"><a href="#GroupedData-55"><span class="linenos">55</span></a> +</span><span id="GroupedData-56"><a href="#GroupedData-56"><span class="linenos">56</span></a> <span class="k">def</span> <span class="nf">sum</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="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="GroupedData-57"><a href="#GroupedData-57"><span class="linenos">57</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">_get_function_applied_columns</span><span class="p">(</span><span class="s2">"sum"</span><span class="p">,</span> <span class="n">cols</span><span class="p">))</span> +</span><span id="GroupedData-58"><a href="#GroupedData-58"><span class="linenos">58</span></a> +</span><span id="GroupedData-59"><a href="#GroupedData-59"><span class="linenos">59</span></a> <span class="k">def</span> <span class="nf">pivot</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="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="GroupedData-60"><a href="#GroupedData-60"><span class="linenos">60</span></a> <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">"Sum distinct is not currently implemented"</span><span class="p">)</span> +</span></pre></div> + + + + + <div id="GroupedData.__init__" class="classattr"> + <input id="GroupedData.__init__-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="name">GroupedData</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="n">df</span><span class="p">:</span> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>,</span><span class="param"> <span class="n">group_by_cols</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span><span class="p">]</span>,</span><span class="param"> <span class="n">last_op</span><span class="p">:</span> <span class="n">sqlglot</span><span class="o">.</span><span class="n">dataframe</span><span class="o">.</span><span class="n">sql</span><span class="o">.</span><span class="n">operations</span><span class="o">.</span><span class="n">Operation</span></span>)</span> + + <label class="view-source-button" for="GroupedData.__init__-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#GroupedData.__init__"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="GroupedData.__init__-15"><a href="#GroupedData.__init__-15"><span class="linenos">15</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">df</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">,</span> <span class="n">group_by_cols</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Column</span><span class="p">],</span> <span class="n">last_op</span><span class="p">:</span> <span class="n">Operation</span><span class="p">):</span> +</span><span id="GroupedData.__init__-16"><a href="#GroupedData.__init__-16"><span class="linenos">16</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_df</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="GroupedData.__init__-17"><a href="#GroupedData.__init__-17"><span class="linenos">17</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">spark</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">spark</span> +</span><span id="GroupedData.__init__-18"><a href="#GroupedData.__init__-18"><span class="linenos">18</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">last_op</span> <span class="o">=</span> <span class="n">last_op</span> +</span><span id="GroupedData.__init__-19"><a href="#GroupedData.__init__-19"><span class="linenos">19</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">group_by_cols</span> <span class="o">=</span> <span class="n">group_by_cols</span> +</span></pre></div> + + + + + </div> + <div id="GroupedData.agg" class="classattr"> + <input id="GroupedData.agg-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@operation(Operation.SELECT)</div> + + <span class="def">def</span> + <span class="name">agg</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="o">*</span><span class="n">exprs</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span><span class="p">,</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]]</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="GroupedData.agg-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#GroupedData.agg"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="GroupedData.agg-27"><a href="#GroupedData.agg-27"><span class="linenos">27</span></a> <span class="nd">@operation</span><span class="p">(</span><span class="n">Operation</span><span class="o">.</span><span class="n">SELECT</span><span class="p">)</span> +</span><span id="GroupedData.agg-28"><a href="#GroupedData.agg-28"><span class="linenos">28</span></a> <span class="k">def</span> <span class="nf">agg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">exprs</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">Column</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]])</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="GroupedData.agg-29"><a href="#GroupedData.agg-29"><span class="linenos">29</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="GroupedData.agg-30"><a href="#GroupedData.agg-30"><span class="linenos">30</span></a> <span class="p">[</span><span class="n">Column</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">agg_func</span><span class="si">}</span><span class="s2">(</span><span class="si">{</span><span class="n">column_name</span><span class="si">}</span><span class="s2">)"</span><span class="p">)</span> <span class="k">for</span> <span class="n">column_name</span><span class="p">,</span> <span class="n">agg_func</span> <span class="ow">in</span> <span class="n">exprs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()]</span> +</span><span id="GroupedData.agg-31"><a href="#GroupedData.agg-31"><span class="linenos">31</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">exprs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">dict</span><span class="p">)</span> +</span><span id="GroupedData.agg-32"><a href="#GroupedData.agg-32"><span class="linenos">32</span></a> <span class="k">else</span> <span class="n">exprs</span> +</span><span id="GroupedData.agg-33"><a href="#GroupedData.agg-33"><span class="linenos">33</span></a> <span class="p">)</span> +</span><span id="GroupedData.agg-34"><a href="#GroupedData.agg-34"><span class="linenos">34</span></a> <span class="n">cols</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_df</span><span class="o">.</span><span class="n">_ensure_and_normalize_cols</span><span class="p">(</span><span class="n">columns</span><span class="p">)</span> +</span><span id="GroupedData.agg-35"><a href="#GroupedData.agg-35"><span class="linenos">35</span></a> +</span><span id="GroupedData.agg-36"><a href="#GroupedData.agg-36"><span class="linenos">36</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_df</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">group_by</span><span class="p">(</span> +</span><span id="GroupedData.agg-37"><a href="#GroupedData.agg-37"><span class="linenos">37</span></a> <span class="o">*</span><span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">group_by_cols</span><span class="p">]</span> +</span><span id="GroupedData.agg-38"><a href="#GroupedData.agg-38"><span class="linenos">38</span></a> <span class="p">)</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">group_by_cols</span> <span class="o">+</span> <span class="n">cols</span><span class="p">],</span> <span class="n">append</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +</span><span id="GroupedData.agg-39"><a href="#GroupedData.agg-39"><span class="linenos">39</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_df</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">expression</span><span class="o">=</span><span class="n">expression</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="GroupedData.count" class="classattr"> + <input id="GroupedData.count-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">count</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="GroupedData.count-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#GroupedData.count"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="GroupedData.count-41"><a href="#GroupedData.count-41"><span class="linenos">41</span></a> <span class="k">def</span> <span class="nf">count</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="GroupedData.count-42"><a href="#GroupedData.count-42"><span class="linenos">42</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s2">"*"</span><span class="p">)</span><span class="o">.</span><span class="n">alias</span><span class="p">(</span><span class="s2">"count"</span><span class="p">))</span> +</span></pre></div> + + + + + </div> + <div id="GroupedData.mean" class="classattr"> + <input id="GroupedData.mean-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">mean</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="nb">str</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="GroupedData.mean-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#GroupedData.mean"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="GroupedData.mean-44"><a href="#GroupedData.mean-44"><span class="linenos">44</span></a> <span class="k">def</span> <span class="nf">mean</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="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="GroupedData.mean-45"><a href="#GroupedData.mean-45"><span class="linenos">45</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">avg</span><span class="p">(</span><span class="o">*</span><span class="n">cols</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="GroupedData.avg" class="classattr"> + <input id="GroupedData.avg-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">avg</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="nb">str</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="GroupedData.avg-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#GroupedData.avg"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="GroupedData.avg-47"><a href="#GroupedData.avg-47"><span class="linenos">47</span></a> <span class="k">def</span> <span class="nf">avg</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="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="GroupedData.avg-48"><a href="#GroupedData.avg-48"><span class="linenos">48</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">_get_function_applied_columns</span><span class="p">(</span><span class="s2">"avg"</span><span class="p">,</span> <span class="n">cols</span><span class="p">))</span> +</span></pre></div> + + + + + </div> + <div id="GroupedData.max" class="classattr"> + <input id="GroupedData.max-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">max</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="nb">str</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="GroupedData.max-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#GroupedData.max"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="GroupedData.max-50"><a href="#GroupedData.max-50"><span class="linenos">50</span></a> <span class="k">def</span> <span class="nf">max</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="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="GroupedData.max-51"><a href="#GroupedData.max-51"><span class="linenos">51</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">_get_function_applied_columns</span><span class="p">(</span><span class="s2">"max"</span><span class="p">,</span> <span class="n">cols</span><span class="p">))</span> +</span></pre></div> + + + + + </div> + <div id="GroupedData.min" class="classattr"> + <input id="GroupedData.min-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">min</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="nb">str</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="GroupedData.min-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#GroupedData.min"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="GroupedData.min-53"><a href="#GroupedData.min-53"><span class="linenos">53</span></a> <span class="k">def</span> <span class="nf">min</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="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="GroupedData.min-54"><a href="#GroupedData.min-54"><span class="linenos">54</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">_get_function_applied_columns</span><span class="p">(</span><span class="s2">"min"</span><span class="p">,</span> <span class="n">cols</span><span class="p">))</span> +</span></pre></div> + + + + + </div> + <div id="GroupedData.sum" class="classattr"> + <input id="GroupedData.sum-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">sum</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="nb">str</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="GroupedData.sum-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#GroupedData.sum"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="GroupedData.sum-56"><a href="#GroupedData.sum-56"><span class="linenos">56</span></a> <span class="k">def</span> <span class="nf">sum</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="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="GroupedData.sum-57"><a href="#GroupedData.sum-57"><span class="linenos">57</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">_get_function_applied_columns</span><span class="p">(</span><span class="s2">"sum"</span><span class="p">,</span> <span class="n">cols</span><span class="p">))</span> +</span></pre></div> + + + + + </div> + <div id="GroupedData.pivot" class="classattr"> + <input id="GroupedData.pivot-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">pivot</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="nb">str</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="GroupedData.pivot-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#GroupedData.pivot"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="GroupedData.pivot-59"><a href="#GroupedData.pivot-59"><span class="linenos">59</span></a> <span class="k">def</span> <span class="nf">pivot</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="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="GroupedData.pivot-60"><a href="#GroupedData.pivot-60"><span class="linenos">60</span></a> <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">"Sum distinct is not currently implemented"</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + </section> + <section id="Column"> + <input id="Column-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr class"> + + <span class="def">class</span> + <span class="name">Column</span>: + + <label class="view-source-button" for="Column-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column-16"><a href="#Column-16"><span class="linenos"> 16</span></a><span class="k">class</span> <span class="nc">Column</span><span class="p">:</span> +</span><span id="Column-17"><a href="#Column-17"><span class="linenos"> 17</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]]):</span> +</span><span id="Column-18"><a href="#Column-18"><span class="linenos"> 18</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">Column</span><span class="p">):</span> +</span><span id="Column-19"><a href="#Column-19"><span class="linenos"> 19</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span> <span class="c1"># type: ignore</span> +</span><span id="Column-20"><a href="#Column-20"><span class="linenos"> 20</span></a> <span class="k">elif</span> <span class="n">expression</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">)):</span> +</span><span id="Column-21"><a href="#Column-21"><span class="linenos"> 21</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> <span class="c1"># type: ignore</span> +</span><span id="Column-22"><a href="#Column-22"><span class="linenos"> 22</span></a> +</span><span id="Column-23"><a href="#Column-23"><span class="linenos"> 23</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">sqlglot</span><span class="o">.</span><span class="n">maybe_parse</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="s2">"spark"</span><span class="p">)</span> +</span><span id="Column-24"><a href="#Column-24"><span class="linenos"> 24</span></a> <span class="k">if</span> <span class="n">expression</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> +</span><span id="Column-25"><a href="#Column-25"><span class="linenos"> 25</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Could not parse </span><span class="si">{</span><span class="n">expression</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="Column-26"><a href="#Column-26"><span class="linenos"> 26</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span> <span class="o">=</span> <span class="n">expression</span> +</span><span id="Column-27"><a href="#Column-27"><span class="linenos"> 27</span></a> +</span><span id="Column-28"><a href="#Column-28"><span class="linenos"> 28</span></a> <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> +</span><span id="Column-29"><a href="#Column-29"><span class="linenos"> 29</span></a> <span class="k">return</span> <span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="Column-30"><a href="#Column-30"><span class="linenos"> 30</span></a> +</span><span id="Column-31"><a href="#Column-31"><span class="linenos"> 31</span></a> <span class="k">def</span> <span class="fm">__hash__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> +</span><span id="Column-32"><a href="#Column-32"><span class="linenos"> 32</span></a> <span class="k">return</span> <span class="nb">hash</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="Column-33"><a href="#Column-33"><span class="linenos"> 33</span></a> +</span><span id="Column-34"><a href="#Column-34"><span class="linenos"> 34</span></a> <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> <span class="c1"># type: ignore</span> +</span><span id="Column-35"><a href="#Column-35"><span class="linenos"> 35</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">EQ</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-36"><a href="#Column-36"><span class="linenos"> 36</span></a> +</span><span id="Column-37"><a href="#Column-37"><span class="linenos"> 37</span></a> <span class="k">def</span> <span class="fm">__ne__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> <span class="c1"># type: ignore</span> +</span><span id="Column-38"><a href="#Column-38"><span class="linenos"> 38</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">NEQ</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-39"><a href="#Column-39"><span class="linenos"> 39</span></a> +</span><span id="Column-40"><a href="#Column-40"><span class="linenos"> 40</span></a> <span class="k">def</span> <span class="fm">__gt__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-41"><a href="#Column-41"><span class="linenos"> 41</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">GT</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-42"><a href="#Column-42"><span class="linenos"> 42</span></a> +</span><span id="Column-43"><a href="#Column-43"><span class="linenos"> 43</span></a> <span class="k">def</span> <span class="fm">__ge__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-44"><a href="#Column-44"><span class="linenos"> 44</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">GTE</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-45"><a href="#Column-45"><span class="linenos"> 45</span></a> +</span><span id="Column-46"><a href="#Column-46"><span class="linenos"> 46</span></a> <span class="k">def</span> <span class="fm">__lt__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-47"><a href="#Column-47"><span class="linenos"> 47</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">LT</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-48"><a href="#Column-48"><span class="linenos"> 48</span></a> +</span><span id="Column-49"><a href="#Column-49"><span class="linenos"> 49</span></a> <span class="k">def</span> <span class="fm">__le__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-50"><a href="#Column-50"><span class="linenos"> 50</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">LTE</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-51"><a href="#Column-51"><span class="linenos"> 51</span></a> +</span><span id="Column-52"><a href="#Column-52"><span class="linenos"> 52</span></a> <span class="k">def</span> <span class="fm">__and__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-53"><a href="#Column-53"><span class="linenos"> 53</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">And</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-54"><a href="#Column-54"><span class="linenos"> 54</span></a> +</span><span id="Column-55"><a href="#Column-55"><span class="linenos"> 55</span></a> <span class="k">def</span> <span class="fm">__or__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-56"><a href="#Column-56"><span class="linenos"> 56</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Or</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-57"><a href="#Column-57"><span class="linenos"> 57</span></a> +</span><span id="Column-58"><a href="#Column-58"><span class="linenos"> 58</span></a> <span class="k">def</span> <span class="fm">__mod__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-59"><a href="#Column-59"><span class="linenos"> 59</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Mod</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-60"><a href="#Column-60"><span class="linenos"> 60</span></a> +</span><span id="Column-61"><a href="#Column-61"><span class="linenos"> 61</span></a> <span class="k">def</span> <span class="fm">__add__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-62"><a href="#Column-62"><span class="linenos"> 62</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Add</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-63"><a href="#Column-63"><span class="linenos"> 63</span></a> +</span><span id="Column-64"><a href="#Column-64"><span class="linenos"> 64</span></a> <span class="k">def</span> <span class="fm">__sub__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-65"><a href="#Column-65"><span class="linenos"> 65</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Sub</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-66"><a href="#Column-66"><span class="linenos"> 66</span></a> +</span><span id="Column-67"><a href="#Column-67"><span class="linenos"> 67</span></a> <span class="k">def</span> <span class="fm">__mul__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-68"><a href="#Column-68"><span class="linenos"> 68</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Mul</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-69"><a href="#Column-69"><span class="linenos"> 69</span></a> +</span><span id="Column-70"><a href="#Column-70"><span class="linenos"> 70</span></a> <span class="k">def</span> <span class="fm">__truediv__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-71"><a href="#Column-71"><span class="linenos"> 71</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Div</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-72"><a href="#Column-72"><span class="linenos"> 72</span></a> +</span><span id="Column-73"><a href="#Column-73"><span class="linenos"> 73</span></a> <span class="k">def</span> <span class="nf">__div__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-74"><a href="#Column-74"><span class="linenos"> 74</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Div</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-75"><a href="#Column-75"><span class="linenos"> 75</span></a> +</span><span id="Column-76"><a href="#Column-76"><span class="linenos"> 76</span></a> <span class="k">def</span> <span class="fm">__neg__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-77"><a href="#Column-77"><span class="linenos"> 77</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">unary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Neg</span><span class="p">)</span> +</span><span id="Column-78"><a href="#Column-78"><span class="linenos"> 78</span></a> +</span><span id="Column-79"><a href="#Column-79"><span class="linenos"> 79</span></a> <span class="k">def</span> <span class="fm">__radd__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-80"><a href="#Column-80"><span class="linenos"> 80</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">inverse_binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Add</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-81"><a href="#Column-81"><span class="linenos"> 81</span></a> +</span><span id="Column-82"><a href="#Column-82"><span class="linenos"> 82</span></a> <span class="k">def</span> <span class="fm">__rsub__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-83"><a href="#Column-83"><span class="linenos"> 83</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">inverse_binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Sub</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-84"><a href="#Column-84"><span class="linenos"> 84</span></a> +</span><span id="Column-85"><a href="#Column-85"><span class="linenos"> 85</span></a> <span class="k">def</span> <span class="fm">__rmul__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-86"><a href="#Column-86"><span class="linenos"> 86</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">inverse_binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Mul</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-87"><a href="#Column-87"><span class="linenos"> 87</span></a> +</span><span id="Column-88"><a href="#Column-88"><span class="linenos"> 88</span></a> <span class="k">def</span> <span class="nf">__rdiv__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-89"><a href="#Column-89"><span class="linenos"> 89</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">inverse_binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Div</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-90"><a href="#Column-90"><span class="linenos"> 90</span></a> +</span><span id="Column-91"><a href="#Column-91"><span class="linenos"> 91</span></a> <span class="k">def</span> <span class="fm">__rtruediv__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-92"><a href="#Column-92"><span class="linenos"> 92</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">inverse_binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Div</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-93"><a href="#Column-93"><span class="linenos"> 93</span></a> +</span><span id="Column-94"><a href="#Column-94"><span class="linenos"> 94</span></a> <span class="k">def</span> <span class="fm">__rmod__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-95"><a href="#Column-95"><span class="linenos"> 95</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">inverse_binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Mod</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-96"><a href="#Column-96"><span class="linenos"> 96</span></a> +</span><span id="Column-97"><a href="#Column-97"><span class="linenos"> 97</span></a> <span class="k">def</span> <span class="fm">__pow__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">power</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">,</span> <span class="n">modulo</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span> +</span><span id="Column-98"><a href="#Column-98"><span class="linenos"> 98</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pow</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">Column</span><span class="p">(</span><span class="n">power</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span><span class="p">))</span> +</span><span id="Column-99"><a href="#Column-99"><span class="linenos"> 99</span></a> +</span><span id="Column-100"><a href="#Column-100"><span class="linenos">100</span></a> <span class="k">def</span> <span class="fm">__rpow__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">power</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">):</span> +</span><span id="Column-101"><a href="#Column-101"><span class="linenos">101</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pow</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">Column</span><span class="p">(</span><span class="n">power</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">))</span> +</span><span id="Column-102"><a href="#Column-102"><span class="linenos">102</span></a> +</span><span id="Column-103"><a href="#Column-103"><span class="linenos">103</span></a> <span class="k">def</span> <span class="fm">__invert__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> +</span><span id="Column-104"><a href="#Column-104"><span class="linenos">104</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">unary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Not</span><span class="p">)</span> +</span><span id="Column-105"><a href="#Column-105"><span class="linenos">105</span></a> +</span><span id="Column-106"><a href="#Column-106"><span class="linenos">106</span></a> <span class="k">def</span> <span class="fm">__rand__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-107"><a href="#Column-107"><span class="linenos">107</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">inverse_binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">And</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-108"><a href="#Column-108"><span class="linenos">108</span></a> +</span><span id="Column-109"><a href="#Column-109"><span class="linenos">109</span></a> <span class="k">def</span> <span class="fm">__ror__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-110"><a href="#Column-110"><span class="linenos">110</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">inverse_binary_op</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Or</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> +</span><span id="Column-111"><a href="#Column-111"><span class="linenos">111</span></a> +</span><span id="Column-112"><a href="#Column-112"><span class="linenos">112</span></a> <span class="nd">@classmethod</span> +</span><span id="Column-113"><a href="#Column-113"><span class="linenos">113</span></a> <span class="k">def</span> <span class="nf">ensure_col</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]]):</span> +</span><span id="Column-114"><a href="#Column-114"><span class="linenos">114</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> +</span><span id="Column-115"><a href="#Column-115"><span class="linenos">115</span></a> +</span><span id="Column-116"><a href="#Column-116"><span class="linenos">116</span></a> <span class="nd">@classmethod</span> +</span><span id="Column-117"><a href="#Column-117"><span class="linenos">117</span></a> <span class="k">def</span> <span class="nf">ensure_cols</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">args</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]])</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Column</span><span class="p">]:</span> +</span><span id="Column-118"><a href="#Column-118"><span class="linenos">118</span></a> <span class="k">return</span> <span class="p">[</span><span class="bp">cls</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">Column</span><span class="p">)</span> <span class="k">else</span> <span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">args</span><span class="p">]</span> +</span><span id="Column-119"><a href="#Column-119"><span class="linenos">119</span></a> +</span><span id="Column-120"><a href="#Column-120"><span class="linenos">120</span></a> <span class="nd">@classmethod</span> +</span><span id="Column-121"><a href="#Column-121"><span class="linenos">121</span></a> <span class="k">def</span> <span class="nf">_lit</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-122"><a href="#Column-122"><span class="linenos">122</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span> +</span><span id="Column-123"><a href="#Column-123"><span class="linenos">123</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="bp">cls</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">v</span><span class="p">)</span><span class="o">.</span><span class="n">alias</span><span class="p">(</span><span class="n">k</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">value</span><span class="o">.</span><span class="n">items</span><span class="p">()]</span> +</span><span id="Column-124"><a href="#Column-124"><span class="linenos">124</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Struct</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="n">columns</span><span class="p">))</span> +</span><span id="Column-125"><a href="#Column-125"><span class="linenos">125</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">convert</span><span class="p">(</span><span class="n">value</span><span class="p">))</span> +</span><span id="Column-126"><a href="#Column-126"><span class="linenos">126</span></a> +</span><span id="Column-127"><a href="#Column-127"><span class="linenos">127</span></a> <span class="nd">@classmethod</span> +</span><span id="Column-128"><a href="#Column-128"><span class="linenos">128</span></a> <span class="k">def</span> <span class="nf">invoke_anonymous_function</span><span class="p">(</span> +</span><span id="Column-129"><a href="#Column-129"><span class="linenos">129</span></a> <span class="bp">cls</span><span class="p">,</span> <span class="n">column</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">],</span> <span class="n">func_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">]</span> +</span><span id="Column-130"><a href="#Column-130"><span class="linenos">130</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-131"><a href="#Column-131"><span class="linenos">131</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="p">[]</span> <span class="k">if</span> <span class="n">column</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="p">[</span><span class="bp">cls</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">column</span><span class="p">)]</span> +</span><span id="Column-132"><a href="#Column-132"><span class="linenos">132</span></a> <span class="n">column_args</span> <span class="o">=</span> <span class="p">[</span><span class="bp">cls</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">arg</span><span class="p">)</span> <span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">args</span><span class="p">]</span> +</span><span id="Column-133"><a href="#Column-133"><span class="linenos">133</span></a> <span class="n">expressions</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">columns</span> <span class="o">+</span> <span class="n">column_args</span><span class="p">]</span> +</span><span id="Column-134"><a href="#Column-134"><span class="linenos">134</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Anonymous</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">func_name</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span> <span class="n">expressions</span><span class="o">=</span><span class="n">expressions</span><span class="p">)</span> +</span><span id="Column-135"><a href="#Column-135"><span class="linenos">135</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span><span id="Column-136"><a href="#Column-136"><span class="linenos">136</span></a> +</span><span id="Column-137"><a href="#Column-137"><span class="linenos">137</span></a> <span class="nd">@classmethod</span> +</span><span id="Column-138"><a href="#Column-138"><span class="linenos">138</span></a> <span class="k">def</span> <span class="nf">invoke_expression_over_column</span><span class="p">(</span> +</span><span id="Column-139"><a href="#Column-139"><span class="linenos">139</span></a> <span class="bp">cls</span><span class="p">,</span> <span class="n">column</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">],</span> <span class="n">callable_expression</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span> +</span><span id="Column-140"><a href="#Column-140"><span class="linenos">140</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-141"><a href="#Column-141"><span class="linenos">141</span></a> <span class="n">ensured_column</span> <span class="o">=</span> <span class="kc">None</span> <span class="k">if</span> <span class="n">column</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="bp">cls</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">column</span><span class="p">)</span> +</span><span id="Column-142"><a href="#Column-142"><span class="linenos">142</span></a> <span class="n">ensure_expression_values</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="Column-143"><a href="#Column-143"><span class="linenos">143</span></a> <span class="n">k</span><span class="p">:</span> <span class="p">[</span><span class="n">Column</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">v</span><span class="p">]</span> +</span><span id="Column-144"><a href="#Column-144"><span class="linenos">144</span></a> <span class="k">if</span> <span class="n">is_iterable</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> +</span><span id="Column-145"><a href="#Column-145"><span class="linenos">145</span></a> <span class="k">else</span> <span class="n">Column</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">v</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> +</span><span id="Column-146"><a href="#Column-146"><span class="linenos">146</span></a> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> +</span><span id="Column-147"><a href="#Column-147"><span class="linenos">147</span></a> <span class="p">}</span> +</span><span id="Column-148"><a href="#Column-148"><span class="linenos">148</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="Column-149"><a href="#Column-149"><span class="linenos">149</span></a> <span class="n">callable_expression</span><span class="p">(</span><span class="o">**</span><span class="n">ensure_expression_values</span><span class="p">)</span> +</span><span id="Column-150"><a href="#Column-150"><span class="linenos">150</span></a> <span class="k">if</span> <span class="n">ensured_column</span> <span class="ow">is</span> <span class="kc">None</span> +</span><span id="Column-151"><a href="#Column-151"><span class="linenos">151</span></a> <span class="k">else</span> <span class="n">callable_expression</span><span class="p">(</span> +</span><span id="Column-152"><a href="#Column-152"><span class="linenos">152</span></a> <span class="n">this</span><span class="o">=</span><span class="n">ensured_column</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="o">**</span><span class="n">ensure_expression_values</span> +</span><span id="Column-153"><a href="#Column-153"><span class="linenos">153</span></a> <span class="p">)</span> +</span><span id="Column-154"><a href="#Column-154"><span class="linenos">154</span></a> <span class="p">)</span> +</span><span id="Column-155"><a href="#Column-155"><span class="linenos">155</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span><span id="Column-156"><a href="#Column-156"><span class="linenos">156</span></a> +</span><span id="Column-157"><a href="#Column-157"><span class="linenos">157</span></a> <span class="k">def</span> <span class="nf">binary_op</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">klass</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-158"><a href="#Column-158"><span class="linenos">158</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span> +</span><span id="Column-159"><a href="#Column-159"><span class="linenos">159</span></a> <span class="n">klass</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">Column</span><span class="p">(</span><span class="n">other</span><span class="p">)</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> +</span><span id="Column-160"><a href="#Column-160"><span class="linenos">160</span></a> <span class="p">)</span> +</span><span id="Column-161"><a href="#Column-161"><span class="linenos">161</span></a> +</span><span id="Column-162"><a href="#Column-162"><span class="linenos">162</span></a> <span class="k">def</span> <span class="nf">inverse_binary_op</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">klass</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-163"><a href="#Column-163"><span class="linenos">163</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span> +</span><span id="Column-164"><a href="#Column-164"><span class="linenos">164</span></a> <span class="n">klass</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">Column</span><span class="p">(</span><span class="n">other</span><span class="p">)</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> +</span><span id="Column-165"><a href="#Column-165"><span class="linenos">165</span></a> <span class="p">)</span> +</span><span id="Column-166"><a href="#Column-166"><span class="linenos">166</span></a> +</span><span id="Column-167"><a href="#Column-167"><span class="linenos">167</span></a> <span class="k">def</span> <span class="nf">unary_op</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">klass</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-168"><a href="#Column-168"><span class="linenos">168</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">klass</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">))</span> +</span><span id="Column-169"><a href="#Column-169"><span class="linenos">169</span></a> +</span><span id="Column-170"><a href="#Column-170"><span class="linenos">170</span></a> <span class="nd">@property</span> +</span><span id="Column-171"><a href="#Column-171"><span class="linenos">171</span></a> <span class="k">def</span> <span class="nf">is_alias</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> +</span><span id="Column-172"><a href="#Column-172"><span class="linenos">172</span></a> <span class="k">return</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Alias</span><span class="p">)</span> +</span><span id="Column-173"><a href="#Column-173"><span class="linenos">173</span></a> +</span><span id="Column-174"><a href="#Column-174"><span class="linenos">174</span></a> <span class="nd">@property</span> +</span><span id="Column-175"><a href="#Column-175"><span class="linenos">175</span></a> <span class="k">def</span> <span class="nf">is_column</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> +</span><span id="Column-176"><a href="#Column-176"><span class="linenos">176</span></a> <span class="k">return</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">)</span> +</span><span id="Column-177"><a href="#Column-177"><span class="linenos">177</span></a> +</span><span id="Column-178"><a href="#Column-178"><span class="linenos">178</span></a> <span class="nd">@property</span> +</span><span id="Column-179"><a href="#Column-179"><span class="linenos">179</span></a> <span class="k">def</span> <span class="nf">column_expression</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">:</span> +</span><span id="Column-180"><a href="#Column-180"><span class="linenos">180</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">unalias</span><span class="p">()</span> +</span><span id="Column-181"><a href="#Column-181"><span class="linenos">181</span></a> +</span><span id="Column-182"><a href="#Column-182"><span class="linenos">182</span></a> <span class="nd">@property</span> +</span><span id="Column-183"><a href="#Column-183"><span class="linenos">183</span></a> <span class="k">def</span> <span class="nf">alias_or_name</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Column-184"><a href="#Column-184"><span class="linenos">184</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">alias_or_name</span> +</span><span id="Column-185"><a href="#Column-185"><span class="linenos">185</span></a> +</span><span id="Column-186"><a href="#Column-186"><span class="linenos">186</span></a> <span class="nd">@classmethod</span> +</span><span id="Column-187"><a href="#Column-187"><span class="linenos">187</span></a> <span class="k">def</span> <span class="nf">ensure_literal</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-188"><a href="#Column-188"><span class="linenos">188</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.functions</span> <span class="kn">import</span> <span class="n">lit</span> +</span><span id="Column-189"><a href="#Column-189"><span class="linenos">189</span></a> +</span><span id="Column-190"><a href="#Column-190"><span class="linenos">190</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="bp">cls</span><span class="p">):</span> +</span><span id="Column-191"><a href="#Column-191"><span class="linenos">191</span></a> <span class="n">value</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">expression</span> +</span><span id="Column-192"><a href="#Column-192"><span class="linenos">192</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="p">):</span> +</span><span id="Column-193"><a href="#Column-193"><span class="linenos">193</span></a> <span class="k">return</span> <span class="n">lit</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> +</span><span id="Column-194"><a href="#Column-194"><span class="linenos">194</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> +</span><span id="Column-195"><a href="#Column-195"><span class="linenos">195</span></a> +</span><span id="Column-196"><a href="#Column-196"><span class="linenos">196</span></a> <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-197"><a href="#Column-197"><span class="linenos">197</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span> +</span><span id="Column-198"><a href="#Column-198"><span class="linenos">198</span></a> +</span><span id="Column-199"><a href="#Column-199"><span class="linenos">199</span></a> <span class="k">def</span> <span class="nf">set_table_name</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">table_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-200"><a href="#Column-200"><span class="linenos">200</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> <span class="k">if</span> <span class="n">copy</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span> +</span><span id="Column-201"><a href="#Column-201"><span class="linenos">201</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"table"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">to_identifier</span><span class="p">(</span><span class="n">table_name</span><span class="p">))</span> +</span><span id="Column-202"><a href="#Column-202"><span class="linenos">202</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="Column-203"><a href="#Column-203"><span class="linenos">203</span></a> +</span><span id="Column-204"><a href="#Column-204"><span class="linenos">204</span></a> <span class="k">def</span> <span class="nf">sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Column-205"><a href="#Column-205"><span class="linenos">205</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="s2">"dialect"</span><span class="p">:</span> <span class="s2">"spark"</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">})</span> +</span><span id="Column-206"><a href="#Column-206"><span class="linenos">206</span></a> +</span><span id="Column-207"><a href="#Column-207"><span class="linenos">207</span></a> <span class="k">def</span> <span class="nf">alias</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-208"><a href="#Column-208"><span class="linenos">208</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">alias_</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span> +</span><span id="Column-209"><a href="#Column-209"><span class="linenos">209</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span><span id="Column-210"><a href="#Column-210"><span class="linenos">210</span></a> +</span><span id="Column-211"><a href="#Column-211"><span class="linenos">211</span></a> <span class="k">def</span> <span class="nf">asc</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-212"><a href="#Column-212"><span class="linenos">212</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Ordered</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">desc</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">nulls_first</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="Column-213"><a href="#Column-213"><span class="linenos">213</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span><span id="Column-214"><a href="#Column-214"><span class="linenos">214</span></a> +</span><span id="Column-215"><a href="#Column-215"><span class="linenos">215</span></a> <span class="k">def</span> <span class="nf">desc</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-216"><a href="#Column-216"><span class="linenos">216</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Ordered</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">desc</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nulls_first</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +</span><span id="Column-217"><a href="#Column-217"><span class="linenos">217</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span><span id="Column-218"><a href="#Column-218"><span class="linenos">218</span></a> +</span><span id="Column-219"><a href="#Column-219"><span class="linenos">219</span></a> <span class="n">asc_nulls_first</span> <span class="o">=</span> <span class="n">asc</span> +</span><span id="Column-220"><a href="#Column-220"><span class="linenos">220</span></a> +</span><span id="Column-221"><a href="#Column-221"><span class="linenos">221</span></a> <span class="k">def</span> <span class="nf">asc_nulls_last</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-222"><a href="#Column-222"><span class="linenos">222</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Ordered</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">desc</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">nulls_first</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +</span><span id="Column-223"><a href="#Column-223"><span class="linenos">223</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span><span id="Column-224"><a href="#Column-224"><span class="linenos">224</span></a> +</span><span id="Column-225"><a href="#Column-225"><span class="linenos">225</span></a> <span class="k">def</span> <span class="nf">desc_nulls_first</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-226"><a href="#Column-226"><span class="linenos">226</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Ordered</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">desc</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nulls_first</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="Column-227"><a href="#Column-227"><span class="linenos">227</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span><span id="Column-228"><a href="#Column-228"><span class="linenos">228</span></a> +</span><span id="Column-229"><a href="#Column-229"><span class="linenos">229</span></a> <span class="n">desc_nulls_last</span> <span class="o">=</span> <span class="n">desc</span> +</span><span id="Column-230"><a href="#Column-230"><span class="linenos">230</span></a> +</span><span id="Column-231"><a href="#Column-231"><span class="linenos">231</span></a> <span class="k">def</span> <span class="nf">when</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">condition</span><span class="p">:</span> <span class="n">Column</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Any</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-232"><a href="#Column-232"><span class="linenos">232</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.functions</span> <span class="kn">import</span> <span class="n">when</span> +</span><span id="Column-233"><a href="#Column-233"><span class="linenos">233</span></a> +</span><span id="Column-234"><a href="#Column-234"><span class="linenos">234</span></a> <span class="n">column_with_if</span> <span class="o">=</span> <span class="n">when</span><span class="p">(</span><span class="n">condition</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> +</span><span id="Column-235"><a href="#Column-235"><span class="linenos">235</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Case</span><span class="p">):</span> +</span><span id="Column-236"><a href="#Column-236"><span class="linenos">236</span></a> <span class="k">return</span> <span class="n">column_with_if</span> +</span><span id="Column-237"><a href="#Column-237"><span class="linenos">237</span></a> <span class="n">new_column</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="Column-238"><a href="#Column-238"><span class="linenos">238</span></a> <span class="n">new_column</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"ifs"</span><span class="p">]</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">column_with_if</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"ifs"</span><span class="p">])</span> +</span><span id="Column-239"><a href="#Column-239"><span class="linenos">239</span></a> <span class="k">return</span> <span class="n">new_column</span> +</span><span id="Column-240"><a href="#Column-240"><span class="linenos">240</span></a> +</span><span id="Column-241"><a href="#Column-241"><span class="linenos">241</span></a> <span class="k">def</span> <span class="nf">otherwise</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Any</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-242"><a href="#Column-242"><span class="linenos">242</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.functions</span> <span class="kn">import</span> <span class="n">lit</span> +</span><span id="Column-243"><a href="#Column-243"><span class="linenos">243</span></a> +</span><span id="Column-244"><a href="#Column-244"><span class="linenos">244</span></a> <span class="n">true_value</span> <span class="o">=</span> <span class="n">value</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">Column</span><span class="p">)</span> <span class="k">else</span> <span class="n">lit</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> +</span><span id="Column-245"><a href="#Column-245"><span class="linenos">245</span></a> <span class="n">new_column</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="Column-246"><a href="#Column-246"><span class="linenos">246</span></a> <span class="n">new_column</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"default"</span><span class="p">,</span> <span class="n">true_value</span><span class="o">.</span><span class="n">column_expression</span><span class="p">)</span> +</span><span id="Column-247"><a href="#Column-247"><span class="linenos">247</span></a> <span class="k">return</span> <span class="n">new_column</span> +</span><span id="Column-248"><a href="#Column-248"><span class="linenos">248</span></a> +</span><span id="Column-249"><a href="#Column-249"><span class="linenos">249</span></a> <span class="k">def</span> <span class="nf">isNull</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-250"><a href="#Column-250"><span class="linenos">250</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Is</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Null</span><span class="p">())</span> +</span><span id="Column-251"><a href="#Column-251"><span class="linenos">251</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span><span id="Column-252"><a href="#Column-252"><span class="linenos">252</span></a> +</span><span id="Column-253"><a href="#Column-253"><span class="linenos">253</span></a> <span class="k">def</span> <span class="nf">isNotNull</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-254"><a href="#Column-254"><span class="linenos">254</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Not</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Is</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Null</span><span class="p">()))</span> +</span><span id="Column-255"><a href="#Column-255"><span class="linenos">255</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span><span id="Column-256"><a href="#Column-256"><span class="linenos">256</span></a> +</span><span id="Column-257"><a href="#Column-257"><span class="linenos">257</span></a> <span class="k">def</span> <span class="nf">cast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dataType</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">DataType</span><span class="p">]):</span> +</span><span id="Column-258"><a href="#Column-258"><span class="linenos">258</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Column-259"><a href="#Column-259"><span class="linenos">259</span></a><span class="sd"> Functionality Difference: PySpark cast accepts a datatype instance of the datatype class</span> +</span><span id="Column-260"><a href="#Column-260"><span class="linenos">260</span></a><span class="sd"> Sqlglot doesn't currently replicate this class so it only accepts a string</span> +</span><span id="Column-261"><a href="#Column-261"><span class="linenos">261</span></a><span class="sd"> """</span> +</span><span id="Column-262"><a href="#Column-262"><span class="linenos">262</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dataType</span><span class="p">,</span> <span class="n">DataType</span><span class="p">):</span> +</span><span id="Column-263"><a href="#Column-263"><span class="linenos">263</span></a> <span class="n">dataType</span> <span class="o">=</span> <span class="n">dataType</span><span class="o">.</span><span class="n">simpleString</span><span class="p">()</span> +</span><span id="Column-264"><a href="#Column-264"><span class="linenos">264</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">dataType</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="s2">"spark"</span><span class="p">))</span> +</span><span id="Column-265"><a href="#Column-265"><span class="linenos">265</span></a> +</span><span id="Column-266"><a href="#Column-266"><span class="linenos">266</span></a> <span class="k">def</span> <span class="nf">startswith</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Column</span><span class="p">])</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-267"><a href="#Column-267"><span class="linenos">267</span></a> <span class="n">value</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">Column</span><span class="p">)</span> <span class="k">else</span> <span class="n">value</span> +</span><span id="Column-268"><a href="#Column-268"><span class="linenos">268</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">invoke_anonymous_function</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">"STARTSWITH"</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> +</span><span id="Column-269"><a href="#Column-269"><span class="linenos">269</span></a> +</span><span id="Column-270"><a href="#Column-270"><span class="linenos">270</span></a> <span class="k">def</span> <span class="nf">endswith</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Column</span><span class="p">])</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-271"><a href="#Column-271"><span class="linenos">271</span></a> <span class="n">value</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">Column</span><span class="p">)</span> <span class="k">else</span> <span class="n">value</span> +</span><span id="Column-272"><a href="#Column-272"><span class="linenos">272</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">invoke_anonymous_function</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">"ENDSWITH"</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> +</span><span id="Column-273"><a href="#Column-273"><span class="linenos">273</span></a> +</span><span id="Column-274"><a href="#Column-274"><span class="linenos">274</span></a> <span class="k">def</span> <span class="nf">rlike</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">regexp</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-275"><a href="#Column-275"><span class="linenos">275</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">invoke_expression_over_column</span><span class="p">(</span> +</span><span id="Column-276"><a href="#Column-276"><span class="linenos">276</span></a> <span class="n">column</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">callable_expression</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">RegexpLike</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">regexp</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> +</span><span id="Column-277"><a href="#Column-277"><span class="linenos">277</span></a> <span class="p">)</span> +</span><span id="Column-278"><a href="#Column-278"><span class="linenos">278</span></a> +</span><span id="Column-279"><a href="#Column-279"><span class="linenos">279</span></a> <span class="k">def</span> <span class="nf">like</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span> +</span><span id="Column-280"><a href="#Column-280"><span class="linenos">280</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">invoke_expression_over_column</span><span class="p">(</span> +</span><span id="Column-281"><a href="#Column-281"><span class="linenos">281</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Like</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">other</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> +</span><span id="Column-282"><a href="#Column-282"><span class="linenos">282</span></a> <span class="p">)</span> +</span><span id="Column-283"><a href="#Column-283"><span class="linenos">283</span></a> +</span><span id="Column-284"><a href="#Column-284"><span class="linenos">284</span></a> <span class="k">def</span> <span class="nf">ilike</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span> +</span><span id="Column-285"><a href="#Column-285"><span class="linenos">285</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">invoke_expression_over_column</span><span class="p">(</span> +</span><span id="Column-286"><a href="#Column-286"><span class="linenos">286</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">ILike</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">other</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> +</span><span id="Column-287"><a href="#Column-287"><span class="linenos">287</span></a> <span class="p">)</span> +</span><span id="Column-288"><a href="#Column-288"><span class="linenos">288</span></a> +</span><span id="Column-289"><a href="#Column-289"><span class="linenos">289</span></a> <span class="k">def</span> <span class="nf">substr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">startPos</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="n">Column</span><span class="p">],</span> <span class="n">length</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="n">Column</span><span class="p">])</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-290"><a href="#Column-290"><span class="linenos">290</span></a> <span class="n">startPos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">startPos</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">startPos</span><span class="p">,</span> <span class="n">Column</span><span class="p">)</span> <span class="k">else</span> <span class="n">startPos</span> +</span><span id="Column-291"><a href="#Column-291"><span class="linenos">291</span></a> <span class="n">length</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">length</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">length</span><span class="p">,</span> <span class="n">Column</span><span class="p">)</span> <span class="k">else</span> <span class="n">length</span> +</span><span id="Column-292"><a href="#Column-292"><span class="linenos">292</span></a> <span class="k">return</span> <span class="n">Column</span><span class="o">.</span><span class="n">invoke_expression_over_column</span><span class="p">(</span> +</span><span id="Column-293"><a href="#Column-293"><span class="linenos">293</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Substring</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="n">startPos</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">length</span><span class="o">=</span><span class="n">length</span><span class="o">.</span><span class="n">expression</span> +</span><span id="Column-294"><a href="#Column-294"><span class="linenos">294</span></a> <span class="p">)</span> +</span><span id="Column-295"><a href="#Column-295"><span class="linenos">295</span></a> +</span><span id="Column-296"><a href="#Column-296"><span class="linenos">296</span></a> <span class="k">def</span> <span class="nf">isin</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">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Iterable</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">]]):</span> +</span><span id="Column-297"><a href="#Column-297"><span class="linenos">297</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="n">flatten</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">cols</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">set</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">))</span> <span class="k">else</span> <span class="n">cols</span> <span class="c1"># type: ignore</span> +</span><span id="Column-298"><a href="#Column-298"><span class="linenos">298</span></a> <span class="n">expressions</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">columns</span><span class="p">]</span> +</span><span id="Column-299"><a href="#Column-299"><span class="linenos">299</span></a> <span class="k">return</span> <span class="n">Column</span><span class="o">.</span><span class="n">invoke_expression_over_column</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">In</span><span class="p">,</span> <span class="n">expressions</span><span class="o">=</span><span class="n">expressions</span><span class="p">)</span> <span class="c1"># type: ignore</span> +</span><span id="Column-300"><a href="#Column-300"><span class="linenos">300</span></a> +</span><span id="Column-301"><a href="#Column-301"><span class="linenos">301</span></a> <span class="k">def</span> <span class="nf">between</span><span class="p">(</span> +</span><span id="Column-302"><a href="#Column-302"><span class="linenos">302</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="Column-303"><a href="#Column-303"><span class="linenos">303</span></a> <span class="n">lowerBound</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">],</span> +</span><span id="Column-304"><a href="#Column-304"><span class="linenos">304</span></a> <span class="n">upperBound</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">],</span> +</span><span id="Column-305"><a href="#Column-305"><span class="linenos">305</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-306"><a href="#Column-306"><span class="linenos">306</span></a> <span class="n">lower_bound_exp</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="Column-307"><a href="#Column-307"><span class="linenos">307</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">lowerBound</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">lowerBound</span><span class="p">,</span> <span class="n">Column</span><span class="p">)</span> <span class="k">else</span> <span class="n">lowerBound</span> +</span><span id="Column-308"><a href="#Column-308"><span class="linenos">308</span></a> <span class="p">)</span> +</span><span id="Column-309"><a href="#Column-309"><span class="linenos">309</span></a> <span class="n">upper_bound_exp</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="Column-310"><a href="#Column-310"><span class="linenos">310</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">upperBound</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">upperBound</span><span class="p">,</span> <span class="n">Column</span><span class="p">)</span> <span class="k">else</span> <span class="n">upperBound</span> +</span><span id="Column-311"><a href="#Column-311"><span class="linenos">311</span></a> <span class="p">)</span> +</span><span id="Column-312"><a href="#Column-312"><span class="linenos">312</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span> +</span><span id="Column-313"><a href="#Column-313"><span class="linenos">313</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Between</span><span class="p">(</span> +</span><span id="Column-314"><a href="#Column-314"><span class="linenos">314</span></a> <span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> +</span><span id="Column-315"><a href="#Column-315"><span class="linenos">315</span></a> <span class="n">low</span><span class="o">=</span><span class="n">lower_bound_exp</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> +</span><span id="Column-316"><a href="#Column-316"><span class="linenos">316</span></a> <span class="n">high</span><span class="o">=</span><span class="n">upper_bound_exp</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> +</span><span id="Column-317"><a href="#Column-317"><span class="linenos">317</span></a> <span class="p">)</span> +</span><span id="Column-318"><a href="#Column-318"><span class="linenos">318</span></a> <span class="p">)</span> +</span><span id="Column-319"><a href="#Column-319"><span class="linenos">319</span></a> +</span><span id="Column-320"><a href="#Column-320"><span class="linenos">320</span></a> <span class="k">def</span> <span class="nf">over</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">window</span><span class="p">:</span> <span class="n">WindowSpec</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column-321"><a href="#Column-321"><span class="linenos">321</span></a> <span class="n">window_expression</span> <span class="o">=</span> <span class="n">window</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="Column-322"><a href="#Column-322"><span class="linenos">322</span></a> <span class="n">window_expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"this"</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">)</span> +</span><span id="Column-323"><a href="#Column-323"><span class="linenos">323</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">window_expression</span><span class="p">)</span> +</span></pre></div> + + + + + <div id="Column.__init__" class="classattr"> + <input id="Column.__init__-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="name">Column</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="n">expression</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700332259696'</span><span class="o">></span><span class="p">,</span> <span class="n"><a href="../expressions.html#Expression">sqlglot.expressions.Expression</a></span><span class="p">,</span> <span class="n">NoneType</span><span class="p">]</span></span>)</span> + + <label class="view-source-button" for="Column.__init__-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.__init__"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.__init__-17"><a href="#Column.__init__-17"><span class="linenos">17</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]]):</span> +</span><span id="Column.__init__-18"><a href="#Column.__init__-18"><span class="linenos">18</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">Column</span><span class="p">):</span> +</span><span id="Column.__init__-19"><a href="#Column.__init__-19"><span class="linenos">19</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span> <span class="c1"># type: ignore</span> +</span><span id="Column.__init__-20"><a href="#Column.__init__-20"><span class="linenos">20</span></a> <span class="k">elif</span> <span class="n">expression</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">)):</span> +</span><span id="Column.__init__-21"><a href="#Column.__init__-21"><span class="linenos">21</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> <span class="c1"># type: ignore</span> +</span><span id="Column.__init__-22"><a href="#Column.__init__-22"><span class="linenos">22</span></a> +</span><span id="Column.__init__-23"><a href="#Column.__init__-23"><span class="linenos">23</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">sqlglot</span><span class="o">.</span><span class="n">maybe_parse</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="s2">"spark"</span><span class="p">)</span> +</span><span id="Column.__init__-24"><a href="#Column.__init__-24"><span class="linenos">24</span></a> <span class="k">if</span> <span class="n">expression</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> +</span><span id="Column.__init__-25"><a href="#Column.__init__-25"><span class="linenos">25</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Could not parse </span><span class="si">{</span><span class="n">expression</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="Column.__init__-26"><a href="#Column.__init__-26"><span class="linenos">26</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span> <span class="o">=</span> <span class="n">expression</span> +</span></pre></div> + + + + + </div> + <div id="Column.ensure_col" class="classattr"> + <input id="Column.ensure_col-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@classmethod</div> + + <span class="def">def</span> + <span class="name">ensure_col</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">cls</span>,</span><span class="param"> <span class="n">value</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700330611696'</span><span class="o">></span><span class="p">,</span> <span class="n"><a href="../expressions.html#Expression">sqlglot.expressions.Expression</a></span><span class="p">,</span> <span class="n">NoneType</span><span class="p">]</span></span><span class="return-annotation">):</span></span> + + <label class="view-source-button" for="Column.ensure_col-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.ensure_col"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.ensure_col-112"><a href="#Column.ensure_col-112"><span class="linenos">112</span></a> <span class="nd">@classmethod</span> +</span><span id="Column.ensure_col-113"><a href="#Column.ensure_col-113"><span class="linenos">113</span></a> <span class="k">def</span> <span class="nf">ensure_col</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]]):</span> +</span><span id="Column.ensure_col-114"><a href="#Column.ensure_col-114"><span class="linenos">114</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.ensure_cols" class="classattr"> + <input id="Column.ensure_cols-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@classmethod</div> + + <span class="def">def</span> + <span class="name">ensure_cols</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">cls</span>,</span><span class="param"> <span class="n">args</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700330840736'</span><span class="o">></span><span class="p">,</span> <span class="n"><a href="../expressions.html#Expression">sqlglot.expressions.Expression</a></span><span class="p">]]</span></span><span class="return-annotation">) -> <span class="n">List</span><span class="p">[</span><span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span><span class="p">]</span>:</span></span> + + <label class="view-source-button" for="Column.ensure_cols-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.ensure_cols"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.ensure_cols-116"><a href="#Column.ensure_cols-116"><span class="linenos">116</span></a> <span class="nd">@classmethod</span> +</span><span id="Column.ensure_cols-117"><a href="#Column.ensure_cols-117"><span class="linenos">117</span></a> <span class="k">def</span> <span class="nf">ensure_cols</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">args</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]])</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Column</span><span class="p">]:</span> +</span><span id="Column.ensure_cols-118"><a href="#Column.ensure_cols-118"><span class="linenos">118</span></a> <span class="k">return</span> <span class="p">[</span><span class="bp">cls</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">Column</span><span class="p">)</span> <span class="k">else</span> <span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">args</span><span class="p">]</span> +</span></pre></div> + + + + + </div> + <div id="Column.invoke_anonymous_function" class="classattr"> + <input id="Column.invoke_anonymous_function-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@classmethod</div> + + <span class="def">def</span> + <span class="name">invoke_anonymous_function</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">cls</span>,</span><span class="param"> <span class="n">column</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700330924096'</span><span class="o">></span><span class="p">]</span>,</span><span class="param"> <span class="n">func_name</span><span class="p">:</span> <span class="nb">str</span>,</span><span class="param"> <span class="o">*</span><span class="n">args</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700330964112'</span><span class="o">></span><span class="p">]</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.invoke_anonymous_function-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.invoke_anonymous_function"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.invoke_anonymous_function-127"><a href="#Column.invoke_anonymous_function-127"><span class="linenos">127</span></a> <span class="nd">@classmethod</span> +</span><span id="Column.invoke_anonymous_function-128"><a href="#Column.invoke_anonymous_function-128"><span class="linenos">128</span></a> <span class="k">def</span> <span class="nf">invoke_anonymous_function</span><span class="p">(</span> +</span><span id="Column.invoke_anonymous_function-129"><a href="#Column.invoke_anonymous_function-129"><span class="linenos">129</span></a> <span class="bp">cls</span><span class="p">,</span> <span class="n">column</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">],</span> <span class="n">func_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">]</span> +</span><span id="Column.invoke_anonymous_function-130"><a href="#Column.invoke_anonymous_function-130"><span class="linenos">130</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.invoke_anonymous_function-131"><a href="#Column.invoke_anonymous_function-131"><span class="linenos">131</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="p">[]</span> <span class="k">if</span> <span class="n">column</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="p">[</span><span class="bp">cls</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">column</span><span class="p">)]</span> +</span><span id="Column.invoke_anonymous_function-132"><a href="#Column.invoke_anonymous_function-132"><span class="linenos">132</span></a> <span class="n">column_args</span> <span class="o">=</span> <span class="p">[</span><span class="bp">cls</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">arg</span><span class="p">)</span> <span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">args</span><span class="p">]</span> +</span><span id="Column.invoke_anonymous_function-133"><a href="#Column.invoke_anonymous_function-133"><span class="linenos">133</span></a> <span class="n">expressions</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">columns</span> <span class="o">+</span> <span class="n">column_args</span><span class="p">]</span> +</span><span id="Column.invoke_anonymous_function-134"><a href="#Column.invoke_anonymous_function-134"><span class="linenos">134</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Anonymous</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">func_name</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span> <span class="n">expressions</span><span class="o">=</span><span class="n">expressions</span><span class="p">)</span> +</span><span id="Column.invoke_anonymous_function-135"><a href="#Column.invoke_anonymous_function-135"><span class="linenos">135</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.invoke_expression_over_column" class="classattr"> + <input id="Column.invoke_expression_over_column-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@classmethod</div> + + <span class="def">def</span> + <span class="name">invoke_expression_over_column</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">cls</span>,</span><span class="param"> <span class="n">column</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700331029648'</span><span class="o">></span><span class="p">]</span>,</span><span class="param"> <span class="n">callable_expression</span><span class="p">:</span> <span class="n">Callable</span>,</span><span class="param"> <span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.invoke_expression_over_column-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.invoke_expression_over_column"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.invoke_expression_over_column-137"><a href="#Column.invoke_expression_over_column-137"><span class="linenos">137</span></a> <span class="nd">@classmethod</span> +</span><span id="Column.invoke_expression_over_column-138"><a href="#Column.invoke_expression_over_column-138"><span class="linenos">138</span></a> <span class="k">def</span> <span class="nf">invoke_expression_over_column</span><span class="p">(</span> +</span><span id="Column.invoke_expression_over_column-139"><a href="#Column.invoke_expression_over_column-139"><span class="linenos">139</span></a> <span class="bp">cls</span><span class="p">,</span> <span class="n">column</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">],</span> <span class="n">callable_expression</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span> +</span><span id="Column.invoke_expression_over_column-140"><a href="#Column.invoke_expression_over_column-140"><span class="linenos">140</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.invoke_expression_over_column-141"><a href="#Column.invoke_expression_over_column-141"><span class="linenos">141</span></a> <span class="n">ensured_column</span> <span class="o">=</span> <span class="kc">None</span> <span class="k">if</span> <span class="n">column</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="bp">cls</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">column</span><span class="p">)</span> +</span><span id="Column.invoke_expression_over_column-142"><a href="#Column.invoke_expression_over_column-142"><span class="linenos">142</span></a> <span class="n">ensure_expression_values</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="Column.invoke_expression_over_column-143"><a href="#Column.invoke_expression_over_column-143"><span class="linenos">143</span></a> <span class="n">k</span><span class="p">:</span> <span class="p">[</span><span class="n">Column</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">v</span><span class="p">]</span> +</span><span id="Column.invoke_expression_over_column-144"><a href="#Column.invoke_expression_over_column-144"><span class="linenos">144</span></a> <span class="k">if</span> <span class="n">is_iterable</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> +</span><span id="Column.invoke_expression_over_column-145"><a href="#Column.invoke_expression_over_column-145"><span class="linenos">145</span></a> <span class="k">else</span> <span class="n">Column</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">v</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> +</span><span id="Column.invoke_expression_over_column-146"><a href="#Column.invoke_expression_over_column-146"><span class="linenos">146</span></a> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> +</span><span id="Column.invoke_expression_over_column-147"><a href="#Column.invoke_expression_over_column-147"><span class="linenos">147</span></a> <span class="p">}</span> +</span><span id="Column.invoke_expression_over_column-148"><a href="#Column.invoke_expression_over_column-148"><span class="linenos">148</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="Column.invoke_expression_over_column-149"><a href="#Column.invoke_expression_over_column-149"><span class="linenos">149</span></a> <span class="n">callable_expression</span><span class="p">(</span><span class="o">**</span><span class="n">ensure_expression_values</span><span class="p">)</span> +</span><span id="Column.invoke_expression_over_column-150"><a href="#Column.invoke_expression_over_column-150"><span class="linenos">150</span></a> <span class="k">if</span> <span class="n">ensured_column</span> <span class="ow">is</span> <span class="kc">None</span> +</span><span id="Column.invoke_expression_over_column-151"><a href="#Column.invoke_expression_over_column-151"><span class="linenos">151</span></a> <span class="k">else</span> <span class="n">callable_expression</span><span class="p">(</span> +</span><span id="Column.invoke_expression_over_column-152"><a href="#Column.invoke_expression_over_column-152"><span class="linenos">152</span></a> <span class="n">this</span><span class="o">=</span><span class="n">ensured_column</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="o">**</span><span class="n">ensure_expression_values</span> +</span><span id="Column.invoke_expression_over_column-153"><a href="#Column.invoke_expression_over_column-153"><span class="linenos">153</span></a> <span class="p">)</span> +</span><span id="Column.invoke_expression_over_column-154"><a href="#Column.invoke_expression_over_column-154"><span class="linenos">154</span></a> <span class="p">)</span> +</span><span id="Column.invoke_expression_over_column-155"><a href="#Column.invoke_expression_over_column-155"><span class="linenos">155</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.binary_op" class="classattr"> + <input id="Column.binary_op-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">binary_op</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">klass</span><span class="p">:</span> <span class="n">Callable</span>,</span><span class="param"> <span class="n">other</span><span class="p">:</span> <span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700331083136'</span><span class="o">></span>,</span><span class="param"> <span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.binary_op-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.binary_op"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.binary_op-157"><a href="#Column.binary_op-157"><span class="linenos">157</span></a> <span class="k">def</span> <span class="nf">binary_op</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">klass</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.binary_op-158"><a href="#Column.binary_op-158"><span class="linenos">158</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span> +</span><span id="Column.binary_op-159"><a href="#Column.binary_op-159"><span class="linenos">159</span></a> <span class="n">klass</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">Column</span><span class="p">(</span><span class="n">other</span><span class="p">)</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> +</span><span id="Column.binary_op-160"><a href="#Column.binary_op-160"><span class="linenos">160</span></a> <span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.inverse_binary_op" class="classattr"> + <input id="Column.inverse_binary_op-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">inverse_binary_op</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">klass</span><span class="p">:</span> <span class="n">Callable</span>,</span><span class="param"> <span class="n">other</span><span class="p">:</span> <span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700331093216'</span><span class="o">></span>,</span><span class="param"> <span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.inverse_binary_op-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.inverse_binary_op"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.inverse_binary_op-162"><a href="#Column.inverse_binary_op-162"><span class="linenos">162</span></a> <span class="k">def</span> <span class="nf">inverse_binary_op</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">klass</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">ColumnOrLiteral</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.inverse_binary_op-163"><a href="#Column.inverse_binary_op-163"><span class="linenos">163</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span> +</span><span id="Column.inverse_binary_op-164"><a href="#Column.inverse_binary_op-164"><span class="linenos">164</span></a> <span class="n">klass</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">Column</span><span class="p">(</span><span class="n">other</span><span class="p">)</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> +</span><span id="Column.inverse_binary_op-165"><a href="#Column.inverse_binary_op-165"><span class="linenos">165</span></a> <span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.unary_op" class="classattr"> + <input id="Column.unary_op-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">unary_op</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">klass</span><span class="p">:</span> <span class="n">Callable</span>, </span><span class="param"><span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.unary_op-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.unary_op"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.unary_op-167"><a href="#Column.unary_op-167"><span class="linenos">167</span></a> <span class="k">def</span> <span class="nf">unary_op</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">klass</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.unary_op-168"><a href="#Column.unary_op-168"><span class="linenos">168</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">klass</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">))</span> +</span></pre></div> + + + + + </div> + <div id="Column.ensure_literal" class="classattr"> + <input id="Column.ensure_literal-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@classmethod</div> + + <span class="def">def</span> + <span class="name">ensure_literal</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">cls</span>, </span><span class="param"><span class="n">value</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.ensure_literal-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.ensure_literal"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.ensure_literal-186"><a href="#Column.ensure_literal-186"><span class="linenos">186</span></a> <span class="nd">@classmethod</span> +</span><span id="Column.ensure_literal-187"><a href="#Column.ensure_literal-187"><span class="linenos">187</span></a> <span class="k">def</span> <span class="nf">ensure_literal</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.ensure_literal-188"><a href="#Column.ensure_literal-188"><span class="linenos">188</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.functions</span> <span class="kn">import</span> <span class="n">lit</span> +</span><span id="Column.ensure_literal-189"><a href="#Column.ensure_literal-189"><span class="linenos">189</span></a> +</span><span id="Column.ensure_literal-190"><a href="#Column.ensure_literal-190"><span class="linenos">190</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="bp">cls</span><span class="p">):</span> +</span><span id="Column.ensure_literal-191"><a href="#Column.ensure_literal-191"><span class="linenos">191</span></a> <span class="n">value</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">expression</span> +</span><span id="Column.ensure_literal-192"><a href="#Column.ensure_literal-192"><span class="linenos">192</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="p">):</span> +</span><span id="Column.ensure_literal-193"><a href="#Column.ensure_literal-193"><span class="linenos">193</span></a> <span class="k">return</span> <span class="n">lit</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> +</span><span id="Column.ensure_literal-194"><a href="#Column.ensure_literal-194"><span class="linenos">194</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.copy" class="classattr"> + <input id="Column.copy-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">copy</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.copy-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.copy"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.copy-196"><a href="#Column.copy-196"><span class="linenos">196</span></a> <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.copy-197"><a href="#Column.copy-197"><span class="linenos">197</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span> +</span></pre></div> + + + + + </div> + <div id="Column.set_table_name" class="classattr"> + <input id="Column.set_table_name-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">set_table_name</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">table_name</span><span class="p">:</span> <span class="nb">str</span>, </span><span class="param"><span class="n">copy</span><span class="o">=</span><span class="kc">False</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.set_table_name-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.set_table_name"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.set_table_name-199"><a href="#Column.set_table_name-199"><span class="linenos">199</span></a> <span class="k">def</span> <span class="nf">set_table_name</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">table_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.set_table_name-200"><a href="#Column.set_table_name-200"><span class="linenos">200</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> <span class="k">if</span> <span class="n">copy</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span> +</span><span id="Column.set_table_name-201"><a href="#Column.set_table_name-201"><span class="linenos">201</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"table"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">to_identifier</span><span class="p">(</span><span class="n">table_name</span><span class="p">))</span> +</span><span id="Column.set_table_name-202"><a href="#Column.set_table_name-202"><span class="linenos">202</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.sql" class="classattr"> + <input id="Column.sql-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">sql</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="nb">str</span>:</span></span> + + <label class="view-source-button" for="Column.sql-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.sql"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.sql-204"><a href="#Column.sql-204"><span class="linenos">204</span></a> <span class="k">def</span> <span class="nf">sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Column.sql-205"><a href="#Column.sql-205"><span class="linenos">205</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="s2">"dialect"</span><span class="p">:</span> <span class="s2">"spark"</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">})</span> +</span></pre></div> + + + + + </div> + <div id="Column.alias" class="classattr"> + <input id="Column.alias-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">alias</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">name</span><span class="p">:</span> <span class="nb">str</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.alias-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.alias"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.alias-207"><a href="#Column.alias-207"><span class="linenos">207</span></a> <span class="k">def</span> <span class="nf">alias</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.alias-208"><a href="#Column.alias-208"><span class="linenos">208</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">alias_</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span> +</span><span id="Column.alias-209"><a href="#Column.alias-209"><span class="linenos">209</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.asc" class="classattr"> + <input id="Column.asc-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">asc</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.asc-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.asc"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.asc-211"><a href="#Column.asc-211"><span class="linenos">211</span></a> <span class="k">def</span> <span class="nf">asc</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.asc-212"><a href="#Column.asc-212"><span class="linenos">212</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Ordered</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">desc</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">nulls_first</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="Column.asc-213"><a href="#Column.asc-213"><span class="linenos">213</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.desc" class="classattr"> + <input id="Column.desc-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">desc</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.desc-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.desc"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.desc-215"><a href="#Column.desc-215"><span class="linenos">215</span></a> <span class="k">def</span> <span class="nf">desc</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.desc-216"><a href="#Column.desc-216"><span class="linenos">216</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Ordered</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">desc</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nulls_first</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +</span><span id="Column.desc-217"><a href="#Column.desc-217"><span class="linenos">217</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.asc_nulls_first" class="classattr"> + <input id="Column.asc_nulls_first-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">asc_nulls_first</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.asc_nulls_first-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.asc_nulls_first"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.asc_nulls_first-211"><a href="#Column.asc_nulls_first-211"><span class="linenos">211</span></a> <span class="k">def</span> <span class="nf">asc</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.asc_nulls_first-212"><a href="#Column.asc_nulls_first-212"><span class="linenos">212</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Ordered</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">desc</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">nulls_first</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="Column.asc_nulls_first-213"><a href="#Column.asc_nulls_first-213"><span class="linenos">213</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.asc_nulls_last" class="classattr"> + <input id="Column.asc_nulls_last-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">asc_nulls_last</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.asc_nulls_last-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.asc_nulls_last"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.asc_nulls_last-221"><a href="#Column.asc_nulls_last-221"><span class="linenos">221</span></a> <span class="k">def</span> <span class="nf">asc_nulls_last</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.asc_nulls_last-222"><a href="#Column.asc_nulls_last-222"><span class="linenos">222</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Ordered</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">desc</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">nulls_first</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +</span><span id="Column.asc_nulls_last-223"><a href="#Column.asc_nulls_last-223"><span class="linenos">223</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.desc_nulls_first" class="classattr"> + <input id="Column.desc_nulls_first-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">desc_nulls_first</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.desc_nulls_first-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.desc_nulls_first"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.desc_nulls_first-225"><a href="#Column.desc_nulls_first-225"><span class="linenos">225</span></a> <span class="k">def</span> <span class="nf">desc_nulls_first</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.desc_nulls_first-226"><a href="#Column.desc_nulls_first-226"><span class="linenos">226</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Ordered</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">desc</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nulls_first</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="Column.desc_nulls_first-227"><a href="#Column.desc_nulls_first-227"><span class="linenos">227</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.desc_nulls_last" class="classattr"> + <input id="Column.desc_nulls_last-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">desc_nulls_last</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.desc_nulls_last-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.desc_nulls_last"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.desc_nulls_last-215"><a href="#Column.desc_nulls_last-215"><span class="linenos">215</span></a> <span class="k">def</span> <span class="nf">desc</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.desc_nulls_last-216"><a href="#Column.desc_nulls_last-216"><span class="linenos">216</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Ordered</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">desc</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nulls_first</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +</span><span id="Column.desc_nulls_last-217"><a href="#Column.desc_nulls_last-217"><span class="linenos">217</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.when" class="classattr"> + <input id="Column.when-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">when</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">condition</span><span class="p">:</span> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>,</span><span class="param"> <span class="n">value</span><span class="p">:</span> <span class="n">Any</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.when-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.when"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.when-231"><a href="#Column.when-231"><span class="linenos">231</span></a> <span class="k">def</span> <span class="nf">when</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">condition</span><span class="p">:</span> <span class="n">Column</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Any</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.when-232"><a href="#Column.when-232"><span class="linenos">232</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.functions</span> <span class="kn">import</span> <span class="n">when</span> +</span><span id="Column.when-233"><a href="#Column.when-233"><span class="linenos">233</span></a> +</span><span id="Column.when-234"><a href="#Column.when-234"><span class="linenos">234</span></a> <span class="n">column_with_if</span> <span class="o">=</span> <span class="n">when</span><span class="p">(</span><span class="n">condition</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> +</span><span id="Column.when-235"><a href="#Column.when-235"><span class="linenos">235</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Case</span><span class="p">):</span> +</span><span id="Column.when-236"><a href="#Column.when-236"><span class="linenos">236</span></a> <span class="k">return</span> <span class="n">column_with_if</span> +</span><span id="Column.when-237"><a href="#Column.when-237"><span class="linenos">237</span></a> <span class="n">new_column</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="Column.when-238"><a href="#Column.when-238"><span class="linenos">238</span></a> <span class="n">new_column</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"ifs"</span><span class="p">]</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">column_with_if</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"ifs"</span><span class="p">])</span> +</span><span id="Column.when-239"><a href="#Column.when-239"><span class="linenos">239</span></a> <span class="k">return</span> <span class="n">new_column</span> +</span></pre></div> + + + + + </div> + <div id="Column.otherwise" class="classattr"> + <input id="Column.otherwise-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">otherwise</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">value</span><span class="p">:</span> <span class="n">Any</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.otherwise-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.otherwise"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.otherwise-241"><a href="#Column.otherwise-241"><span class="linenos">241</span></a> <span class="k">def</span> <span class="nf">otherwise</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Any</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.otherwise-242"><a href="#Column.otherwise-242"><span class="linenos">242</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.functions</span> <span class="kn">import</span> <span class="n">lit</span> +</span><span id="Column.otherwise-243"><a href="#Column.otherwise-243"><span class="linenos">243</span></a> +</span><span id="Column.otherwise-244"><a href="#Column.otherwise-244"><span class="linenos">244</span></a> <span class="n">true_value</span> <span class="o">=</span> <span class="n">value</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">Column</span><span class="p">)</span> <span class="k">else</span> <span class="n">lit</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> +</span><span id="Column.otherwise-245"><a href="#Column.otherwise-245"><span class="linenos">245</span></a> <span class="n">new_column</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="Column.otherwise-246"><a href="#Column.otherwise-246"><span class="linenos">246</span></a> <span class="n">new_column</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"default"</span><span class="p">,</span> <span class="n">true_value</span><span class="o">.</span><span class="n">column_expression</span><span class="p">)</span> +</span><span id="Column.otherwise-247"><a href="#Column.otherwise-247"><span class="linenos">247</span></a> <span class="k">return</span> <span class="n">new_column</span> +</span></pre></div> + + + + + </div> + <div id="Column.isNull" class="classattr"> + <input id="Column.isNull-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">isNull</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.isNull-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.isNull"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.isNull-249"><a href="#Column.isNull-249"><span class="linenos">249</span></a> <span class="k">def</span> <span class="nf">isNull</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.isNull-250"><a href="#Column.isNull-250"><span class="linenos">250</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Is</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Null</span><span class="p">())</span> +</span><span id="Column.isNull-251"><a href="#Column.isNull-251"><span class="linenos">251</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.isNotNull" class="classattr"> + <input id="Column.isNotNull-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">isNotNull</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.isNotNull-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.isNotNull"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.isNotNull-253"><a href="#Column.isNotNull-253"><span class="linenos">253</span></a> <span class="k">def</span> <span class="nf">isNotNull</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.isNotNull-254"><a href="#Column.isNotNull-254"><span class="linenos">254</span></a> <span class="n">new_expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Not</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Is</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Null</span><span class="p">()))</span> +</span><span id="Column.isNotNull-255"><a href="#Column.isNotNull-255"><span class="linenos">255</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">new_expression</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.cast" class="classattr"> + <input id="Column.cast-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">cast</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">dataType</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">sqlglot</span><span class="o">.</span><span class="n">dataframe</span><span class="o">.</span><span class="n">sql</span><span class="o">.</span><span class="n">types</span><span class="o">.</span><span class="n">DataType</span><span class="p">]</span></span><span class="return-annotation">):</span></span> + + <label class="view-source-button" for="Column.cast-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.cast"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.cast-257"><a href="#Column.cast-257"><span class="linenos">257</span></a> <span class="k">def</span> <span class="nf">cast</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dataType</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">DataType</span><span class="p">]):</span> +</span><span id="Column.cast-258"><a href="#Column.cast-258"><span class="linenos">258</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Column.cast-259"><a href="#Column.cast-259"><span class="linenos">259</span></a><span class="sd"> Functionality Difference: PySpark cast accepts a datatype instance of the datatype class</span> +</span><span id="Column.cast-260"><a href="#Column.cast-260"><span class="linenos">260</span></a><span class="sd"> Sqlglot doesn't currently replicate this class so it only accepts a string</span> +</span><span id="Column.cast-261"><a href="#Column.cast-261"><span class="linenos">261</span></a><span class="sd"> """</span> +</span><span id="Column.cast-262"><a href="#Column.cast-262"><span class="linenos">262</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dataType</span><span class="p">,</span> <span class="n">DataType</span><span class="p">):</span> +</span><span id="Column.cast-263"><a href="#Column.cast-263"><span class="linenos">263</span></a> <span class="n">dataType</span> <span class="o">=</span> <span class="n">dataType</span><span class="o">.</span><span class="n">simpleString</span><span class="p">()</span> +</span><span id="Column.cast-264"><a href="#Column.cast-264"><span class="linenos">264</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> <span class="n">dataType</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="s2">"spark"</span><span class="p">))</span> +</span></pre></div> + + + <div class="docstring"><p>Functionality Difference: PySpark cast accepts a datatype instance of the datatype class +Sqlglot doesn't currently replicate this class so it only accepts a string</p> +</div> + + + </div> + <div id="Column.startswith" class="classattr"> + <input id="Column.startswith-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">startswith</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">value</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span><span class="p">]</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.startswith-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.startswith"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.startswith-266"><a href="#Column.startswith-266"><span class="linenos">266</span></a> <span class="k">def</span> <span class="nf">startswith</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Column</span><span class="p">])</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.startswith-267"><a href="#Column.startswith-267"><span class="linenos">267</span></a> <span class="n">value</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">Column</span><span class="p">)</span> <span class="k">else</span> <span class="n">value</span> +</span><span id="Column.startswith-268"><a href="#Column.startswith-268"><span class="linenos">268</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">invoke_anonymous_function</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">"STARTSWITH"</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.endswith" class="classattr"> + <input id="Column.endswith-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">endswith</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">value</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span><span class="p">]</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.endswith-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.endswith"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.endswith-270"><a href="#Column.endswith-270"><span class="linenos">270</span></a> <span class="k">def</span> <span class="nf">endswith</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Column</span><span class="p">])</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.endswith-271"><a href="#Column.endswith-271"><span class="linenos">271</span></a> <span class="n">value</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">Column</span><span class="p">)</span> <span class="k">else</span> <span class="n">value</span> +</span><span id="Column.endswith-272"><a href="#Column.endswith-272"><span class="linenos">272</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">invoke_anonymous_function</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">"ENDSWITH"</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.rlike" class="classattr"> + <input id="Column.rlike-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">rlike</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">regexp</span><span class="p">:</span> <span class="nb">str</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.rlike-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.rlike"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.rlike-274"><a href="#Column.rlike-274"><span class="linenos">274</span></a> <span class="k">def</span> <span class="nf">rlike</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">regexp</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.rlike-275"><a href="#Column.rlike-275"><span class="linenos">275</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">invoke_expression_over_column</span><span class="p">(</span> +</span><span id="Column.rlike-276"><a href="#Column.rlike-276"><span class="linenos">276</span></a> <span class="n">column</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">callable_expression</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">RegexpLike</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">regexp</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> +</span><span id="Column.rlike-277"><a href="#Column.rlike-277"><span class="linenos">277</span></a> <span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.like" class="classattr"> + <input id="Column.like-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">like</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">other</span><span class="p">:</span> <span class="nb">str</span></span><span class="return-annotation">):</span></span> + + <label class="view-source-button" for="Column.like-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.like"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.like-279"><a href="#Column.like-279"><span class="linenos">279</span></a> <span class="k">def</span> <span class="nf">like</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span> +</span><span id="Column.like-280"><a href="#Column.like-280"><span class="linenos">280</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">invoke_expression_over_column</span><span class="p">(</span> +</span><span id="Column.like-281"><a href="#Column.like-281"><span class="linenos">281</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Like</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">other</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> +</span><span id="Column.like-282"><a href="#Column.like-282"><span class="linenos">282</span></a> <span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.ilike" class="classattr"> + <input id="Column.ilike-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">ilike</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">other</span><span class="p">:</span> <span class="nb">str</span></span><span class="return-annotation">):</span></span> + + <label class="view-source-button" for="Column.ilike-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.ilike"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.ilike-284"><a href="#Column.ilike-284"><span class="linenos">284</span></a> <span class="k">def</span> <span class="nf">ilike</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span> +</span><span id="Column.ilike-285"><a href="#Column.ilike-285"><span class="linenos">285</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">invoke_expression_over_column</span><span class="p">(</span> +</span><span id="Column.ilike-286"><a href="#Column.ilike-286"><span class="linenos">286</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">ILike</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">other</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> +</span><span id="Column.ilike-287"><a href="#Column.ilike-287"><span class="linenos">287</span></a> <span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.substr" class="classattr"> + <input id="Column.substr-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">substr</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">startPos</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span><span class="p">]</span>,</span><span class="param"> <span class="n">length</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span><span class="p">]</span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.substr-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.substr"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.substr-289"><a href="#Column.substr-289"><span class="linenos">289</span></a> <span class="k">def</span> <span class="nf">substr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">startPos</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="n">Column</span><span class="p">],</span> <span class="n">length</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="n">Column</span><span class="p">])</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.substr-290"><a href="#Column.substr-290"><span class="linenos">290</span></a> <span class="n">startPos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">startPos</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">startPos</span><span class="p">,</span> <span class="n">Column</span><span class="p">)</span> <span class="k">else</span> <span class="n">startPos</span> +</span><span id="Column.substr-291"><a href="#Column.substr-291"><span class="linenos">291</span></a> <span class="n">length</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">length</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">length</span><span class="p">,</span> <span class="n">Column</span><span class="p">)</span> <span class="k">else</span> <span class="n">length</span> +</span><span id="Column.substr-292"><a href="#Column.substr-292"><span class="linenos">292</span></a> <span class="k">return</span> <span class="n">Column</span><span class="o">.</span><span class="n">invoke_expression_over_column</span><span class="p">(</span> +</span><span id="Column.substr-293"><a href="#Column.substr-293"><span class="linenos">293</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Substring</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="n">startPos</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">length</span><span class="o">=</span><span class="n">length</span><span class="o">.</span><span class="n">expression</span> +</span><span id="Column.substr-294"><a href="#Column.substr-294"><span class="linenos">294</span></a> <span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.isin" class="classattr"> + <input id="Column.isin-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">isin</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700331213104'</span><span class="o">></span><span class="p">,</span> <span class="n">Iterable</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700331213104'</span><span class="o">></span><span class="p">]]</span></span><span class="return-annotation">):</span></span> + + <label class="view-source-button" for="Column.isin-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.isin"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.isin-296"><a href="#Column.isin-296"><span class="linenos">296</span></a> <span class="k">def</span> <span class="nf">isin</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">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Iterable</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">]]):</span> +</span><span id="Column.isin-297"><a href="#Column.isin-297"><span class="linenos">297</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="n">flatten</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">cols</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">set</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">))</span> <span class="k">else</span> <span class="n">cols</span> <span class="c1"># type: ignore</span> +</span><span id="Column.isin-298"><a href="#Column.isin-298"><span class="linenos">298</span></a> <span class="n">expressions</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">columns</span><span class="p">]</span> +</span><span id="Column.isin-299"><a href="#Column.isin-299"><span class="linenos">299</span></a> <span class="k">return</span> <span class="n">Column</span><span class="o">.</span><span class="n">invoke_expression_over_column</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">In</span><span class="p">,</span> <span class="n">expressions</span><span class="o">=</span><span class="n">expressions</span><span class="p">)</span> <span class="c1"># type: ignore</span> +</span></pre></div> + + + + + </div> + <div id="Column.between" class="classattr"> + <input id="Column.between-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">between</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">lowerBound</span><span class="p">:</span> <span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700331299440'</span><span class="o">></span>,</span><span class="param"> <span class="n">upperBound</span><span class="p">:</span> <span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700329240384'</span><span class="o">></span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.between-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.between"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.between-301"><a href="#Column.between-301"><span class="linenos">301</span></a> <span class="k">def</span> <span class="nf">between</span><span class="p">(</span> +</span><span id="Column.between-302"><a href="#Column.between-302"><span class="linenos">302</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="Column.between-303"><a href="#Column.between-303"><span class="linenos">303</span></a> <span class="n">lowerBound</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">],</span> +</span><span id="Column.between-304"><a href="#Column.between-304"><span class="linenos">304</span></a> <span class="n">upperBound</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrLiteral</span><span class="p">],</span> +</span><span id="Column.between-305"><a href="#Column.between-305"><span class="linenos">305</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.between-306"><a href="#Column.between-306"><span class="linenos">306</span></a> <span class="n">lower_bound_exp</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="Column.between-307"><a href="#Column.between-307"><span class="linenos">307</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">lowerBound</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">lowerBound</span><span class="p">,</span> <span class="n">Column</span><span class="p">)</span> <span class="k">else</span> <span class="n">lowerBound</span> +</span><span id="Column.between-308"><a href="#Column.between-308"><span class="linenos">308</span></a> <span class="p">)</span> +</span><span id="Column.between-309"><a href="#Column.between-309"><span class="linenos">309</span></a> <span class="n">upper_bound_exp</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="Column.between-310"><a href="#Column.between-310"><span class="linenos">310</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_lit</span><span class="p">(</span><span class="n">upperBound</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">upperBound</span><span class="p">,</span> <span class="n">Column</span><span class="p">)</span> <span class="k">else</span> <span class="n">upperBound</span> +</span><span id="Column.between-311"><a href="#Column.between-311"><span class="linenos">311</span></a> <span class="p">)</span> +</span><span id="Column.between-312"><a href="#Column.between-312"><span class="linenos">312</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span> +</span><span id="Column.between-313"><a href="#Column.between-313"><span class="linenos">313</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Between</span><span class="p">(</span> +</span><span id="Column.between-314"><a href="#Column.between-314"><span class="linenos">314</span></a> <span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">,</span> +</span><span id="Column.between-315"><a href="#Column.between-315"><span class="linenos">315</span></a> <span class="n">low</span><span class="o">=</span><span class="n">lower_bound_exp</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> +</span><span id="Column.between-316"><a href="#Column.between-316"><span class="linenos">316</span></a> <span class="n">high</span><span class="o">=</span><span class="n">upper_bound_exp</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> +</span><span id="Column.between-317"><a href="#Column.between-317"><span class="linenos">317</span></a> <span class="p">)</span> +</span><span id="Column.between-318"><a href="#Column.between-318"><span class="linenos">318</span></a> <span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Column.over" class="classattr"> + <input id="Column.over-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">over</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">window</span><span class="p">:</span> <span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700329314480'</span><span class="o">></span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></span> + + <label class="view-source-button" for="Column.over-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Column.over"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Column.over-320"><a href="#Column.over-320"><span class="linenos">320</span></a> <span class="k">def</span> <span class="nf">over</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">window</span><span class="p">:</span> <span class="n">WindowSpec</span><span class="p">)</span> <span class="o">-></span> <span class="n">Column</span><span class="p">:</span> +</span><span id="Column.over-321"><a href="#Column.over-321"><span class="linenos">321</span></a> <span class="n">window_expression</span> <span class="o">=</span> <span class="n">window</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="Column.over-322"><a href="#Column.over-322"><span class="linenos">322</span></a> <span class="n">window_expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"this"</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">column_expression</span><span class="p">)</span> +</span><span id="Column.over-323"><a href="#Column.over-323"><span class="linenos">323</span></a> <span class="k">return</span> <span class="n">Column</span><span class="p">(</span><span class="n">window_expression</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + </section> + <section id="DataFrameNaFunctions"> + <input id="DataFrameNaFunctions-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr class"> + + <span class="def">class</span> + <span class="name">DataFrameNaFunctions</span>: + + <label class="view-source-button" for="DataFrameNaFunctions-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrameNaFunctions"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameNaFunctions-785"><a href="#DataFrameNaFunctions-785"><span class="linenos">785</span></a><span class="k">class</span> <span class="nc">DataFrameNaFunctions</span><span class="p">:</span> +</span><span id="DataFrameNaFunctions-786"><a href="#DataFrameNaFunctions-786"><span class="linenos">786</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">df</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">):</span> +</span><span id="DataFrameNaFunctions-787"><a href="#DataFrameNaFunctions-787"><span class="linenos">787</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">df</span> <span class="o">=</span> <span class="n">df</span> +</span><span id="DataFrameNaFunctions-788"><a href="#DataFrameNaFunctions-788"><span class="linenos">788</span></a> +</span><span id="DataFrameNaFunctions-789"><a href="#DataFrameNaFunctions-789"><span class="linenos">789</span></a> <span class="k">def</span> <span class="nf">drop</span><span class="p">(</span> +</span><span id="DataFrameNaFunctions-790"><a href="#DataFrameNaFunctions-790"><span class="linenos">790</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions-791"><a href="#DataFrameNaFunctions-791"><span class="linenos">791</span></a> <span class="n">how</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"any"</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions-792"><a href="#DataFrameNaFunctions-792"><span class="linenos">792</span></a> <span class="n">thresh</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions-793"><a href="#DataFrameNaFunctions-793"><span class="linenos">793</span></a> <span class="n">subset</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="o">...</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions-794"><a href="#DataFrameNaFunctions-794"><span class="linenos">794</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrameNaFunctions-795"><a href="#DataFrameNaFunctions-795"><span class="linenos">795</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">dropna</span><span class="p">(</span><span class="n">how</span><span class="o">=</span><span class="n">how</span><span class="p">,</span> <span class="n">thresh</span><span class="o">=</span><span class="n">thresh</span><span class="p">,</span> <span class="n">subset</span><span class="o">=</span><span class="n">subset</span><span class="p">)</span> +</span><span id="DataFrameNaFunctions-796"><a href="#DataFrameNaFunctions-796"><span class="linenos">796</span></a> +</span><span id="DataFrameNaFunctions-797"><a href="#DataFrameNaFunctions-797"><span class="linenos">797</span></a> <span class="k">def</span> <span class="nf">fill</span><span class="p">(</span> +</span><span id="DataFrameNaFunctions-798"><a href="#DataFrameNaFunctions-798"><span class="linenos">798</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions-799"><a href="#DataFrameNaFunctions-799"><span class="linenos">799</span></a> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">bool</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Any</span><span class="p">]],</span> +</span><span id="DataFrameNaFunctions-800"><a href="#DataFrameNaFunctions-800"><span class="linenos">800</span></a> <span class="n">subset</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="o">...</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions-801"><a href="#DataFrameNaFunctions-801"><span class="linenos">801</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrameNaFunctions-802"><a href="#DataFrameNaFunctions-802"><span class="linenos">802</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">fillna</span><span class="p">(</span><span class="n">value</span><span class="o">=</span><span class="n">value</span><span class="p">,</span> <span class="n">subset</span><span class="o">=</span><span class="n">subset</span><span class="p">)</span> +</span><span id="DataFrameNaFunctions-803"><a href="#DataFrameNaFunctions-803"><span class="linenos">803</span></a> +</span><span id="DataFrameNaFunctions-804"><a href="#DataFrameNaFunctions-804"><span class="linenos">804</span></a> <span class="k">def</span> <span class="nf">replace</span><span class="p">(</span> +</span><span id="DataFrameNaFunctions-805"><a href="#DataFrameNaFunctions-805"><span class="linenos">805</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions-806"><a href="#DataFrameNaFunctions-806"><span class="linenos">806</span></a> <span class="n">to_replace</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">bool</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">],</span> +</span><span id="DataFrameNaFunctions-807"><a href="#DataFrameNaFunctions-807"><span class="linenos">807</span></a> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">bool</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions-808"><a href="#DataFrameNaFunctions-808"><span class="linenos">808</span></a> <span class="n">subset</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions-809"><a href="#DataFrameNaFunctions-809"><span class="linenos">809</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrameNaFunctions-810"><a href="#DataFrameNaFunctions-810"><span class="linenos">810</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">to_replace</span><span class="o">=</span><span class="n">to_replace</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="n">value</span><span class="p">,</span> <span class="n">subset</span><span class="o">=</span><span class="n">subset</span><span class="p">)</span> +</span></pre></div> + + + + + <div id="DataFrameNaFunctions.__init__" class="classattr"> + <input id="DataFrameNaFunctions.__init__-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="name">DataFrameNaFunctions</span><span class="signature pdoc-code condensed">(<span class="param"><span class="n">df</span><span class="p">:</span> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span></span>)</span> + + <label class="view-source-button" for="DataFrameNaFunctions.__init__-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrameNaFunctions.__init__"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameNaFunctions.__init__-786"><a href="#DataFrameNaFunctions.__init__-786"><span class="linenos">786</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">df</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">):</span> +</span><span id="DataFrameNaFunctions.__init__-787"><a href="#DataFrameNaFunctions.__init__-787"><span class="linenos">787</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">df</span> <span class="o">=</span> <span class="n">df</span> +</span></pre></div> + + + + + </div> + <div id="DataFrameNaFunctions.drop" class="classattr"> + <input id="DataFrameNaFunctions.drop-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">drop</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">how</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s1">'any'</span>,</span><span class="param"> <span class="n">thresh</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">subset</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="o">...</span><span class="p">],</span> <span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">],</span> <span class="n">NoneType</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrameNaFunctions.drop-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrameNaFunctions.drop"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameNaFunctions.drop-789"><a href="#DataFrameNaFunctions.drop-789"><span class="linenos">789</span></a> <span class="k">def</span> <span class="nf">drop</span><span class="p">(</span> +</span><span id="DataFrameNaFunctions.drop-790"><a href="#DataFrameNaFunctions.drop-790"><span class="linenos">790</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions.drop-791"><a href="#DataFrameNaFunctions.drop-791"><span class="linenos">791</span></a> <span class="n">how</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"any"</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions.drop-792"><a href="#DataFrameNaFunctions.drop-792"><span class="linenos">792</span></a> <span class="n">thresh</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions.drop-793"><a href="#DataFrameNaFunctions.drop-793"><span class="linenos">793</span></a> <span class="n">subset</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="o">...</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions.drop-794"><a href="#DataFrameNaFunctions.drop-794"><span class="linenos">794</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrameNaFunctions.drop-795"><a href="#DataFrameNaFunctions.drop-795"><span class="linenos">795</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">dropna</span><span class="p">(</span><span class="n">how</span><span class="o">=</span><span class="n">how</span><span class="p">,</span> <span class="n">thresh</span><span class="o">=</span><span class="n">thresh</span><span class="p">,</span> <span class="n">subset</span><span class="o">=</span><span class="n">subset</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrameNaFunctions.fill" class="classattr"> + <input id="DataFrameNaFunctions.fill-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">fill</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">value</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">bool</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Any</span><span class="p">]]</span>,</span><span class="param"> <span class="n">subset</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="o">...</span><span class="p">],</span> <span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">],</span> <span class="n">NoneType</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrameNaFunctions.fill-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrameNaFunctions.fill"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameNaFunctions.fill-797"><a href="#DataFrameNaFunctions.fill-797"><span class="linenos">797</span></a> <span class="k">def</span> <span class="nf">fill</span><span class="p">(</span> +</span><span id="DataFrameNaFunctions.fill-798"><a href="#DataFrameNaFunctions.fill-798"><span class="linenos">798</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions.fill-799"><a href="#DataFrameNaFunctions.fill-799"><span class="linenos">799</span></a> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">bool</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Any</span><span class="p">]],</span> +</span><span id="DataFrameNaFunctions.fill-800"><a href="#DataFrameNaFunctions.fill-800"><span class="linenos">800</span></a> <span class="n">subset</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="o">...</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions.fill-801"><a href="#DataFrameNaFunctions.fill-801"><span class="linenos">801</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrameNaFunctions.fill-802"><a href="#DataFrameNaFunctions.fill-802"><span class="linenos">802</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">fillna</span><span class="p">(</span><span class="n">value</span><span class="o">=</span><span class="n">value</span><span class="p">,</span> <span class="n">subset</span><span class="o">=</span><span class="n">subset</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrameNaFunctions.replace" class="classattr"> + <input id="DataFrameNaFunctions.replace-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">replace</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">to_replace</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">bool</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="n">List</span><span class="p">,</span> <span class="n">Dict</span><span class="p">]</span>,</span><span class="param"> <span class="n">value</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">bool</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="n">List</span><span class="p">,</span> <span class="n">NoneType</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">subset</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">],</span> <span class="n">NoneType</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrameNaFunctions.replace-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrameNaFunctions.replace"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameNaFunctions.replace-804"><a href="#DataFrameNaFunctions.replace-804"><span class="linenos">804</span></a> <span class="k">def</span> <span class="nf">replace</span><span class="p">(</span> +</span><span id="DataFrameNaFunctions.replace-805"><a href="#DataFrameNaFunctions.replace-805"><span class="linenos">805</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions.replace-806"><a href="#DataFrameNaFunctions.replace-806"><span class="linenos">806</span></a> <span class="n">to_replace</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">bool</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">],</span> +</span><span id="DataFrameNaFunctions.replace-807"><a href="#DataFrameNaFunctions.replace-807"><span class="linenos">807</span></a> <span class="n">value</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">bool</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions.replace-808"><a href="#DataFrameNaFunctions.replace-808"><span class="linenos">808</span></a> <span class="n">subset</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions.replace-809"><a href="#DataFrameNaFunctions.replace-809"><span class="linenos">809</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrameNaFunctions.replace-810"><a href="#DataFrameNaFunctions.replace-810"><span class="linenos">810</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">df</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">to_replace</span><span class="o">=</span><span class="n">to_replace</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="n">value</span><span class="p">,</span> <span class="n">subset</span><span class="o">=</span><span class="n">subset</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + </section> + <section id="Window"> + <input id="Window-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr class"> + + <span class="def">class</span> + <span class="name">Window</span>: + + <label class="view-source-button" for="Window-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Window"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Window-15"><a href="#Window-15"><span class="linenos">15</span></a><span class="k">class</span> <span class="nc">Window</span><span class="p">:</span> +</span><span id="Window-16"><a href="#Window-16"><span class="linenos">16</span></a> <span class="n">_JAVA_MIN_LONG</span> <span class="o">=</span> <span class="o">-</span><span class="p">(</span><span class="mi">1</span> <span class="o"><<</span> <span class="mi">63</span><span class="p">)</span> <span class="c1"># -9223372036854775808</span> +</span><span id="Window-17"><a href="#Window-17"><span class="linenos">17</span></a> <span class="n">_JAVA_MAX_LONG</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span> <span class="o"><<</span> <span class="mi">63</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span> <span class="c1"># 9223372036854775807</span> +</span><span id="Window-18"><a href="#Window-18"><span class="linenos">18</span></a> <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">_JAVA_MIN_LONG</span><span class="p">)</span> +</span><span id="Window-19"><a href="#Window-19"><span class="linenos">19</span></a> <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">_JAVA_MAX_LONG</span><span class="p">)</span> +</span><span id="Window-20"><a href="#Window-20"><span class="linenos">20</span></a> +</span><span id="Window-21"><a href="#Window-21"><span class="linenos">21</span></a> <span class="n">unboundedPreceding</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="n">_JAVA_MIN_LONG</span> +</span><span id="Window-22"><a href="#Window-22"><span class="linenos">22</span></a> +</span><span id="Window-23"><a href="#Window-23"><span class="linenos">23</span></a> <span class="n">unboundedFollowing</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="n">_JAVA_MAX_LONG</span> +</span><span id="Window-24"><a href="#Window-24"><span class="linenos">24</span></a> +</span><span id="Window-25"><a href="#Window-25"><span class="linenos">25</span></a> <span class="n">currentRow</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">0</span> +</span><span id="Window-26"><a href="#Window-26"><span class="linenos">26</span></a> +</span><span id="Window-27"><a href="#Window-27"><span class="linenos">27</span></a> <span class="nd">@classmethod</span> +</span><span id="Window-28"><a href="#Window-28"><span class="linenos">28</span></a> <span class="k">def</span> <span class="nf">partitionBy</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">]])</span> <span class="o">-></span> <span class="n">WindowSpec</span><span class="p">:</span> +</span><span id="Window-29"><a href="#Window-29"><span class="linenos">29</span></a> <span class="k">return</span> <span class="n">WindowSpec</span><span class="p">()</span><span class="o">.</span><span class="n">partitionBy</span><span class="p">(</span><span class="o">*</span><span class="n">cols</span><span class="p">)</span> +</span><span id="Window-30"><a href="#Window-30"><span class="linenos">30</span></a> +</span><span id="Window-31"><a href="#Window-31"><span class="linenos">31</span></a> <span class="nd">@classmethod</span> +</span><span id="Window-32"><a href="#Window-32"><span class="linenos">32</span></a> <span class="k">def</span> <span class="nf">orderBy</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">]])</span> <span class="o">-></span> <span class="n">WindowSpec</span><span class="p">:</span> +</span><span id="Window-33"><a href="#Window-33"><span class="linenos">33</span></a> <span class="k">return</span> <span class="n">WindowSpec</span><span class="p">()</span><span class="o">.</span><span class="n">orderBy</span><span class="p">(</span><span class="o">*</span><span class="n">cols</span><span class="p">)</span> +</span><span id="Window-34"><a href="#Window-34"><span class="linenos">34</span></a> +</span><span id="Window-35"><a href="#Window-35"><span class="linenos">35</span></a> <span class="nd">@classmethod</span> +</span><span id="Window-36"><a href="#Window-36"><span class="linenos">36</span></a> <span class="k">def</span> <span class="nf">rowsBetween</span><span class="p">(</span><span class="bp">cls</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="n">WindowSpec</span><span class="p">:</span> +</span><span id="Window-37"><a href="#Window-37"><span class="linenos">37</span></a> <span class="k">return</span> <span class="n">WindowSpec</span><span class="p">()</span><span class="o">.</span><span class="n">rowsBetween</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span> +</span><span id="Window-38"><a href="#Window-38"><span class="linenos">38</span></a> +</span><span id="Window-39"><a href="#Window-39"><span class="linenos">39</span></a> <span class="nd">@classmethod</span> +</span><span id="Window-40"><a href="#Window-40"><span class="linenos">40</span></a> <span class="k">def</span> <span class="nf">rangeBetween</span><span class="p">(</span><span class="bp">cls</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="n">WindowSpec</span><span class="p">:</span> +</span><span id="Window-41"><a href="#Window-41"><span class="linenos">41</span></a> <span class="k">return</span> <span class="n">WindowSpec</span><span class="p">()</span><span class="o">.</span><span class="n">rangeBetween</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span> +</span></pre></div> + + + + + <div id="Window.__init__" class="classattr"> + <div class="attr function"> + + <span class="name">Window</span><span class="signature pdoc-code condensed">()</span> + + + </div> + <a class="headerlink" href="#Window.__init__"></a> + + + + </div> + <div id="Window.partitionBy" class="classattr"> + <input id="Window.partitionBy-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@classmethod</div> + + <span class="def">def</span> + <span class="name">partitionBy</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">cls</span>,</span><span class="param"> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700329626592'</span><span class="o">></span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700329626592'</span><span class="o">></span><span class="p">]]</span></span><span class="return-annotation">) -> <span class="n"><a href="#WindowSpec">sqlglot.dataframe.sql.WindowSpec</a></span>:</span></span> + + <label class="view-source-button" for="Window.partitionBy-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Window.partitionBy"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Window.partitionBy-27"><a href="#Window.partitionBy-27"><span class="linenos">27</span></a> <span class="nd">@classmethod</span> +</span><span id="Window.partitionBy-28"><a href="#Window.partitionBy-28"><span class="linenos">28</span></a> <span class="k">def</span> <span class="nf">partitionBy</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">]])</span> <span class="o">-></span> <span class="n">WindowSpec</span><span class="p">:</span> +</span><span id="Window.partitionBy-29"><a href="#Window.partitionBy-29"><span class="linenos">29</span></a> <span class="k">return</span> <span class="n">WindowSpec</span><span class="p">()</span><span class="o">.</span><span class="n">partitionBy</span><span class="p">(</span><span class="o">*</span><span class="n">cols</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Window.orderBy" class="classattr"> + <input id="Window.orderBy-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@classmethod</div> + + <span class="def">def</span> + <span class="name">orderBy</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">cls</span>,</span><span class="param"> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700329828768'</span><span class="o">></span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700329828768'</span><span class="o">></span><span class="p">]]</span></span><span class="return-annotation">) -> <span class="n"><a href="#WindowSpec">sqlglot.dataframe.sql.WindowSpec</a></span>:</span></span> + + <label class="view-source-button" for="Window.orderBy-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Window.orderBy"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Window.orderBy-31"><a href="#Window.orderBy-31"><span class="linenos">31</span></a> <span class="nd">@classmethod</span> +</span><span id="Window.orderBy-32"><a href="#Window.orderBy-32"><span class="linenos">32</span></a> <span class="k">def</span> <span class="nf">orderBy</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">]])</span> <span class="o">-></span> <span class="n">WindowSpec</span><span class="p">:</span> +</span><span id="Window.orderBy-33"><a href="#Window.orderBy-33"><span class="linenos">33</span></a> <span class="k">return</span> <span class="n">WindowSpec</span><span class="p">()</span><span class="o">.</span><span class="n">orderBy</span><span class="p">(</span><span class="o">*</span><span class="n">cols</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Window.rowsBetween" class="classattr"> + <input id="Window.rowsBetween-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@classmethod</div> + + <span class="def">def</span> + <span class="name">rowsBetween</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">cls</span>, </span><span class="param"><span class="n">start</span><span class="p">:</span> <span class="nb">int</span>, </span><span class="param"><span class="n">end</span><span class="p">:</span> <span class="nb">int</span></span><span class="return-annotation">) -> <span class="n"><a href="#WindowSpec">sqlglot.dataframe.sql.WindowSpec</a></span>:</span></span> + + <label class="view-source-button" for="Window.rowsBetween-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Window.rowsBetween"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Window.rowsBetween-35"><a href="#Window.rowsBetween-35"><span class="linenos">35</span></a> <span class="nd">@classmethod</span> +</span><span id="Window.rowsBetween-36"><a href="#Window.rowsBetween-36"><span class="linenos">36</span></a> <span class="k">def</span> <span class="nf">rowsBetween</span><span class="p">(</span><span class="bp">cls</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="n">WindowSpec</span><span class="p">:</span> +</span><span id="Window.rowsBetween-37"><a href="#Window.rowsBetween-37"><span class="linenos">37</span></a> <span class="k">return</span> <span class="n">WindowSpec</span><span class="p">()</span><span class="o">.</span><span class="n">rowsBetween</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="Window.rangeBetween" class="classattr"> + <input id="Window.rangeBetween-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + <div class="decorator">@classmethod</div> + + <span class="def">def</span> + <span class="name">rangeBetween</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">cls</span>, </span><span class="param"><span class="n">start</span><span class="p">:</span> <span class="nb">int</span>, </span><span class="param"><span class="n">end</span><span class="p">:</span> <span class="nb">int</span></span><span class="return-annotation">) -> <span class="n"><a href="#WindowSpec">sqlglot.dataframe.sql.WindowSpec</a></span>:</span></span> + + <label class="view-source-button" for="Window.rangeBetween-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#Window.rangeBetween"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="Window.rangeBetween-39"><a href="#Window.rangeBetween-39"><span class="linenos">39</span></a> <span class="nd">@classmethod</span> +</span><span id="Window.rangeBetween-40"><a href="#Window.rangeBetween-40"><span class="linenos">40</span></a> <span class="k">def</span> <span class="nf">rangeBetween</span><span class="p">(</span><span class="bp">cls</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="n">WindowSpec</span><span class="p">:</span> +</span><span id="Window.rangeBetween-41"><a href="#Window.rangeBetween-41"><span class="linenos">41</span></a> <span class="k">return</span> <span class="n">WindowSpec</span><span class="p">()</span><span class="o">.</span><span class="n">rangeBetween</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + </section> + <section id="WindowSpec"> + <input id="WindowSpec-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr class"> + + <span class="def">class</span> + <span class="name">WindowSpec</span>: + + <label class="view-source-button" for="WindowSpec-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#WindowSpec"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="WindowSpec-44"><a href="#WindowSpec-44"><span class="linenos"> 44</span></a><span class="k">class</span> <span class="nc">WindowSpec</span><span class="p">:</span> +</span><span id="WindowSpec-45"><a href="#WindowSpec-45"><span class="linenos"> 45</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Window</span><span class="p">()):</span> +</span><span id="WindowSpec-46"><a href="#WindowSpec-46"><span class="linenos"> 46</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span> <span class="o">=</span> <span class="n">expression</span> +</span><span id="WindowSpec-47"><a href="#WindowSpec-47"><span class="linenos"> 47</span></a> +</span><span id="WindowSpec-48"><a href="#WindowSpec-48"><span class="linenos"> 48</span></a> <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> +</span><span id="WindowSpec-49"><a href="#WindowSpec-49"><span class="linenos"> 49</span></a> <span class="k">return</span> <span class="n">WindowSpec</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span> +</span><span id="WindowSpec-50"><a href="#WindowSpec-50"><span class="linenos"> 50</span></a> +</span><span id="WindowSpec-51"><a href="#WindowSpec-51"><span class="linenos"> 51</span></a> <span class="k">def</span> <span class="nf">sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="WindowSpec-52"><a href="#WindowSpec-52"><span class="linenos"> 52</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="s2">"spark"</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> +</span><span id="WindowSpec-53"><a href="#WindowSpec-53"><span class="linenos"> 53</span></a> +</span><span id="WindowSpec-54"><a href="#WindowSpec-54"><span class="linenos"> 54</span></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">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">]])</span> <span class="o">-></span> <span class="n">WindowSpec</span><span class="p">:</span> +</span><span id="WindowSpec-55"><a href="#WindowSpec-55"><span class="linenos"> 55</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.column</span> <span class="kn">import</span> <span class="n">Column</span> +</span><span id="WindowSpec-56"><a href="#WindowSpec-56"><span class="linenos"> 56</span></a> +</span><span id="WindowSpec-57"><a href="#WindowSpec-57"><span class="linenos"> 57</span></a> <span class="n">cols</span> <span class="o">=</span> <span class="n">flatten</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">cols</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">set</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">))</span> <span class="k">else</span> <span class="n">cols</span> <span class="c1"># type: ignore</span> +</span><span id="WindowSpec-58"><a href="#WindowSpec-58"><span class="linenos"> 58</span></a> <span class="n">expressions</span> <span class="o">=</span> <span class="p">[</span><span class="n">Column</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">cols</span><span class="p">]</span> +</span><span id="WindowSpec-59"><a href="#WindowSpec-59"><span class="linenos"> 59</span></a> <span class="n">window_spec</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="WindowSpec-60"><a href="#WindowSpec-60"><span class="linenos"> 60</span></a> <span class="n">partition_by_expressions</span> <span class="o">=</span> <span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"partition_by"</span><span class="p">,</span> <span class="p">[])</span> +</span><span id="WindowSpec-61"><a href="#WindowSpec-61"><span class="linenos"> 61</span></a> <span class="n">partition_by_expressions</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">expressions</span><span class="p">)</span> +</span><span id="WindowSpec-62"><a href="#WindowSpec-62"><span class="linenos"> 62</span></a> <span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"partition_by"</span><span class="p">,</span> <span class="n">partition_by_expressions</span><span class="p">)</span> +</span><span id="WindowSpec-63"><a href="#WindowSpec-63"><span class="linenos"> 63</span></a> <span class="k">return</span> <span class="n">window_spec</span> +</span><span id="WindowSpec-64"><a href="#WindowSpec-64"><span class="linenos"> 64</span></a> +</span><span id="WindowSpec-65"><a href="#WindowSpec-65"><span class="linenos"> 65</span></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">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">]])</span> <span class="o">-></span> <span class="n">WindowSpec</span><span class="p">:</span> +</span><span id="WindowSpec-66"><a href="#WindowSpec-66"><span class="linenos"> 66</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.column</span> <span class="kn">import</span> <span class="n">Column</span> +</span><span id="WindowSpec-67"><a href="#WindowSpec-67"><span class="linenos"> 67</span></a> +</span><span id="WindowSpec-68"><a href="#WindowSpec-68"><span class="linenos"> 68</span></a> <span class="n">cols</span> <span class="o">=</span> <span class="n">flatten</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">cols</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">set</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">))</span> <span class="k">else</span> <span class="n">cols</span> <span class="c1"># type: ignore</span> +</span><span id="WindowSpec-69"><a href="#WindowSpec-69"><span class="linenos"> 69</span></a> <span class="n">expressions</span> <span class="o">=</span> <span class="p">[</span><span class="n">Column</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">cols</span><span class="p">]</span> +</span><span id="WindowSpec-70"><a href="#WindowSpec-70"><span class="linenos"> 70</span></a> <span class="n">window_spec</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="WindowSpec-71"><a href="#WindowSpec-71"><span class="linenos"> 71</span></a> <span class="k">if</span> <span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"order"</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> +</span><span id="WindowSpec-72"><a href="#WindowSpec-72"><span class="linenos"> 72</span></a> <span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"order"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Order</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="p">[]))</span> +</span><span id="WindowSpec-73"><a href="#WindowSpec-73"><span class="linenos"> 73</span></a> <span class="n">order_by</span> <span class="o">=</span> <span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"order"</span><span class="p">]</span><span class="o">.</span><span class="n">expressions</span> +</span><span id="WindowSpec-74"><a href="#WindowSpec-74"><span class="linenos"> 74</span></a> <span class="n">order_by</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">expressions</span><span class="p">)</span> +</span><span id="WindowSpec-75"><a href="#WindowSpec-75"><span class="linenos"> 75</span></a> <span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"order"</span><span class="p">]</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="n">order_by</span><span class="p">)</span> +</span><span id="WindowSpec-76"><a href="#WindowSpec-76"><span class="linenos"> 76</span></a> <span class="k">return</span> <span class="n">window_spec</span> +</span><span id="WindowSpec-77"><a href="#WindowSpec-77"><span class="linenos"> 77</span></a> +</span><span id="WindowSpec-78"><a href="#WindowSpec-78"><span class="linenos"> 78</span></a> <span class="k">def</span> <span class="nf">_calc_start_end</span><span class="p">(</span> +</span><span id="WindowSpec-79"><a href="#WindowSpec-79"><span class="linenos"> 79</span></a> <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><span id="WindowSpec-80"><a href="#WindowSpec-80"><span class="linenos"> 80</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]]]:</span> +</span><span id="WindowSpec-81"><a href="#WindowSpec-81"><span class="linenos"> 81</span></a> <span class="n">kwargs</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]]]</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="WindowSpec-82"><a href="#WindowSpec-82"><span class="linenos"> 82</span></a> <span class="s2">"start_side"</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="WindowSpec-83"><a href="#WindowSpec-83"><span class="linenos"> 83</span></a> <span class="s2">"end_side"</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="WindowSpec-84"><a href="#WindowSpec-84"><span class="linenos"> 84</span></a> <span class="p">}</span> +</span><span id="WindowSpec-85"><a href="#WindowSpec-85"><span class="linenos"> 85</span></a> <span class="k">if</span> <span class="n">start</span> <span class="o">==</span> <span class="n">Window</span><span class="o">.</span><span class="n">currentRow</span><span class="p">:</span> +</span><span id="WindowSpec-86"><a href="#WindowSpec-86"><span class="linenos"> 86</span></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">"start"</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"CURRENT ROW"</span> +</span><span id="WindowSpec-87"><a href="#WindowSpec-87"><span class="linenos"> 87</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="WindowSpec-88"><a href="#WindowSpec-88"><span class="linenos"> 88</span></a> <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="WindowSpec-89"><a href="#WindowSpec-89"><span class="linenos"> 89</span></a> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span> +</span><span id="WindowSpec-90"><a href="#WindowSpec-90"><span class="linenos"> 90</span></a> <span class="o">**</span><span class="p">{</span> +</span><span id="WindowSpec-91"><a href="#WindowSpec-91"><span class="linenos"> 91</span></a> <span class="s2">"start_side"</span><span class="p">:</span> <span class="s2">"PRECEDING"</span><span class="p">,</span> +</span><span id="WindowSpec-92"><a href="#WindowSpec-92"><span class="linenos"> 92</span></a> <span class="s2">"start"</span><span class="p">:</span> <span class="s2">"UNBOUNDED"</span> +</span><span id="WindowSpec-93"><a href="#WindowSpec-93"><span class="linenos"> 93</span></a> <span class="k">if</span> <span class="n">start</span> <span class="o"><=</span> <span class="n">Window</span><span class="o">.</span><span class="n">unboundedPreceding</span> +</span><span id="WindowSpec-94"><a href="#WindowSpec-94"><span class="linenos"> 94</span></a> <span class="k">else</span> <span class="n">F</span><span class="o">.</span><span class="n">lit</span><span class="p">(</span><span class="n">start</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> +</span><span id="WindowSpec-95"><a href="#WindowSpec-95"><span class="linenos"> 95</span></a> <span class="p">},</span> +</span><span id="WindowSpec-96"><a href="#WindowSpec-96"><span class="linenos"> 96</span></a> <span class="p">}</span> +</span><span id="WindowSpec-97"><a href="#WindowSpec-97"><span class="linenos"> 97</span></a> <span class="k">if</span> <span class="n">end</span> <span class="o">==</span> <span class="n">Window</span><span class="o">.</span><span class="n">currentRow</span><span class="p">:</span> +</span><span id="WindowSpec-98"><a href="#WindowSpec-98"><span class="linenos"> 98</span></a> <span class="n">kwargs</span><span class="p">[</span><span class="s2">"end"</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"CURRENT ROW"</span> +</span><span id="WindowSpec-99"><a href="#WindowSpec-99"><span class="linenos"> 99</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="WindowSpec-100"><a href="#WindowSpec-100"><span class="linenos">100</span></a> <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="WindowSpec-101"><a href="#WindowSpec-101"><span class="linenos">101</span></a> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span> +</span><span id="WindowSpec-102"><a href="#WindowSpec-102"><span class="linenos">102</span></a> <span class="o">**</span><span class="p">{</span> +</span><span id="WindowSpec-103"><a href="#WindowSpec-103"><span class="linenos">103</span></a> <span class="s2">"end_side"</span><span class="p">:</span> <span class="s2">"FOLLOWING"</span><span class="p">,</span> +</span><span id="WindowSpec-104"><a href="#WindowSpec-104"><span class="linenos">104</span></a> <span class="s2">"end"</span><span class="p">:</span> <span class="s2">"UNBOUNDED"</span> +</span><span id="WindowSpec-105"><a href="#WindowSpec-105"><span class="linenos">105</span></a> <span class="k">if</span> <span class="n">end</span> <span class="o">>=</span> <span class="n">Window</span><span class="o">.</span><span class="n">unboundedFollowing</span> +</span><span id="WindowSpec-106"><a href="#WindowSpec-106"><span class="linenos">106</span></a> <span class="k">else</span> <span class="n">F</span><span class="o">.</span><span class="n">lit</span><span class="p">(</span><span class="n">end</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> +</span><span id="WindowSpec-107"><a href="#WindowSpec-107"><span class="linenos">107</span></a> <span class="p">},</span> +</span><span id="WindowSpec-108"><a href="#WindowSpec-108"><span class="linenos">108</span></a> <span class="p">}</span> +</span><span id="WindowSpec-109"><a href="#WindowSpec-109"><span class="linenos">109</span></a> <span class="k">return</span> <span class="n">kwargs</span> +</span><span id="WindowSpec-110"><a href="#WindowSpec-110"><span class="linenos">110</span></a> +</span><span id="WindowSpec-111"><a href="#WindowSpec-111"><span class="linenos">111</span></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="n">WindowSpec</span><span class="p">:</span> +</span><span id="WindowSpec-112"><a href="#WindowSpec-112"><span class="linenos">112</span></a> <span class="n">window_spec</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="WindowSpec-113"><a href="#WindowSpec-113"><span class="linenos">113</span></a> <span class="n">spec</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc_start_end</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span> +</span><span id="WindowSpec-114"><a href="#WindowSpec-114"><span class="linenos">114</span></a> <span class="n">spec</span><span class="p">[</span><span class="s2">"kind"</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"ROWS"</span> +</span><span id="WindowSpec-115"><a href="#WindowSpec-115"><span class="linenos">115</span></a> <span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> +</span><span id="WindowSpec-116"><a href="#WindowSpec-116"><span class="linenos">116</span></a> <span class="s2">"spec"</span><span class="p">,</span> +</span><span id="WindowSpec-117"><a href="#WindowSpec-117"><span class="linenos">117</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">WindowSpec</span><span class="p">(</span> +</span><span id="WindowSpec-118"><a href="#WindowSpec-118"><span class="linenos">118</span></a> <span class="o">**</span><span class="p">{</span><span class="o">**</span><span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"spec"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">WindowSpec</span><span class="p">())</span><span class="o">.</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">spec</span><span class="p">}</span> +</span><span id="WindowSpec-119"><a href="#WindowSpec-119"><span class="linenos">119</span></a> <span class="p">),</span> +</span><span id="WindowSpec-120"><a href="#WindowSpec-120"><span class="linenos">120</span></a> <span class="p">)</span> +</span><span id="WindowSpec-121"><a href="#WindowSpec-121"><span class="linenos">121</span></a> <span class="k">return</span> <span class="n">window_spec</span> +</span><span id="WindowSpec-122"><a href="#WindowSpec-122"><span class="linenos">122</span></a> +</span><span id="WindowSpec-123"><a href="#WindowSpec-123"><span class="linenos">123</span></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="n">WindowSpec</span><span class="p">:</span> +</span><span id="WindowSpec-124"><a href="#WindowSpec-124"><span class="linenos">124</span></a> <span class="n">window_spec</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="WindowSpec-125"><a href="#WindowSpec-125"><span class="linenos">125</span></a> <span class="n">spec</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc_start_end</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span> +</span><span id="WindowSpec-126"><a href="#WindowSpec-126"><span class="linenos">126</span></a> <span class="n">spec</span><span class="p">[</span><span class="s2">"kind"</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"RANGE"</span> +</span><span id="WindowSpec-127"><a href="#WindowSpec-127"><span class="linenos">127</span></a> <span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> +</span><span id="WindowSpec-128"><a href="#WindowSpec-128"><span class="linenos">128</span></a> <span class="s2">"spec"</span><span class="p">,</span> +</span><span id="WindowSpec-129"><a href="#WindowSpec-129"><span class="linenos">129</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">WindowSpec</span><span class="p">(</span> +</span><span id="WindowSpec-130"><a href="#WindowSpec-130"><span class="linenos">130</span></a> <span class="o">**</span><span class="p">{</span><span class="o">**</span><span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"spec"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">WindowSpec</span><span class="p">())</span><span class="o">.</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">spec</span><span class="p">}</span> +</span><span id="WindowSpec-131"><a href="#WindowSpec-131"><span class="linenos">131</span></a> <span class="p">),</span> +</span><span id="WindowSpec-132"><a href="#WindowSpec-132"><span class="linenos">132</span></a> <span class="p">)</span> +</span><span id="WindowSpec-133"><a href="#WindowSpec-133"><span class="linenos">133</span></a> <span class="k">return</span> <span class="n">window_spec</span> +</span></pre></div> + + + + + <div id="WindowSpec.__init__" class="classattr"> + <input id="WindowSpec.__init__-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="name">WindowSpec</span><span class="signature pdoc-code condensed">(<span class="param"><span class="n">expression</span><span class="p">:</span> <span class="n"><a href="../expressions.html#Expression">sqlglot.expressions.Expression</a></span> <span class="o">=</span> <span class="p">(</span><span class="n">WINDOW</span> <span class="p">)</span></span>)</span> + + <label class="view-source-button" for="WindowSpec.__init__-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#WindowSpec.__init__"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="WindowSpec.__init__-45"><a href="#WindowSpec.__init__-45"><span class="linenos">45</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Window</span><span class="p">()):</span> +</span><span id="WindowSpec.__init__-46"><a href="#WindowSpec.__init__-46"><span class="linenos">46</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span> <span class="o">=</span> <span class="n">expression</span> +</span></pre></div> + + + + + </div> + <div id="WindowSpec.copy" class="classattr"> + <input id="WindowSpec.copy-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">copy</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span></span><span class="return-annotation">):</span></span> + + <label class="view-source-button" for="WindowSpec.copy-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#WindowSpec.copy"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="WindowSpec.copy-48"><a href="#WindowSpec.copy-48"><span class="linenos">48</span></a> <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> +</span><span id="WindowSpec.copy-49"><a href="#WindowSpec.copy-49"><span class="linenos">49</span></a> <span class="k">return</span> <span class="n">WindowSpec</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span> +</span></pre></div> + + + + + </div> + <div id="WindowSpec.sql" class="classattr"> + <input id="WindowSpec.sql-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">sql</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="nb">str</span>:</span></span> + + <label class="view-source-button" for="WindowSpec.sql-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#WindowSpec.sql"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="WindowSpec.sql-51"><a href="#WindowSpec.sql-51"><span class="linenos">51</span></a> <span class="k">def</span> <span class="nf">sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="WindowSpec.sql-52"><a href="#WindowSpec.sql-52"><span class="linenos">52</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="s2">"spark"</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="WindowSpec.partitionBy" class="classattr"> + <input id="WindowSpec.partitionBy-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">partitionBy</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700329685440'</span><span class="o">></span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700329685440'</span><span class="o">></span><span class="p">]]</span></span><span class="return-annotation">) -> <span class="n"><a href="#WindowSpec">sqlglot.dataframe.sql.WindowSpec</a></span>:</span></span> + + <label class="view-source-button" for="WindowSpec.partitionBy-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#WindowSpec.partitionBy"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="WindowSpec.partitionBy-54"><a href="#WindowSpec.partitionBy-54"><span class="linenos">54</span></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">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">]])</span> <span class="o">-></span> <span class="n">WindowSpec</span><span class="p">:</span> +</span><span id="WindowSpec.partitionBy-55"><a href="#WindowSpec.partitionBy-55"><span class="linenos">55</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.column</span> <span class="kn">import</span> <span class="n">Column</span> +</span><span id="WindowSpec.partitionBy-56"><a href="#WindowSpec.partitionBy-56"><span class="linenos">56</span></a> +</span><span id="WindowSpec.partitionBy-57"><a href="#WindowSpec.partitionBy-57"><span class="linenos">57</span></a> <span class="n">cols</span> <span class="o">=</span> <span class="n">flatten</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">cols</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">set</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">))</span> <span class="k">else</span> <span class="n">cols</span> <span class="c1"># type: ignore</span> +</span><span id="WindowSpec.partitionBy-58"><a href="#WindowSpec.partitionBy-58"><span class="linenos">58</span></a> <span class="n">expressions</span> <span class="o">=</span> <span class="p">[</span><span class="n">Column</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">cols</span><span class="p">]</span> +</span><span id="WindowSpec.partitionBy-59"><a href="#WindowSpec.partitionBy-59"><span class="linenos">59</span></a> <span class="n">window_spec</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="WindowSpec.partitionBy-60"><a href="#WindowSpec.partitionBy-60"><span class="linenos">60</span></a> <span class="n">partition_by_expressions</span> <span class="o">=</span> <span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"partition_by"</span><span class="p">,</span> <span class="p">[])</span> +</span><span id="WindowSpec.partitionBy-61"><a href="#WindowSpec.partitionBy-61"><span class="linenos">61</span></a> <span class="n">partition_by_expressions</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">expressions</span><span class="p">)</span> +</span><span id="WindowSpec.partitionBy-62"><a href="#WindowSpec.partitionBy-62"><span class="linenos">62</span></a> <span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"partition_by"</span><span class="p">,</span> <span class="n">partition_by_expressions</span><span class="p">)</span> +</span><span id="WindowSpec.partitionBy-63"><a href="#WindowSpec.partitionBy-63"><span class="linenos">63</span></a> <span class="k">return</span> <span class="n">window_spec</span> +</span></pre></div> + + + + + </div> + <div id="WindowSpec.orderBy" class="classattr"> + <input id="WindowSpec.orderBy-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">orderBy</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="o">*</span><span class="n">cols</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700329654400'</span><span class="o">></span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="o"><</span><span class="n">MagicMock</span> <span class="nb">id</span><span class="o">=</span><span class="s1">'140700329654400'</span><span class="o">></span><span class="p">]]</span></span><span class="return-annotation">) -> <span class="n"><a href="#WindowSpec">sqlglot.dataframe.sql.WindowSpec</a></span>:</span></span> + + <label class="view-source-button" for="WindowSpec.orderBy-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#WindowSpec.orderBy"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="WindowSpec.orderBy-65"><a href="#WindowSpec.orderBy-65"><span class="linenos">65</span></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">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">ColumnOrName</span><span class="p">]])</span> <span class="o">-></span> <span class="n">WindowSpec</span><span class="p">:</span> +</span><span id="WindowSpec.orderBy-66"><a href="#WindowSpec.orderBy-66"><span class="linenos">66</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.column</span> <span class="kn">import</span> <span class="n">Column</span> +</span><span id="WindowSpec.orderBy-67"><a href="#WindowSpec.orderBy-67"><span class="linenos">67</span></a> +</span><span id="WindowSpec.orderBy-68"><a href="#WindowSpec.orderBy-68"><span class="linenos">68</span></a> <span class="n">cols</span> <span class="o">=</span> <span class="n">flatten</span><span class="p">(</span><span class="n">cols</span><span class="p">)</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">cols</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">set</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">))</span> <span class="k">else</span> <span class="n">cols</span> <span class="c1"># type: ignore</span> +</span><span id="WindowSpec.orderBy-69"><a href="#WindowSpec.orderBy-69"><span class="linenos">69</span></a> <span class="n">expressions</span> <span class="o">=</span> <span class="p">[</span><span class="n">Column</span><span class="o">.</span><span class="n">ensure_col</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">expression</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">cols</span><span class="p">]</span> +</span><span id="WindowSpec.orderBy-70"><a href="#WindowSpec.orderBy-70"><span class="linenos">70</span></a> <span class="n">window_spec</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="WindowSpec.orderBy-71"><a href="#WindowSpec.orderBy-71"><span class="linenos">71</span></a> <span class="k">if</span> <span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"order"</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> +</span><span id="WindowSpec.orderBy-72"><a href="#WindowSpec.orderBy-72"><span class="linenos">72</span></a> <span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"order"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Order</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="p">[]))</span> +</span><span id="WindowSpec.orderBy-73"><a href="#WindowSpec.orderBy-73"><span class="linenos">73</span></a> <span class="n">order_by</span> <span class="o">=</span> <span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"order"</span><span class="p">]</span><span class="o">.</span><span class="n">expressions</span> +</span><span id="WindowSpec.orderBy-74"><a href="#WindowSpec.orderBy-74"><span class="linenos">74</span></a> <span class="n">order_by</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">expressions</span><span class="p">)</span> +</span><span id="WindowSpec.orderBy-75"><a href="#WindowSpec.orderBy-75"><span class="linenos">75</span></a> <span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"order"</span><span class="p">]</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="n">order_by</span><span class="p">)</span> +</span><span id="WindowSpec.orderBy-76"><a href="#WindowSpec.orderBy-76"><span class="linenos">76</span></a> <span class="k">return</span> <span class="n">window_spec</span> +</span></pre></div> + + + + + </div> + <div id="WindowSpec.rowsBetween" class="classattr"> + <input id="WindowSpec.rowsBetween-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">rowsBetween</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">start</span><span class="p">:</span> <span class="nb">int</span>, </span><span class="param"><span class="n">end</span><span class="p">:</span> <span class="nb">int</span></span><span class="return-annotation">) -> <span class="n"><a href="#WindowSpec">sqlglot.dataframe.sql.WindowSpec</a></span>:</span></span> + + <label class="view-source-button" for="WindowSpec.rowsBetween-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#WindowSpec.rowsBetween"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="WindowSpec.rowsBetween-111"><a href="#WindowSpec.rowsBetween-111"><span class="linenos">111</span></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="n">WindowSpec</span><span class="p">:</span> +</span><span id="WindowSpec.rowsBetween-112"><a href="#WindowSpec.rowsBetween-112"><span class="linenos">112</span></a> <span class="n">window_spec</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="WindowSpec.rowsBetween-113"><a href="#WindowSpec.rowsBetween-113"><span class="linenos">113</span></a> <span class="n">spec</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc_start_end</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span> +</span><span id="WindowSpec.rowsBetween-114"><a href="#WindowSpec.rowsBetween-114"><span class="linenos">114</span></a> <span class="n">spec</span><span class="p">[</span><span class="s2">"kind"</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"ROWS"</span> +</span><span id="WindowSpec.rowsBetween-115"><a href="#WindowSpec.rowsBetween-115"><span class="linenos">115</span></a> <span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> +</span><span id="WindowSpec.rowsBetween-116"><a href="#WindowSpec.rowsBetween-116"><span class="linenos">116</span></a> <span class="s2">"spec"</span><span class="p">,</span> +</span><span id="WindowSpec.rowsBetween-117"><a href="#WindowSpec.rowsBetween-117"><span class="linenos">117</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">WindowSpec</span><span class="p">(</span> +</span><span id="WindowSpec.rowsBetween-118"><a href="#WindowSpec.rowsBetween-118"><span class="linenos">118</span></a> <span class="o">**</span><span class="p">{</span><span class="o">**</span><span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"spec"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">WindowSpec</span><span class="p">())</span><span class="o">.</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">spec</span><span class="p">}</span> +</span><span id="WindowSpec.rowsBetween-119"><a href="#WindowSpec.rowsBetween-119"><span class="linenos">119</span></a> <span class="p">),</span> +</span><span id="WindowSpec.rowsBetween-120"><a href="#WindowSpec.rowsBetween-120"><span class="linenos">120</span></a> <span class="p">)</span> +</span><span id="WindowSpec.rowsBetween-121"><a href="#WindowSpec.rowsBetween-121"><span class="linenos">121</span></a> <span class="k">return</span> <span class="n">window_spec</span> +</span></pre></div> + + + + + </div> + <div id="WindowSpec.rangeBetween" class="classattr"> + <input id="WindowSpec.rangeBetween-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">rangeBetween</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">start</span><span class="p">:</span> <span class="nb">int</span>, </span><span class="param"><span class="n">end</span><span class="p">:</span> <span class="nb">int</span></span><span class="return-annotation">) -> <span class="n"><a href="#WindowSpec">sqlglot.dataframe.sql.WindowSpec</a></span>:</span></span> + + <label class="view-source-button" for="WindowSpec.rangeBetween-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#WindowSpec.rangeBetween"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="WindowSpec.rangeBetween-123"><a href="#WindowSpec.rangeBetween-123"><span class="linenos">123</span></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="n">WindowSpec</span><span class="p">:</span> +</span><span id="WindowSpec.rangeBetween-124"><a href="#WindowSpec.rangeBetween-124"><span class="linenos">124</span></a> <span class="n">window_spec</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="WindowSpec.rangeBetween-125"><a href="#WindowSpec.rangeBetween-125"><span class="linenos">125</span></a> <span class="n">spec</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_calc_start_end</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span> +</span><span id="WindowSpec.rangeBetween-126"><a href="#WindowSpec.rangeBetween-126"><span class="linenos">126</span></a> <span class="n">spec</span><span class="p">[</span><span class="s2">"kind"</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"RANGE"</span> +</span><span id="WindowSpec.rangeBetween-127"><a href="#WindowSpec.rangeBetween-127"><span class="linenos">127</span></a> <span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> +</span><span id="WindowSpec.rangeBetween-128"><a href="#WindowSpec.rangeBetween-128"><span class="linenos">128</span></a> <span class="s2">"spec"</span><span class="p">,</span> +</span><span id="WindowSpec.rangeBetween-129"><a href="#WindowSpec.rangeBetween-129"><span class="linenos">129</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">WindowSpec</span><span class="p">(</span> +</span><span id="WindowSpec.rangeBetween-130"><a href="#WindowSpec.rangeBetween-130"><span class="linenos">130</span></a> <span class="o">**</span><span class="p">{</span><span class="o">**</span><span class="n">window_spec</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"spec"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">WindowSpec</span><span class="p">())</span><span class="o">.</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">spec</span><span class="p">}</span> +</span><span id="WindowSpec.rangeBetween-131"><a href="#WindowSpec.rangeBetween-131"><span class="linenos">131</span></a> <span class="p">),</span> +</span><span id="WindowSpec.rangeBetween-132"><a href="#WindowSpec.rangeBetween-132"><span class="linenos">132</span></a> <span class="p">)</span> +</span><span id="WindowSpec.rangeBetween-133"><a href="#WindowSpec.rangeBetween-133"><span class="linenos">133</span></a> <span class="k">return</span> <span class="n">window_spec</span> +</span></pre></div> + + + + + </div> + </section> + <section id="DataFrameReader"> + <input id="DataFrameReader-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr class"> + + <span class="def">class</span> + <span class="name">DataFrameReader</span>: + + <label class="view-source-button" for="DataFrameReader-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrameReader"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameReader-15"><a href="#DataFrameReader-15"><span class="linenos">15</span></a><span class="k">class</span> <span class="nc">DataFrameReader</span><span class="p">:</span> +</span><span id="DataFrameReader-16"><a href="#DataFrameReader-16"><span class="linenos">16</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">spark</span><span class="p">:</span> <span class="n">SparkSession</span><span class="p">):</span> +</span><span id="DataFrameReader-17"><a href="#DataFrameReader-17"><span class="linenos">17</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">spark</span> <span class="o">=</span> <span class="n">spark</span> +</span><span id="DataFrameReader-18"><a href="#DataFrameReader-18"><span class="linenos">18</span></a> +</span><span id="DataFrameReader-19"><a href="#DataFrameReader-19"><span class="linenos">19</span></a> <span class="k">def</span> <span class="nf">table</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tableName</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrameReader-20"><a href="#DataFrameReader-20"><span class="linenos">20</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.dataframe</span> <span class="kn">import</span> <span class="n">DataFrame</span> +</span><span id="DataFrameReader-21"><a href="#DataFrameReader-21"><span class="linenos">21</span></a> +</span><span id="DataFrameReader-22"><a href="#DataFrameReader-22"><span class="linenos">22</span></a> <span class="n">sqlglot</span><span class="o">.</span><span class="n">schema</span><span class="o">.</span><span class="n">add_table</span><span class="p">(</span><span class="n">tableName</span><span class="p">)</span> +</span><span id="DataFrameReader-23"><a href="#DataFrameReader-23"><span class="linenos">23</span></a> <span class="k">return</span> <span class="n">DataFrame</span><span class="p">(</span> +</span><span id="DataFrameReader-24"><a href="#DataFrameReader-24"><span class="linenos">24</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">spark</span><span class="p">,</span> +</span><span id="DataFrameReader-25"><a href="#DataFrameReader-25"><span class="linenos">25</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">()</span><span class="o">.</span><span class="n">from_</span><span class="p">(</span><span class="n">tableName</span><span class="p">)</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="n">sqlglot</span><span class="o">.</span><span class="n">schema</span><span class="o">.</span><span class="n">column_names</span><span class="p">(</span><span class="n">tableName</span><span class="p">)),</span> +</span><span id="DataFrameReader-26"><a href="#DataFrameReader-26"><span class="linenos">26</span></a> <span class="p">)</span> +</span></pre></div> + + + + + <div id="DataFrameReader.__init__" class="classattr"> + <input id="DataFrameReader.__init__-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="name">DataFrameReader</span><span class="signature pdoc-code condensed">(<span class="param"><span class="n">spark</span><span class="p">:</span> <span class="n"><a href="#SparkSession">sqlglot.dataframe.sql.SparkSession</a></span></span>)</span> + + <label class="view-source-button" for="DataFrameReader.__init__-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrameReader.__init__"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameReader.__init__-16"><a href="#DataFrameReader.__init__-16"><span class="linenos">16</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">spark</span><span class="p">:</span> <span class="n">SparkSession</span><span class="p">):</span> +</span><span id="DataFrameReader.__init__-17"><a href="#DataFrameReader.__init__-17"><span class="linenos">17</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">spark</span> <span class="o">=</span> <span class="n">spark</span> +</span></pre></div> + + + + + </div> + <div id="DataFrameReader.table" class="classattr"> + <input id="DataFrameReader.table-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">table</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">tableName</span><span class="p">:</span> <span class="nb">str</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></span> + + <label class="view-source-button" for="DataFrameReader.table-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrameReader.table"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameReader.table-19"><a href="#DataFrameReader.table-19"><span class="linenos">19</span></a> <span class="k">def</span> <span class="nf">table</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tableName</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrameReader.table-20"><a href="#DataFrameReader.table-20"><span class="linenos">20</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dataframe.sql.dataframe</span> <span class="kn">import</span> <span class="n">DataFrame</span> +</span><span id="DataFrameReader.table-21"><a href="#DataFrameReader.table-21"><span class="linenos">21</span></a> +</span><span id="DataFrameReader.table-22"><a href="#DataFrameReader.table-22"><span class="linenos">22</span></a> <span class="n">sqlglot</span><span class="o">.</span><span class="n">schema</span><span class="o">.</span><span class="n">add_table</span><span class="p">(</span><span class="n">tableName</span><span class="p">)</span> +</span><span id="DataFrameReader.table-23"><a href="#DataFrameReader.table-23"><span class="linenos">23</span></a> <span class="k">return</span> <span class="n">DataFrame</span><span class="p">(</span> +</span><span id="DataFrameReader.table-24"><a href="#DataFrameReader.table-24"><span class="linenos">24</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">spark</span><span class="p">,</span> +</span><span id="DataFrameReader.table-25"><a href="#DataFrameReader.table-25"><span class="linenos">25</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">()</span><span class="o">.</span><span class="n">from_</span><span class="p">(</span><span class="n">tableName</span><span class="p">)</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="n">sqlglot</span><span class="o">.</span><span class="n">schema</span><span class="o">.</span><span class="n">column_names</span><span class="p">(</span><span class="n">tableName</span><span class="p">)),</span> +</span><span id="DataFrameReader.table-26"><a href="#DataFrameReader.table-26"><span class="linenos">26</span></a> <span class="p">)</span> +</span></pre></div> + + + + + </div> + </section> + <section id="DataFrameWriter"> + <input id="DataFrameWriter-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr class"> + + <span class="def">class</span> + <span class="name">DataFrameWriter</span>: + + <label class="view-source-button" for="DataFrameWriter-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrameWriter"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameWriter-29"><a href="#DataFrameWriter-29"><span class="linenos">29</span></a><span class="k">class</span> <span class="nc">DataFrameWriter</span><span class="p">:</span> +</span><span id="DataFrameWriter-30"><a href="#DataFrameWriter-30"><span class="linenos">30</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span> +</span><span id="DataFrameWriter-31"><a href="#DataFrameWriter-31"><span class="linenos">31</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrameWriter-32"><a href="#DataFrameWriter-32"><span class="linenos">32</span></a> <span class="n">df</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">,</span> +</span><span id="DataFrameWriter-33"><a href="#DataFrameWriter-33"><span class="linenos">33</span></a> <span class="n">spark</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">SparkSession</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrameWriter-34"><a href="#DataFrameWriter-34"><span class="linenos">34</span></a> <span class="n">mode</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrameWriter-35"><a href="#DataFrameWriter-35"><span class="linenos">35</span></a> <span class="n">by_name</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> +</span><span id="DataFrameWriter-36"><a href="#DataFrameWriter-36"><span class="linenos">36</span></a> <span class="p">):</span> +</span><span id="DataFrameWriter-37"><a href="#DataFrameWriter-37"><span class="linenos">37</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_df</span> <span class="o">=</span> <span class="n">df</span> +</span><span id="DataFrameWriter-38"><a href="#DataFrameWriter-38"><span class="linenos">38</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_spark</span> <span class="o">=</span> <span class="n">spark</span> <span class="ow">or</span> <span class="n">df</span><span class="o">.</span><span class="n">spark</span> +</span><span id="DataFrameWriter-39"><a href="#DataFrameWriter-39"><span class="linenos">39</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_mode</span> <span class="o">=</span> <span class="n">mode</span> +</span><span id="DataFrameWriter-40"><a href="#DataFrameWriter-40"><span class="linenos">40</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_by_name</span> <span class="o">=</span> <span class="n">by_name</span> +</span><span id="DataFrameWriter-41"><a href="#DataFrameWriter-41"><span class="linenos">41</span></a> +</span><span id="DataFrameWriter-42"><a href="#DataFrameWriter-42"><span class="linenos">42</span></a> <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrameWriter</span><span class="p">:</span> +</span><span id="DataFrameWriter-43"><a href="#DataFrameWriter-43"><span class="linenos">43</span></a> <span class="k">return</span> <span class="n">DataFrameWriter</span><span class="p">(</span> +</span><span id="DataFrameWriter-44"><a href="#DataFrameWriter-44"><span class="linenos">44</span></a> <span class="o">**</span><span class="p">{</span> +</span><span id="DataFrameWriter-45"><a href="#DataFrameWriter-45"><span class="linenos">45</span></a> <span class="n">k</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span> <span class="k">if</span> <span class="n">k</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">"_"</span><span class="p">)</span> <span class="k">else</span> <span class="n">k</span><span class="p">:</span> <span class="n">v</span> +</span><span id="DataFrameWriter-46"><a href="#DataFrameWriter-46"><span class="linenos">46</span></a> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">object_to_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> +</span><span id="DataFrameWriter-47"><a href="#DataFrameWriter-47"><span class="linenos">47</span></a> <span class="p">}</span> +</span><span id="DataFrameWriter-48"><a href="#DataFrameWriter-48"><span class="linenos">48</span></a> <span class="p">)</span> +</span><span id="DataFrameWriter-49"><a href="#DataFrameWriter-49"><span class="linenos">49</span></a> +</span><span id="DataFrameWriter-50"><a href="#DataFrameWriter-50"><span class="linenos">50</span></a> <span class="k">def</span> <span class="nf">sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> +</span><span id="DataFrameWriter-51"><a href="#DataFrameWriter-51"><span class="linenos">51</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_df</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> +</span><span id="DataFrameWriter-52"><a href="#DataFrameWriter-52"><span class="linenos">52</span></a> +</span><span id="DataFrameWriter-53"><a href="#DataFrameWriter-53"><span class="linenos">53</span></a> <span class="k">def</span> <span class="nf">mode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">saveMode</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">])</span> <span class="o">-></span> <span class="n">DataFrameWriter</span><span class="p">:</span> +</span><span id="DataFrameWriter-54"><a href="#DataFrameWriter-54"><span class="linenos">54</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">_mode</span><span class="o">=</span><span class="n">saveMode</span><span class="p">)</span> +</span><span id="DataFrameWriter-55"><a href="#DataFrameWriter-55"><span class="linenos">55</span></a> +</span><span id="DataFrameWriter-56"><a href="#DataFrameWriter-56"><span class="linenos">56</span></a> <span class="nd">@property</span> +</span><span id="DataFrameWriter-57"><a href="#DataFrameWriter-57"><span class="linenos">57</span></a> <span class="k">def</span> <span class="nf">byName</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> +</span><span id="DataFrameWriter-58"><a href="#DataFrameWriter-58"><span class="linenos">58</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">by_name</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="DataFrameWriter-59"><a href="#DataFrameWriter-59"><span class="linenos">59</span></a> +</span><span id="DataFrameWriter-60"><a href="#DataFrameWriter-60"><span class="linenos">60</span></a> <span class="k">def</span> <span class="nf">insertInto</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tableName</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">overwrite</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">bool</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrameWriter</span><span class="p">:</span> +</span><span id="DataFrameWriter-61"><a href="#DataFrameWriter-61"><span class="linenos">61</span></a> <span class="n">output_expression_container</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Insert</span><span class="p">(</span> +</span><span id="DataFrameWriter-62"><a href="#DataFrameWriter-62"><span class="linenos">62</span></a> <span class="o">**</span><span class="p">{</span> +</span><span id="DataFrameWriter-63"><a href="#DataFrameWriter-63"><span class="linenos">63</span></a> <span class="s2">"this"</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">to_table</span><span class="p">(</span><span class="n">tableName</span><span class="p">),</span> +</span><span id="DataFrameWriter-64"><a href="#DataFrameWriter-64"><span class="linenos">64</span></a> <span class="s2">"overwrite"</span><span class="p">:</span> <span class="n">overwrite</span><span class="p">,</span> +</span><span id="DataFrameWriter-65"><a href="#DataFrameWriter-65"><span class="linenos">65</span></a> <span class="p">}</span> +</span><span id="DataFrameWriter-66"><a href="#DataFrameWriter-66"><span class="linenos">66</span></a> <span class="p">)</span> +</span><span id="DataFrameWriter-67"><a href="#DataFrameWriter-67"><span class="linenos">67</span></a> <span class="n">df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_df</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">output_expression_container</span><span class="o">=</span><span class="n">output_expression_container</span><span class="p">)</span> +</span><span id="DataFrameWriter-68"><a href="#DataFrameWriter-68"><span class="linenos">68</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_by_name</span><span class="p">:</span> +</span><span id="DataFrameWriter-69"><a href="#DataFrameWriter-69"><span class="linenos">69</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="n">sqlglot</span><span class="o">.</span><span class="n">schema</span><span class="o">.</span><span class="n">column_names</span><span class="p">(</span><span class="n">tableName</span><span class="p">,</span> <span class="n">only_visible</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="DataFrameWriter-70"><a href="#DataFrameWriter-70"><span class="linenos">70</span></a> <span class="n">df</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">_convert_leaf_to_cte</span><span class="p">()</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="n">columns</span><span class="p">)</span> +</span><span id="DataFrameWriter-71"><a href="#DataFrameWriter-71"><span class="linenos">71</span></a> +</span><span id="DataFrameWriter-72"><a href="#DataFrameWriter-72"><span class="linenos">72</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">_df</span><span class="o">=</span><span class="n">df</span><span class="p">)</span> +</span><span id="DataFrameWriter-73"><a href="#DataFrameWriter-73"><span class="linenos">73</span></a> +</span><span id="DataFrameWriter-74"><a href="#DataFrameWriter-74"><span class="linenos">74</span></a> <span class="k">def</span> <span class="nf">saveAsTable</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="nb">format</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">mode</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span> +</span><span id="DataFrameWriter-75"><a href="#DataFrameWriter-75"><span class="linenos">75</span></a> <span class="k">if</span> <span class="nb">format</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> +</span><span id="DataFrameWriter-76"><a href="#DataFrameWriter-76"><span class="linenos">76</span></a> <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">"Providing Format in the save as table is not supported"</span><span class="p">)</span> +</span><span id="DataFrameWriter-77"><a href="#DataFrameWriter-77"><span class="linenos">77</span></a> <span class="n">exists</span><span class="p">,</span> <span class="n">replace</span><span class="p">,</span> <span class="n">mode</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">mode</span> <span class="ow">or</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_mode</span><span class="p">)</span> +</span><span id="DataFrameWriter-78"><a href="#DataFrameWriter-78"><span class="linenos">78</span></a> <span class="k">if</span> <span class="n">mode</span> <span class="o">==</span> <span class="s2">"append"</span><span class="p">:</span> +</span><span id="DataFrameWriter-79"><a href="#DataFrameWriter-79"><span class="linenos">79</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">insertInto</span><span class="p">(</span><span class="n">name</span><span class="p">)</span> +</span><span id="DataFrameWriter-80"><a href="#DataFrameWriter-80"><span class="linenos">80</span></a> <span class="k">if</span> <span class="n">mode</span> <span class="o">==</span> <span class="s2">"ignore"</span><span class="p">:</span> +</span><span id="DataFrameWriter-81"><a href="#DataFrameWriter-81"><span class="linenos">81</span></a> <span class="n">exists</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="DataFrameWriter-82"><a href="#DataFrameWriter-82"><span class="linenos">82</span></a> <span class="k">if</span> <span class="n">mode</span> <span class="o">==</span> <span class="s2">"overwrite"</span><span class="p">:</span> +</span><span id="DataFrameWriter-83"><a href="#DataFrameWriter-83"><span class="linenos">83</span></a> <span class="n">replace</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="DataFrameWriter-84"><a href="#DataFrameWriter-84"><span class="linenos">84</span></a> <span class="n">output_expression_container</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Create</span><span class="p">(</span> +</span><span id="DataFrameWriter-85"><a href="#DataFrameWriter-85"><span class="linenos">85</span></a> <span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">to_table</span><span class="p">(</span><span class="n">name</span><span class="p">),</span> +</span><span id="DataFrameWriter-86"><a href="#DataFrameWriter-86"><span class="linenos">86</span></a> <span class="n">kind</span><span class="o">=</span><span class="s2">"TABLE"</span><span class="p">,</span> +</span><span id="DataFrameWriter-87"><a href="#DataFrameWriter-87"><span class="linenos">87</span></a> <span class="n">exists</span><span class="o">=</span><span class="n">exists</span><span class="p">,</span> +</span><span id="DataFrameWriter-88"><a href="#DataFrameWriter-88"><span class="linenos">88</span></a> <span class="n">replace</span><span class="o">=</span><span class="n">replace</span><span class="p">,</span> +</span><span id="DataFrameWriter-89"><a href="#DataFrameWriter-89"><span class="linenos">89</span></a> <span class="p">)</span> +</span><span id="DataFrameWriter-90"><a href="#DataFrameWriter-90"><span class="linenos">90</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">_df</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_df</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">output_expression_container</span><span class="o">=</span><span class="n">output_expression_container</span><span class="p">))</span> +</span></pre></div> + + + + + <div id="DataFrameWriter.__init__" class="classattr"> + <input id="DataFrameWriter.__init__-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="name">DataFrameWriter</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="n">df</span><span class="p">:</span> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>,</span><span class="param"> <span class="n">spark</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n"><a href="#SparkSession">sqlglot.dataframe.sql.SparkSession</a></span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">mode</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">by_name</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span></span>)</span> + + <label class="view-source-button" for="DataFrameWriter.__init__-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrameWriter.__init__"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameWriter.__init__-30"><a href="#DataFrameWriter.__init__-30"><span class="linenos">30</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span> +</span><span id="DataFrameWriter.__init__-31"><a href="#DataFrameWriter.__init__-31"><span class="linenos">31</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrameWriter.__init__-32"><a href="#DataFrameWriter.__init__-32"><span class="linenos">32</span></a> <span class="n">df</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">,</span> +</span><span id="DataFrameWriter.__init__-33"><a href="#DataFrameWriter.__init__-33"><span class="linenos">33</span></a> <span class="n">spark</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">SparkSession</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrameWriter.__init__-34"><a href="#DataFrameWriter.__init__-34"><span class="linenos">34</span></a> <span class="n">mode</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="DataFrameWriter.__init__-35"><a href="#DataFrameWriter.__init__-35"><span class="linenos">35</span></a> <span class="n">by_name</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> +</span><span id="DataFrameWriter.__init__-36"><a href="#DataFrameWriter.__init__-36"><span class="linenos">36</span></a> <span class="p">):</span> +</span><span id="DataFrameWriter.__init__-37"><a href="#DataFrameWriter.__init__-37"><span class="linenos">37</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_df</span> <span class="o">=</span> <span class="n">df</span> +</span><span id="DataFrameWriter.__init__-38"><a href="#DataFrameWriter.__init__-38"><span class="linenos">38</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_spark</span> <span class="o">=</span> <span class="n">spark</span> <span class="ow">or</span> <span class="n">df</span><span class="o">.</span><span class="n">spark</span> +</span><span id="DataFrameWriter.__init__-39"><a href="#DataFrameWriter.__init__-39"><span class="linenos">39</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_mode</span> <span class="o">=</span> <span class="n">mode</span> +</span><span id="DataFrameWriter.__init__-40"><a href="#DataFrameWriter.__init__-40"><span class="linenos">40</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_by_name</span> <span class="o">=</span> <span class="n">by_name</span> +</span></pre></div> + + + + + </div> + <div id="DataFrameWriter.copy" class="classattr"> + <input id="DataFrameWriter.copy-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">copy</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrameWriter">sqlglot.dataframe.sql.DataFrameWriter</a></span>:</span></span> + + <label class="view-source-button" for="DataFrameWriter.copy-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrameWriter.copy"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameWriter.copy-42"><a href="#DataFrameWriter.copy-42"><span class="linenos">42</span></a> <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrameWriter</span><span class="p">:</span> +</span><span id="DataFrameWriter.copy-43"><a href="#DataFrameWriter.copy-43"><span class="linenos">43</span></a> <span class="k">return</span> <span class="n">DataFrameWriter</span><span class="p">(</span> +</span><span id="DataFrameWriter.copy-44"><a href="#DataFrameWriter.copy-44"><span class="linenos">44</span></a> <span class="o">**</span><span class="p">{</span> +</span><span id="DataFrameWriter.copy-45"><a href="#DataFrameWriter.copy-45"><span class="linenos">45</span></a> <span class="n">k</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span> <span class="k">if</span> <span class="n">k</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">"_"</span><span class="p">)</span> <span class="k">else</span> <span class="n">k</span><span class="p">:</span> <span class="n">v</span> +</span><span id="DataFrameWriter.copy-46"><a href="#DataFrameWriter.copy-46"><span class="linenos">46</span></a> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">object_to_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> +</span><span id="DataFrameWriter.copy-47"><a href="#DataFrameWriter.copy-47"><span class="linenos">47</span></a> <span class="p">}</span> +</span><span id="DataFrameWriter.copy-48"><a href="#DataFrameWriter.copy-48"><span class="linenos">48</span></a> <span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrameWriter.sql" class="classattr"> + <input id="DataFrameWriter.sql-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">sql</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span>:</span></span> + + <label class="view-source-button" for="DataFrameWriter.sql-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrameWriter.sql"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameWriter.sql-50"><a href="#DataFrameWriter.sql-50"><span class="linenos">50</span></a> <span class="k">def</span> <span class="nf">sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> +</span><span id="DataFrameWriter.sql-51"><a href="#DataFrameWriter.sql-51"><span class="linenos">51</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_df</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrameWriter.mode" class="classattr"> + <input id="DataFrameWriter.mode-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">mode</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">saveMode</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrameWriter">sqlglot.dataframe.sql.DataFrameWriter</a></span>:</span></span> + + <label class="view-source-button" for="DataFrameWriter.mode-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrameWriter.mode"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameWriter.mode-53"><a href="#DataFrameWriter.mode-53"><span class="linenos">53</span></a> <span class="k">def</span> <span class="nf">mode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">saveMode</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">])</span> <span class="o">-></span> <span class="n">DataFrameWriter</span><span class="p">:</span> +</span><span id="DataFrameWriter.mode-54"><a href="#DataFrameWriter.mode-54"><span class="linenos">54</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">_mode</span><span class="o">=</span><span class="n">saveMode</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrameWriter.insertInto" class="classattr"> + <input id="DataFrameWriter.insertInto-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">insertInto</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">tableName</span><span class="p">:</span> <span class="nb">str</span>,</span><span class="param"> <span class="n">overwrite</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">bool</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrameWriter">sqlglot.dataframe.sql.DataFrameWriter</a></span>:</span></span> + + <label class="view-source-button" for="DataFrameWriter.insertInto-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrameWriter.insertInto"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameWriter.insertInto-60"><a href="#DataFrameWriter.insertInto-60"><span class="linenos">60</span></a> <span class="k">def</span> <span class="nf">insertInto</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tableName</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">overwrite</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">bool</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-></span> <span class="n">DataFrameWriter</span><span class="p">:</span> +</span><span id="DataFrameWriter.insertInto-61"><a href="#DataFrameWriter.insertInto-61"><span class="linenos">61</span></a> <span class="n">output_expression_container</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Insert</span><span class="p">(</span> +</span><span id="DataFrameWriter.insertInto-62"><a href="#DataFrameWriter.insertInto-62"><span class="linenos">62</span></a> <span class="o">**</span><span class="p">{</span> +</span><span id="DataFrameWriter.insertInto-63"><a href="#DataFrameWriter.insertInto-63"><span class="linenos">63</span></a> <span class="s2">"this"</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">to_table</span><span class="p">(</span><span class="n">tableName</span><span class="p">),</span> +</span><span id="DataFrameWriter.insertInto-64"><a href="#DataFrameWriter.insertInto-64"><span class="linenos">64</span></a> <span class="s2">"overwrite"</span><span class="p">:</span> <span class="n">overwrite</span><span class="p">,</span> +</span><span id="DataFrameWriter.insertInto-65"><a href="#DataFrameWriter.insertInto-65"><span class="linenos">65</span></a> <span class="p">}</span> +</span><span id="DataFrameWriter.insertInto-66"><a href="#DataFrameWriter.insertInto-66"><span class="linenos">66</span></a> <span class="p">)</span> +</span><span id="DataFrameWriter.insertInto-67"><a href="#DataFrameWriter.insertInto-67"><span class="linenos">67</span></a> <span class="n">df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_df</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">output_expression_container</span><span class="o">=</span><span class="n">output_expression_container</span><span class="p">)</span> +</span><span id="DataFrameWriter.insertInto-68"><a href="#DataFrameWriter.insertInto-68"><span class="linenos">68</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_by_name</span><span class="p">:</span> +</span><span id="DataFrameWriter.insertInto-69"><a href="#DataFrameWriter.insertInto-69"><span class="linenos">69</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="n">sqlglot</span><span class="o">.</span><span class="n">schema</span><span class="o">.</span><span class="n">column_names</span><span class="p">(</span><span class="n">tableName</span><span class="p">,</span> <span class="n">only_visible</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="DataFrameWriter.insertInto-70"><a href="#DataFrameWriter.insertInto-70"><span class="linenos">70</span></a> <span class="n">df</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">_convert_leaf_to_cte</span><span class="p">()</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">*</span><span class="n">columns</span><span class="p">)</span> +</span><span id="DataFrameWriter.insertInto-71"><a href="#DataFrameWriter.insertInto-71"><span class="linenos">71</span></a> +</span><span id="DataFrameWriter.insertInto-72"><a href="#DataFrameWriter.insertInto-72"><span class="linenos">72</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">_df</span><span class="o">=</span><span class="n">df</span><span class="p">)</span> +</span></pre></div> + + + + + </div> + <div id="DataFrameWriter.saveAsTable" class="classattr"> + <input id="DataFrameWriter.saveAsTable-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">saveAsTable</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span>,</span><span class="param"> <span class="nb">format</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">mode</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span></span><span class="return-annotation">):</span></span> + + <label class="view-source-button" for="DataFrameWriter.saveAsTable-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#DataFrameWriter.saveAsTable"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameWriter.saveAsTable-74"><a href="#DataFrameWriter.saveAsTable-74"><span class="linenos">74</span></a> <span class="k">def</span> <span class="nf">saveAsTable</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="nb">format</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">mode</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span> +</span><span id="DataFrameWriter.saveAsTable-75"><a href="#DataFrameWriter.saveAsTable-75"><span class="linenos">75</span></a> <span class="k">if</span> <span class="nb">format</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> +</span><span id="DataFrameWriter.saveAsTable-76"><a href="#DataFrameWriter.saveAsTable-76"><span class="linenos">76</span></a> <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">"Providing Format in the save as table is not supported"</span><span class="p">)</span> +</span><span id="DataFrameWriter.saveAsTable-77"><a href="#DataFrameWriter.saveAsTable-77"><span class="linenos">77</span></a> <span class="n">exists</span><span class="p">,</span> <span class="n">replace</span><span class="p">,</span> <span class="n">mode</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">mode</span> <span class="ow">or</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_mode</span><span class="p">)</span> +</span><span id="DataFrameWriter.saveAsTable-78"><a href="#DataFrameWriter.saveAsTable-78"><span class="linenos">78</span></a> <span class="k">if</span> <span class="n">mode</span> <span class="o">==</span> <span class="s2">"append"</span><span class="p">:</span> +</span><span id="DataFrameWriter.saveAsTable-79"><a href="#DataFrameWriter.saveAsTable-79"><span class="linenos">79</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">insertInto</span><span class="p">(</span><span class="n">name</span><span class="p">)</span> +</span><span id="DataFrameWriter.saveAsTable-80"><a href="#DataFrameWriter.saveAsTable-80"><span class="linenos">80</span></a> <span class="k">if</span> <span class="n">mode</span> <span class="o">==</span> <span class="s2">"ignore"</span><span class="p">:</span> +</span><span id="DataFrameWriter.saveAsTable-81"><a href="#DataFrameWriter.saveAsTable-81"><span class="linenos">81</span></a> <span class="n">exists</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="DataFrameWriter.saveAsTable-82"><a href="#DataFrameWriter.saveAsTable-82"><span class="linenos">82</span></a> <span class="k">if</span> <span class="n">mode</span> <span class="o">==</span> <span class="s2">"overwrite"</span><span class="p">:</span> +</span><span id="DataFrameWriter.saveAsTable-83"><a href="#DataFrameWriter.saveAsTable-83"><span class="linenos">83</span></a> <span class="n">replace</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="DataFrameWriter.saveAsTable-84"><a href="#DataFrameWriter.saveAsTable-84"><span class="linenos">84</span></a> <span class="n">output_expression_container</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Create</span><span class="p">(</span> +</span><span id="DataFrameWriter.saveAsTable-85"><a href="#DataFrameWriter.saveAsTable-85"><span class="linenos">85</span></a> <span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">to_table</span><span class="p">(</span><span class="n">name</span><span class="p">),</span> +</span><span id="DataFrameWriter.saveAsTable-86"><a href="#DataFrameWriter.saveAsTable-86"><span class="linenos">86</span></a> <span class="n">kind</span><span class="o">=</span><span class="s2">"TABLE"</span><span class="p">,</span> +</span><span id="DataFrameWriter.saveAsTable-87"><a href="#DataFrameWriter.saveAsTable-87"><span class="linenos">87</span></a> <span class="n">exists</span><span class="o">=</span><span class="n">exists</span><span class="p">,</span> +</span><span id="DataFrameWriter.saveAsTable-88"><a href="#DataFrameWriter.saveAsTable-88"><span class="linenos">88</span></a> <span class="n">replace</span><span class="o">=</span><span class="n">replace</span><span class="p">,</span> +</span><span id="DataFrameWriter.saveAsTable-89"><a href="#DataFrameWriter.saveAsTable-89"><span class="linenos">89</span></a> <span class="p">)</span> +</span><span id="DataFrameWriter.saveAsTable-90"><a href="#DataFrameWriter.saveAsTable-90"><span class="linenos">90</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">_df</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_df</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">output_expression_container</span><span class="o">=</span><span class="n">output_expression_container</span><span class="p">))</span> +</span></pre></div> + + + + + </div> + </section> + </main> +<script> + function escapeHTML(html) { + return document.createElement('div').appendChild(document.createTextNode(html)).parentNode.innerHTML; + } + + const originalContent = document.querySelector("main.pdoc"); + let currentContent = originalContent; + + function setContent(innerHTML) { + let elem; + if (innerHTML) { + elem = document.createElement("main"); + elem.classList.add("pdoc"); + elem.innerHTML = innerHTML; + } else { + elem = originalContent; + } + if (currentContent !== elem) { + currentContent.replaceWith(elem); + currentContent = elem; + } + } + + function getSearchTerm() { + return (new URL(window.location)).searchParams.get("search"); + } + + const searchBox = document.querySelector(".pdoc input[type=search]"); + searchBox.addEventListener("input", function () { + let url = new URL(window.location); + if (searchBox.value.trim()) { + url.hash = ""; + url.searchParams.set("search", searchBox.value); + } else { + url.searchParams.delete("search"); + } + history.replaceState("", "", url.toString()); + onInput(); + }); + window.addEventListener("popstate", onInput); + + + let search, searchErr; + + async function initialize() { + try { + search = await new Promise((resolve, reject) => { + const script = document.createElement("script"); + script.type = "text/javascript"; + script.async = true; + script.onload = () => resolve(window.pdocSearch); + script.onerror = (e) => reject(e); + script.src = "../../search.js"; + document.getElementsByTagName("head")[0].appendChild(script); + }); + } catch (e) { + console.error("Cannot fetch pdoc search index"); + searchErr = "Cannot fetch search index."; + } + onInput(); + + document.querySelector("nav.pdoc").addEventListener("click", e => { + if (e.target.hash) { + searchBox.value = ""; + searchBox.dispatchEvent(new Event("input")); + } + }); + } + + function onInput() { + setContent((() => { + const term = getSearchTerm(); + if (!term) { + return null + } + if (searchErr) { + return `<h3>Error: ${searchErr}</h3>` + } + if (!search) { + return "<h3>Searching...</h3>" + } + + window.scrollTo({top: 0, left: 0, behavior: 'auto'}); + + const results = search(term); + + let html; + if (results.length === 0) { + html = `No search results for '${escapeHTML(term)}'.` + } else { + html = `<h4>${results.length} search result${results.length > 1 ? "s" : ""} for '${escapeHTML(term)}'.</h4>`; + } + for (let result of results.slice(0, 10)) { + let doc = result.doc; + let url = `../../${doc.modulename.replaceAll(".", "/")}.html`; + if (doc.qualname) { + url += `#${doc.qualname}`; + } + + let heading; + switch (result.doc.kind) { + case "function": + if (doc.fullname.endsWith(".__init__")) { + heading = `<span class="name">${doc.fullname.replace(/\.__init__$/, "")}</span>${doc.signature}`; + } else { + heading = `<span class="def">${doc.funcdef}</span> <span class="name">${doc.fullname}</span>${doc.signature}`; + } + break; + case "class": + heading = `<span class="def">class</span> <span class="name">${doc.fullname}</span>`; + if (doc.bases) + heading += `<wbr>(<span class="base">${doc.bases}</span>)`; + heading += `:`; + break; + case "variable": + heading = `<span class="name">${doc.fullname}</span>`; + if (doc.annotation) + heading += `<span class="annotation">${doc.annotation}</span>`; + if (doc.default_value) + heading += `<span class="default_value">${doc.default_value}</span>`; + break; + default: + heading = `<span class="name">${doc.fullname}</span>`; + break; + } + html += ` + <section class="search-result"> + <a href="${url}" class="attr ${doc.kind}">${heading}</a> + <div class="docstring">${doc.doc}</div> + </section> + `; + + } + return html; + })()); + } + + if (getSearchTerm()) { + initialize(); + searchBox.value = getSearchTerm(); + onInput(); + } else { + searchBox.addEventListener("focus", initialize, {once: true}); + } + + searchBox.addEventListener("keydown", e => { + if (["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) { + let focused = currentContent.querySelector(".search-result.focused"); + if (!focused) { + currentContent.querySelector(".search-result").classList.add("focused"); + } else if ( + e.key === "ArrowDown" + && focused.nextElementSibling + && focused.nextElementSibling.classList.contains("search-result") + ) { + focused.classList.remove("focused"); + focused.nextElementSibling.classList.add("focused"); + focused.nextElementSibling.scrollIntoView({ + behavior: "smooth", + block: "nearest", + inline: "nearest" + }); + } else if ( + e.key === "ArrowUp" + && focused.previousElementSibling + && focused.previousElementSibling.classList.contains("search-result") + ) { + focused.classList.remove("focused"); + focused.previousElementSibling.classList.add("focused"); + focused.previousElementSibling.scrollIntoView({ + behavior: "smooth", + block: "nearest", + inline: "nearest" + }); + } else if ( + e.key === "Enter" + ) { + focused.querySelector("a").click(); + } + } + }); +</script></body> +</html>
\ No newline at end of file |