Skip to content

Commit 8cf82f0

Browse files
committed
continue
1 parent b61b2fc commit 8cf82f0

File tree

5 files changed

+220
-269
lines changed

5 files changed

+220
-269
lines changed

datafusion/expr/src/built_in_window_function.rs

Lines changed: 1 addition & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -17,115 +17,12 @@
1717

1818
//! Built-in functions module contains all the built-in functions definitions.
1919
20-
use std::fmt;
21-
use std::str::FromStr;
22-
23-
use crate::type_coercion::functions::data_types;
24-
use crate::utils;
25-
use crate::{Signature, Volatility};
26-
use datafusion_common::{plan_datafusion_err, plan_err, DataFusionError, Result};
27-
28-
use arrow::datatypes::DataType;
29-
3020
use strum_macros::EnumIter;
3121

32-
impl fmt::Display for BuiltInWindowFunction {
33-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
34-
write!(f, "{}", self.name())
35-
}
36-
}
37-
3822
/// A [window function] built in to DataFusion
3923
///
4024
/// [Window Function]: https://en.wikipedia.org/wiki/Window_function_(SQL)
4125
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash, EnumIter)]
4226
pub enum BuiltInWindowFunction {
43-
/// returns value evaluated at the row that is the first row of the window frame
44-
FirstValue,
45-
/// Returns value evaluated at the row that is the last row of the window frame
46-
LastValue,
47-
/// Returns value evaluated at the row that is the nth row of the window frame (counting from 1); returns null if no such row
48-
NthValue,
49-
}
50-
51-
impl BuiltInWindowFunction {
52-
pub fn name(&self) -> &str {
53-
use BuiltInWindowFunction::*;
54-
match self {
55-
FirstValue => "first_value",
56-
LastValue => "last_value",
57-
NthValue => "NTH_VALUE",
58-
}
59-
}
60-
}
61-
62-
impl FromStr for BuiltInWindowFunction {
63-
type Err = DataFusionError;
64-
fn from_str(name: &str) -> Result<BuiltInWindowFunction> {
65-
Ok(match name.to_uppercase().as_str() {
66-
"FIRST_VALUE" => BuiltInWindowFunction::FirstValue,
67-
"LAST_VALUE" => BuiltInWindowFunction::LastValue,
68-
"NTH_VALUE" => BuiltInWindowFunction::NthValue,
69-
_ => return plan_err!("There is no built-in window function named {name}"),
70-
})
71-
}
72-
}
73-
74-
/// Returns the datatype of the built-in window function
75-
impl BuiltInWindowFunction {
76-
pub fn return_type(&self, input_expr_types: &[DataType]) -> Result<DataType> {
77-
// Note that this function *must* return the same type that the respective physical expression returns
78-
// or the execution panics.
79-
80-
// Verify that this is a valid set of data types for this function
81-
data_types(input_expr_types, &self.signature())
82-
// Original errors are all related to wrong function signature
83-
// Aggregate them for better error message
84-
.map_err(|_| {
85-
plan_datafusion_err!(
86-
"{}",
87-
utils::generate_signature_error_msg(
88-
&format!("{self}"),
89-
self.signature(),
90-
input_expr_types,
91-
)
92-
)
93-
})?;
94-
95-
match self {
96-
BuiltInWindowFunction::FirstValue
97-
| BuiltInWindowFunction::LastValue
98-
| BuiltInWindowFunction::NthValue => Ok(input_expr_types[0].clone()),
99-
}
100-
}
101-
102-
/// The signatures supported by the built-in window function `fun`.
103-
pub fn signature(&self) -> Signature {
104-
// Note: The physical expression must accept the type returned by this function or the execution panics.
105-
match self {
106-
BuiltInWindowFunction::FirstValue | BuiltInWindowFunction::LastValue => {
107-
Signature::any(1, Volatility::Immutable)
108-
}
109-
BuiltInWindowFunction::NthValue => Signature::any(2, Volatility::Immutable),
110-
}
111-
}
112-
}
113-
114-
#[cfg(test)]
115-
mod tests {
116-
use super::*;
117-
use strum::IntoEnumIterator;
118-
#[test]
119-
// Test for BuiltInWindowFunction's Display and from_str() implementations.
120-
// For each variant in BuiltInWindowFunction, it converts the variant to a string
121-
// and then back to a variant. The test asserts that the original variant and
122-
// the reconstructed variant are the same. This assertion is also necessary for
123-
// function suggestion. See https://github.com/apache/datafusion/issues/8082
124-
fn test_display_and_from_str() {
125-
for func_original in BuiltInWindowFunction::iter() {
126-
let func_name = func_original.to_string();
127-
let func_from_str = BuiltInWindowFunction::from_str(&func_name).unwrap();
128-
assert_eq!(func_from_str, func_original);
129-
}
130-
}
27+
Stub,
13128
}

datafusion/functions-window/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
//!
2323
//! [DataFusion]: https://crates.io/crates/datafusion
2424
//!
25+
26+
extern crate core;
27+
2528
use std::sync::Arc;
2629

2730
use log::debug;

0 commit comments

Comments
 (0)