@@ -356,6 +356,15 @@ def bit_get(col: Expr, pos: Expr | str) -> Expr:
356356 return Expr (_f .bit_get (col .expr , _to_raw_expr (pos )))
357357
358358
359+ def getbit (col : Expr , pos : Expr | str ) -> Expr :
360+ """Spark ``getbit``: returns the bit (0 or 1) at ``pos``.
361+
362+ See Also:
363+ This is an alias for :py:func:`bit_get`.
364+ """
365+ return bit_get (col , pos )
366+
367+
359368def bit_count (col : Expr ) -> Expr :
360369 """Spark ``bit_count``: number of bits set in the integer's binary form.
361370
@@ -539,6 +548,15 @@ def date_add(start: Expr, days: Expr | int) -> Expr:
539548 return Expr (_f .date_add (start .expr , _coerce_i32 (days ).expr ))
540549
541550
551+ def dateadd (start : Expr , days : Expr | int ) -> Expr :
552+ """Spark ``dateadd``: date + N days.
553+
554+ See Also:
555+ This is an alias for :py:func:`date_add`.
556+ """
557+ return date_add (start , days )
558+
559+
542560def date_sub (start : Expr , days : Expr | int ) -> Expr :
543561 """Spark ``date_sub``: date - N days.
544562
@@ -627,7 +645,7 @@ def second(col: Expr) -> Expr:
627645 return Expr (_f .second (col .expr ))
628646
629647
630- def last_day (col : Expr ) -> Expr :
648+ def last_day (date : Expr ) -> Expr :
631649 """Spark ``last_day``: last day of the month containing the date.
632650
633651 Examples:
@@ -640,7 +658,7 @@ def last_day(col: Expr) -> Expr:
640658 >>> r.collect_column("v")[0].as_py()
641659 datetime.date(2020, 1, 31)
642660 """
643- return Expr (_f .last_day (col .expr ))
661+ return Expr (_f .last_day (date .expr ))
644662
645663
646664def make_dt_interval (
@@ -754,6 +772,15 @@ def date_diff(end: Expr, start: Expr) -> Expr:
754772 return Expr (_f .date_diff (end .expr , start .expr ))
755773
756774
775+ def datediff (end : Expr , start : Expr ) -> Expr :
776+ """Spark ``datediff``: number of days from ``start`` to ``end``.
777+
778+ See Also:
779+ This is an alias for :py:func:`date_diff`.
780+ """
781+ return date_diff (end , start )
782+
783+
757784def date_trunc (format : Expr | str , timestamp : Expr ) -> Expr :
758785 """Spark ``date_trunc``: truncate timestamp to unit ``fmt``.
759786
@@ -832,6 +859,15 @@ def date_part(field: Expr | str, source: Expr) -> Expr:
832859 return Expr (_f .date_part (coerce_to_expr (field ).expr , source .expr ))
833860
834861
862+ def datepart (field : Expr | str , source : Expr ) -> Expr :
863+ """Spark ``datepart``: extract ``field`` from a date/time/timestamp.
864+
865+ See Also:
866+ This is an alias for :py:func:`date_part`.
867+ """
868+ return date_part (field , source )
869+
870+
835871def from_utc_timestamp (timestamp : Expr , tz : Expr | str ) -> Expr :
836872 """Spark ``from_utc_timestamp``: interpret ``ts`` as UTC, convert to ``tz``.
837873
@@ -991,6 +1027,15 @@ def sha1(col: Expr) -> Expr:
9911027 return Expr (_f .sha1 (col .expr ))
9921028
9931029
1030+ def sha (col : Expr ) -> Expr :
1031+ """Spark ``sha``: SHA-1 hash as a hex string.
1032+
1033+ See Also:
1034+ This is an alias for :py:func:`sha1`.
1035+ """
1036+ return sha1 (col )
1037+
1038+
9941039def sha2 (col : Expr , numBits : Expr | int ) -> Expr : # noqa: N803
9951040 """Spark ``sha2``: SHA-2 family hash (224, 256, 384, 512). Bit length 0 = 256.
9961041
@@ -1175,6 +1220,15 @@ def ceil(col: Expr) -> Expr:
11751220 return Expr (_f .ceil (col .expr ))
11761221
11771222
1223+ def ceiling (col : Expr ) -> Expr :
1224+ """Spark ``ceiling``: smallest integer ≥ arg.
1225+
1226+ See Also:
1227+ This is an alias for :py:func:`ceil`.
1228+ """
1229+ return ceil (col )
1230+
1231+
11781232def expm1 (col : Expr ) -> Expr :
11791233 """Spark ``expm1``: exp(arg) - 1.
11801234
@@ -1562,6 +1616,24 @@ def length(col: Expr) -> Expr:
15621616 return Expr (_f .length (col .expr ))
15631617
15641618
1619+ def character_length (col : Expr ) -> Expr :
1620+ """Spark ``character_length``: character length of a string, or bytes of binary.
1621+
1622+ See Also:
1623+ This is an alias for :py:func:`length`.
1624+ """
1625+ return length (col )
1626+
1627+
1628+ def char_length (col : Expr ) -> Expr :
1629+ """Spark ``char_length``: character length of a string, or bytes of binary.
1630+
1631+ See Also:
1632+ This is an alias for :py:func:`length`.
1633+ """
1634+ return length (col )
1635+
1636+
15651637def like (
15661638 str : Expr ,
15671639 pattern : Expr | str ,
@@ -1639,6 +1711,15 @@ def format_string(format: str | Expr, *cols: Expr) -> Expr:
16391711 return Expr (_f .format_string (fmt_expr .expr , * [c .expr for c in cols ]))
16401712
16411713
1714+ def printf (format : str | Expr , * cols : Expr ) -> Expr :
1715+ """Spark ``printf``: printf-style format string.
1716+
1717+ See Also:
1718+ This is an alias for :py:func:`format_string`.
1719+ """
1720+ return format_string (format , * cols )
1721+
1722+
16421723def space (col : Expr | int ) -> Expr :
16431724 """Spark ``space``: string of n spaces.
16441725
@@ -1673,6 +1754,28 @@ def substring(str: Expr, pos: Expr | int, len: Expr | int) -> Expr:
16731754 )
16741755
16751756
1757+ def substr (str : Expr , pos : Expr | int , len : Expr | int | None = None ) -> Expr :
1758+ """Spark ``substr``: 1-indexed substring, to the end when ``len`` is omitted.
1759+
1760+ Same as :py:func:`substring` except that ``len`` is optional. ``pos`` and
1761+ ``len`` accept native ``int`` values or :class:`Expr`.
1762+
1763+ Examples:
1764+ >>> ctx = dfn.SessionContext()
1765+ >>> df = ctx.from_pydict({"x": [1]})
1766+ >>> r = df.select(dfn.functions.spark.substr(dfn.lit("hello"), 2).alias("v"))
1767+ >>> r.collect_column("v")[0].as_py()
1768+ 'ello'
1769+
1770+ >>> r = df.select(
1771+ ... dfn.functions.spark.substr(dfn.lit("hello"), 2, len=3).alias("v"))
1772+ >>> r.collect_column("v")[0].as_py()
1773+ 'ell'
1774+ """
1775+ len_raw = coerce_to_expr (len ).expr if len is not None else None
1776+ return Expr (_f .substr (str .expr , coerce_to_expr (pos ).expr , len_raw ))
1777+
1778+
16761779def unbase64 (col : Expr ) -> Expr :
16771780 """Spark ``unbase64``: decode a base64 string to binary.
16781781
@@ -1867,7 +1970,10 @@ def url_encode(str: Expr) -> Expr:
18671970 "bitmap_count" ,
18681971 "bitwise_not" ,
18691972 "ceil" ,
1973+ "ceiling" ,
18701974 "char" ,
1975+ "char_length" ,
1976+ "character_length" ,
18711977 "collect_list" ,
18721978 "collect_set" ,
18731979 "concat" ,
@@ -1880,12 +1986,16 @@ def url_encode(str: Expr) -> Expr:
18801986 "date_part" ,
18811987 "date_sub" ,
18821988 "date_trunc" ,
1989+ "dateadd" ,
1990+ "datediff" ,
1991+ "datepart" ,
18831992 "elt" ,
18841993 "expm1" ,
18851994 "factorial" ,
18861995 "floor" ,
18871996 "format_string" ,
18881997 "from_utc_timestamp" ,
1998+ "getbit" ,
18891999 "hex" ,
18902000 "hour" ,
18912001 "hypot" ,
@@ -1914,11 +2024,13 @@ def url_encode(str: Expr) -> Expr:
19142024 "pmod" ,
19152025 "pow" ,
19162026 "power" ,
2027+ "printf" ,
19172028 "quote" ,
19182029 "rint" ,
19192030 "round" ,
19202031 "sec" ,
19212032 "second" ,
2033+ "sha" ,
19222034 "sha1" ,
19232035 "sha2" ,
19242036 "shiftleft" ,
@@ -1932,6 +2044,7 @@ def url_encode(str: Expr) -> Expr:
19322044 "space" ,
19332045 "spark_cast" ,
19342046 "str_to_map" ,
2047+ "substr" ,
19352048 "substring" ,
19362049 "time_trunc" ,
19372050 "to_utc_timestamp" ,
0 commit comments