1use crate::expr::{
8 AggregateFunction, BinaryExpr, Cast, Exists, GroupingSet, InList, InSubquery, Lambda,
9 LambdaVariable, NullTreatment, Placeholder, TryCast, Unnest, WildcardOptions,
10 WindowFunction,
11};
12use crate::function::{
13 AccumulatorArgs, AccumulatorFactoryFunction, PartitionEvaluatorFactory,
14 StateFieldsArgs,
15};
16use crate::ptr_eq::PtrEq;
17use crate::select_expr::SelectExpr;
18use crate::{
19 AggregateUDF, Expr, LimitEffect, LogicalPlan, Operator, PartitionEvaluator,
20 ScalarFunctionArgs, ScalarFunctionImplementation, ScalarUDF, Signature, Volatility,
21 conditional_expressions::CaseBuilder, expr::Sort, logical_plan::Subquery,
22};
23use crate::{
24 AggregateUDFImpl, ColumnarValue, ScalarUDFImpl, WindowFrame, WindowUDF, WindowUDFImpl,
25};
26use arrow::compute::kernels::cast_utils::{
27 parse_interval_day_time, parse_interval_month_day_nano, parse_interval_year_month,
28};
29use arrow::datatypes::{DataType, Field, FieldRef};
30use datafusion_common::{Column, Result, ScalarValue, Spans, TableReference, plan_err};
31use datafusion_functions_window_common::field::WindowUDFFieldArgs;
32use datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
33use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
34use std::collections::HashMap;
35use std::fmt::Debug;
36use std::hash::Hash;
37use std::ops::Not;
38use std::sync::Arc;
39
40pub fn col(ident: impl Into<Column>) -> Expr {
56 Expr::Column(ident.into())
57}
58
59pub fn out_ref_col(dt: DataType, ident: impl Into<Column>) -> Expr {
64 out_ref_col_with_metadata(dt, HashMap::new(), ident)
65}
66
67pub fn out_ref_col_with_metadata(
69 dt: DataType,
70 metadata: HashMap<String, String>,
71 ident: impl Into<Column>,
72) -> Expr {
73 let column = ident.into();
74 let field: FieldRef =
75 Arc::new(Field::new(column.name(), dt, true).with_metadata(metadata));
76 Expr::OuterReferenceColumn(field, column)
77}
78
79pub fn ident(name: impl Into<String>) -> Expr {
98 Expr::Column(Column::from_name(name))
99}
100
101pub fn placeholder(id: impl Into<String>) -> Expr {
113 Expr::Placeholder(Placeholder {
114 id: id.into(),
115 field: None,
116 })
117}
118
119pub fn wildcard() -> SelectExpr {
129 SelectExpr::Wildcard(WildcardOptions::default())
130}
131
132pub fn wildcard_with_options(options: WildcardOptions) -> SelectExpr {
134 SelectExpr::Wildcard(options)
135}
136
137pub fn qualified_wildcard(qualifier: impl Into<TableReference>) -> SelectExpr {
148 SelectExpr::QualifiedWildcard(qualifier.into(), WildcardOptions::default())
149}
150
151pub fn qualified_wildcard_with_options(
153 qualifier: impl Into<TableReference>,
154 options: WildcardOptions,
155) -> SelectExpr {
156 SelectExpr::QualifiedWildcard(qualifier.into(), options)
157}
158
159pub fn binary_expr(left: Expr, op: Operator, right: Expr) -> Expr {
161 Expr::BinaryExpr(BinaryExpr::new(Box::new(left), op, Box::new(right)))
162}
163
164pub fn and(left: Expr, right: Expr) -> Expr {
166 Expr::BinaryExpr(BinaryExpr::new(
167 Box::new(left),
168 Operator::And,
169 Box::new(right),
170 ))
171}
172
173pub fn or(left: Expr, right: Expr) -> Expr {
175 Expr::BinaryExpr(BinaryExpr::new(
176 Box::new(left),
177 Operator::Or,
178 Box::new(right),
179 ))
180}
181
182pub fn not(expr: Expr) -> Expr {
184 expr.not()
185}
186
187pub fn bitwise_and(left: Expr, right: Expr) -> Expr {
189 Expr::BinaryExpr(BinaryExpr::new(
190 Box::new(left),
191 Operator::BitwiseAnd,
192 Box::new(right),
193 ))
194}
195
196pub fn bitwise_or(left: Expr, right: Expr) -> Expr {
198 Expr::BinaryExpr(BinaryExpr::new(
199 Box::new(left),
200 Operator::BitwiseOr,
201 Box::new(right),
202 ))
203}
204
205pub fn bitwise_xor(left: Expr, right: Expr) -> Expr {
207 Expr::BinaryExpr(BinaryExpr::new(
208 Box::new(left),
209 Operator::BitwiseXor,
210 Box::new(right),
211 ))
212}
213
214pub fn bitwise_shift_right(left: Expr, right: Expr) -> Expr {
216 Expr::BinaryExpr(BinaryExpr::new(
217 Box::new(left),
218 Operator::BitwiseShiftRight,
219 Box::new(right),
220 ))
221}
222
223pub fn bitwise_shift_left(left: Expr, right: Expr) -> Expr {
225 Expr::BinaryExpr(BinaryExpr::new(
226 Box::new(left),
227 Operator::BitwiseShiftLeft,
228 Box::new(right),
229 ))
230}
231
232pub fn in_list(expr: Expr, list: Vec<Expr>, negated: bool) -> Expr {
234 Expr::InList(InList::new(Box::new(expr), list, negated))
235}
236
237pub fn exists(subquery: Arc<LogicalPlan>) -> Expr {
239 let outer_ref_columns = subquery.all_out_ref_exprs();
240 Expr::Exists(Exists {
241 subquery: Subquery {
242 subquery,
243 outer_ref_columns,
244 spans: Spans::new(),
245 },
246 negated: false,
247 })
248}
249
250pub fn not_exists(subquery: Arc<LogicalPlan>) -> Expr {
252 let outer_ref_columns = subquery.all_out_ref_exprs();
253 Expr::Exists(Exists {
254 subquery: Subquery {
255 subquery,
256 outer_ref_columns,
257 spans: Spans::new(),
258 },
259 negated: true,
260 })
261}
262
263pub fn in_subquery(expr: Expr, subquery: Arc<LogicalPlan>) -> Expr {
265 let outer_ref_columns = subquery.all_out_ref_exprs();
266 Expr::InSubquery(InSubquery::new(
267 Box::new(expr),
268 Subquery {
269 subquery,
270 outer_ref_columns,
271 spans: Spans::new(),
272 },
273 false,
274 ))
275}
276
277pub fn not_in_subquery(expr: Expr, subquery: Arc<LogicalPlan>) -> Expr {
279 let outer_ref_columns = subquery.all_out_ref_exprs();
280 Expr::InSubquery(InSubquery::new(
281 Box::new(expr),
282 Subquery {
283 subquery,
284 outer_ref_columns,
285 spans: Spans::new(),
286 },
287 true,
288 ))
289}
290
291pub fn scalar_subquery(subquery: Arc<LogicalPlan>) -> Expr {
293 let outer_ref_columns = subquery.all_out_ref_exprs();
294 Expr::ScalarSubquery(Subquery {
295 subquery,
296 outer_ref_columns,
297 spans: Spans::new(),
298 })
299}
300
301pub fn grouping_set(exprs: Vec<Vec<Expr>>) -> Expr {
303 Expr::GroupingSet(GroupingSet::GroupingSets(exprs))
304}
305
306pub fn cube(exprs: Vec<Expr>) -> Expr {
308 Expr::GroupingSet(GroupingSet::Cube(exprs))
309}
310
311pub fn rollup(exprs: Vec<Expr>) -> Expr {
313 Expr::GroupingSet(GroupingSet::Rollup(exprs))
314}
315
316pub fn cast(expr: Expr, data_type: DataType) -> Expr {
318 Expr::Cast(Cast::new(Box::new(expr), data_type))
319}
320
321pub fn try_cast(expr: Expr, data_type: DataType) -> Expr {
323 Expr::TryCast(TryCast::new(Box::new(expr), data_type))
324}
325
326pub fn is_null(expr: Expr) -> Expr {
328 Expr::IsNull(Box::new(expr))
329}
330
331pub fn is_not_null(expr: Expr) -> Expr {
333 Expr::IsNotNull(Box::new(expr))
334}
335
336pub fn is_true(expr: Expr) -> Expr {
338 Expr::IsTrue(Box::new(expr))
339}
340
341pub fn is_not_true(expr: Expr) -> Expr {
343 Expr::IsNotTrue(Box::new(expr))
344}
345
346pub fn is_false(expr: Expr) -> Expr {
348 Expr::IsFalse(Box::new(expr))
349}
350
351pub fn is_not_false(expr: Expr) -> Expr {
353 Expr::IsNotFalse(Box::new(expr))
354}
355
356pub fn is_unknown(expr: Expr) -> Expr {
358 Expr::IsUnknown(Box::new(expr))
359}
360
361pub fn is_not_unknown(expr: Expr) -> Expr {
363 Expr::IsNotUnknown(Box::new(expr))
364}
365
366pub fn case(expr: Expr) -> CaseBuilder {
368 CaseBuilder::new(Some(Box::new(expr)), vec![], vec![], None)
369}
370
371pub fn when(when: Expr, then: Expr) -> CaseBuilder {
373 CaseBuilder::new(None, vec![when], vec![then], None)
374}
375
376pub fn unnest(expr: Expr) -> Expr {
378 Expr::Unnest(Unnest {
379 expr: Box::new(expr),
380 outer: false,
381 })
382}
383
384pub fn create_udf(
397 name: &str,
398 input_types: Vec<DataType>,
399 return_type: DataType,
400 volatility: Volatility,
401 fun: ScalarFunctionImplementation,
402) -> ScalarUDF {
403 ScalarUDF::from(SimpleScalarUDF::new(
404 name,
405 input_types,
406 return_type,
407 volatility,
408 fun,
409 ))
410}
411
412#[derive(PartialEq, Eq, Hash)]
415pub struct SimpleScalarUDF {
416 name: String,
417 signature: Signature,
418 return_type: DataType,
419 fun: PtrEq<ScalarFunctionImplementation>,
420}
421
422impl Debug for SimpleScalarUDF {
423 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
424 f.debug_struct("SimpleScalarUDF")
425 .field("name", &self.name)
426 .field("signature", &self.signature)
427 .field("return_type", &self.return_type)
428 .field("fun", &"<FUNC>")
429 .finish()
430 }
431}
432
433impl SimpleScalarUDF {
434 pub fn new(
437 name: impl Into<String>,
438 input_types: Vec<DataType>,
439 return_type: DataType,
440 volatility: Volatility,
441 fun: ScalarFunctionImplementation,
442 ) -> Self {
443 Self::new_with_signature(
444 name,
445 Signature::exact(input_types, volatility),
446 return_type,
447 fun,
448 )
449 }
450
451 pub fn new_with_signature(
454 name: impl Into<String>,
455 signature: Signature,
456 return_type: DataType,
457 fun: ScalarFunctionImplementation,
458 ) -> Self {
459 Self {
460 name: name.into(),
461 signature,
462 return_type,
463 fun: fun.into(),
464 }
465 }
466}
467
468impl ScalarUDFImpl for SimpleScalarUDF {
469 fn name(&self) -> &str {
470 &self.name
471 }
472
473 fn signature(&self) -> &Signature {
474 &self.signature
475 }
476
477 fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
478 Ok(self.return_type.clone())
479 }
480
481 fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
482 (self.fun)(&args.args)
483 }
484}
485
486pub fn create_udaf(
489 name: &str,
490 input_type: Vec<DataType>,
491 return_type: Arc<DataType>,
492 volatility: Volatility,
493 accumulator: AccumulatorFactoryFunction,
494 state_type: Arc<Vec<DataType>>,
495) -> AggregateUDF {
496 let return_type = Arc::unwrap_or_clone(return_type);
497 let state_type = Arc::unwrap_or_clone(state_type);
498 let state_fields = state_type
499 .into_iter()
500 .enumerate()
501 .map(|(i, t)| Field::new(format!("{i}"), t, true))
502 .map(Arc::new)
503 .collect::<Vec<_>>();
504 AggregateUDF::from(SimpleAggregateUDF::new(
505 name,
506 input_type,
507 return_type,
508 volatility,
509 accumulator,
510 state_fields,
511 ))
512}
513
514#[derive(PartialEq, Eq, Hash)]
517pub struct SimpleAggregateUDF {
518 name: String,
519 signature: Signature,
520 return_type: DataType,
521 accumulator: PtrEq<AccumulatorFactoryFunction>,
522 state_fields: Vec<FieldRef>,
523}
524
525impl Debug for SimpleAggregateUDF {
526 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
527 f.debug_struct("SimpleAggregateUDF")
528 .field("name", &self.name)
529 .field("signature", &self.signature)
530 .field("return_type", &self.return_type)
531 .field("fun", &"<FUNC>")
532 .finish()
533 }
534}
535
536impl SimpleAggregateUDF {
537 pub fn new(
540 name: impl Into<String>,
541 input_type: Vec<DataType>,
542 return_type: DataType,
543 volatility: Volatility,
544 accumulator: AccumulatorFactoryFunction,
545 state_fields: Vec<FieldRef>,
546 ) -> Self {
547 let name = name.into();
548 let signature = Signature::exact(input_type, volatility);
549 Self {
550 name,
551 signature,
552 return_type,
553 accumulator: accumulator.into(),
554 state_fields,
555 }
556 }
557
558 pub fn new_with_signature(
561 name: impl Into<String>,
562 signature: Signature,
563 return_type: DataType,
564 accumulator: AccumulatorFactoryFunction,
565 state_fields: Vec<FieldRef>,
566 ) -> Self {
567 let name = name.into();
568 Self {
569 name,
570 signature,
571 return_type,
572 accumulator: accumulator.into(),
573 state_fields,
574 }
575 }
576}
577
578impl AggregateUDFImpl for SimpleAggregateUDF {
579 fn name(&self) -> &str {
580 &self.name
581 }
582
583 fn signature(&self) -> &Signature {
584 &self.signature
585 }
586
587 fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
588 Ok(self.return_type.clone())
589 }
590
591 fn accumulator(
592 &self,
593 acc_args: AccumulatorArgs,
594 ) -> Result<Box<dyn crate::Accumulator>> {
595 (self.accumulator)(acc_args)
596 }
597
598 fn state_fields(&self, _args: StateFieldsArgs) -> Result<Vec<FieldRef>> {
599 Ok(self.state_fields.clone())
600 }
601}
602
603pub fn create_udwf(
609 name: &str,
610 input_type: DataType,
611 return_type: Arc<DataType>,
612 volatility: Volatility,
613 partition_evaluator_factory: PartitionEvaluatorFactory,
614) -> WindowUDF {
615 let return_type = Arc::unwrap_or_clone(return_type);
616 WindowUDF::from(SimpleWindowUDF::new(
617 name,
618 input_type,
619 return_type,
620 volatility,
621 partition_evaluator_factory,
622 ))
623}
624
625#[derive(PartialEq, Eq, Hash)]
628pub struct SimpleWindowUDF {
629 name: String,
630 signature: Signature,
631 return_type: DataType,
632 partition_evaluator_factory: PtrEq<PartitionEvaluatorFactory>,
633}
634
635impl Debug for SimpleWindowUDF {
636 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
637 f.debug_struct("WindowUDF")
638 .field("name", &self.name)
639 .field("signature", &self.signature)
640 .field("return_type", &"<func>")
641 .field("partition_evaluator_factory", &"<FUNC>")
642 .finish()
643 }
644}
645
646impl SimpleWindowUDF {
647 pub fn new(
650 name: impl Into<String>,
651 input_type: DataType,
652 return_type: DataType,
653 volatility: Volatility,
654 partition_evaluator_factory: PartitionEvaluatorFactory,
655 ) -> Self {
656 let name = name.into();
657 let signature = Signature::exact([input_type].to_vec(), volatility);
658 Self {
659 name,
660 signature,
661 return_type,
662 partition_evaluator_factory: partition_evaluator_factory.into(),
663 }
664 }
665}
666
667impl WindowUDFImpl for SimpleWindowUDF {
668 fn name(&self) -> &str {
669 &self.name
670 }
671
672 fn signature(&self) -> &Signature {
673 &self.signature
674 }
675
676 fn partition_evaluator(
677 &self,
678 _partition_evaluator_args: PartitionEvaluatorArgs,
679 ) -> Result<Box<dyn PartitionEvaluator>> {
680 (self.partition_evaluator_factory)()
681 }
682
683 fn field(&self, field_args: WindowUDFFieldArgs) -> Result<FieldRef> {
684 Ok(Arc::new(Field::new(
685 field_args.name(),
686 self.return_type.clone(),
687 true,
688 )))
689 }
690
691 fn limit_effect(&self, _args: &[Arc<dyn PhysicalExpr>]) -> LimitEffect {
692 LimitEffect::Unknown
693 }
694}
695
696pub fn interval_year_month_lit(value: &str) -> Expr {
697 let interval = parse_interval_year_month(value).ok();
698 Expr::Literal(ScalarValue::IntervalYearMonth(interval), None)
699}
700
701pub fn interval_datetime_lit(value: &str) -> Expr {
702 let interval = parse_interval_day_time(value).ok();
703 Expr::Literal(ScalarValue::IntervalDayTime(interval), None)
704}
705
706pub fn interval_month_day_nano_lit(value: &str) -> Expr {
707 let interval = parse_interval_month_day_nano(value).ok();
708 Expr::Literal(ScalarValue::IntervalMonthDayNano(interval), None)
709}
710
711pub fn lambda(params: impl IntoIterator<Item = impl Into<String>>, body: Expr) -> Expr {
713 Expr::Lambda(Lambda::new(
714 params.into_iter().map(Into::into).collect(),
715 body,
716 ))
717}
718
719pub fn lambda_var(name: impl Into<String>) -> Expr {
727 Expr::LambdaVariable(LambdaVariable::new(name.into(), None))
728}
729
730pub trait ExprFunctionExt {
772 fn order_by(self, order_by: Vec<Sort>) -> ExprFuncBuilder;
774 fn filter(self, filter: Expr) -> ExprFuncBuilder;
776 fn distinct(self) -> ExprFuncBuilder;
778 fn null_treatment(
780 self,
781 null_treatment: impl Into<Option<NullTreatment>>,
782 ) -> ExprFuncBuilder;
783 fn partition_by(self, partition_by: Vec<Expr>) -> ExprFuncBuilder;
785 fn window_frame(self, window_frame: WindowFrame) -> ExprFuncBuilder;
787}
788
789#[derive(Debug, Clone)]
790pub enum ExprFuncKind {
791 Aggregate(AggregateFunction),
792 Window(Box<WindowFunction>),
793}
794
795#[derive(Debug, Clone)]
799pub struct ExprFuncBuilder {
800 fun: Option<ExprFuncKind>,
801 order_by: Option<Vec<Sort>>,
802 filter: Option<Expr>,
803 distinct: bool,
804 null_treatment: Option<NullTreatment>,
805 partition_by: Option<Vec<Expr>>,
806 window_frame: Option<WindowFrame>,
807}
808
809impl ExprFuncBuilder {
810 fn new(fun: Option<ExprFuncKind>) -> Self {
812 Self {
813 fun,
814 order_by: None,
815 filter: None,
816 distinct: false,
817 null_treatment: None,
818 partition_by: None,
819 window_frame: None,
820 }
821 }
822
823 pub fn build(self) -> Result<Expr> {
830 let Self {
831 fun,
832 order_by,
833 filter,
834 distinct,
835 null_treatment,
836 partition_by,
837 window_frame,
838 } = self;
839
840 let Some(fun) = fun else {
841 return plan_err!(
842 "ExprFunctionExt can only be used with Expr::AggregateFunction or Expr::WindowFunction"
843 );
844 };
845
846 let fun_expr = match fun {
847 ExprFuncKind::Aggregate(mut udaf) => {
848 udaf.params.order_by = order_by.unwrap_or_default();
849 udaf.params.filter = filter.map(Box::new);
850 udaf.params.distinct = distinct;
851 udaf.params.null_treatment = null_treatment;
852 Expr::AggregateFunction(udaf)
853 }
854 ExprFuncKind::Window(mut udwf) => {
855 let has_order_by = order_by.as_ref().map(|o| !o.is_empty());
856 udwf.params.partition_by = partition_by.unwrap_or_default();
857 udwf.params.order_by = order_by.unwrap_or_default();
858 udwf.params.window_frame =
859 window_frame.unwrap_or_else(|| WindowFrame::new(has_order_by));
860 udwf.params.filter = filter.map(Box::new);
861 udwf.params.null_treatment = null_treatment;
862 udwf.params.distinct = distinct;
863 Expr::WindowFunction(udwf)
864 }
865 };
866
867 Ok(fun_expr)
868 }
869}
870
871impl ExprFunctionExt for ExprFuncBuilder {
872 fn order_by(mut self, order_by: Vec<Sort>) -> ExprFuncBuilder {
874 self.order_by = Some(order_by);
875 self
876 }
877
878 fn filter(mut self, filter: Expr) -> ExprFuncBuilder {
880 self.filter = Some(filter);
881 self
882 }
883
884 fn distinct(mut self) -> ExprFuncBuilder {
886 self.distinct = true;
887 self
888 }
889
890 fn null_treatment(
892 mut self,
893 null_treatment: impl Into<Option<NullTreatment>>,
894 ) -> ExprFuncBuilder {
895 self.null_treatment = null_treatment.into();
896 self
897 }
898
899 fn partition_by(mut self, partition_by: Vec<Expr>) -> ExprFuncBuilder {
900 self.partition_by = Some(partition_by);
901 self
902 }
903
904 fn window_frame(mut self, window_frame: WindowFrame) -> ExprFuncBuilder {
905 self.window_frame = Some(window_frame);
906 self
907 }
908}
909
910impl ExprFunctionExt for Expr {
911 fn order_by(self, order_by: Vec<Sort>) -> ExprFuncBuilder {
912 let mut builder = match self {
913 Expr::AggregateFunction(udaf) => {
914 ExprFuncBuilder::new(Some(ExprFuncKind::Aggregate(udaf)))
915 }
916 Expr::WindowFunction(udwf) => {
917 ExprFuncBuilder::new(Some(ExprFuncKind::Window(udwf)))
918 }
919 _ => ExprFuncBuilder::new(None),
920 };
921 if builder.fun.is_some() {
922 builder.order_by = Some(order_by);
923 }
924 builder
925 }
926 fn filter(self, filter: Expr) -> ExprFuncBuilder {
927 match self {
928 Expr::AggregateFunction(udaf) => {
929 let mut builder =
930 ExprFuncBuilder::new(Some(ExprFuncKind::Aggregate(udaf)));
931 builder.filter = Some(filter);
932 builder
933 }
934 _ => ExprFuncBuilder::new(None),
935 }
936 }
937 fn distinct(self) -> ExprFuncBuilder {
938 match self {
939 Expr::AggregateFunction(udaf) => {
940 let mut builder =
941 ExprFuncBuilder::new(Some(ExprFuncKind::Aggregate(udaf)));
942 builder.distinct = true;
943 builder
944 }
945 _ => ExprFuncBuilder::new(None),
946 }
947 }
948 fn null_treatment(
949 self,
950 null_treatment: impl Into<Option<NullTreatment>>,
951 ) -> ExprFuncBuilder {
952 let mut builder = match self {
953 Expr::AggregateFunction(udaf) => {
954 ExprFuncBuilder::new(Some(ExprFuncKind::Aggregate(udaf)))
955 }
956 Expr::WindowFunction(udwf) => {
957 ExprFuncBuilder::new(Some(ExprFuncKind::Window(udwf)))
958 }
959 _ => ExprFuncBuilder::new(None),
960 };
961 if builder.fun.is_some() {
962 builder.null_treatment = null_treatment.into();
963 }
964 builder
965 }
966
967 fn partition_by(self, partition_by: Vec<Expr>) -> ExprFuncBuilder {
968 match self {
969 Expr::WindowFunction(udwf) => {
970 let mut builder = ExprFuncBuilder::new(Some(ExprFuncKind::Window(udwf)));
971 builder.partition_by = Some(partition_by);
972 builder
973 }
974 _ => ExprFuncBuilder::new(None),
975 }
976 }
977
978 fn window_frame(self, window_frame: WindowFrame) -> ExprFuncBuilder {
979 match self {
980 Expr::WindowFunction(udwf) => {
981 let mut builder = ExprFuncBuilder::new(Some(ExprFuncKind::Window(udwf)));
982 builder.window_frame = Some(window_frame);
983 builder
984 }
985 _ => ExprFuncBuilder::new(None),
986 }
987 }
988}
989
990#[cfg(test)]
991mod test {
992 use super::*;
993
994 #[test]
995 fn filter_is_null_and_is_not_null() {
996 let col_null = col("col1");
997 let col_not_null = ident("col2");
998 assert_eq!(format!("{}", col_null.is_null()), "col1 IS NULL");
999 assert_eq!(
1000 format!("{}", col_not_null.is_not_null()),
1001 "col2 IS NOT NULL"
1002 );
1003 }
1004}