diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-27 10:46:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-27 10:46:33 +0000 |
commit | aa1d1f1ea72887a3efb78f4950e27bc79dfa3766 (patch) | |
tree | a9f5bf5ab14c69d011e21d40f8504c4f94a8de72 /docs/sqlglot/dataframe/sql.html | |
parent | Adding upstream version 11.2.0. (diff) | |
download | sqlglot-upstream/11.2.3.tar.xz sqlglot-upstream/11.2.3.zip |
Adding upstream version 11.2.3.upstream/11.2.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | docs/sqlglot/dataframe/sql.html | 2682 |
1 files changed, 1323 insertions, 1359 deletions
diff --git a/docs/sqlglot/dataframe/sql.html b/docs/sqlglot/dataframe/sql.html index ea00232..3298708 100644 --- a/docs/sqlglot/dataframe/sql.html +++ b/docs/sqlglot/dataframe/sql.html @@ -3,14 +3,14 @@ <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> - <meta name="generator" content="pdoc 12.3.1"/> + <meta name="generator" content="pdoc 13.0.0"/> <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>/*! 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;z-index:999;}#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{cursor:pointer;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 .view-value-toggle-state,.pdoc .view-value-toggle-state ~ .default_value{display:none;}.pdoc .view-value-toggle-state:checked ~ .default_value{display:inherit;}.pdoc .view-value-button{font-size:.5rem;vertical-align:middle;border-style:dashed;margin-top:-0.1rem;}.pdoc .view-value-button:hover{background:white;}.pdoc .view-value-button::before{content:"show";text-align:center;width:2.2em;display:inline-block;}.pdoc .view-value-toggle-state:checked ~ .view-value-button::before{content:"hide";}.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"> @@ -34,9 +34,6 @@ <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> @@ -310,9 +307,6 @@ <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> @@ -590,24 +584,6 @@ - <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"> @@ -632,7 +608,7 @@ <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">'140483441683968'</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">'140483441683968'</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">'140483443386656'</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> + <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">'140512212685136'</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">'140512212685136'</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">'140512212632768'</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> @@ -754,743 +730,743 @@ </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame-45"><a href="#DataFrame-45"><span class="linenos"> 45</span></a><span class="k">class</span> <span class="nc">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-46"><a href="#DataFrame-46"><span class="linenos"> 46</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span> +</span><span id="DataFrame-47"><a href="#DataFrame-47"><span class="linenos"> 47</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame-48"><a href="#DataFrame-48"><span class="linenos"> 48</span></a> <span class="n">spark</span><span class="p">:</span> <span class="n">SparkSession</span><span class="p">,</span> +</span><span id="DataFrame-49"><a href="#DataFrame-49"><span class="linenos"> 49</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-50"><a href="#DataFrame-50"><span class="linenos"> 50</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-51"><a href="#DataFrame-51"><span class="linenos"> 51</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-52"><a href="#DataFrame-52"><span class="linenos"> 52</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-53"><a href="#DataFrame-53"><span class="linenos"> 53</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-54"><a href="#DataFrame-54"><span class="linenos"> 54</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-55"><a href="#DataFrame-55"><span class="linenos"> 55</span></a> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span> +</span><span id="DataFrame-56"><a href="#DataFrame-56"><span class="linenos"> 56</span></a> <span class="p">):</span> +</span><span id="DataFrame-57"><a href="#DataFrame-57"><span class="linenos"> 57</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-58"><a href="#DataFrame-58"><span class="linenos"> 58</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-59"><a href="#DataFrame-59"><span class="linenos"> 59</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-60"><a href="#DataFrame-60"><span class="linenos"> 60</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-61"><a href="#DataFrame-61"><span class="linenos"> 61</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-62"><a href="#DataFrame-62"><span class="linenos"> 62</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-63"><a href="#DataFrame-63"><span class="linenos"> 63</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-64"><a href="#DataFrame-64"><span class="linenos"> 64</span></a> +</span><span id="DataFrame-65"><a href="#DataFrame-65"><span class="linenos"> 65</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-66"><a href="#DataFrame-66"><span class="linenos"> 66</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-67"><a href="#DataFrame-67"><span class="linenos"> 67</span></a> +</span><span id="DataFrame-68"><a href="#DataFrame-68"><span class="linenos"> 68</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-69"><a href="#DataFrame-69"><span class="linenos"> 69</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-70"><a href="#DataFrame-70"><span class="linenos"> 70</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-71"><a href="#DataFrame-71"><span class="linenos"> 71</span></a> +</span><span id="DataFrame-72"><a href="#DataFrame-72"><span class="linenos"> 72</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-73"><a href="#DataFrame-73"><span class="linenos"> 73</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-74"><a href="#DataFrame-74"><span class="linenos"> 74</span></a> +</span><span id="DataFrame-75"><a href="#DataFrame-75"><span class="linenos"> 75</span></a> <span class="nd">@property</span> +</span><span id="DataFrame-76"><a href="#DataFrame-76"><span class="linenos"> 76</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-77"><a href="#DataFrame-77"><span class="linenos"> 77</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-78"><a href="#DataFrame-78"><span class="linenos"> 78</span></a> +</span><span id="DataFrame-79"><a href="#DataFrame-79"><span class="linenos"> 79</span></a> <span class="nd">@property</span> +</span><span id="DataFrame-80"><a href="#DataFrame-80"><span class="linenos"> 80</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-81"><a href="#DataFrame-81"><span class="linenos"> 81</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-82"><a href="#DataFrame-82"><span class="linenos"> 82</span></a> +</span><span id="DataFrame-83"><a href="#DataFrame-83"><span class="linenos"> 83</span></a> <span class="nd">@property</span> +</span><span id="DataFrame-84"><a href="#DataFrame-84"><span class="linenos"> 84</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-85"><a href="#DataFrame-85"><span class="linenos"> 85</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-86"><a href="#DataFrame-86"><span class="linenos"> 86</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-87"><a href="#DataFrame-87"><span class="linenos"> 87</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-88"><a href="#DataFrame-88"><span class="linenos"> 88</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-89"><a href="#DataFrame-89"><span class="linenos"> 89</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-90"><a href="#DataFrame-90"><span class="linenos"> 90</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-91"><a href="#DataFrame-91"><span class="linenos"> 91</span></a> <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span> +</span><span id="DataFrame-92"><a href="#DataFrame-92"><span class="linenos"> 92</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-93"><a href="#DataFrame-93"><span class="linenos"> 93</span></a> <span class="p">)</span> +</span><span id="DataFrame-94"><a href="#DataFrame-94"><span class="linenos"> 94</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-95"><a href="#DataFrame-95"><span class="linenos"> 95</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-96"><a href="#DataFrame-96"><span class="linenos"> 96</span></a> +</span><span id="DataFrame-97"><a href="#DataFrame-97"><span class="linenos"> 97</span></a> <span class="nd">@property</span> +</span><span id="DataFrame-98"><a href="#DataFrame-98"><span class="linenos"> 98</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-99"><a href="#DataFrame-99"><span class="linenos"> 99</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-100"><a href="#DataFrame-100"><span class="linenos">100</span></a> +</span><span id="DataFrame-101"><a href="#DataFrame-101"><span class="linenos">101</span></a> <span class="nd">@property</span> +</span><span id="DataFrame-102"><a href="#DataFrame-102"><span class="linenos">102</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-103"><a href="#DataFrame-103"><span class="linenos">103</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-104"><a href="#DataFrame-104"><span class="linenos">104</span></a> +</span><span id="DataFrame-105"><a href="#DataFrame-105"><span class="linenos">105</span></a> <span class="nd">@property</span> +</span><span id="DataFrame-106"><a href="#DataFrame-106"><span class="linenos">106</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-107"><a href="#DataFrame-107"><span class="linenos">107</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-108"><a href="#DataFrame-108"><span class="linenos">108</span></a> +</span><span id="DataFrame-109"><a href="#DataFrame-109"><span class="linenos">109</span></a> <span class="nd">@property</span> +</span><span id="DataFrame-110"><a href="#DataFrame-110"><span class="linenos">110</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-111"><a href="#DataFrame-111"><span class="linenos">111</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-112"><a href="#DataFrame-112"><span class="linenos">112</span></a> +</span><span id="DataFrame-113"><a href="#DataFrame-113"><span class="linenos">113</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-114"><a href="#DataFrame-114"><span class="linenos">114</span></a> <span class="n">replacement_mapping</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="DataFrame-115"><a href="#DataFrame-115"><span class="linenos">115</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-116"><a href="#DataFrame-116"><span class="linenos">116</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-117"><a href="#DataFrame-117"><span class="linenos">117</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-118"><a href="#DataFrame-118"><span class="linenos">118</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-119"><a href="#DataFrame-119"><span class="linenos">119</span></a> <span class="p">)</span> +</span><span id="DataFrame-120"><a href="#DataFrame-120"><span class="linenos">120</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-121"><a href="#DataFrame-121"><span class="linenos">121</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-122"><a href="#DataFrame-122"><span class="linenos">122</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="DataFrame-123"><a href="#DataFrame-123"><span class="linenos">123</span></a> +</span><span id="DataFrame-124"><a href="#DataFrame-124"><span class="linenos">124</span></a> <span class="k">def</span> <span class="nf">_create_cte_from_expression</span><span class="p">(</span> +</span><span id="DataFrame-125"><a href="#DataFrame-125"><span class="linenos">125</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame-126"><a href="#DataFrame-126"><span class="linenos">126</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-127"><a href="#DataFrame-127"><span class="linenos">127</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-128"><a href="#DataFrame-128"><span class="linenos">128</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-129"><a href="#DataFrame-129"><span class="linenos">129</span></a> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span> +</span><span id="DataFrame-130"><a href="#DataFrame-130"><span class="linenos">130</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-131"><a href="#DataFrame-131"><span class="linenos">131</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-132"><a href="#DataFrame-132"><span class="linenos">132</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-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">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-134"><a href="#DataFrame-134"><span class="linenos">134</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-135"><a href="#DataFrame-135"><span class="linenos">135</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-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">"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-137"><a href="#DataFrame-137"><span class="linenos">137</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-138"><a href="#DataFrame-138"><span class="linenos">138</span></a> +</span><span id="DataFrame-139"><a href="#DataFrame-139"><span class="linenos">139</span></a> <span class="nd">@t</span><span class="o">.</span><span class="n">overload</span> +</span><span id="DataFrame-140"><a href="#DataFrame-140"><span class="linenos">140</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-141"><a href="#DataFrame-141"><span class="linenos">141</span></a> <span class="o">...</span> +</span><span id="DataFrame-142"><a href="#DataFrame-142"><span class="linenos">142</span></a> +</span><span id="DataFrame-143"><a href="#DataFrame-143"><span class="linenos">143</span></a> <span class="nd">@t</span><span class="o">.</span><span class="n">overload</span> +</span><span id="DataFrame-144"><a href="#DataFrame-144"><span class="linenos">144</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-145"><a href="#DataFrame-145"><span class="linenos">145</span></a> <span class="o">...</span> +</span><span id="DataFrame-146"><a href="#DataFrame-146"><span class="linenos">146</span></a> +</span><span id="DataFrame-147"><a href="#DataFrame-147"><span class="linenos">147</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-148"><a href="#DataFrame-148"><span class="linenos">148</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-149"><a href="#DataFrame-149"><span class="linenos">149</span></a> +</span><span id="DataFrame-150"><a href="#DataFrame-150"><span class="linenos">150</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-151"><a href="#DataFrame-151"><span class="linenos">151</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-152"><a href="#DataFrame-152"><span class="linenos">152</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-153"><a href="#DataFrame-153"><span class="linenos">153</span></a> <span class="k">return</span> <span class="n">cols</span> +</span><span id="DataFrame-154"><a href="#DataFrame-154"><span class="linenos">154</span></a> +</span><span id="DataFrame-155"><a href="#DataFrame-155"><span class="linenos">155</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-156"><a href="#DataFrame-156"><span class="linenos">156</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-157"><a href="#DataFrame-157"><span class="linenos">157</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-158"><a href="#DataFrame-158"><span class="linenos">158</span></a> <span class="k">return</span> <span class="n">col</span> +</span><span id="DataFrame-159"><a href="#DataFrame-159"><span class="linenos">159</span></a> +</span><span id="DataFrame-160"><a href="#DataFrame-160"><span class="linenos">160</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-161"><a href="#DataFrame-161"><span class="linenos">161</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-162"><a href="#DataFrame-162"><span class="linenos">162</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-163"><a href="#DataFrame-163"><span class="linenos">163</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-164"><a href="#DataFrame-164"><span class="linenos">164</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-165"><a href="#DataFrame-165"><span class="linenos">165</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-166"><a href="#DataFrame-166"><span class="linenos">166</span></a> <span class="p">)</span> +</span><span id="DataFrame-167"><a href="#DataFrame-167"><span class="linenos">167</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-168"><a href="#DataFrame-168"><span class="linenos">168</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-169"><a href="#DataFrame-169"><span class="linenos">169</span></a> <span class="p">)</span> +</span><span id="DataFrame-170"><a href="#DataFrame-170"><span class="linenos">170</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-171"><a href="#DataFrame-171"><span class="linenos">171</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-172"><a href="#DataFrame-172"><span class="linenos">172</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-173"><a href="#DataFrame-173"><span class="linenos">173</span></a> <span class="p">)</span> +</span><span id="DataFrame-174"><a href="#DataFrame-174"><span class="linenos">174</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-175"><a href="#DataFrame-175"><span class="linenos">175</span></a> +</span><span id="DataFrame-176"><a href="#DataFrame-176"><span class="linenos">176</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-177"><a href="#DataFrame-177"><span class="linenos">177</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-178"><a href="#DataFrame-178"><span class="linenos">178</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-179"><a href="#DataFrame-179"><span class="linenos">179</span></a> <span class="k">return</span> <span class="n">df</span> +</span><span id="DataFrame-180"><a href="#DataFrame-180"><span class="linenos">180</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-181"><a href="#DataFrame-181"><span class="linenos">181</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-182"><a href="#DataFrame-182"><span class="linenos">182</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-183"><a href="#DataFrame-183"><span class="linenos">183</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-184"><a href="#DataFrame-184"><span class="linenos">184</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-185"><a href="#DataFrame-185"><span class="linenos">185</span></a> +</span><span id="DataFrame-186"><a href="#DataFrame-186"><span class="linenos">186</span></a> <span class="n">join_aliases</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="DataFrame-187"><a href="#DataFrame-187"><span class="linenos">187</span></a> <span class="n">join_table</span><span class="o">.</span><span class="n">alias_or_name</span> +</span><span id="DataFrame-188"><a href="#DataFrame-188"><span class="linenos">188</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-189"><a href="#DataFrame-189"><span class="linenos">189</span></a> <span class="p">}</span> +</span><span id="DataFrame-190"><a href="#DataFrame-190"><span class="linenos">190</span></a> <span class="k">if</span> <span class="n">join_aliases</span><span class="p">:</span> +</span><span id="DataFrame-191"><a href="#DataFrame-191"><span class="linenos">191</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-192"><a href="#DataFrame-192"><span class="linenos">192</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-193"><a href="#DataFrame-193"><span class="linenos">193</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-194"><a href="#DataFrame-194"><span class="linenos">194</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-195"><a href="#DataFrame-195"><span class="linenos">195</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-196"><a href="#DataFrame-196"><span class="linenos">196</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-197"><a href="#DataFrame-197"><span class="linenos">197</span></a> <span class="n">sequence_id_or_name</span> +</span><span id="DataFrame-198"><a href="#DataFrame-198"><span class="linenos">198</span></a> <span class="p">]</span> +</span><span id="DataFrame-199"><a href="#DataFrame-199"><span class="linenos">199</span></a> <span class="n">matching_ctes</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-200"><a href="#DataFrame-200"><span class="linenos">200</span></a> <span class="n">cte</span> +</span><span id="DataFrame-201"><a href="#DataFrame-201"><span class="linenos">201</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-202"><a href="#DataFrame-202"><span class="linenos">202</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-203"><a href="#DataFrame-203"><span class="linenos">203</span></a> <span class="p">]</span> +</span><span id="DataFrame-204"><a href="#DataFrame-204"><span class="linenos">204</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-205"><a href="#DataFrame-205"><span class="linenos">205</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-206"><a href="#DataFrame-206"><span class="linenos">206</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-207"><a href="#DataFrame-207"><span class="linenos">207</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-208"><a href="#DataFrame-208"><span class="linenos">208</span></a> <span class="k">break</span> +</span><span id="DataFrame-209"><a href="#DataFrame-209"><span class="linenos">209</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-210"><a href="#DataFrame-210"><span class="linenos">210</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-211"><a href="#DataFrame-211"><span class="linenos">211</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-212"><a href="#DataFrame-212"><span class="linenos">212</span></a> <span class="k">return</span> <span class="n">df</span> +</span><span id="DataFrame-213"><a href="#DataFrame-213"><span class="linenos">213</span></a> +</span><span id="DataFrame-214"><a href="#DataFrame-214"><span class="linenos">214</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-215"><a href="#DataFrame-215"><span class="linenos">215</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-216"><a href="#DataFrame-216"><span class="linenos">216</span></a> <span class="n">hint_expression</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="DataFrame-217"><a href="#DataFrame-217"><span class="linenos">217</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">JoinHint</span><span class="p">(</span> +</span><span id="DataFrame-218"><a href="#DataFrame-218"><span class="linenos">218</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-219"><a href="#DataFrame-219"><span class="linenos">219</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-220"><a href="#DataFrame-220"><span class="linenos">220</span></a> <span class="p">)</span> +</span><span id="DataFrame-221"><a href="#DataFrame-221"><span class="linenos">221</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-222"><a href="#DataFrame-222"><span class="linenos">222</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-223"><a href="#DataFrame-223"><span class="linenos">223</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-224"><a href="#DataFrame-224"><span class="linenos">224</span></a> <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="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-227"><a href="#DataFrame-227"><span class="linenos">227</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-228"><a href="#DataFrame-228"><span class="linenos">228</span></a> <span class="k">return</span> <span class="n">new_df</span> +</span><span id="DataFrame-229"><a href="#DataFrame-229"><span class="linenos">229</span></a> +</span><span id="DataFrame-230"><a href="#DataFrame-230"><span class="linenos">230</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-231"><a href="#DataFrame-231"><span class="linenos">231</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-232"><a href="#DataFrame-232"><span class="linenos">232</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-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">_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-234"><a href="#DataFrame-234"><span class="linenos">234</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-235"><a href="#DataFrame-235"><span class="linenos">235</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-236"><a href="#DataFrame-236"><span class="linenos">236</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-237"><a href="#DataFrame-237"><span class="linenos">237</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-238"><a href="#DataFrame-238"><span class="linenos">238</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-239"><a href="#DataFrame-239"><span class="linenos">239</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-240"><a href="#DataFrame-240"><span class="linenos">240</span></a> +</span><span id="DataFrame-241"><a href="#DataFrame-241"><span class="linenos">241</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-242"><a href="#DataFrame-242"><span class="linenos">242</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-243"><a href="#DataFrame-243"><span class="linenos">243</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-244"><a href="#DataFrame-244"><span class="linenos">244</span></a> <span class="k">return</span> <span class="n">df</span> +</span><span id="DataFrame-245"><a href="#DataFrame-245"><span class="linenos">245</span></a> +</span><span id="DataFrame-246"><a href="#DataFrame-246"><span class="linenos">246</span></a> <span class="nd">@classmethod</span> +</span><span id="DataFrame-247"><a href="#DataFrame-247"><span class="linenos">247</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-248"><a href="#DataFrame-248"><span class="linenos">248</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-249"><a href="#DataFrame-249"><span class="linenos">249</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-250"><a href="#DataFrame-250"><span class="linenos">250</span></a> <span class="k">if</span> <span class="n">with_expression</span><span class="p">:</span> +</span><span id="DataFrame-251"><a href="#DataFrame-251"><span class="linenos">251</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-252"><a href="#DataFrame-252"><span class="linenos">252</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-253"><a href="#DataFrame-253"><span class="linenos">253</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-254"><a href="#DataFrame-254"><span class="linenos">254</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-255"><a href="#DataFrame-255"><span class="linenos">255</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-256"><a href="#DataFrame-256"><span class="linenos">256</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-257"><a href="#DataFrame-257"><span class="linenos">257</span></a> <span class="n">existing_ctes</span> <span class="o">=</span> <span class="n">ctes</span> +</span><span id="DataFrame-258"><a href="#DataFrame-258"><span class="linenos">258</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-259"><a href="#DataFrame-259"><span class="linenos">259</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="DataFrame-260"><a href="#DataFrame-260"><span class="linenos">260</span></a> +</span><span id="DataFrame-261"><a href="#DataFrame-261"><span class="linenos">261</span></a> <span class="nd">@classmethod</span> +</span><span id="DataFrame-262"><a href="#DataFrame-262"><span class="linenos">262</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-263"><a href="#DataFrame-263"><span class="linenos">263</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-264"><a href="#DataFrame-264"><span class="linenos">264</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-265"><a href="#DataFrame-265"><span class="linenos">265</span></a> +</span><span id="DataFrame-266"><a href="#DataFrame-266"><span class="linenos">266</span></a> <span class="nd">@classmethod</span> +</span><span id="DataFrame-267"><a href="#DataFrame-267"><span class="linenos">267</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-268"><a href="#DataFrame-268"><span class="linenos">268</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-269"><a href="#DataFrame-269"><span class="linenos">269</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-270"><a href="#DataFrame-270"><span class="linenos">270</span></a> +</span><span id="DataFrame-271"><a href="#DataFrame-271"><span class="linenos">271</span></a> <span class="k">def</span> <span class="nf">_get_select_expressions</span><span class="p">(</span> +</span><span id="DataFrame-272"><a href="#DataFrame-272"><span class="linenos">272</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame-273"><a href="#DataFrame-273"><span class="linenos">273</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-274"><a href="#DataFrame-274"><span class="linenos">274</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-275"><a href="#DataFrame-275"><span class="linenos">275</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-276"><a href="#DataFrame-276"><span class="linenos">276</span></a> <span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="DataFrame-277"><a href="#DataFrame-277"><span class="linenos">277</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-278"><a href="#DataFrame-278"><span class="linenos">278</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-279"><a href="#DataFrame-279"><span class="linenos">279</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-280"><a href="#DataFrame-280"><span class="linenos">280</span></a> <span class="k">if</span> <span class="n">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="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-282"><a href="#DataFrame-282"><span class="linenos">282</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-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">"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-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">"cache_storage_level"</span><span class="p">,</span> <span class="n">cache_storage_level</span><span class="p">)</span> +</span><span id="DataFrame-285"><a href="#DataFrame-285"><span class="linenos">285</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-286"><a href="#DataFrame-286"><span class="linenos">286</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-287"><a href="#DataFrame-287"><span class="linenos">287</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-288"><a href="#DataFrame-288"><span class="linenos">288</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-289"><a href="#DataFrame-289"><span class="linenos">289</span></a> <span class="k">if</span> <span class="n">main_select_ctes</span><span class="p">:</span> +</span><span id="DataFrame-290"><a href="#DataFrame-290"><span class="linenos">290</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-291"><a href="#DataFrame-291"><span class="linenos">291</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-292"><a href="#DataFrame-292"><span class="linenos">292</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-293"><a href="#DataFrame-293"><span class="linenos">293</span></a> <span class="k">return</span> <span class="n">select_expressions</span> +</span><span id="DataFrame-294"><a href="#DataFrame-294"><span class="linenos">294</span></a> +</span><span id="DataFrame-295"><a href="#DataFrame-295"><span class="linenos">295</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-296"><a href="#DataFrame-296"><span class="linenos">296</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-297"><a href="#DataFrame-297"><span class="linenos">297</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-298"><a href="#DataFrame-298"><span class="linenos">298</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-299"><a href="#DataFrame-299"><span class="linenos">299</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-300"><a href="#DataFrame-300"><span class="linenos">300</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-301"><a href="#DataFrame-301"><span class="linenos">301</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-302"><a href="#DataFrame-302"><span class="linenos">302</span></a> <span class="k">if</span> <span class="n">optimize</span><span class="p">:</span> +</span><span id="DataFrame-303"><a href="#DataFrame-303"><span class="linenos">303</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-304"><a href="#DataFrame-304"><span class="linenos">304</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-305"><a href="#DataFrame-305"><span class="linenos">305</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-306"><a href="#DataFrame-306"><span class="linenos">306</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-307"><a href="#DataFrame-307"><span class="linenos">307</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-308"><a href="#DataFrame-308"><span class="linenos">308</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-309"><a href="#DataFrame-309"><span class="linenos">309</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-310"><a href="#DataFrame-310"><span class="linenos">310</span></a> +</span><span id="DataFrame-311"><a href="#DataFrame-311"><span class="linenos">311</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-312"><a href="#DataFrame-312"><span class="linenos">312</span></a> <span class="n">cache_table_name</span> +</span><span id="DataFrame-313"><a href="#DataFrame-313"><span class="linenos">313</span></a> <span class="p">)</span> +</span><span id="DataFrame-314"><a href="#DataFrame-314"><span class="linenos">314</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-315"><a href="#DataFrame-315"><span class="linenos">315</span></a> <span class="n">cache_table_name</span><span class="p">,</span> +</span><span id="DataFrame-316"><a href="#DataFrame-316"><span class="linenos">316</span></a> <span class="p">{</span> +</span><span id="DataFrame-317"><a href="#DataFrame-317"><span class="linenos">317</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-318"><a href="#DataFrame-318"><span class="linenos">318</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-319"><a href="#DataFrame-319"><span class="linenos">319</span></a> <span class="p">},</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="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-322"><a href="#DataFrame-322"><span class="linenos">322</span></a> <span class="n">options</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-323"><a href="#DataFrame-323"><span class="linenos">323</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-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="n">cache_storage_level</span><span class="p">),</span> +</span><span id="DataFrame-325"><a href="#DataFrame-325"><span class="linenos">325</span></a> <span class="p">]</span> +</span><span id="DataFrame-326"><a href="#DataFrame-326"><span class="linenos">326</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-327"><a href="#DataFrame-327"><span class="linenos">327</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-328"><a href="#DataFrame-328"><span class="linenos">328</span></a> <span class="p">)</span> +</span><span id="DataFrame-329"><a href="#DataFrame-329"><span class="linenos">329</span></a> <span class="c1"># We will drop the "view" if it exists before running the cache table</span> +</span><span id="DataFrame-330"><a href="#DataFrame-330"><span class="linenos">330</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-331"><a href="#DataFrame-331"><span class="linenos">331</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-332"><a href="#DataFrame-332"><span class="linenos">332</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-333"><a href="#DataFrame-333"><span class="linenos">333</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-334"><a href="#DataFrame-334"><span class="linenos">334</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-335"><a href="#DataFrame-335"><span class="linenos">335</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-336"><a href="#DataFrame-336"><span class="linenos">336</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-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">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-338"><a href="#DataFrame-338"><span class="linenos">338</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-339"><a href="#DataFrame-339"><span class="linenos">339</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-340"><a href="#DataFrame-340"><span class="linenos">340</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-341"><a href="#DataFrame-341"><span class="linenos">341</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-342"><a href="#DataFrame-342"><span class="linenos">342</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">select_expression</span> +</span><span id="DataFrame-343"><a href="#DataFrame-343"><span class="linenos">343</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-344"><a href="#DataFrame-344"><span class="linenos">344</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-345"><a href="#DataFrame-345"><span class="linenos">345</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-346"><a href="#DataFrame-346"><span class="linenos">346</span></a> +</span><span id="DataFrame-347"><a href="#DataFrame-347"><span class="linenos">347</span></a> <span class="k">return</span> <span class="p">[</span> +</span><span id="DataFrame-348"><a href="#DataFrame-348"><span class="linenos">348</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-349"><a href="#DataFrame-349"><span class="linenos">349</span></a> <span class="p">]</span> +</span><span id="DataFrame-350"><a href="#DataFrame-350"><span class="linenos">350</span></a> +</span><span id="DataFrame-351"><a href="#DataFrame-351"><span class="linenos">351</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-352"><a href="#DataFrame-352"><span class="linenos">352</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-353"><a href="#DataFrame-353"><span class="linenos">353</span></a> +</span><span id="DataFrame-354"><a href="#DataFrame-354"><span class="linenos">354</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-355"><a href="#DataFrame-355"><span class="linenos">355</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-356"><a href="#DataFrame-356"><span class="linenos">356</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-357"><a href="#DataFrame-357"><span class="linenos">357</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-358"><a href="#DataFrame-358"><span class="linenos">358</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-359"><a href="#DataFrame-359"><span class="linenos">359</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-360"><a href="#DataFrame-360"><span class="linenos">360</span></a> <span class="k">if</span> <span class="n">ambiguous_cols</span><span class="p">:</span> +</span><span id="DataFrame-361"><a href="#DataFrame-361"><span class="linenos">361</span></a> <span class="n">join_table_identifiers</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-362"><a href="#DataFrame-362"><span class="linenos">362</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-363"><a href="#DataFrame-363"><span class="linenos">363</span></a> <span class="p">]</span> +</span><span id="DataFrame-364"><a href="#DataFrame-364"><span class="linenos">364</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-365"><a href="#DataFrame-365"><span class="linenos">365</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-366"><a href="#DataFrame-366"><span class="linenos">366</span></a> <span class="n">ctes_with_column</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-367"><a href="#DataFrame-367"><span class="linenos">367</span></a> <span class="n">cte</span> +</span><span id="DataFrame-368"><a href="#DataFrame-368"><span class="linenos">368</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-369"><a href="#DataFrame-369"><span class="linenos">369</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-370"><a href="#DataFrame-370"><span class="linenos">370</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-371"><a href="#DataFrame-371"><span class="linenos">371</span></a> <span class="p">]</span> +</span><span id="DataFrame-372"><a href="#DataFrame-372"><span class="linenos">372</span></a> <span class="c1"># If the select column does not specify a table and there is a join</span> +</span><span id="DataFrame-373"><a href="#DataFrame-373"><span class="linenos">373</span></a> <span class="c1"># then we assume they are referring to the left table</span> +</span><span id="DataFrame-374"><a href="#DataFrame-374"><span class="linenos">374</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-375"><a href="#DataFrame-375"><span class="linenos">375</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-376"><a href="#DataFrame-376"><span class="linenos">376</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-377"><a href="#DataFrame-377"><span class="linenos">377</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-378"><a href="#DataFrame-378"><span class="linenos">378</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-379"><a href="#DataFrame-379"><span class="linenos">379</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-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 class="o">**</span><span class="n">kwargs</span> +</span><span id="DataFrame-381"><a href="#DataFrame-381"><span class="linenos">381</span></a> <span class="p">)</span> +</span><span id="DataFrame-382"><a href="#DataFrame-382"><span class="linenos">382</span></a> +</span><span id="DataFrame-383"><a href="#DataFrame-383"><span class="linenos">383</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-384"><a href="#DataFrame-384"><span class="linenos">384</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-385"><a href="#DataFrame-385"><span class="linenos">385</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-386"><a href="#DataFrame-386"><span class="linenos">386</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-387"><a href="#DataFrame-387"><span class="linenos">387</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-388"><a href="#DataFrame-388"><span class="linenos">388</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-389"><a href="#DataFrame-389"><span class="linenos">389</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-390"><a href="#DataFrame-390"><span class="linenos">390</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-391"><a href="#DataFrame-391"><span class="linenos">391</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-392"><a href="#DataFrame-392"><span class="linenos">392</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-393"><a href="#DataFrame-393"><span class="linenos">393</span></a> +</span><span id="DataFrame-394"><a href="#DataFrame-394"><span class="linenos">394</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-395"><a href="#DataFrame-395"><span class="linenos">395</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-396"><a href="#DataFrame-396"><span class="linenos">396</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-397"><a href="#DataFrame-397"><span class="linenos">397</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-398"><a href="#DataFrame-398"><span class="linenos">398</span></a> +</span><span id="DataFrame-399"><a href="#DataFrame-399"><span class="linenos">399</span></a> <span class="nb">filter</span> <span class="o">=</span> <span class="n">where</span> +</span><span id="DataFrame-400"><a href="#DataFrame-400"><span class="linenos">400</span></a> +</span><span id="DataFrame-401"><a href="#DataFrame-401"><span class="linenos">401</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-402"><a href="#DataFrame-402"><span class="linenos">402</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-403"><a href="#DataFrame-403"><span class="linenos">403</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-404"><a href="#DataFrame-404"><span class="linenos">404</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-405"><a href="#DataFrame-405"><span class="linenos">405</span></a> +</span><span id="DataFrame-406"><a href="#DataFrame-406"><span class="linenos">406</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-407"><a href="#DataFrame-407"><span class="linenos">407</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-408"><a href="#DataFrame-408"><span class="linenos">408</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-409"><a href="#DataFrame-409"><span class="linenos">409</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-410"><a href="#DataFrame-410"><span class="linenos">410</span></a> +</span><span id="DataFrame-411"><a href="#DataFrame-411"><span class="linenos">411</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-412"><a href="#DataFrame-412"><span class="linenos">412</span></a> <span class="k">def</span> <span class="nf">join</span><span class="p">(</span> +</span><span id="DataFrame-413"><a href="#DataFrame-413"><span class="linenos">413</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame-414"><a href="#DataFrame-414"><span class="linenos">414</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-415"><a href="#DataFrame-415"><span class="linenos">415</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-416"><a href="#DataFrame-416"><span class="linenos">416</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-417"><a href="#DataFrame-417"><span class="linenos">417</span></a> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span> +</span><span id="DataFrame-418"><a href="#DataFrame-418"><span class="linenos">418</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-419"><a href="#DataFrame-419"><span class="linenos">419</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-420"><a href="#DataFrame-420"><span class="linenos">420</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-421"><a href="#DataFrame-421"><span class="linenos">421</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-422"><a href="#DataFrame-422"><span class="linenos">422</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-423"><a href="#DataFrame-423"><span class="linenos">423</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-424"><a href="#DataFrame-424"><span class="linenos">424</span></a> <span class="n">join_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-425"><a href="#DataFrame-425"><span class="linenos">425</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-426"><a href="#DataFrame-426"><span class="linenos">426</span></a> <span class="p">]</span> +</span><span id="DataFrame-427"><a href="#DataFrame-427"><span class="linenos">427</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-428"><a href="#DataFrame-428"><span class="linenos">428</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-429"><a href="#DataFrame-429"><span class="linenos">429</span></a> <span class="p">[</span> +</span><span id="DataFrame-430"><a href="#DataFrame-430"><span class="linenos">430</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-431"><a href="#DataFrame-431"><span class="linenos">431</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-432"><a href="#DataFrame-432"><span class="linenos">432</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-433"><a href="#DataFrame-433"><span class="linenos">433</span></a> <span class="p">],</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="k">else</span><span class="p">:</span> +</span><span id="DataFrame-436"><a href="#DataFrame-436"><span class="linenos">436</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-437"><a href="#DataFrame-437"><span class="linenos">437</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-438"><a href="#DataFrame-438"><span class="linenos">438</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-439"><a href="#DataFrame-439"><span class="linenos">439</span></a> <span class="n">join_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-440"><a href="#DataFrame-440"><span class="linenos">440</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-441"><a href="#DataFrame-441"><span class="linenos">441</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-442"><a href="#DataFrame-442"><span class="linenos">442</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-443"><a href="#DataFrame-443"><span class="linenos">443</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-444"><a href="#DataFrame-444"><span class="linenos">444</span></a> <span class="p">]</span> +</span><span id="DataFrame-445"><a href="#DataFrame-445"><span class="linenos">445</span></a> <span class="n">self_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-446"><a href="#DataFrame-446"><span class="linenos">446</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-447"><a href="#DataFrame-447"><span class="linenos">447</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-448"><a href="#DataFrame-448"><span class="linenos">448</span></a> <span class="p">]</span> +</span><span id="DataFrame-449"><a href="#DataFrame-449"><span class="linenos">449</span></a> <span class="n">other_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-450"><a href="#DataFrame-450"><span class="linenos">450</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-451"><a href="#DataFrame-451"><span class="linenos">451</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-452"><a href="#DataFrame-452"><span class="linenos">452</span></a> <span class="p">]</span> +</span><span id="DataFrame-453"><a href="#DataFrame-453"><span class="linenos">453</span></a> <span class="n">column_value_mapping</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="DataFrame-454"><a href="#DataFrame-454"><span class="linenos">454</span></a> <span class="n">column</span><span class="o">.</span><span class="n">alias_or_name</span> +</span><span id="DataFrame-455"><a href="#DataFrame-455"><span class="linenos">455</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-456"><a href="#DataFrame-456"><span class="linenos">456</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-457"><a href="#DataFrame-457"><span class="linenos">457</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-458"><a href="#DataFrame-458"><span class="linenos">458</span></a> <span class="p">}</span> +</span><span id="DataFrame-459"><a href="#DataFrame-459"><span class="linenos">459</span></a> <span class="n">all_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-460"><a href="#DataFrame-460"><span class="linenos">460</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-461"><a href="#DataFrame-461"><span class="linenos">461</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-462"><a href="#DataFrame-462"><span class="linenos">462</span></a> <span class="p">]</span> +</span><span id="DataFrame-463"><a href="#DataFrame-463"><span class="linenos">463</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-464"><a href="#DataFrame-464"><span class="linenos">464</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-465"><a href="#DataFrame-465"><span class="linenos">465</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-466"><a href="#DataFrame-466"><span class="linenos">466</span></a> <span class="p">)</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="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-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="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-470"><a href="#DataFrame-470"><span class="linenos">470</span></a> <span class="p">)</span> +</span><span id="DataFrame-471"><a href="#DataFrame-471"><span class="linenos">471</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-472"><a href="#DataFrame-472"><span class="linenos">472</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-473"><a href="#DataFrame-473"><span class="linenos">473</span></a> <span class="k">return</span> <span class="n">new_df</span> +</span><span id="DataFrame-474"><a href="#DataFrame-474"><span class="linenos">474</span></a> +</span><span id="DataFrame-475"><a href="#DataFrame-475"><span class="linenos">475</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-476"><a href="#DataFrame-476"><span class="linenos">476</span></a> <span class="k">def</span> <span class="nf">orderBy</span><span class="p">(</span> +</span><span id="DataFrame-477"><a href="#DataFrame-477"><span class="linenos">477</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame-478"><a href="#DataFrame-478"><span class="linenos">478</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-479"><a href="#DataFrame-479"><span class="linenos">479</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-480"><a href="#DataFrame-480"><span class="linenos">480</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-481"><a href="#DataFrame-481"><span class="linenos">481</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="DataFrame-482"><a href="#DataFrame-482"><span class="linenos">482</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-483"><a href="#DataFrame-483"><span class="linenos">483</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-484"><a href="#DataFrame-484"><span class="linenos">484</span></a><span class="sd"> is unlikely to come up.</span> +</span><span id="DataFrame-485"><a href="#DataFrame-485"><span class="linenos">485</span></a><span class="sd"> """</span> +</span><span id="DataFrame-486"><a href="#DataFrame-486"><span class="linenos">486</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-487"><a href="#DataFrame-487"><span class="linenos">487</span></a> <span class="n">pre_ordered_col_indexes</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-488"><a href="#DataFrame-488"><span class="linenos">488</span></a> <span class="n">x</span> +</span><span id="DataFrame-489"><a href="#DataFrame-489"><span class="linenos">489</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-490"><a href="#DataFrame-490"><span class="linenos">490</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-491"><a href="#DataFrame-491"><span class="linenos">491</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-492"><a href="#DataFrame-492"><span class="linenos">492</span></a> <span class="p">]</span> +</span><span id="DataFrame-493"><a href="#DataFrame-493"><span class="linenos">493</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-494"><a href="#DataFrame-494"><span class="linenos">494</span></a> <span class="p">]</span> +</span><span id="DataFrame-495"><a href="#DataFrame-495"><span class="linenos">495</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-496"><a href="#DataFrame-496"><span class="linenos">496</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-497"><a href="#DataFrame-497"><span class="linenos">497</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-498"><a href="#DataFrame-498"><span class="linenos">498</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-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="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-500"><a href="#DataFrame-500"><span class="linenos">500</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-501"><a href="#DataFrame-501"><span class="linenos">501</span></a> <span class="n">ascending</span> +</span><span id="DataFrame-502"><a href="#DataFrame-502"><span class="linenos">502</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-503"><a href="#DataFrame-503"><span class="linenos">503</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-504"><a href="#DataFrame-504"><span class="linenos">504</span></a> <span class="n">order_by_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-505"><a href="#DataFrame-505"><span class="linenos">505</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-506"><a href="#DataFrame-506"><span class="linenos">506</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-507"><a href="#DataFrame-507"><span class="linenos">507</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-508"><a href="#DataFrame-508"><span class="linenos">508</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-509"><a href="#DataFrame-509"><span class="linenos">509</span></a> <span class="p">]</span> +</span><span id="DataFrame-510"><a href="#DataFrame-510"><span class="linenos">510</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-511"><a href="#DataFrame-511"><span class="linenos">511</span></a> +</span><span id="DataFrame-512"><a href="#DataFrame-512"><span class="linenos">512</span></a> <span class="n">sort</span> <span class="o">=</span> <span class="n">orderBy</span> +</span><span id="DataFrame-513"><a href="#DataFrame-513"><span class="linenos">513</span></a> +</span><span id="DataFrame-514"><a href="#DataFrame-514"><span class="linenos">514</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-515"><a href="#DataFrame-515"><span class="linenos">515</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-516"><a href="#DataFrame-516"><span class="linenos">516</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-517"><a href="#DataFrame-517"><span class="linenos">517</span></a> +</span><span id="DataFrame-518"><a href="#DataFrame-518"><span class="linenos">518</span></a> <span class="n">unionAll</span> <span class="o">=</span> <span class="n">union</span> +</span><span id="DataFrame-519"><a href="#DataFrame-519"><span class="linenos">519</span></a> +</span><span id="DataFrame-520"><a href="#DataFrame-520"><span class="linenos">520</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-521"><a href="#DataFrame-521"><span class="linenos">521</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-522"><a href="#DataFrame-522"><span class="linenos">522</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-523"><a href="#DataFrame-523"><span class="linenos">523</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-524"><a href="#DataFrame-524"><span class="linenos">524</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-525"><a href="#DataFrame-525"><span class="linenos">525</span></a> <span class="n">l_expressions</span> <span class="o">=</span> <span class="n">l_columns</span> +</span><span id="DataFrame-526"><a href="#DataFrame-526"><span class="linenos">526</span></a> <span class="n">r_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="k">else</span><span class="p">:</span> +</span><span id="DataFrame-528"><a href="#DataFrame-528"><span class="linenos">528</span></a> <span class="n">l_expressions</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="DataFrame-529"><a href="#DataFrame-529"><span class="linenos">529</span></a> <span class="n">r_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_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-531"><a href="#DataFrame-531"><span class="linenos">531</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-532"><a href="#DataFrame-532"><span class="linenos">532</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-533"><a href="#DataFrame-533"><span class="linenos">533</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-534"><a href="#DataFrame-534"><span class="linenos">534</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-535"><a href="#DataFrame-535"><span class="linenos">535</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-536"><a href="#DataFrame-536"><span class="linenos">536</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-537"><a href="#DataFrame-537"><span class="linenos">537</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-538"><a href="#DataFrame-538"><span class="linenos">538</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-539"><a href="#DataFrame-539"><span class="linenos">539</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-540"><a href="#DataFrame-540"><span class="linenos">540</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-541"><a href="#DataFrame-541"><span class="linenos">541</span></a> <span class="n">r_df</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="DataFrame-542"><a href="#DataFrame-542"><span class="linenos">542</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-543"><a href="#DataFrame-543"><span class="linenos">543</span></a> <span class="p">)</span> +</span><span id="DataFrame-544"><a href="#DataFrame-544"><span class="linenos">544</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-545"><a href="#DataFrame-545"><span class="linenos">545</span></a> <span class="k">if</span> <span class="n">allowMissingColumns</span><span class="p">:</span> +</span><span id="DataFrame-546"><a href="#DataFrame-546"><span class="linenos">546</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-547"><a href="#DataFrame-547"><span class="linenos">547</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-548"><a href="#DataFrame-548"><span class="linenos">548</span></a> +</span><span id="DataFrame-549"><a href="#DataFrame-549"><span class="linenos">549</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-550"><a href="#DataFrame-550"><span class="linenos">550</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-551"><a href="#DataFrame-551"><span class="linenos">551</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-552"><a href="#DataFrame-552"><span class="linenos">552</span></a> +</span><span id="DataFrame-553"><a href="#DataFrame-553"><span class="linenos">553</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-554"><a href="#DataFrame-554"><span class="linenos">554</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-555"><a href="#DataFrame-555"><span class="linenos">555</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-556"><a href="#DataFrame-556"><span class="linenos">556</span></a> +</span><span id="DataFrame-557"><a href="#DataFrame-557"><span class="linenos">557</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-558"><a href="#DataFrame-558"><span class="linenos">558</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-559"><a href="#DataFrame-559"><span class="linenos">559</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-560"><a href="#DataFrame-560"><span class="linenos">560</span></a> +</span><span id="DataFrame-561"><a href="#DataFrame-561"><span class="linenos">561</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-562"><a href="#DataFrame-562"><span class="linenos">562</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-563"><a href="#DataFrame-563"><span class="linenos">563</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-564"><a href="#DataFrame-564"><span class="linenos">564</span></a> +</span><span id="DataFrame-565"><a href="#DataFrame-565"><span class="linenos">565</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-566"><a href="#DataFrame-566"><span class="linenos">566</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-567"><a href="#DataFrame-567"><span class="linenos">567</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-568"><a href="#DataFrame-568"><span class="linenos">568</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-569"><a href="#DataFrame-569"><span class="linenos">569</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-570"><a href="#DataFrame-570"><span class="linenos">570</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-571"><a href="#DataFrame-571"><span class="linenos">571</span></a> <span class="k">return</span> <span class="p">(</span> +</span><span id="DataFrame-572"><a href="#DataFrame-572"><span class="linenos">572</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="DataFrame-573"><a href="#DataFrame-573"><span class="linenos">573</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-574"><a href="#DataFrame-574"><span class="linenos">574</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-575"><a href="#DataFrame-575"><span class="linenos">575</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-576"><a href="#DataFrame-576"><span class="linenos">576</span></a> <span class="p">)</span> +</span><span id="DataFrame-577"><a href="#DataFrame-577"><span class="linenos">577</span></a> +</span><span id="DataFrame-578"><a href="#DataFrame-578"><span class="linenos">578</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-579"><a href="#DataFrame-579"><span class="linenos">579</span></a> <span class="k">def</span> <span class="nf">dropna</span><span class="p">(</span> +</span><span id="DataFrame-580"><a href="#DataFrame-580"><span class="linenos">580</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame-581"><a href="#DataFrame-581"><span class="linenos">581</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-582"><a href="#DataFrame-582"><span class="linenos">582</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-583"><a href="#DataFrame-583"><span class="linenos">583</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-584"><a href="#DataFrame-584"><span class="linenos">584</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-585"><a href="#DataFrame-585"><span class="linenos">585</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-586"><a href="#DataFrame-586"><span class="linenos">586</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-587"><a href="#DataFrame-587"><span class="linenos">587</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-588"><a href="#DataFrame-588"><span class="linenos">588</span></a> <span class="k">if</span> <span class="n">subset</span><span class="p">:</span> +</span><span id="DataFrame-589"><a href="#DataFrame-589"><span class="linenos">589</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-590"><a href="#DataFrame-590"><span class="linenos">590</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-591"><a href="#DataFrame-591"><span class="linenos">591</span></a> <span class="n">null_check_columns</span> <span class="o">=</span> <span class="n">all_columns</span> +</span><span id="DataFrame-592"><a href="#DataFrame-592"><span class="linenos">592</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-593"><a href="#DataFrame-593"><span class="linenos">593</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-594"><a href="#DataFrame-594"><span class="linenos">594</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-595"><a href="#DataFrame-595"><span class="linenos">595</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-596"><a href="#DataFrame-596"><span class="linenos">596</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-597"><a href="#DataFrame-597"><span class="linenos">597</span></a> <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span> +</span><span id="DataFrame-598"><a href="#DataFrame-598"><span class="linenos">598</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-599"><a href="#DataFrame-599"><span class="linenos">599</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-600"><a href="#DataFrame-600"><span class="linenos">600</span></a> <span class="p">)</span> +</span><span id="DataFrame-601"><a href="#DataFrame-601"><span class="linenos">601</span></a> <span class="n">if_null_checks</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-602"><a href="#DataFrame-602"><span class="linenos">602</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-603"><a href="#DataFrame-603"><span class="linenos">603</span></a> <span class="p">]</span> +</span><span id="DataFrame-604"><a href="#DataFrame-604"><span class="linenos">604</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-605"><a href="#DataFrame-605"><span class="linenos">605</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-606"><a href="#DataFrame-606"><span class="linenos">606</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-607"><a href="#DataFrame-607"><span class="linenos">607</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-608"><a href="#DataFrame-608"><span class="linenos">608</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-609"><a href="#DataFrame-609"><span class="linenos">609</span></a> <span class="k">return</span> <span class="n">final_df</span> +</span><span id="DataFrame-610"><a href="#DataFrame-610"><span class="linenos">610</span></a> +</span><span id="DataFrame-611"><a href="#DataFrame-611"><span class="linenos">611</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-612"><a href="#DataFrame-612"><span class="linenos">612</span></a> <span class="k">def</span> <span class="nf">fillna</span><span class="p">(</span> +</span><span id="DataFrame-613"><a href="#DataFrame-613"><span class="linenos">613</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame-614"><a href="#DataFrame-614"><span class="linenos">614</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-615"><a href="#DataFrame-615"><span class="linenos">615</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-616"><a href="#DataFrame-616"><span class="linenos">616</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-617"><a href="#DataFrame-617"><span class="linenos">617</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="DataFrame-618"><a href="#DataFrame-618"><span class="linenos">618</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-619"><a href="#DataFrame-619"><span class="linenos">619</span></a><span class="sd"> with the type of the column then PySpark will just ignore your replacement.</span> +</span><span id="DataFrame-620"><a href="#DataFrame-620"><span class="linenos">620</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-621"><a href="#DataFrame-621"><span class="linenos">621</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-622"><a href="#DataFrame-622"><span class="linenos">622</span></a> +</span><span id="DataFrame-623"><a href="#DataFrame-623"><span class="linenos">623</span></a><span class="sd"> Possibility for improvement: Use `typeof` function to get the type of the column</span> +</span><span id="DataFrame-624"><a href="#DataFrame-624"><span class="linenos">624</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-625"><a href="#DataFrame-625"><span class="linenos">625</span></a><span class="sd"> """</span> +</span><span id="DataFrame-626"><a href="#DataFrame-626"><span class="linenos">626</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-627"><a href="#DataFrame-627"><span class="linenos">627</span></a> +</span><span id="DataFrame-628"><a href="#DataFrame-628"><span class="linenos">628</span></a> <span class="n">values</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="DataFrame-629"><a href="#DataFrame-629"><span class="linenos">629</span></a> <span class="n">columns</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">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-631"><a href="#DataFrame-631"><span class="linenos">631</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-632"><a href="#DataFrame-632"><span class="linenos">632</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-633"><a href="#DataFrame-633"><span class="linenos">633</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-634"><a href="#DataFrame-634"><span class="linenos">634</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-635"><a href="#DataFrame-635"><span class="linenos">635</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-636"><a href="#DataFrame-636"><span class="linenos">636</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-637"><a href="#DataFrame-637"><span class="linenos">637</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-638"><a href="#DataFrame-638"><span class="linenos">638</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-639"><a href="#DataFrame-639"><span class="linenos">639</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-640"><a href="#DataFrame-640"><span class="linenos">640</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-641"><a href="#DataFrame-641"><span class="linenos">641</span></a> +</span><span id="DataFrame-642"><a href="#DataFrame-642"><span class="linenos">642</span></a> <span class="n">null_replacement_mapping</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="DataFrame-643"><a href="#DataFrame-643"><span class="linenos">643</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-644"><a href="#DataFrame-644"><span class="linenos">644</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-645"><a href="#DataFrame-645"><span class="linenos">645</span></a> <span class="p">)</span> +</span><span id="DataFrame-646"><a href="#DataFrame-646"><span class="linenos">646</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-647"><a href="#DataFrame-647"><span class="linenos">647</span></a> <span class="p">}</span> +</span><span id="DataFrame-648"><a href="#DataFrame-648"><span class="linenos">648</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-649"><a href="#DataFrame-649"><span class="linenos">649</span></a> <span class="n">null_replacement_columns</span> <span class="o">=</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_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-651"><a href="#DataFrame-651"><span class="linenos">651</span></a> <span class="p">]</span> +</span><span id="DataFrame-652"><a href="#DataFrame-652"><span class="linenos">652</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-653"><a href="#DataFrame-653"><span class="linenos">653</span></a> <span class="k">return</span> <span class="n">new_df</span> +</span><span id="DataFrame-654"><a href="#DataFrame-654"><span class="linenos">654</span></a> +</span><span id="DataFrame-655"><a href="#DataFrame-655"><span class="linenos">655</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-656"><a href="#DataFrame-656"><span class="linenos">656</span></a> <span class="k">def</span> <span class="nf">replace</span><span class="p">(</span> +</span><span id="DataFrame-657"><a href="#DataFrame-657"><span class="linenos">657</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame-658"><a href="#DataFrame-658"><span class="linenos">658</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-659"><a href="#DataFrame-659"><span class="linenos">659</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-660"><a href="#DataFrame-660"><span class="linenos">660</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-661"><a href="#DataFrame-661"><span class="linenos">661</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-662"><a href="#DataFrame-662"><span class="linenos">662</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-663"><a href="#DataFrame-663"><span class="linenos">663</span></a> +</span><span id="DataFrame-664"><a href="#DataFrame-664"><span class="linenos">664</span></a> <span class="n">old_values</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="DataFrame-665"><a href="#DataFrame-665"><span class="linenos">665</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-666"><a href="#DataFrame-666"><span class="linenos">666</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-667"><a href="#DataFrame-667"><span class="linenos">667</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-668"><a href="#DataFrame-668"><span class="linenos">668</span></a> +</span><span id="DataFrame-669"><a href="#DataFrame-669"><span class="linenos">669</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-670"><a href="#DataFrame-670"><span class="linenos">670</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-671"><a href="#DataFrame-671"><span class="linenos">671</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-672"><a href="#DataFrame-672"><span class="linenos">672</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-673"><a href="#DataFrame-673"><span class="linenos">673</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-674"><a href="#DataFrame-674"><span class="linenos">674</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-675"><a href="#DataFrame-675"><span class="linenos">675</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-676"><a href="#DataFrame-676"><span class="linenos">676</span></a> <span class="n">value</span> +</span><span id="DataFrame-677"><a href="#DataFrame-677"><span class="linenos">677</span></a> <span class="p">),</span> <span class="s2">"the replacements and values must be the same length"</span> +</span><span id="DataFrame-678"><a href="#DataFrame-678"><span class="linenos">678</span></a> <span class="n">old_values</span> <span class="o">=</span> <span class="n">to_replace</span> +</span><span id="DataFrame-679"><a href="#DataFrame-679"><span class="linenos">679</span></a> <span class="n">new_values</span> <span class="o">=</span> <span class="n">value</span> +</span><span id="DataFrame-680"><a href="#DataFrame-680"><span class="linenos">680</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-681"><a href="#DataFrame-681"><span class="linenos">681</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-682"><a href="#DataFrame-682"><span class="linenos">682</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-683"><a href="#DataFrame-683"><span class="linenos">683</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-684"><a href="#DataFrame-684"><span class="linenos">684</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-685"><a href="#DataFrame-685"><span class="linenos">685</span></a> +</span><span id="DataFrame-686"><a href="#DataFrame-686"><span class="linenos">686</span></a> <span class="n">replacement_mapping</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="DataFrame-687"><a href="#DataFrame-687"><span class="linenos">687</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-688"><a href="#DataFrame-688"><span class="linenos">688</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-689"><a href="#DataFrame-689"><span class="linenos">689</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-690"><a href="#DataFrame-690"><span class="linenos">690</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-691"><a href="#DataFrame-691"><span class="linenos">691</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-692"><a href="#DataFrame-692"><span class="linenos">692</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-693"><a href="#DataFrame-693"><span class="linenos">693</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-694"><a href="#DataFrame-694"><span class="linenos">694</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-695"><a href="#DataFrame-695"><span class="linenos">695</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-696"><a href="#DataFrame-696"><span class="linenos">696</span></a> <span class="p">)</span> +</span><span id="DataFrame-697"><a href="#DataFrame-697"><span class="linenos">697</span></a> +</span><span id="DataFrame-698"><a href="#DataFrame-698"><span class="linenos">698</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-699"><a href="#DataFrame-699"><span class="linenos">699</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-700"><a href="#DataFrame-700"><span class="linenos">700</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-701"><a href="#DataFrame-701"><span class="linenos">701</span></a> <span class="k">return</span> <span class="n">new_df</span> +</span><span id="DataFrame-702"><a href="#DataFrame-702"><span class="linenos">702</span></a> +</span><span id="DataFrame-703"><a href="#DataFrame-703"><span class="linenos">703</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-704"><a href="#DataFrame-704"><span class="linenos">704</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-705"><a href="#DataFrame-705"><span class="linenos">705</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-706"><a href="#DataFrame-706"><span class="linenos">706</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-707"><a href="#DataFrame-707"><span class="linenos">707</span></a> <span class="n">existing_col_index</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="DataFrame-708"><a href="#DataFrame-708"><span class="linenos">708</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-709"><a href="#DataFrame-709"><span class="linenos">709</span></a> <span class="p">)</span> +</span><span id="DataFrame-710"><a href="#DataFrame-710"><span class="linenos">710</span></a> <span class="k">if</span> <span class="n">existing_col_index</span><span class="p">:</span> +</span><span id="DataFrame-711"><a href="#DataFrame-711"><span class="linenos">711</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-712"><a href="#DataFrame-712"><span class="linenos">712</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-713"><a href="#DataFrame-713"><span class="linenos">713</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-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="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-715"><a href="#DataFrame-715"><span class="linenos">715</span></a> +</span><span id="DataFrame-716"><a href="#DataFrame-716"><span class="linenos">716</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-717"><a href="#DataFrame-717"><span class="linenos">717</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-718"><a href="#DataFrame-718"><span class="linenos">718</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-719"><a href="#DataFrame-719"><span class="linenos">719</span></a> <span class="n">existing_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-720"><a href="#DataFrame-720"><span class="linenos">720</span></a> <span class="n">expression</span> +</span><span id="DataFrame-721"><a href="#DataFrame-721"><span class="linenos">721</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-722"><a href="#DataFrame-722"><span class="linenos">722</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-723"><a href="#DataFrame-723"><span class="linenos">723</span></a> <span class="p">]</span> +</span><span id="DataFrame-724"><a href="#DataFrame-724"><span class="linenos">724</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-725"><a href="#DataFrame-725"><span class="linenos">725</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-726"><a href="#DataFrame-726"><span class="linenos">726</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-727"><a href="#DataFrame-727"><span class="linenos">727</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-728"><a href="#DataFrame-728"><span class="linenos">728</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-729"><a href="#DataFrame-729"><span class="linenos">729</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame-730"><a href="#DataFrame-730"><span class="linenos">730</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-731"><a href="#DataFrame-731"><span class="linenos">731</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-732"><a href="#DataFrame-732"><span class="linenos">732</span></a> +</span><span id="DataFrame-733"><a href="#DataFrame-733"><span class="linenos">733</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-734"><a href="#DataFrame-734"><span class="linenos">734</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-735"><a href="#DataFrame-735"><span class="linenos">735</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-736"><a href="#DataFrame-736"><span class="linenos">736</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-737"><a href="#DataFrame-737"><span class="linenos">737</span></a> <span class="n">new_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame-738"><a href="#DataFrame-738"><span class="linenos">738</span></a> <span class="n">col</span> +</span><span id="DataFrame-739"><a href="#DataFrame-739"><span class="linenos">739</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-740"><a href="#DataFrame-740"><span class="linenos">740</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-741"><a href="#DataFrame-741"><span class="linenos">741</span></a> <span class="p">]</span> +</span><span id="DataFrame-742"><a href="#DataFrame-742"><span class="linenos">742</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-743"><a href="#DataFrame-743"><span class="linenos">743</span></a> +</span><span id="DataFrame-744"><a href="#DataFrame-744"><span class="linenos">744</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-745"><a href="#DataFrame-745"><span class="linenos">745</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-746"><a href="#DataFrame-746"><span class="linenos">746</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-747"><a href="#DataFrame-747"><span class="linenos">747</span></a> +</span><span id="DataFrame-748"><a href="#DataFrame-748"><span class="linenos">748</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-749"><a href="#DataFrame-749"><span class="linenos">749</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-750"><a href="#DataFrame-750"><span class="linenos">750</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-751"><a href="#DataFrame-751"><span class="linenos">751</span></a> <span class="n">parameter_columns</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="DataFrame-752"><a href="#DataFrame-752"><span class="linenos">752</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-753"><a href="#DataFrame-753"><span class="linenos">753</span></a> <span class="k">if</span> <span class="n">parameters</span> +</span><span id="DataFrame-754"><a href="#DataFrame-754"><span class="linenos">754</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-755"><a href="#DataFrame-755"><span class="linenos">755</span></a> <span class="p">)</span> +</span><span id="DataFrame-756"><a href="#DataFrame-756"><span class="linenos">756</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-757"><a href="#DataFrame-757"><span class="linenos">757</span></a> +</span><span id="DataFrame-758"><a href="#DataFrame-758"><span class="linenos">758</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-759"><a href="#DataFrame-759"><span class="linenos">759</span></a> <span class="k">def</span> <span class="nf">repartition</span><span class="p">(</span> +</span><span id="DataFrame-760"><a href="#DataFrame-760"><span class="linenos">760</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-761"><a href="#DataFrame-761"><span class="linenos">761</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame-762"><a href="#DataFrame-762"><span class="linenos">762</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-763"><a href="#DataFrame-763"><span class="linenos">763</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-764"><a href="#DataFrame-764"><span class="linenos">764</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-765"><a href="#DataFrame-765"><span class="linenos">765</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-766"><a href="#DataFrame-766"><span class="linenos">766</span></a> +</span><span id="DataFrame-767"><a href="#DataFrame-767"><span class="linenos">767</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-768"><a href="#DataFrame-768"><span class="linenos">768</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-769"><a href="#DataFrame-769"><span class="linenos">769</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-770"><a href="#DataFrame-770"><span class="linenos">770</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-771"><a href="#DataFrame-771"><span class="linenos">771</span></a> +</span><span id="DataFrame-772"><a href="#DataFrame-772"><span class="linenos">772</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-773"><a href="#DataFrame-773"><span class="linenos">773</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-774"><a href="#DataFrame-774"><span class="linenos">774</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-775"><a href="#DataFrame-775"><span class="linenos">775</span></a> +</span><span id="DataFrame-776"><a href="#DataFrame-776"><span class="linenos">776</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-777"><a href="#DataFrame-777"><span class="linenos">777</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-778"><a href="#DataFrame-778"><span class="linenos">778</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="DataFrame-779"><a href="#DataFrame-779"><span class="linenos">779</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-780"><a href="#DataFrame-780"><span class="linenos">780</span></a><span class="sd"> """</span> +</span><span id="DataFrame-781"><a href="#DataFrame-781"><span class="linenos">781</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> @@ -1500,30 +1476,30 @@ <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">'140483442251840'</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">'140483442487456'</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> + <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">'140512217589712'</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">'140512217372640'</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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.__init__-46"><a href="#DataFrame.__init__-46"><span class="linenos">46</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span> +</span><span id="DataFrame.__init__-47"><a href="#DataFrame.__init__-47"><span class="linenos">47</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame.__init__-48"><a href="#DataFrame.__init__-48"><span class="linenos">48</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__-49"><a href="#DataFrame.__init__-49"><span class="linenos">49</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__-50"><a href="#DataFrame.__init__-50"><span class="linenos">50</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__-51"><a href="#DataFrame.__init__-51"><span class="linenos">51</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__-52"><a href="#DataFrame.__init__-52"><span class="linenos">52</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__-53"><a href="#DataFrame.__init__-53"><span class="linenos">53</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__-54"><a href="#DataFrame.__init__-54"><span class="linenos">54</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__-55"><a href="#DataFrame.__init__-55"><span class="linenos">55</span></a> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span> +</span><span id="DataFrame.__init__-56"><a href="#DataFrame.__init__-56"><span class="linenos">56</span></a> <span class="p">):</span> +</span><span id="DataFrame.__init__-57"><a href="#DataFrame.__init__-57"><span class="linenos">57</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__-58"><a href="#DataFrame.__init__-58"><span class="linenos">58</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__-59"><a href="#DataFrame.__init__-59"><span class="linenos">59</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__-60"><a href="#DataFrame.__init__-60"><span class="linenos">60</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__-61"><a href="#DataFrame.__init__-61"><span class="linenos">61</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__-62"><a href="#DataFrame.__init__-62"><span class="linenos">62</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__-63"><a href="#DataFrame.__init__-63"><span class="linenos">63</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> @@ -1541,61 +1517,61 @@ </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.sql-295"><a href="#DataFrame.sql-295"><span class="linenos">295</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-296"><a href="#DataFrame.sql-296"><span class="linenos">296</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-297"><a href="#DataFrame.sql-297"><span class="linenos">297</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-298"><a href="#DataFrame.sql-298"><span class="linenos">298</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-299"><a href="#DataFrame.sql-299"><span class="linenos">299</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-300"><a href="#DataFrame.sql-300"><span class="linenos">300</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-301"><a href="#DataFrame.sql-301"><span class="linenos">301</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-302"><a href="#DataFrame.sql-302"><span class="linenos">302</span></a> <span class="k">if</span> <span class="n">optimize</span><span class="p">:</span> +</span><span id="DataFrame.sql-303"><a href="#DataFrame.sql-303"><span class="linenos">303</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-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">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-305"><a href="#DataFrame.sql-305"><span class="linenos">305</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-306"><a href="#DataFrame.sql-306"><span class="linenos">306</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-307"><a href="#DataFrame.sql-307"><span class="linenos">307</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-308"><a href="#DataFrame.sql-308"><span class="linenos">308</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-309"><a href="#DataFrame.sql-309"><span class="linenos">309</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-310"><a href="#DataFrame.sql-310"><span class="linenos">310</span></a> +</span><span id="DataFrame.sql-311"><a href="#DataFrame.sql-311"><span class="linenos">311</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-312"><a href="#DataFrame.sql-312"><span class="linenos">312</span></a> <span class="n">cache_table_name</span> +</span><span id="DataFrame.sql-313"><a href="#DataFrame.sql-313"><span class="linenos">313</span></a> <span class="p">)</span> +</span><span id="DataFrame.sql-314"><a href="#DataFrame.sql-314"><span class="linenos">314</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-315"><a href="#DataFrame.sql-315"><span class="linenos">315</span></a> <span class="n">cache_table_name</span><span class="p">,</span> +</span><span id="DataFrame.sql-316"><a href="#DataFrame.sql-316"><span class="linenos">316</span></a> <span class="p">{</span> +</span><span id="DataFrame.sql-317"><a href="#DataFrame.sql-317"><span class="linenos">317</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-318"><a href="#DataFrame.sql-318"><span class="linenos">318</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-319"><a href="#DataFrame.sql-319"><span class="linenos">319</span></a> <span class="p">},</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="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-322"><a href="#DataFrame.sql-322"><span class="linenos">322</span></a> <span class="n">options</span> <span class="o">=</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">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-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="n">cache_storage_level</span><span class="p">),</span> +</span><span id="DataFrame.sql-325"><a href="#DataFrame.sql-325"><span class="linenos">325</span></a> <span class="p">]</span> +</span><span id="DataFrame.sql-326"><a href="#DataFrame.sql-326"><span class="linenos">326</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-327"><a href="#DataFrame.sql-327"><span class="linenos">327</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-328"><a href="#DataFrame.sql-328"><span class="linenos">328</span></a> <span class="p">)</span> +</span><span id="DataFrame.sql-329"><a href="#DataFrame.sql-329"><span class="linenos">329</span></a> <span class="c1"># We will drop the "view" if it exists before running the cache table</span> +</span><span id="DataFrame.sql-330"><a href="#DataFrame.sql-330"><span class="linenos">330</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-331"><a href="#DataFrame.sql-331"><span class="linenos">331</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-332"><a href="#DataFrame.sql-332"><span class="linenos">332</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-333"><a href="#DataFrame.sql-333"><span class="linenos">333</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-334"><a href="#DataFrame.sql-334"><span class="linenos">334</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-335"><a href="#DataFrame.sql-335"><span class="linenos">335</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-336"><a href="#DataFrame.sql-336"><span class="linenos">336</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-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">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-338"><a href="#DataFrame.sql-338"><span class="linenos">338</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-339"><a href="#DataFrame.sql-339"><span class="linenos">339</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-340"><a href="#DataFrame.sql-340"><span class="linenos">340</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-341"><a href="#DataFrame.sql-341"><span class="linenos">341</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-342"><a href="#DataFrame.sql-342"><span class="linenos">342</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">select_expression</span> +</span><span id="DataFrame.sql-343"><a href="#DataFrame.sql-343"><span class="linenos">343</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.sql-344"><a href="#DataFrame.sql-344"><span class="linenos">344</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-345"><a href="#DataFrame.sql-345"><span class="linenos">345</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-346"><a href="#DataFrame.sql-346"><span class="linenos">346</span></a> +</span><span id="DataFrame.sql-347"><a href="#DataFrame.sql-347"><span class="linenos">347</span></a> <span class="k">return</span> <span class="p">[</span> +</span><span id="DataFrame.sql-348"><a href="#DataFrame.sql-348"><span class="linenos">348</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-349"><a href="#DataFrame.sql-349"><span class="linenos">349</span></a> <span class="p">]</span> </span></pre></div> @@ -1613,8 +1589,8 @@ </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.copy-351"><a href="#DataFrame.copy-351"><span class="linenos">351</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-352"><a href="#DataFrame.copy-352"><span class="linenos">352</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> @@ -1633,34 +1609,34 @@ </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.select-354"><a href="#DataFrame.select-354"><span class="linenos">354</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-355"><a href="#DataFrame.select-355"><span class="linenos">355</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-356"><a href="#DataFrame.select-356"><span class="linenos">356</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-357"><a href="#DataFrame.select-357"><span class="linenos">357</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-358"><a href="#DataFrame.select-358"><span class="linenos">358</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-359"><a href="#DataFrame.select-359"><span class="linenos">359</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-360"><a href="#DataFrame.select-360"><span class="linenos">360</span></a> <span class="k">if</span> <span class="n">ambiguous_cols</span><span class="p">:</span> +</span><span id="DataFrame.select-361"><a href="#DataFrame.select-361"><span class="linenos">361</span></a> <span class="n">join_table_identifiers</span> <span class="o">=</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">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-363"><a href="#DataFrame.select-363"><span class="linenos">363</span></a> <span class="p">]</span> +</span><span id="DataFrame.select-364"><a href="#DataFrame.select-364"><span class="linenos">364</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-365"><a href="#DataFrame.select-365"><span class="linenos">365</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-366"><a href="#DataFrame.select-366"><span class="linenos">366</span></a> <span class="n">ctes_with_column</span> <span class="o">=</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">cte</span> +</span><span id="DataFrame.select-368"><a href="#DataFrame.select-368"><span class="linenos">368</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-369"><a href="#DataFrame.select-369"><span class="linenos">369</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-370"><a href="#DataFrame.select-370"><span class="linenos">370</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-371"><a href="#DataFrame.select-371"><span class="linenos">371</span></a> <span class="p">]</span> +</span><span id="DataFrame.select-372"><a href="#DataFrame.select-372"><span class="linenos">372</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-373"><a href="#DataFrame.select-373"><span class="linenos">373</span></a> <span class="c1"># then we assume they are referring to the left table</span> +</span><span id="DataFrame.select-374"><a href="#DataFrame.select-374"><span class="linenos">374</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-375"><a href="#DataFrame.select-375"><span class="linenos">375</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-376"><a href="#DataFrame.select-376"><span class="linenos">376</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.select-377"><a href="#DataFrame.select-377"><span class="linenos">377</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-378"><a href="#DataFrame.select-378"><span class="linenos">378</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-379"><a href="#DataFrame.select-379"><span class="linenos">379</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.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 class="o">**</span><span class="n">kwargs</span> +</span><span id="DataFrame.select-381"><a href="#DataFrame.select-381"><span class="linenos">381</span></a> <span class="p">)</span> </span></pre></div> @@ -1679,16 +1655,16 @@ </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.alias-383"><a href="#DataFrame.alias-383"><span class="linenos">383</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-384"><a href="#DataFrame.alias-384"><span class="linenos">384</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-385"><a href="#DataFrame.alias-385"><span class="linenos">385</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-386"><a href="#DataFrame.alias-386"><span class="linenos">386</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-387"><a href="#DataFrame.alias-387"><span class="linenos">387</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-388"><a href="#DataFrame.alias-388"><span class="linenos">388</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-389"><a href="#DataFrame.alias-389"><span class="linenos">389</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-390"><a href="#DataFrame.alias-390"><span class="linenos">390</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-391"><a href="#DataFrame.alias-391"><span class="linenos">391</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-392"><a href="#DataFrame.alias-392"><span class="linenos">392</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> @@ -1707,10 +1683,10 @@ </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.where-394"><a href="#DataFrame.where-394"><span class="linenos">394</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-395"><a href="#DataFrame.where-395"><span class="linenos">395</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-396"><a href="#DataFrame.where-396"><span class="linenos">396</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-397"><a href="#DataFrame.where-397"><span class="linenos">397</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> @@ -1729,10 +1705,10 @@ </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.filter-394"><a href="#DataFrame.filter-394"><span class="linenos">394</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-395"><a href="#DataFrame.filter-395"><span class="linenos">395</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-396"><a href="#DataFrame.filter-396"><span class="linenos">396</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-397"><a href="#DataFrame.filter-397"><span class="linenos">397</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> @@ -1751,10 +1727,10 @@ </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.groupBy-401"><a href="#DataFrame.groupBy-401"><span class="linenos">401</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-402"><a href="#DataFrame.groupBy-402"><span class="linenos">402</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-403"><a href="#DataFrame.groupBy-403"><span class="linenos">403</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-404"><a href="#DataFrame.groupBy-404"><span class="linenos">404</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> @@ -1773,10 +1749,10 @@ </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.agg-406"><a href="#DataFrame.agg-406"><span class="linenos">406</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-407"><a href="#DataFrame.agg-407"><span class="linenos">407</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-408"><a href="#DataFrame.agg-408"><span class="linenos">408</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-409"><a href="#DataFrame.agg-409"><span class="linenos">409</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> @@ -1795,69 +1771,69 @@ </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.join-411"><a href="#DataFrame.join-411"><span class="linenos">411</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-412"><a href="#DataFrame.join-412"><span class="linenos">412</span></a> <span class="k">def</span> <span class="nf">join</span><span class="p">(</span> +</span><span id="DataFrame.join-413"><a href="#DataFrame.join-413"><span class="linenos">413</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame.join-414"><a href="#DataFrame.join-414"><span class="linenos">414</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-415"><a href="#DataFrame.join-415"><span class="linenos">415</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-416"><a href="#DataFrame.join-416"><span class="linenos">416</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-417"><a href="#DataFrame.join-417"><span class="linenos">417</span></a> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span> +</span><span id="DataFrame.join-418"><a href="#DataFrame.join-418"><span class="linenos">418</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.join-419"><a href="#DataFrame.join-419"><span class="linenos">419</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-420"><a href="#DataFrame.join-420"><span class="linenos">420</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-421"><a href="#DataFrame.join-421"><span class="linenos">421</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-422"><a href="#DataFrame.join-422"><span class="linenos">422</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-423"><a href="#DataFrame.join-423"><span class="linenos">423</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-424"><a href="#DataFrame.join-424"><span class="linenos">424</span></a> <span class="n">join_columns</span> <span class="o">=</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">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-426"><a href="#DataFrame.join-426"><span class="linenos">426</span></a> <span class="p">]</span> +</span><span id="DataFrame.join-427"><a href="#DataFrame.join-427"><span class="linenos">427</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-428"><a href="#DataFrame.join-428"><span class="linenos">428</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-429"><a href="#DataFrame.join-429"><span class="linenos">429</span></a> <span class="p">[</span> +</span><span id="DataFrame.join-430"><a href="#DataFrame.join-430"><span class="linenos">430</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-431"><a href="#DataFrame.join-431"><span class="linenos">431</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-432"><a href="#DataFrame.join-432"><span class="linenos">432</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-433"><a href="#DataFrame.join-433"><span class="linenos">433</span></a> <span class="p">],</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="k">else</span><span class="p">:</span> +</span><span id="DataFrame.join-436"><a href="#DataFrame.join-436"><span class="linenos">436</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-437"><a href="#DataFrame.join-437"><span class="linenos">437</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-438"><a href="#DataFrame.join-438"><span class="linenos">438</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-439"><a href="#DataFrame.join-439"><span class="linenos">439</span></a> <span class="n">join_columns</span> <span class="o">=</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">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-441"><a href="#DataFrame.join-441"><span class="linenos">441</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-442"><a href="#DataFrame.join-442"><span class="linenos">442</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-443"><a href="#DataFrame.join-443"><span class="linenos">443</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-444"><a href="#DataFrame.join-444"><span class="linenos">444</span></a> <span class="p">]</span> +</span><span id="DataFrame.join-445"><a href="#DataFrame.join-445"><span class="linenos">445</span></a> <span class="n">self_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.join-446"><a href="#DataFrame.join-446"><span class="linenos">446</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-447"><a href="#DataFrame.join-447"><span class="linenos">447</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-448"><a href="#DataFrame.join-448"><span class="linenos">448</span></a> <span class="p">]</span> +</span><span id="DataFrame.join-449"><a href="#DataFrame.join-449"><span class="linenos">449</span></a> <span class="n">other_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.join-450"><a href="#DataFrame.join-450"><span class="linenos">450</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-451"><a href="#DataFrame.join-451"><span class="linenos">451</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-452"><a href="#DataFrame.join-452"><span class="linenos">452</span></a> <span class="p">]</span> +</span><span id="DataFrame.join-453"><a href="#DataFrame.join-453"><span class="linenos">453</span></a> <span class="n">column_value_mapping</span> <span class="o">=</span> <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</span><span class="o">.</span><span class="n">alias_or_name</span> +</span><span id="DataFrame.join-455"><a href="#DataFrame.join-455"><span class="linenos">455</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-456"><a href="#DataFrame.join-456"><span class="linenos">456</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-457"><a href="#DataFrame.join-457"><span class="linenos">457</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-458"><a href="#DataFrame.join-458"><span class="linenos">458</span></a> <span class="p">}</span> +</span><span id="DataFrame.join-459"><a href="#DataFrame.join-459"><span class="linenos">459</span></a> <span class="n">all_columns</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.join-460"><a href="#DataFrame.join-460"><span class="linenos">460</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-461"><a href="#DataFrame.join-461"><span class="linenos">461</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-462"><a href="#DataFrame.join-462"><span class="linenos">462</span></a> <span class="p">]</span> +</span><span id="DataFrame.join-463"><a href="#DataFrame.join-463"><span class="linenos">463</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-464"><a href="#DataFrame.join-464"><span class="linenos">464</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-465"><a href="#DataFrame.join-465"><span class="linenos">465</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-466"><a href="#DataFrame.join-466"><span class="linenos">466</span></a> <span class="p">)</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="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-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="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-470"><a href="#DataFrame.join-470"><span class="linenos">470</span></a> <span class="p">)</span> +</span><span id="DataFrame.join-471"><a href="#DataFrame.join-471"><span class="linenos">471</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-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">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-473"><a href="#DataFrame.join-473"><span class="linenos">473</span></a> <span class="k">return</span> <span class="n">new_df</span> </span></pre></div> @@ -1876,42 +1852,42 @@ </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.orderBy-475"><a href="#DataFrame.orderBy-475"><span class="linenos">475</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-476"><a href="#DataFrame.orderBy-476"><span class="linenos">476</span></a> <span class="k">def</span> <span class="nf">orderBy</span><span class="p">(</span> +</span><span id="DataFrame.orderBy-477"><a href="#DataFrame.orderBy-477"><span class="linenos">477</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame.orderBy-478"><a href="#DataFrame.orderBy-478"><span class="linenos">478</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-479"><a href="#DataFrame.orderBy-479"><span class="linenos">479</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-480"><a href="#DataFrame.orderBy-480"><span class="linenos">480</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.orderBy-481"><a href="#DataFrame.orderBy-481"><span class="linenos">481</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="DataFrame.orderBy-482"><a href="#DataFrame.orderBy-482"><span class="linenos">482</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-483"><a href="#DataFrame.orderBy-483"><span class="linenos">483</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-484"><a href="#DataFrame.orderBy-484"><span class="linenos">484</span></a><span class="sd"> is unlikely to come up.</span> +</span><span id="DataFrame.orderBy-485"><a href="#DataFrame.orderBy-485"><span class="linenos">485</span></a><span class="sd"> """</span> +</span><span id="DataFrame.orderBy-486"><a href="#DataFrame.orderBy-486"><span class="linenos">486</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-487"><a href="#DataFrame.orderBy-487"><span class="linenos">487</span></a> <span class="n">pre_ordered_col_indexes</span> <span class="o">=</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">x</span> +</span><span id="DataFrame.orderBy-489"><a href="#DataFrame.orderBy-489"><span class="linenos">489</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-490"><a href="#DataFrame.orderBy-490"><span class="linenos">490</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-491"><a href="#DataFrame.orderBy-491"><span class="linenos">491</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-492"><a href="#DataFrame.orderBy-492"><span class="linenos">492</span></a> <span class="p">]</span> +</span><span id="DataFrame.orderBy-493"><a href="#DataFrame.orderBy-493"><span class="linenos">493</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-494"><a href="#DataFrame.orderBy-494"><span class="linenos">494</span></a> <span class="p">]</span> +</span><span id="DataFrame.orderBy-495"><a href="#DataFrame.orderBy-495"><span class="linenos">495</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-496"><a href="#DataFrame.orderBy-496"><span class="linenos">496</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-497"><a href="#DataFrame.orderBy-497"><span class="linenos">497</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-498"><a href="#DataFrame.orderBy-498"><span class="linenos">498</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-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="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-500"><a href="#DataFrame.orderBy-500"><span class="linenos">500</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-501"><a href="#DataFrame.orderBy-501"><span class="linenos">501</span></a> <span class="n">ascending</span> +</span><span id="DataFrame.orderBy-502"><a href="#DataFrame.orderBy-502"><span class="linenos">502</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-503"><a href="#DataFrame.orderBy-503"><span class="linenos">503</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-504"><a href="#DataFrame.orderBy-504"><span class="linenos">504</span></a> <span class="n">order_by_columns</span> <span class="o">=</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">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-506"><a href="#DataFrame.orderBy-506"><span class="linenos">506</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-507"><a href="#DataFrame.orderBy-507"><span class="linenos">507</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-508"><a href="#DataFrame.orderBy-508"><span class="linenos">508</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-509"><a href="#DataFrame.orderBy-509"><span class="linenos">509</span></a> <span class="p">]</span> +</span><span id="DataFrame.orderBy-510"><a href="#DataFrame.orderBy-510"><span class="linenos">510</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> @@ -1934,42 +1910,42 @@ is unlikely to come up.</p> </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.sort-475"><a href="#DataFrame.sort-475"><span class="linenos">475</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-476"><a href="#DataFrame.sort-476"><span class="linenos">476</span></a> <span class="k">def</span> <span class="nf">orderBy</span><span class="p">(</span> +</span><span id="DataFrame.sort-477"><a href="#DataFrame.sort-477"><span class="linenos">477</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame.sort-478"><a href="#DataFrame.sort-478"><span class="linenos">478</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-479"><a href="#DataFrame.sort-479"><span class="linenos">479</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-480"><a href="#DataFrame.sort-480"><span class="linenos">480</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.sort-481"><a href="#DataFrame.sort-481"><span class="linenos">481</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="DataFrame.sort-482"><a href="#DataFrame.sort-482"><span class="linenos">482</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-483"><a href="#DataFrame.sort-483"><span class="linenos">483</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-484"><a href="#DataFrame.sort-484"><span class="linenos">484</span></a><span class="sd"> is unlikely to come up.</span> +</span><span id="DataFrame.sort-485"><a href="#DataFrame.sort-485"><span class="linenos">485</span></a><span class="sd"> """</span> +</span><span id="DataFrame.sort-486"><a href="#DataFrame.sort-486"><span class="linenos">486</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-487"><a href="#DataFrame.sort-487"><span class="linenos">487</span></a> <span class="n">pre_ordered_col_indexes</span> <span class="o">=</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">x</span> +</span><span id="DataFrame.sort-489"><a href="#DataFrame.sort-489"><span class="linenos">489</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-490"><a href="#DataFrame.sort-490"><span class="linenos">490</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-491"><a href="#DataFrame.sort-491"><span class="linenos">491</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-492"><a href="#DataFrame.sort-492"><span class="linenos">492</span></a> <span class="p">]</span> +</span><span id="DataFrame.sort-493"><a href="#DataFrame.sort-493"><span class="linenos">493</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-494"><a href="#DataFrame.sort-494"><span class="linenos">494</span></a> <span class="p">]</span> +</span><span id="DataFrame.sort-495"><a href="#DataFrame.sort-495"><span class="linenos">495</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-496"><a href="#DataFrame.sort-496"><span class="linenos">496</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-497"><a href="#DataFrame.sort-497"><span class="linenos">497</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-498"><a href="#DataFrame.sort-498"><span class="linenos">498</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-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="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-500"><a href="#DataFrame.sort-500"><span class="linenos">500</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-501"><a href="#DataFrame.sort-501"><span class="linenos">501</span></a> <span class="n">ascending</span> +</span><span id="DataFrame.sort-502"><a href="#DataFrame.sort-502"><span class="linenos">502</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-503"><a href="#DataFrame.sort-503"><span class="linenos">503</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-504"><a href="#DataFrame.sort-504"><span class="linenos">504</span></a> <span class="n">order_by_columns</span> <span class="o">=</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">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-506"><a href="#DataFrame.sort-506"><span class="linenos">506</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-507"><a href="#DataFrame.sort-507"><span class="linenos">507</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-508"><a href="#DataFrame.sort-508"><span class="linenos">508</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-509"><a href="#DataFrame.sort-509"><span class="linenos">509</span></a> <span class="p">]</span> +</span><span id="DataFrame.sort-510"><a href="#DataFrame.sort-510"><span class="linenos">510</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> @@ -1992,9 +1968,9 @@ is unlikely to come up.</p> </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.union-514"><a href="#DataFrame.union-514"><span class="linenos">514</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-515"><a href="#DataFrame.union-515"><span class="linenos">515</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-516"><a href="#DataFrame.union-516"><span class="linenos">516</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> @@ -2013,9 +1989,9 @@ is unlikely to come up.</p> </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.unionAll-514"><a href="#DataFrame.unionAll-514"><span class="linenos">514</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-515"><a href="#DataFrame.unionAll-515"><span class="linenos">515</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-516"><a href="#DataFrame.unionAll-516"><span class="linenos">516</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> @@ -2034,34 +2010,34 @@ is unlikely to come up.</p> </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.unionByName-520"><a href="#DataFrame.unionByName-520"><span class="linenos">520</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-521"><a href="#DataFrame.unionByName-521"><span class="linenos">521</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-522"><a href="#DataFrame.unionByName-522"><span class="linenos">522</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-523"><a href="#DataFrame.unionByName-523"><span class="linenos">523</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-524"><a href="#DataFrame.unionByName-524"><span class="linenos">524</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-525"><a href="#DataFrame.unionByName-525"><span class="linenos">525</span></a> <span class="n">l_expressions</span> <span class="o">=</span> <span class="n">l_columns</span> +</span><span id="DataFrame.unionByName-526"><a href="#DataFrame.unionByName-526"><span class="linenos">526</span></a> <span class="n">r_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="k">else</span><span class="p">:</span> +</span><span id="DataFrame.unionByName-528"><a href="#DataFrame.unionByName-528"><span class="linenos">528</span></a> <span class="n">l_expressions</span> <span class="o">=</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">r_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_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-531"><a href="#DataFrame.unionByName-531"><span class="linenos">531</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-532"><a href="#DataFrame.unionByName-532"><span class="linenos">532</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-533"><a href="#DataFrame.unionByName-533"><span class="linenos">533</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-534"><a href="#DataFrame.unionByName-534"><span class="linenos">534</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-535"><a href="#DataFrame.unionByName-535"><span class="linenos">535</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-536"><a href="#DataFrame.unionByName-536"><span class="linenos">536</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.unionByName-537"><a href="#DataFrame.unionByName-537"><span class="linenos">537</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-538"><a href="#DataFrame.unionByName-538"><span class="linenos">538</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-539"><a href="#DataFrame.unionByName-539"><span class="linenos">539</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-540"><a href="#DataFrame.unionByName-540"><span class="linenos">540</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-541"><a href="#DataFrame.unionByName-541"><span class="linenos">541</span></a> <span class="n">r_df</span> <span class="o">=</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">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-543"><a href="#DataFrame.unionByName-543"><span class="linenos">543</span></a> <span class="p">)</span> +</span><span id="DataFrame.unionByName-544"><a href="#DataFrame.unionByName-544"><span class="linenos">544</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-545"><a href="#DataFrame.unionByName-545"><span class="linenos">545</span></a> <span class="k">if</span> <span class="n">allowMissingColumns</span><span class="p">:</span> +</span><span id="DataFrame.unionByName-546"><a href="#DataFrame.unionByName-546"><span class="linenos">546</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-547"><a href="#DataFrame.unionByName-547"><span class="linenos">547</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> @@ -2080,9 +2056,9 @@ is unlikely to come up.</p> </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.intersect-549"><a href="#DataFrame.intersect-549"><span class="linenos">549</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-550"><a href="#DataFrame.intersect-550"><span class="linenos">550</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-551"><a href="#DataFrame.intersect-551"><span class="linenos">551</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> @@ -2101,9 +2077,9 @@ is unlikely to come up.</p> </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.intersectAll-553"><a href="#DataFrame.intersectAll-553"><span class="linenos">553</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-554"><a href="#DataFrame.intersectAll-554"><span class="linenos">554</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-555"><a href="#DataFrame.intersectAll-555"><span class="linenos">555</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> @@ -2122,9 +2098,9 @@ is unlikely to come up.</p> </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.exceptAll-557"><a href="#DataFrame.exceptAll-557"><span class="linenos">557</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-558"><a href="#DataFrame.exceptAll-558"><span class="linenos">558</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-559"><a href="#DataFrame.exceptAll-559"><span class="linenos">559</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> @@ -2143,9 +2119,9 @@ is unlikely to come up.</p> </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.distinct-561"><a href="#DataFrame.distinct-561"><span class="linenos">561</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-562"><a href="#DataFrame.distinct-562"><span class="linenos">562</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-563"><a href="#DataFrame.distinct-563"><span class="linenos">563</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> @@ -2164,18 +2140,18 @@ is unlikely to come up.</p> </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.dropDuplicates-565"><a href="#DataFrame.dropDuplicates-565"><span class="linenos">565</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-566"><a href="#DataFrame.dropDuplicates-566"><span class="linenos">566</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-567"><a href="#DataFrame.dropDuplicates-567"><span class="linenos">567</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-568"><a href="#DataFrame.dropDuplicates-568"><span class="linenos">568</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-569"><a href="#DataFrame.dropDuplicates-569"><span class="linenos">569</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-570"><a href="#DataFrame.dropDuplicates-570"><span class="linenos">570</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-571"><a href="#DataFrame.dropDuplicates-571"><span class="linenos">571</span></a> <span class="k">return</span> <span class="p">(</span> +</span><span id="DataFrame.dropDuplicates-572"><a href="#DataFrame.dropDuplicates-572"><span class="linenos">572</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-573"><a href="#DataFrame.dropDuplicates-573"><span class="linenos">573</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-574"><a href="#DataFrame.dropDuplicates-574"><span class="linenos">574</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-575"><a href="#DataFrame.dropDuplicates-575"><span class="linenos">575</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-576"><a href="#DataFrame.dropDuplicates-576"><span class="linenos">576</span></a> <span class="p">)</span> </span></pre></div> @@ -2194,38 +2170,38 @@ is unlikely to come up.</p> </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.dropna-578"><a href="#DataFrame.dropna-578"><span class="linenos">578</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-579"><a href="#DataFrame.dropna-579"><span class="linenos">579</span></a> <span class="k">def</span> <span class="nf">dropna</span><span class="p">(</span> +</span><span id="DataFrame.dropna-580"><a href="#DataFrame.dropna-580"><span class="linenos">580</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame.dropna-581"><a href="#DataFrame.dropna-581"><span class="linenos">581</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-582"><a href="#DataFrame.dropna-582"><span class="linenos">582</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-583"><a href="#DataFrame.dropna-583"><span class="linenos">583</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-584"><a href="#DataFrame.dropna-584"><span class="linenos">584</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.dropna-585"><a href="#DataFrame.dropna-585"><span class="linenos">585</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-586"><a href="#DataFrame.dropna-586"><span class="linenos">586</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-587"><a href="#DataFrame.dropna-587"><span class="linenos">587</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-588"><a href="#DataFrame.dropna-588"><span class="linenos">588</span></a> <span class="k">if</span> <span class="n">subset</span><span class="p">:</span> +</span><span id="DataFrame.dropna-589"><a href="#DataFrame.dropna-589"><span class="linenos">589</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-590"><a href="#DataFrame.dropna-590"><span class="linenos">590</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.dropna-591"><a href="#DataFrame.dropna-591"><span class="linenos">591</span></a> <span class="n">null_check_columns</span> <span class="o">=</span> <span class="n">all_columns</span> +</span><span id="DataFrame.dropna-592"><a href="#DataFrame.dropna-592"><span class="linenos">592</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-593"><a href="#DataFrame.dropna-593"><span class="linenos">593</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-594"><a href="#DataFrame.dropna-594"><span class="linenos">594</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.dropna-595"><a href="#DataFrame.dropna-595"><span class="linenos">595</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-596"><a href="#DataFrame.dropna-596"><span class="linenos">596</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-597"><a href="#DataFrame.dropna-597"><span class="linenos">597</span></a> <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span> +</span><span id="DataFrame.dropna-598"><a href="#DataFrame.dropna-598"><span class="linenos">598</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-599"><a href="#DataFrame.dropna-599"><span class="linenos">599</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-600"><a href="#DataFrame.dropna-600"><span class="linenos">600</span></a> <span class="p">)</span> +</span><span id="DataFrame.dropna-601"><a href="#DataFrame.dropna-601"><span class="linenos">601</span></a> <span class="n">if_null_checks</span> <span class="o">=</span> <span class="p">[</span> +</span><span id="DataFrame.dropna-602"><a href="#DataFrame.dropna-602"><span class="linenos">602</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-603"><a href="#DataFrame.dropna-603"><span class="linenos">603</span></a> <span class="p">]</span> +</span><span id="DataFrame.dropna-604"><a href="#DataFrame.dropna-604"><span class="linenos">604</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-605"><a href="#DataFrame.dropna-605"><span class="linenos">605</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-606"><a href="#DataFrame.dropna-606"><span class="linenos">606</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-607"><a href="#DataFrame.dropna-607"><span class="linenos">607</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-608"><a href="#DataFrame.dropna-608"><span class="linenos">608</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-609"><a href="#DataFrame.dropna-609"><span class="linenos">609</span></a> <span class="k">return</span> <span class="n">final_df</span> </span></pre></div> @@ -2238,55 +2214,55 @@ is unlikely to come up.</p> <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">'140483439601424'</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> + <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">'140512213181888'</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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.fillna-611"><a href="#DataFrame.fillna-611"><span class="linenos">611</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-612"><a href="#DataFrame.fillna-612"><span class="linenos">612</span></a> <span class="k">def</span> <span class="nf">fillna</span><span class="p">(</span> +</span><span id="DataFrame.fillna-613"><a href="#DataFrame.fillna-613"><span class="linenos">613</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame.fillna-614"><a href="#DataFrame.fillna-614"><span class="linenos">614</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-615"><a href="#DataFrame.fillna-615"><span class="linenos">615</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-616"><a href="#DataFrame.fillna-616"><span class="linenos">616</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.fillna-617"><a href="#DataFrame.fillna-617"><span class="linenos">617</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="DataFrame.fillna-618"><a href="#DataFrame.fillna-618"><span class="linenos">618</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-619"><a href="#DataFrame.fillna-619"><span class="linenos">619</span></a><span class="sd"> with the type of the column then PySpark will just ignore your replacement.</span> +</span><span id="DataFrame.fillna-620"><a href="#DataFrame.fillna-620"><span class="linenos">620</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-621"><a href="#DataFrame.fillna-621"><span class="linenos">621</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-622"><a href="#DataFrame.fillna-622"><span class="linenos">622</span></a> +</span><span id="DataFrame.fillna-623"><a href="#DataFrame.fillna-623"><span class="linenos">623</span></a><span class="sd"> Possibility for improvement: Use `typeof` function to get the type of the column</span> +</span><span id="DataFrame.fillna-624"><a href="#DataFrame.fillna-624"><span class="linenos">624</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-625"><a href="#DataFrame.fillna-625"><span class="linenos">625</span></a><span class="sd"> """</span> +</span><span id="DataFrame.fillna-626"><a href="#DataFrame.fillna-626"><span class="linenos">626</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-627"><a href="#DataFrame.fillna-627"><span class="linenos">627</span></a> +</span><span id="DataFrame.fillna-628"><a href="#DataFrame.fillna-628"><span class="linenos">628</span></a> <span class="n">values</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="DataFrame.fillna-629"><a href="#DataFrame.fillna-629"><span class="linenos">629</span></a> <span class="n">columns</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">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-631"><a href="#DataFrame.fillna-631"><span class="linenos">631</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-632"><a href="#DataFrame.fillna-632"><span class="linenos">632</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-633"><a href="#DataFrame.fillna-633"><span class="linenos">633</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-634"><a href="#DataFrame.fillna-634"><span class="linenos">634</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-635"><a href="#DataFrame.fillna-635"><span class="linenos">635</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-636"><a href="#DataFrame.fillna-636"><span class="linenos">636</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-637"><a href="#DataFrame.fillna-637"><span class="linenos">637</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-638"><a href="#DataFrame.fillna-638"><span class="linenos">638</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-639"><a href="#DataFrame.fillna-639"><span class="linenos">639</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-640"><a href="#DataFrame.fillna-640"><span class="linenos">640</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-641"><a href="#DataFrame.fillna-641"><span class="linenos">641</span></a> +</span><span id="DataFrame.fillna-642"><a href="#DataFrame.fillna-642"><span class="linenos">642</span></a> <span class="n">null_replacement_mapping</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="DataFrame.fillna-643"><a href="#DataFrame.fillna-643"><span class="linenos">643</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-644"><a href="#DataFrame.fillna-644"><span class="linenos">644</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-645"><a href="#DataFrame.fillna-645"><span class="linenos">645</span></a> <span class="p">)</span> +</span><span id="DataFrame.fillna-646"><a href="#DataFrame.fillna-646"><span class="linenos">646</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-647"><a href="#DataFrame.fillna-647"><span class="linenos">647</span></a> <span class="p">}</span> +</span><span id="DataFrame.fillna-648"><a href="#DataFrame.fillna-648"><span class="linenos">648</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-649"><a href="#DataFrame.fillna-649"><span class="linenos">649</span></a> <span class="n">null_replacement_columns</span> <span class="o">=</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_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-651"><a href="#DataFrame.fillna-651"><span class="linenos">651</span></a> <span class="p">]</span> +</span><span id="DataFrame.fillna-652"><a href="#DataFrame.fillna-652"><span class="linenos">652</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-653"><a href="#DataFrame.fillna-653"><span class="linenos">653</span></a> <span class="k">return</span> <span class="n">new_df</span> </span></pre></div> @@ -2307,59 +2283,59 @@ and check if it matches the type of the value provided. If not then make it null <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">'140483439717408'</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">'140483439717408'</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> + <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">'140512213212256'</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">'140512213212256'</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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.replace-655"><a href="#DataFrame.replace-655"><span class="linenos">655</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-656"><a href="#DataFrame.replace-656"><span class="linenos">656</span></a> <span class="k">def</span> <span class="nf">replace</span><span class="p">(</span> +</span><span id="DataFrame.replace-657"><a href="#DataFrame.replace-657"><span class="linenos">657</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrame.replace-658"><a href="#DataFrame.replace-658"><span class="linenos">658</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-659"><a href="#DataFrame.replace-659"><span class="linenos">659</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-660"><a href="#DataFrame.replace-660"><span class="linenos">660</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-661"><a href="#DataFrame.replace-661"><span class="linenos">661</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.replace-662"><a href="#DataFrame.replace-662"><span class="linenos">662</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-663"><a href="#DataFrame.replace-663"><span class="linenos">663</span></a> +</span><span id="DataFrame.replace-664"><a href="#DataFrame.replace-664"><span class="linenos">664</span></a> <span class="n">old_values</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="DataFrame.replace-665"><a href="#DataFrame.replace-665"><span class="linenos">665</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-666"><a href="#DataFrame.replace-666"><span class="linenos">666</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-667"><a href="#DataFrame.replace-667"><span class="linenos">667</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-668"><a href="#DataFrame.replace-668"><span class="linenos">668</span></a> +</span><span id="DataFrame.replace-669"><a href="#DataFrame.replace-669"><span class="linenos">669</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-670"><a href="#DataFrame.replace-670"><span class="linenos">670</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-671"><a href="#DataFrame.replace-671"><span class="linenos">671</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-672"><a href="#DataFrame.replace-672"><span class="linenos">672</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-673"><a href="#DataFrame.replace-673"><span class="linenos">673</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-674"><a href="#DataFrame.replace-674"><span class="linenos">674</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-675"><a href="#DataFrame.replace-675"><span class="linenos">675</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-676"><a href="#DataFrame.replace-676"><span class="linenos">676</span></a> <span class="n">value</span> +</span><span id="DataFrame.replace-677"><a href="#DataFrame.replace-677"><span class="linenos">677</span></a> <span class="p">),</span> <span class="s2">"the replacements and values must be the same length"</span> +</span><span id="DataFrame.replace-678"><a href="#DataFrame.replace-678"><span class="linenos">678</span></a> <span class="n">old_values</span> <span class="o">=</span> <span class="n">to_replace</span> +</span><span id="DataFrame.replace-679"><a href="#DataFrame.replace-679"><span class="linenos">679</span></a> <span class="n">new_values</span> <span class="o">=</span> <span class="n">value</span> +</span><span id="DataFrame.replace-680"><a href="#DataFrame.replace-680"><span class="linenos">680</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.replace-681"><a href="#DataFrame.replace-681"><span class="linenos">681</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-682"><a href="#DataFrame.replace-682"><span class="linenos">682</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-683"><a href="#DataFrame.replace-683"><span class="linenos">683</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-684"><a href="#DataFrame.replace-684"><span class="linenos">684</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-685"><a href="#DataFrame.replace-685"><span class="linenos">685</span></a> +</span><span id="DataFrame.replace-686"><a href="#DataFrame.replace-686"><span class="linenos">686</span></a> <span class="n">replacement_mapping</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="DataFrame.replace-687"><a href="#DataFrame.replace-687"><span class="linenos">687</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-688"><a href="#DataFrame.replace-688"><span class="linenos">688</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-689"><a href="#DataFrame.replace-689"><span class="linenos">689</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-690"><a href="#DataFrame.replace-690"><span class="linenos">690</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-691"><a href="#DataFrame.replace-691"><span class="linenos">691</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-692"><a href="#DataFrame.replace-692"><span class="linenos">692</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.replace-693"><a href="#DataFrame.replace-693"><span class="linenos">693</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-694"><a href="#DataFrame.replace-694"><span class="linenos">694</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-695"><a href="#DataFrame.replace-695"><span class="linenos">695</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-696"><a href="#DataFrame.replace-696"><span class="linenos">696</span></a> <span class="p">)</span> +</span><span id="DataFrame.replace-697"><a href="#DataFrame.replace-697"><span class="linenos">697</span></a> +</span><span id="DataFrame.replace-698"><a href="#DataFrame.replace-698"><span class="linenos">698</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-699"><a href="#DataFrame.replace-699"><span class="linenos">699</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-700"><a href="#DataFrame.replace-700"><span class="linenos">700</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-701"><a href="#DataFrame.replace-701"><span class="linenos">701</span></a> <span class="k">return</span> <span class="n">new_df</span> </span></pre></div> @@ -2378,18 +2354,18 @@ and check if it matches the type of the value provided. If not then make it null </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.withColumn-703"><a href="#DataFrame.withColumn-703"><span class="linenos">703</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-704"><a href="#DataFrame.withColumn-704"><span class="linenos">704</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-705"><a href="#DataFrame.withColumn-705"><span class="linenos">705</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-706"><a href="#DataFrame.withColumn-706"><span class="linenos">706</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-707"><a href="#DataFrame.withColumn-707"><span class="linenos">707</span></a> <span class="n">existing_col_index</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="DataFrame.withColumn-708"><a href="#DataFrame.withColumn-708"><span class="linenos">708</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-709"><a href="#DataFrame.withColumn-709"><span class="linenos">709</span></a> <span class="p">)</span> +</span><span id="DataFrame.withColumn-710"><a href="#DataFrame.withColumn-710"><span class="linenos">710</span></a> <span class="k">if</span> <span class="n">existing_col_index</span><span class="p">:</span> +</span><span id="DataFrame.withColumn-711"><a href="#DataFrame.withColumn-711"><span class="linenos">711</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-712"><a href="#DataFrame.withColumn-712"><span class="linenos">712</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-713"><a href="#DataFrame.withColumn-713"><span class="linenos">713</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-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="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> @@ -2408,22 +2384,22 @@ and check if it matches the type of the value provided. If not then make it null </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.withColumnRenamed-716"><a href="#DataFrame.withColumnRenamed-716"><span class="linenos">716</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-717"><a href="#DataFrame.withColumnRenamed-717"><span class="linenos">717</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-718"><a href="#DataFrame.withColumnRenamed-718"><span class="linenos">718</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-719"><a href="#DataFrame.withColumnRenamed-719"><span class="linenos">719</span></a> <span class="n">existing_columns</span> <span class="o">=</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">expression</span> +</span><span id="DataFrame.withColumnRenamed-721"><a href="#DataFrame.withColumnRenamed-721"><span class="linenos">721</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-722"><a href="#DataFrame.withColumnRenamed-722"><span class="linenos">722</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-723"><a href="#DataFrame.withColumnRenamed-723"><span class="linenos">723</span></a> <span class="p">]</span> +</span><span id="DataFrame.withColumnRenamed-724"><a href="#DataFrame.withColumnRenamed-724"><span class="linenos">724</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-725"><a href="#DataFrame.withColumnRenamed-725"><span class="linenos">725</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-726"><a href="#DataFrame.withColumnRenamed-726"><span class="linenos">726</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-727"><a href="#DataFrame.withColumnRenamed-727"><span class="linenos">727</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-728"><a href="#DataFrame.withColumnRenamed-728"><span class="linenos">728</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-729"><a href="#DataFrame.withColumnRenamed-729"><span class="linenos">729</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="DataFrame.withColumnRenamed-730"><a href="#DataFrame.withColumnRenamed-730"><span class="linenos">730</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-731"><a href="#DataFrame.withColumnRenamed-731"><span class="linenos">731</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> @@ -2442,16 +2418,16 @@ and check if it matches the type of the value provided. If not then make it null </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.drop-733"><a href="#DataFrame.drop-733"><span class="linenos">733</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-734"><a href="#DataFrame.drop-734"><span class="linenos">734</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-735"><a href="#DataFrame.drop-735"><span class="linenos">735</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-736"><a href="#DataFrame.drop-736"><span class="linenos">736</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-737"><a href="#DataFrame.drop-737"><span class="linenos">737</span></a> <span class="n">new_columns</span> <span class="o">=</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">col</span> +</span><span id="DataFrame.drop-739"><a href="#DataFrame.drop-739"><span class="linenos">739</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-740"><a href="#DataFrame.drop-740"><span class="linenos">740</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-741"><a href="#DataFrame.drop-741"><span class="linenos">741</span></a> <span class="p">]</span> +</span><span id="DataFrame.drop-742"><a href="#DataFrame.drop-742"><span class="linenos">742</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> @@ -2470,9 +2446,9 @@ and check if it matches the type of the value provided. If not then make it null </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.limit-744"><a href="#DataFrame.limit-744"><span class="linenos">744</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-745"><a href="#DataFrame.limit-745"><span class="linenos">745</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-746"><a href="#DataFrame.limit-746"><span class="linenos">746</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> @@ -2491,15 +2467,15 @@ and check if it matches the type of the value provided. If not then make it null </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.hint-748"><a href="#DataFrame.hint-748"><span class="linenos">748</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-749"><a href="#DataFrame.hint-749"><span class="linenos">749</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-750"><a href="#DataFrame.hint-750"><span class="linenos">750</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-751"><a href="#DataFrame.hint-751"><span class="linenos">751</span></a> <span class="n">parameter_columns</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="DataFrame.hint-752"><a href="#DataFrame.hint-752"><span class="linenos">752</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-753"><a href="#DataFrame.hint-753"><span class="linenos">753</span></a> <span class="k">if</span> <span class="n">parameters</span> +</span><span id="DataFrame.hint-754"><a href="#DataFrame.hint-754"><span class="linenos">754</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-755"><a href="#DataFrame.hint-755"><span class="linenos">755</span></a> <span class="p">)</span> +</span><span id="DataFrame.hint-756"><a href="#DataFrame.hint-756"><span class="linenos">756</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> @@ -2512,20 +2488,20 @@ and check if it matches the type of the value provided. If not then make it null <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">'140483439886592'</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">'140483439948896'</span><span class="o">></span></span><span class="return-annotation">) -> <span class="n"><a href="#DataFrame">sqlglot.dataframe.sql.DataFrame</a></span>:</span></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">'140512211332416'</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">'140512211476032'</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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.repartition-758"><a href="#DataFrame.repartition-758"><span class="linenos">758</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-759"><a href="#DataFrame.repartition-759"><span class="linenos">759</span></a> <span class="k">def</span> <span class="nf">repartition</span><span class="p">(</span> +</span><span id="DataFrame.repartition-760"><a href="#DataFrame.repartition-760"><span class="linenos">760</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-761"><a href="#DataFrame.repartition-761"><span class="linenos">761</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrame.repartition-762"><a href="#DataFrame.repartition-762"><span class="linenos">762</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-763"><a href="#DataFrame.repartition-763"><span class="linenos">763</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-764"><a href="#DataFrame.repartition-764"><span class="linenos">764</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-765"><a href="#DataFrame.repartition-765"><span class="linenos">765</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> @@ -2544,10 +2520,10 @@ and check if it matches the type of the value provided. If not then make it null </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.coalesce-767"><a href="#DataFrame.coalesce-767"><span class="linenos">767</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-768"><a href="#DataFrame.coalesce-768"><span class="linenos">768</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-769"><a href="#DataFrame.coalesce-769"><span class="linenos">769</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-770"><a href="#DataFrame.coalesce-770"><span class="linenos">770</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> @@ -2566,9 +2542,9 @@ and check if it matches the type of the value provided. If not then make it null </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.cache-772"><a href="#DataFrame.cache-772"><span class="linenos">772</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-773"><a href="#DataFrame.cache-773"><span class="linenos">773</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-774"><a href="#DataFrame.cache-774"><span class="linenos">774</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> @@ -2587,12 +2563,12 @@ and check if it matches the type of the value provided. If not then make it null </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrame.persist-776"><a href="#DataFrame.persist-776"><span class="linenos">776</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-777"><a href="#DataFrame.persist-777"><span class="linenos">777</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-778"><a href="#DataFrame.persist-778"><span class="linenos">778</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="DataFrame.persist-779"><a href="#DataFrame.persist-779"><span class="linenos">779</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-780"><a href="#DataFrame.persist-780"><span class="linenos">780</span></a><span class="sd"> """</span> +</span><span id="DataFrame.persist-781"><a href="#DataFrame.persist-781"><span class="linenos">781</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> @@ -3180,7 +3156,7 @@ and check if it matches the type of the value provided. If not then make it null <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">'140483439967056'</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> + <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">'140512213723520'</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> @@ -3208,7 +3184,7 @@ and check if it matches the type of the value provided. If not then make it null <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">'140483440277968'</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> + <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">'140512211539456'</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> @@ -3229,7 +3205,7 @@ and check if it matches the type of the value provided. If not then make it null <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">'140483438527104'</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> + <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">'140512211530224'</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> @@ -3250,7 +3226,7 @@ and check if it matches the type of the value provided. If not then make it null <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">'140483438591760'</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">'140483438648176'</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> + <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">'140512211656352'</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">'140512211702864'</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> @@ -3277,7 +3253,7 @@ and check if it matches the type of the value provided. If not then make it null <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">'140483438730096'</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> + <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">'140512211833936'</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> @@ -3314,7 +3290,7 @@ and check if it matches the type of the value provided. If not then make it null <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">'140483438706640'</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> + <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">'140512211366576'</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> @@ -3335,7 +3311,7 @@ and check if it matches the type of the value provided. If not then make it null <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">'140483438814656'</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> + <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">'140512211984032'</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> @@ -3845,7 +3821,7 @@ Sqlglot doesn't currently replicate this class so it only accepts a string</p> <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">'140483438973072'</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">'140483438973072'</span><span class="o">></span><span class="p">]]</span></span><span class="return-annotation">):</span></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">'140512212096848'</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">'140512212096848'</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> @@ -3866,7 +3842,7 @@ Sqlglot doesn't currently replicate this class so it only accepts a string</p> <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">'140483439030096'</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">'140483439074304'</span><span class="o">></span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></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">'140512212218784'</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">'140512212292832'</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> @@ -3901,7 +3877,7 @@ Sqlglot doesn't currently replicate this class so it only accepts a string</p> <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">'140483439149984'</span><span class="o">></span></span><span class="return-annotation">) -> <span class="n"><a href="#Column">sqlglot.dataframe.sql.Column</a></span>:</span></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">'140512212334048'</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> @@ -3929,32 +3905,32 @@ Sqlglot doesn't currently replicate this class so it only accepts a string</p> </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameNaFunctions-784"><a href="#DataFrameNaFunctions-784"><span class="linenos">784</span></a><span class="k">class</span> <span class="nc">DataFrameNaFunctions</span><span class="p">:</span> +</span><span id="DataFrameNaFunctions-785"><a href="#DataFrameNaFunctions-785"><span class="linenos">785</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-786"><a href="#DataFrameNaFunctions-786"><span class="linenos">786</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-787"><a href="#DataFrameNaFunctions-787"><span class="linenos">787</span></a> +</span><span id="DataFrameNaFunctions-788"><a href="#DataFrameNaFunctions-788"><span class="linenos">788</span></a> <span class="k">def</span> <span class="nf">drop</span><span class="p">(</span> +</span><span id="DataFrameNaFunctions-789"><a href="#DataFrameNaFunctions-789"><span class="linenos">789</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions-790"><a href="#DataFrameNaFunctions-790"><span class="linenos">790</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-791"><a href="#DataFrameNaFunctions-791"><span class="linenos">791</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-792"><a href="#DataFrameNaFunctions-792"><span class="linenos">792</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-793"><a href="#DataFrameNaFunctions-793"><span class="linenos">793</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrameNaFunctions-794"><a href="#DataFrameNaFunctions-794"><span class="linenos">794</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-795"><a href="#DataFrameNaFunctions-795"><span class="linenos">795</span></a> +</span><span id="DataFrameNaFunctions-796"><a href="#DataFrameNaFunctions-796"><span class="linenos">796</span></a> <span class="k">def</span> <span class="nf">fill</span><span class="p">(</span> +</span><span id="DataFrameNaFunctions-797"><a href="#DataFrameNaFunctions-797"><span class="linenos">797</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions-798"><a href="#DataFrameNaFunctions-798"><span class="linenos">798</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-799"><a href="#DataFrameNaFunctions-799"><span class="linenos">799</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-800"><a href="#DataFrameNaFunctions-800"><span class="linenos">800</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrameNaFunctions-801"><a href="#DataFrameNaFunctions-801"><span class="linenos">801</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-802"><a href="#DataFrameNaFunctions-802"><span class="linenos">802</span></a> +</span><span id="DataFrameNaFunctions-803"><a href="#DataFrameNaFunctions-803"><span class="linenos">803</span></a> <span class="k">def</span> <span class="nf">replace</span><span class="p">(</span> +</span><span id="DataFrameNaFunctions-804"><a href="#DataFrameNaFunctions-804"><span class="linenos">804</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions-805"><a href="#DataFrameNaFunctions-805"><span class="linenos">805</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-806"><a href="#DataFrameNaFunctions-806"><span class="linenos">806</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-807"><a href="#DataFrameNaFunctions-807"><span class="linenos">807</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-808"><a href="#DataFrameNaFunctions-808"><span class="linenos">808</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrameNaFunctions-809"><a href="#DataFrameNaFunctions-809"><span class="linenos">809</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> @@ -3970,8 +3946,8 @@ Sqlglot doesn't currently replicate this class so it only accepts a string</p> </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameNaFunctions.__init__-785"><a href="#DataFrameNaFunctions.__init__-785"><span class="linenos">785</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__-786"><a href="#DataFrameNaFunctions.__init__-786"><span class="linenos">786</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> @@ -3989,13 +3965,13 @@ Sqlglot doesn't currently replicate this class so it only accepts a string</p> </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameNaFunctions.drop-788"><a href="#DataFrameNaFunctions.drop-788"><span class="linenos">788</span></a> <span class="k">def</span> <span class="nf">drop</span><span class="p">(</span> +</span><span id="DataFrameNaFunctions.drop-789"><a href="#DataFrameNaFunctions.drop-789"><span class="linenos">789</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions.drop-790"><a href="#DataFrameNaFunctions.drop-790"><span class="linenos">790</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-791"><a href="#DataFrameNaFunctions.drop-791"><span class="linenos">791</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-792"><a href="#DataFrameNaFunctions.drop-792"><span class="linenos">792</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-793"><a href="#DataFrameNaFunctions.drop-793"><span class="linenos">793</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrameNaFunctions.drop-794"><a href="#DataFrameNaFunctions.drop-794"><span class="linenos">794</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> @@ -4013,12 +3989,12 @@ Sqlglot doesn't currently replicate this class so it only accepts a string</p> </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameNaFunctions.fill-796"><a href="#DataFrameNaFunctions.fill-796"><span class="linenos">796</span></a> <span class="k">def</span> <span class="nf">fill</span><span class="p">(</span> +</span><span id="DataFrameNaFunctions.fill-797"><a href="#DataFrameNaFunctions.fill-797"><span class="linenos">797</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions.fill-798"><a href="#DataFrameNaFunctions.fill-798"><span class="linenos">798</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-799"><a href="#DataFrameNaFunctions.fill-799"><span class="linenos">799</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-800"><a href="#DataFrameNaFunctions.fill-800"><span class="linenos">800</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrameNaFunctions.fill-801"><a href="#DataFrameNaFunctions.fill-801"><span class="linenos">801</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> @@ -4036,13 +4012,13 @@ Sqlglot doesn't currently replicate this class so it only accepts a string</p> </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> + <div class="pdoc-code codehilite"><pre><span></span><span id="DataFrameNaFunctions.replace-803"><a href="#DataFrameNaFunctions.replace-803"><span class="linenos">803</span></a> <span class="k">def</span> <span class="nf">replace</span><span class="p">(</span> +</span><span id="DataFrameNaFunctions.replace-804"><a href="#DataFrameNaFunctions.replace-804"><span class="linenos">804</span></a> <span class="bp">self</span><span class="p">,</span> +</span><span id="DataFrameNaFunctions.replace-805"><a href="#DataFrameNaFunctions.replace-805"><span class="linenos">805</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-806"><a href="#DataFrameNaFunctions.replace-806"><span class="linenos">806</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-807"><a href="#DataFrameNaFunctions.replace-807"><span class="linenos">807</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-808"><a href="#DataFrameNaFunctions.replace-808"><span class="linenos">808</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">DataFrame</span><span class="p">:</span> +</span><span id="DataFrameNaFunctions.replace-809"><a href="#DataFrameNaFunctions.replace-809"><span class="linenos">809</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> @@ -4093,25 +4069,13 @@ Sqlglot doesn't currently replicate this class so it only accepts a string</p> - <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">'140483439288784'</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">'140483439288784'</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> + <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">'140512209413808'</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">'140512209413808'</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> @@ -4132,7 +4096,7 @@ Sqlglot doesn't currently replicate this class so it only accepts a string</p> <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">'140483439363408'</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">'140483439363408'</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> + <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">'140512209283600'</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">'140512209283600'</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> @@ -4357,7 +4321,7 @@ Sqlglot doesn't currently replicate this class so it only accepts a string</p> <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">'140483437616032'</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">'140483437616032'</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> + <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">'140512209559296'</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">'140512209559296'</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> @@ -4384,7 +4348,7 @@ Sqlglot doesn't currently replicate this class so it only accepts a string</p> <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">'140483438173232'</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">'140483438173232'</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> + <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">'140512209618832'</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">'140512209618832'</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> @@ -4889,7 +4853,7 @@ Sqlglot doesn't currently replicate this class so it only accepts a string</p> if (doc.annotation) heading += `<span class="annotation">${doc.annotation}</span>`; if (doc.default_value) - heading += `<span class="default_value">${doc.default_value}</span>`; + heading += `<span class="default_value"> = ${doc.default_value}</span>`; break; default: heading = `<span class="name">${doc.fullname}</span>`; |