viirya commented on code in PR #193: URL: https://github.com/apache/arrow-datafusion-python/pull/193#discussion_r1111275998
########## src/expr/limit.rs: ########## @@ -0,0 +1,99 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use datafusion_expr::logical_plan::Limit; +use pyo3::prelude::*; +use std::fmt::{self, Display, Formatter}; + +use crate::common::df_schema::PyDFSchema; +use crate::errors::py_runtime_err; +use crate::expr::logical_node::LogicalNode; +use crate::sql::logical::PyLogicalPlan; + +#[pyclass(name = "Limit", module = "datafusion.expr", subclass)] +#[derive(Clone)] +pub struct PyLimit { + limit: Limit, +} + +impl From<Limit> for PyLimit { + fn from(limit: Limit) -> PyLimit { + PyLimit { limit } + } +} + +impl From<PyLimit> for Limit { + fn from(limit: PyLimit) -> Self { + limit.limit + } +} + +impl Display for PyLimit { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + write!( + f, + "Limit + \nSkip: {} + \nFetch: {:?} + \nInput: {:?}", + &self.limit.skip, &self.limit.fetch, &self.limit.input + ) + } +} + +#[pymethods] +impl PyLimit { + /// Retrieves the skip value for this `Limit` + fn skip(&self) -> usize { + self.limit.skip + } + + /// Retrieves the fetch value for this `Limit` + fn fetch(&self) -> Option<usize> { + self.limit.fetch + } + + // Retrieves the input `LogicalPlan` to this `Limit` node + fn input(&self) -> PyResult<PyLogicalPlan> { + // DataFusion make a loose guarantee that each Limit should have an input, however Review Comment: Hmm, is `Limit` different to other op e.g., `Sort`? I.e., https://github.com/apache/arrow-datafusion-python/pull/196, it is simply `PyLogicalPlan::from((*self.sort.input).clone())`. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
