Skip to content

Commit 9a4af41

Browse files
timsaucerclaude
andcommitted
refactor: rename MultiColumnWindowUDF -> PythonFunctionWindowUDF
The "multi-column" name was a relic of an earlier upstream limitation where `SimpleWindowUDF` only accepted a single input column. With the struct now also storing the Python evaluator factory directly for pickle support, the relevant distinction is no longer column count but "Python-defined". Rename to match `PythonFunctionScalarUDF` and `PythonFunctionAggregateUDF` for a consistent naming convention across all three Python UDF kinds. Also tighten visibility from `pub` to `pub(crate)`. No external consumer; the struct only needs to be reachable from `PyWindowUDF` and the codec. No functional change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b99d973 commit 9a4af41

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

crates/core/src/codec.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ use pyo3::types::{PyBytes, PyTuple};
9797

9898
use crate::udaf::PythonFunctionAggregateUDF;
9999
use crate::udf::PythonFunctionScalarUDF;
100-
use crate::udwf::MultiColumnWindowUDF;
100+
use crate::udwf::PythonFunctionWindowUDF;
101101

102102
/// Wire-format prefix that tags a `fun_definition` payload as an
103103
/// inlined Python scalar UDF (cloudpickled tuple of name, callable,
@@ -518,7 +518,11 @@ fn schema_from_ipc_bytes(bytes: &[u8]) -> arrow::error::Result<Schema> {
518518
// =============================================================================
519519

520520
pub(crate) fn try_encode_python_window_udf(node: &WindowUDF, buf: &mut Vec<u8>) -> Result<bool> {
521-
let Some(py_udf) = node.inner().as_any().downcast_ref::<MultiColumnWindowUDF>() else {
521+
let Some(py_udf) = node
522+
.inner()
523+
.as_any()
524+
.downcast_ref::<PythonFunctionWindowUDF>()
525+
else {
522526
return Ok(false);
523527
};
524528

@@ -544,15 +548,15 @@ pub(crate) fn try_decode_python_window_udf(buf: &[u8]) -> Result<Option<Arc<Wind
544548
})
545549
}
546550

547-
fn encode_python_window_udf(py: Python<'_>, udf: &MultiColumnWindowUDF) -> PyResult<Vec<u8>> {
551+
fn encode_python_window_udf(py: Python<'_>, udf: &PythonFunctionWindowUDF) -> PyResult<Vec<u8>> {
548552
let cloudpickle = py.import("cloudpickle")?;
549553

550554
let signature = WindowUDFImpl::signature(udf);
551555
let input_dtypes: Vec<arrow::datatypes::DataType> = match &signature.type_signature {
552556
TypeSignature::Exact(types) => types.clone(),
553557
other => {
554558
return Err(pyo3::exceptions::PyValueError::new_err(format!(
555-
"MultiColumnWindowUDF expected Signature::Exact, got {other:?}"
559+
"PythonFunctionWindowUDF expected Signature::Exact, got {other:?}"
556560
)));
557561
}
558562
};
@@ -586,7 +590,7 @@ fn encode_python_window_udf(py: Python<'_>, udf: &MultiColumnWindowUDF) -> PyRes
586590
blob.extract::<Vec<u8>>()
587591
}
588592

589-
fn decode_python_window_udf(py: Python<'_>, payload: &[u8]) -> PyResult<MultiColumnWindowUDF> {
593+
fn decode_python_window_udf(py: Python<'_>, payload: &[u8]) -> PyResult<PythonFunctionWindowUDF> {
590594
let cloudpickle = py.import("cloudpickle")?;
591595

592596
let tuple = cloudpickle
@@ -614,7 +618,7 @@ fn decode_python_window_udf(py: Python<'_>, payload: &[u8]) -> PyResult<MultiCol
614618
.first()
615619
.ok_or_else(|| {
616620
pyo3::exceptions::PyValueError::new_err(
617-
"MultiColumnWindowUDF return schema must contain exactly one field",
621+
"PythonFunctionWindowUDF return schema must contain exactly one field",
618622
)
619623
})?
620624
.data_type()
@@ -623,7 +627,7 @@ fn decode_python_window_udf(py: Python<'_>, payload: &[u8]) -> PyResult<MultiCol
623627
let volatility = datafusion_python_util::parse_volatility(&volatility_str)
624628
.map_err(|e| pyo3::exceptions::PyValueError::new_err(format!("{e}")))?;
625629

626-
Ok(MultiColumnWindowUDF::from_parts(
630+
Ok(PythonFunctionWindowUDF::from_parts(
627631
name,
628632
evaluator,
629633
input_types,

crates/core/src/udwf.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl PyWindowUDF {
233233
let return_type = return_type.0;
234234
let input_types: Vec<DataType> = input_types.into_iter().map(|t| t.0).collect();
235235

236-
let function = WindowUDF::from(MultiColumnWindowUDF::new(
236+
let function = WindowUDF::from(PythonFunctionWindowUDF::new(
237237
name,
238238
evaluator,
239239
input_types,
@@ -276,15 +276,15 @@ impl PyWindowUDF {
276276
}
277277

278278
#[derive(Debug)]
279-
pub struct MultiColumnWindowUDF {
279+
pub(crate) struct PythonFunctionWindowUDF {
280280
name: String,
281281
evaluator: Py<PyAny>,
282282
signature: Signature,
283283
return_type: DataType,
284284
}
285285

286-
impl MultiColumnWindowUDF {
287-
pub fn new(
286+
impl PythonFunctionWindowUDF {
287+
pub(crate) fn new(
288288
name: impl Into<String>,
289289
evaluator: Py<PyAny>,
290290
input_types: Vec<DataType>,
@@ -323,8 +323,8 @@ impl MultiColumnWindowUDF {
323323
}
324324
}
325325

326-
impl Eq for MultiColumnWindowUDF {}
327-
impl PartialEq for MultiColumnWindowUDF {
326+
impl Eq for PythonFunctionWindowUDF {}
327+
impl PartialEq for PythonFunctionWindowUDF {
328328
fn eq(&self, other: &Self) -> bool {
329329
self.name == other.name
330330
&& self.signature == other.signature
@@ -338,7 +338,7 @@ impl PartialEq for MultiColumnWindowUDF {
338338
}
339339
}
340340

341-
impl std::hash::Hash for MultiColumnWindowUDF {
341+
impl std::hash::Hash for PythonFunctionWindowUDF {
342342
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
343343
self.name.hash(state);
344344
self.signature.hash(state);
@@ -350,7 +350,7 @@ impl std::hash::Hash for MultiColumnWindowUDF {
350350
}
351351
}
352352

353-
impl WindowUDFImpl for MultiColumnWindowUDF {
353+
impl WindowUDFImpl for PythonFunctionWindowUDF {
354354
fn as_any(&self) -> &dyn Any {
355355
self
356356
}

0 commit comments

Comments
 (0)