kevinjqliu commented on code in PR #628: URL: https://github.com/apache/iceberg-rust/pull/628#discussion_r1755222868
########## bindings/python/src/transform.rs: ########## @@ -15,24 +15,55 @@ // specific language governing permissions and limitations // under the License. +use arrow::array::{make_array, Array, ArrayData}; +use arrow::pyarrow::{FromPyArrow, ToPyArrow}; use iceberg::spec::Transform; use iceberg::transform::create_transform_function; +use pyo3::prelude::*; -use arrow::{ - array::{make_array, Array, ArrayData}, -}; -use arrow::pyarrow::{FromPyArrow, ToPyArrow}; -use pyo3::{exceptions::PyValueError, prelude::*}; +use crate::error::to_py_err; + +#[pyfunction] +pub fn identity(py: Python, array: PyObject) -> PyResult<PyObject> { + apply(py, array, Transform::Identity) +} + +#[pyfunction] +pub fn void(py: Python, array: PyObject) -> PyResult<PyObject> { + apply(py, array, Transform::Void) +} + +#[pyfunction] +pub fn year(py: Python, array: PyObject) -> PyResult<PyObject> { + apply(py, array, Transform::Year) +} + +#[pyfunction] +pub fn month(py: Python, array: PyObject) -> PyResult<PyObject> { + apply(py, array, Transform::Month) +} -fn to_py_err(err: iceberg::Error) -> PyErr { - PyValueError::new_err(err.to_string()) +#[pyfunction] +pub fn day(py: Python, array: PyObject) -> PyResult<PyObject> { + apply(py, array, Transform::Day) } -#[pyclass] -pub struct ArrowArrayTransform { +#[pyfunction] +pub fn hour(py: Python, array: PyObject) -> PyResult<PyObject> { + apply(py, array, Transform::Hour) } -fn apply(array: PyObject, transform: Transform, py: Python) -> PyResult<PyObject> { +#[pyfunction] +pub fn bucket(py: Python, array: PyObject, num_buckets: u32) -> PyResult<PyObject> { + apply(py, array, Transform::Bucket(num_buckets)) +} + +#[pyfunction] +pub fn truncate(py: Python, array: PyObject, width: u32) -> PyResult<PyObject> { + apply(py, array, Transform::Truncate(width)) +} + Review Comment: sg! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org