polars_python/lazyframe/
optflags.rs

1use parking_lot::RwLock;
2use polars::prelude::OptFlags;
3use pyo3::pymethods;
4
5use super::PyOptFlags;
6
7macro_rules! flag_getter_setters {
8    ($(($flag:ident, $getter:ident, $setter:ident, clear=$clear:literal))+) => {
9        #[pymethods]
10        impl PyOptFlags {
11            #[staticmethod]
12            pub fn empty() -> Self {
13                Self {
14                    inner: RwLock::new(OptFlags::empty())
15                }
16            }
17
18            #[staticmethod]
19            #[allow(clippy::should_implement_trait)]
20            pub fn default() -> Self {
21                Self { inner: RwLock::default() }
22            }
23
24            pub fn no_optimizations(&self) {
25                $(if $clear {
26                    self.inner.write().remove(OptFlags::$flag);
27                })+
28            }
29
30            pub fn copy(&self) -> Self {
31                Self { inner: RwLock::new(self.inner.read().clone()) }
32            }
33
34            $(
35            #[getter]
36            fn $getter(&self) -> bool {
37                self.inner.read().contains(OptFlags::$flag)
38            }
39            #[setter]
40            fn $setter(&self, value: bool) {
41                self.inner.write().set(OptFlags::$flag, value)
42            }
43            )+
44        }
45    };
46}
47
48flag_getter_setters! {
49    (TYPE_COERCION, get_type_coercion, set_type_coercion, clear=false)
50    (TYPE_CHECK, get_type_check, set_type_check, clear=false)
51
52    (PROJECTION_PUSHDOWN, get_projection_pushdown, set_projection_pushdown, clear=true)
53    (PREDICATE_PUSHDOWN, get_predicate_pushdown, set_predicate_pushdown, clear=true)
54    (CLUSTER_WITH_COLUMNS, get_cluster_with_columns, set_cluster_with_columns, clear=true)
55    (SIMPLIFY_EXPR, get_simplify_expression, set_simplify_expression, clear=true)
56    (SLICE_PUSHDOWN, get_slice_pushdown, set_slice_pushdown, clear=true)
57    (COMM_SUBPLAN_ELIM, get_comm_subplan_elim, set_comm_subplan_elim, clear=true)
58    (COMM_SUBEXPR_ELIM, get_comm_subexpr_elim, set_comm_subexpr_elim, clear=true)
59    (COLLAPSE_JOINS, get_collapse_joins, set_collapse_joins, clear=true)
60    (CHECK_ORDER_OBSERVE, get_check_order_observe, set_check_order_observe, clear=true)
61    (FAST_PROJECTION, get_fast_projection, set_fast_projection, clear=true)
62
63    (EAGER, get_eager, set_eager, clear=true)
64    (NEW_STREAMING, get_streaming, set_streaming, clear=true)
65}