|
149 | 149 | "floor", |
150 | 150 | "from_unixtime", |
151 | 151 | "gcd", |
| 152 | + "greatest", |
| 153 | + "ifnull", |
152 | 154 | "in_list", |
153 | 155 | "initcap", |
154 | 156 | "isnan", |
|
157 | 159 | "last_value", |
158 | 160 | "lcm", |
159 | 161 | "lead", |
| 162 | + "least", |
160 | 163 | "left", |
161 | 164 | "length", |
162 | 165 | "levenshtein", |
|
212 | 215 | "ntile", |
213 | 216 | "nullif", |
214 | 217 | "nvl", |
| 218 | + "nvl2", |
215 | 219 | "octet_length", |
216 | 220 | "order_by", |
217 | 221 | "overlay", |
@@ -1027,6 +1031,44 @@ def gcd(x: Expr, y: Expr) -> Expr: |
1027 | 1031 | return Expr(f.gcd(x.expr, y.expr)) |
1028 | 1032 |
|
1029 | 1033 |
|
| 1034 | +def greatest(*args: Expr) -> Expr: |
| 1035 | + """Returns the greatest value from a list of expressions. |
| 1036 | +
|
| 1037 | + Returns NULL if all expressions are NULL. |
| 1038 | +
|
| 1039 | + Examples: |
| 1040 | + >>> ctx = dfn.SessionContext() |
| 1041 | + >>> df = ctx.from_pydict({"a": [1, 3], "b": [2, 1]}) |
| 1042 | + >>> result = df.select( |
| 1043 | + ... dfn.functions.greatest(dfn.col("a"), dfn.col("b")).alias("greatest")) |
| 1044 | + >>> result.collect_column("greatest")[0].as_py() |
| 1045 | + 2 |
| 1046 | + >>> result.collect_column("greatest")[1].as_py() |
| 1047 | + 3 |
| 1048 | + """ |
| 1049 | + args = [arg.expr for arg in args] |
| 1050 | + return Expr(f.greatest(*args)) |
| 1051 | + |
| 1052 | + |
| 1053 | +def ifnull(x: Expr, y: Expr) -> Expr: |
| 1054 | + """Returns ``x`` if ``x`` is not NULL. Otherwise returns ``y``. |
| 1055 | +
|
| 1056 | + This is an alias for :py:func:`nvl`. |
| 1057 | +
|
| 1058 | + Examples: |
| 1059 | + >>> ctx = dfn.SessionContext() |
| 1060 | + >>> df = ctx.from_pydict({"a": [None, 1], "b": [0, 0]}) |
| 1061 | + >>> result = df.select( |
| 1062 | + ... dfn.functions.ifnull(dfn.col("a"), dfn.col("b")).alias("ifnull") |
| 1063 | + ... ) |
| 1064 | + >>> result.collect_column("ifnull")[0].as_py() |
| 1065 | + 0 |
| 1066 | + >>> result.collect_column("ifnull")[1].as_py() |
| 1067 | + 1 |
| 1068 | + """ |
| 1069 | + return nvl(x, y) |
| 1070 | + |
| 1071 | + |
1030 | 1072 | def initcap(string: Expr) -> Expr: |
1031 | 1073 | """Set the initial letter of each word to capital. |
1032 | 1074 |
|
@@ -1080,6 +1122,25 @@ def lcm(x: Expr, y: Expr) -> Expr: |
1080 | 1122 | return Expr(f.lcm(x.expr, y.expr)) |
1081 | 1123 |
|
1082 | 1124 |
|
| 1125 | +def least(*args: Expr) -> Expr: |
| 1126 | + """Returns the least value from a list of expressions. |
| 1127 | +
|
| 1128 | + Returns NULL if all expressions are NULL. |
| 1129 | +
|
| 1130 | + Examples: |
| 1131 | + >>> ctx = dfn.SessionContext() |
| 1132 | + >>> df = ctx.from_pydict({"a": [1, 3], "b": [2, 1]}) |
| 1133 | + >>> result = df.select( |
| 1134 | + ... dfn.functions.least(dfn.col("a"), dfn.col("b")).alias("least")) |
| 1135 | + >>> result.collect_column("least")[0].as_py() |
| 1136 | + 1 |
| 1137 | + >>> result.collect_column("least")[1].as_py() |
| 1138 | + 1 |
| 1139 | + """ |
| 1140 | + args = [arg.expr for arg in args] |
| 1141 | + return Expr(f.least(*args)) |
| 1142 | + |
| 1143 | + |
1083 | 1144 | def left(string: Expr, n: Expr) -> Expr: |
1084 | 1145 | """Returns the first ``n`` characters in the ``string``. |
1085 | 1146 |
|
@@ -1264,6 +1325,24 @@ def nvl(x: Expr, y: Expr) -> Expr: |
1264 | 1325 | return Expr(f.nvl(x.expr, y.expr)) |
1265 | 1326 |
|
1266 | 1327 |
|
| 1328 | +def nvl2(x: Expr, y: Expr, z: Expr) -> Expr: |
| 1329 | + """Returns ``y`` if ``x`` is not NULL. Otherwise returns ``z``. |
| 1330 | +
|
| 1331 | + Examples: |
| 1332 | + >>> ctx = dfn.SessionContext() |
| 1333 | + >>> df = ctx.from_pydict({"a": [None, 1], "b": [10, 20], "c": [30, 40]}) |
| 1334 | + >>> result = df.select( |
| 1335 | + ... dfn.functions.nvl2( |
| 1336 | + ... dfn.col("a"), dfn.col("b"), dfn.col("c")).alias("nvl2") |
| 1337 | + ... ) |
| 1338 | + >>> result.collect_column("nvl2")[0].as_py() |
| 1339 | + 30 |
| 1340 | + >>> result.collect_column("nvl2")[1].as_py() |
| 1341 | + 20 |
| 1342 | + """ |
| 1343 | + return Expr(f.nvl2(x.expr, y.expr, z.expr)) |
| 1344 | + |
| 1345 | + |
1267 | 1346 | def octet_length(arg: Expr) -> Expr: |
1268 | 1347 | """Returns the number of bytes of a string. |
1269 | 1348 |
|
|
0 commit comments