This is an automated email from the ASF dual-hosted git repository.

agrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion-python.git


The following commit(s) were added to refs/heads/master by this push:
     new 940eec8  [Functions] - Add python function binding to `functions` (#73)
940eec8 is described below

commit 940eec853b7faa0f30774b13f179eecedf005d0c
Author: Francis Du <[email protected]>
AuthorDate: Sat Dec 31 12:36:33 2022 +0800

    [Functions] - Add python function binding to `functions` (#73)
---
 src/functions.rs | 73 ++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 50 insertions(+), 23 deletions(-)

diff --git a/src/functions.rs b/src/functions.rs
index d7b1b9e..5a0a20d 100644
--- a/src/functions.rs
+++ b/src/functions.rs
@@ -23,13 +23,6 @@ use datafusion_expr::{lit, BuiltinScalarFunction};
 use crate::errors;
 use crate::expression::PyExpr;
 
-#[pyfunction]
-fn array(value: Vec<PyExpr>) -> PyExpr {
-    PyExpr {
-        expr: datafusion_expr::array(value.into_iter().map(|x| 
x.expr).collect::<Vec<_>>()),
-    }
-}
-
 #[pyfunction]
 fn in_list(expr: PyExpr, value: Vec<PyExpr>, negated: bool) -> PyExpr {
     datafusion_expr::in_list(
@@ -40,22 +33,6 @@ fn in_list(expr: PyExpr, value: Vec<PyExpr>, negated: bool) 
-> PyExpr {
     .into()
 }
 
-/// Current date and time
-#[pyfunction]
-fn now() -> PyExpr {
-    PyExpr {
-        expr: datafusion_expr::now(),
-    }
-}
-
-/// Returns a random value in the range 0.0 <= x < 1.0
-#[pyfunction]
-fn random() -> PyExpr {
-    PyExpr {
-        expr: datafusion_expr::random(),
-    }
-}
-
 /// Computes a binary hash of the given data. type is the algorithm to use.
 /// Standard algorithms are md5, sha224, sha256, sha384, sha512, blake2s, 
blake2b, and blake3.
 #[pyfunction(value, method)]
@@ -136,6 +113,7 @@ macro_rules! scalar_function {
     ($NAME: ident, $FUNC: ident) => {
         scalar_function!($NAME, $FUNC, stringify!($NAME));
     };
+
     ($NAME: ident, $FUNC: ident, $DOC: expr) => {
         #[doc = $DOC]
         #[pyfunction(args = "*")]
@@ -173,6 +151,7 @@ scalar_function!(acos, Acos);
 scalar_function!(ascii, Ascii, "Returns the numeric code of the first 
character of the argument. In UTF8 encoding, returns the Unicode code point of 
the character. In other multibyte encodings, the argument must be an ASCII 
character.");
 scalar_function!(asin, Asin);
 scalar_function!(atan, Atan);
+scalar_function!(atan2, Atan2);
 scalar_function!(
     bit_length,
     BitLength,
@@ -185,13 +164,17 @@ scalar_function!(
     CharacterLength,
     "Returns number of characters in the string."
 );
+scalar_function!(length, CharacterLength);
+scalar_function!(char_length, CharacterLength);
 scalar_function!(chr, Chr, "Returns the character with the given code.");
+scalar_function!(coalesce, Coalesce);
 scalar_function!(cos, Cos);
 scalar_function!(exp, Exp);
 scalar_function!(floor, Floor);
 scalar_function!(initcap, InitCap, "Converts the first letter of each word to 
upper case and the rest to lower case. Words are sequences of alphanumeric 
characters separated by non-alphanumeric characters.");
 scalar_function!(left, Left, "Returns first n characters in the string, or 
when n is negative, returns all but last |n| characters.");
 scalar_function!(ln, Ln);
+scalar_function!(log, Log);
 scalar_function!(log10, Log10);
 scalar_function!(log2, Log2);
 scalar_function!(lower, Lower, "Converts the string to all lower case");
@@ -203,6 +186,8 @@ scalar_function!(
     "Computes the MD5 hash of the argument, with the result written in 
hexadecimal."
 );
 scalar_function!(octet_length, OctetLength, "Returns number of bytes in the 
string. Since this version of the function accepts type character directly, it 
will not strip trailing spaces.");
+scalar_function!(power, Power);
+scalar_function!(pow, Power);
 scalar_function!(regexp_match, RegexpMatch);
 scalar_function!(
     regexp_replace,
@@ -253,11 +238,30 @@ scalar_function!(
     ToHex,
     "Converts the number to its equivalent hexadecimal representation."
 );
+scalar_function!(now, Now);
 scalar_function!(to_timestamp, ToTimestamp);
+scalar_function!(to_timestamp_millis, ToTimestampMillis);
+scalar_function!(to_timestamp_micros, ToTimestampMicros);
+scalar_function!(to_timestamp_seconds, ToTimestampSeconds);
+scalar_function!(current_date, CurrentDate);
+scalar_function!(current_time, CurrentTime);
+scalar_function!(datepart, DatePart);
+scalar_function!(date_part, DatePart);
+scalar_function!(date_trunc, DateTrunc);
+scalar_function!(datetrunc, DateTrunc);
+scalar_function!(date_bin, DateBin);
 scalar_function!(translate, Translate, "Replaces each character in string that 
matches a character in the from set with the corresponding character in the to 
set. If from is longer than to, occurrences of the extra characters in from are 
deleted.");
 scalar_function!(trim, Trim, "Removes the longest string containing only 
characters in characters (a space by default) from the start, end, or both ends 
(BOTH is the default) of string.");
 scalar_function!(trunc, Trunc);
 scalar_function!(upper, Upper, "Converts the string to all upper case.");
+scalar_function!(make_array, MakeArray);
+scalar_function!(array, MakeArray);
+scalar_function!(nullif, NullIf);
+//scalar_function!(uuid, Uuid);
+//scalar_function!(struct, Struct);
+scalar_function!(from_unixtime, FromUnixtime);
+scalar_function!(arrow_typeof, ArrowTypeof);
+scalar_function!(random, Random);
 
 aggregate_function!(avg, Avg);
 aggregate_function!(count, Count);
@@ -272,37 +276,55 @@ pub(crate) fn init_module(m: &PyModule) -> PyResult<()> {
     m.add_wrapped(wrap_pyfunction!(approx_distinct))?;
     m.add_wrapped(wrap_pyfunction!(alias))?;
     m.add_wrapped(wrap_pyfunction!(array))?;
+    m.add_wrapped(wrap_pyfunction!(arrow_typeof))?;
     m.add_wrapped(wrap_pyfunction!(ascii))?;
     m.add_wrapped(wrap_pyfunction!(asin))?;
     m.add_wrapped(wrap_pyfunction!(atan))?;
+    m.add_wrapped(wrap_pyfunction!(atan2))?;
     m.add_wrapped(wrap_pyfunction!(avg))?;
     m.add_wrapped(wrap_pyfunction!(bit_length))?;
     m.add_wrapped(wrap_pyfunction!(btrim))?;
     m.add_wrapped(wrap_pyfunction!(ceil))?;
     m.add_wrapped(wrap_pyfunction!(character_length))?;
     m.add_wrapped(wrap_pyfunction!(chr))?;
+    m.add_wrapped(wrap_pyfunction!(char_length))?;
+    m.add_wrapped(wrap_pyfunction!(coalesce))?;
     m.add_wrapped(wrap_pyfunction!(concat_ws))?;
     m.add_wrapped(wrap_pyfunction!(concat))?;
     m.add_wrapped(wrap_pyfunction!(cos))?;
     m.add_wrapped(wrap_pyfunction!(count))?;
+    m.add_wrapped(wrap_pyfunction!(current_date))?;
+    m.add_wrapped(wrap_pyfunction!(current_time))?;
+    m.add_wrapped(wrap_pyfunction!(date_bin))?;
+    m.add_wrapped(wrap_pyfunction!(datepart))?;
+    m.add_wrapped(wrap_pyfunction!(date_part))?;
+    m.add_wrapped(wrap_pyfunction!(datetrunc))?;
+    m.add_wrapped(wrap_pyfunction!(date_trunc))?;
     m.add_wrapped(wrap_pyfunction!(digest))?;
     m.add_wrapped(wrap_pyfunction!(exp))?;
     m.add_wrapped(wrap_pyfunction!(floor))?;
+    m.add_wrapped(wrap_pyfunction!(from_unixtime))?;
     m.add_wrapped(wrap_pyfunction!(in_list))?;
     m.add_wrapped(wrap_pyfunction!(initcap))?;
     m.add_wrapped(wrap_pyfunction!(left))?;
+    m.add_wrapped(wrap_pyfunction!(length))?;
     m.add_wrapped(wrap_pyfunction!(ln))?;
+    m.add_wrapped(wrap_pyfunction!(log))?;
     m.add_wrapped(wrap_pyfunction!(log10))?;
     m.add_wrapped(wrap_pyfunction!(log2))?;
     m.add_wrapped(wrap_pyfunction!(lower))?;
     m.add_wrapped(wrap_pyfunction!(lpad))?;
     m.add_wrapped(wrap_pyfunction!(ltrim))?;
     m.add_wrapped(wrap_pyfunction!(max))?;
+    m.add_wrapped(wrap_pyfunction!(make_array))?;
     m.add_wrapped(wrap_pyfunction!(md5))?;
     m.add_wrapped(wrap_pyfunction!(min))?;
     m.add_wrapped(wrap_pyfunction!(now))?;
+    m.add_wrapped(wrap_pyfunction!(nullif))?;
     m.add_wrapped(wrap_pyfunction!(octet_length))?;
     m.add_wrapped(wrap_pyfunction!(order_by))?;
+    m.add_wrapped(wrap_pyfunction!(power))?;
+    m.add_wrapped(wrap_pyfunction!(pow))?;
     m.add_wrapped(wrap_pyfunction!(random))?;
     m.add_wrapped(wrap_pyfunction!(regexp_match))?;
     m.add_wrapped(wrap_pyfunction!(regexp_replace))?;
@@ -323,15 +345,20 @@ pub(crate) fn init_module(m: &PyModule) -> PyResult<()> {
     m.add_wrapped(wrap_pyfunction!(sqrt))?;
     m.add_wrapped(wrap_pyfunction!(starts_with))?;
     m.add_wrapped(wrap_pyfunction!(strpos))?;
+    //m.add_wrapped(wrap_pyfunction!(struct))?;
     m.add_wrapped(wrap_pyfunction!(substr))?;
     m.add_wrapped(wrap_pyfunction!(sum))?;
     m.add_wrapped(wrap_pyfunction!(tan))?;
     m.add_wrapped(wrap_pyfunction!(to_hex))?;
     m.add_wrapped(wrap_pyfunction!(to_timestamp))?;
+    m.add_wrapped(wrap_pyfunction!(to_timestamp_millis))?;
+    m.add_wrapped(wrap_pyfunction!(to_timestamp_micros))?;
+    m.add_wrapped(wrap_pyfunction!(to_timestamp_seconds))?;
     m.add_wrapped(wrap_pyfunction!(translate))?;
     m.add_wrapped(wrap_pyfunction!(trim))?;
     m.add_wrapped(wrap_pyfunction!(trunc))?;
     m.add_wrapped(wrap_pyfunction!(upper))?;
+    //m.add_wrapped(wrap_pyfunction!(uuid))?;
     m.add_wrapped(wrap_pyfunction!(window))?;
     Ok(())
 }

Reply via email to