jcsherin commented on code in PR #13201: URL: https://github.com/apache/datafusion/pull/13201#discussion_r1829236883
########## datafusion/functions-window/src/nth_value.rs: ########## @@ -15,143 +15,254 @@ // specific language governing permissions and limitations // under the License. -//! Defines physical expressions for `FIRST_VALUE`, `LAST_VALUE`, and `NTH_VALUE` -//! functions that can be evaluated at run time during query execution. +//! `nth_value` window function implementation + +use crate::utils::{get_scalar_value_from_args, get_signed_integer}; use std::any::Any; use std::cmp::Ordering; +use std::fmt::Debug; use std::ops::Range; -use std::sync::Arc; - -use crate::window::window_expr::{NthValueKind, NthValueState}; -use crate::window::BuiltInWindowFunctionExpr; -use crate::PhysicalExpr; +use std::sync::OnceLock; -use arrow::array::{Array, ArrayRef}; -use arrow::datatypes::{DataType, Field}; -use datafusion_common::Result; -use datafusion_common::ScalarValue; +use datafusion_common::arrow::array::ArrayRef; +use datafusion_common::arrow::datatypes::{DataType, Field}; +use datafusion_common::{exec_err, Result, ScalarValue}; +use datafusion_expr::window_doc_sections::DOC_SECTION_ANALYTICAL; use datafusion_expr::window_state::WindowAggState; -use datafusion_expr::PartitionEvaluator; +use datafusion_expr::{ + Documentation, PartitionEvaluator, ReversedUDWF, Signature, TypeSignature, + Volatility, WindowUDFImpl, +}; +use datafusion_functions_window_common::field; +use datafusion_functions_window_common::partition::PartitionEvaluatorArgs; +use field::WindowUDFFieldArgs; + +define_udwf_and_expr!( + First, + first_value, + "returns the first value in the window frame", + NthValue::first +); +define_udwf_and_expr!( + Last, + last_value, + "returns the last value in the window frame", + NthValue::last +); +define_udwf_and_expr!( + NthValue, + nth_value, + "returns the nth value in the window frame", + NthValue::nth +); Review Comment: Once you have a working `nth_value` expression API please add a roundtrip logical plan test here: https://github.com/apache/datafusion/blob/ac79ef3442e65f6197c7234da9fad964895b9101/datafusion/proto/tests/cases/roundtrip_logical_plan.rs#L943-L945 -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org