-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathvalues.rs
More file actions
45 lines (39 loc) · 1.23 KB
/
values.rs
File metadata and controls
45 lines (39 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use std::sync::Arc;
use datafusion_python::datafusion_expr::{logical_plan::Values, LogicalPlan};
use pyo3::prelude::*;
use crate::{
expression::{py_expr_list, PyExpr},
sql::exceptions::py_type_err,
};
#[pyclass(name = "Values", module = "dask_planner", subclass)]
#[derive(Clone)]
pub struct PyValues {
values: Values,
plan: Arc<LogicalPlan>,
}
#[pymethods]
impl PyValues {
/// Creating a model requires that a subquery be passed to the CREATE MODEL
/// statement to be used to gather the dataset which should be used for the
/// model. This function returns that portion of the statement.
#[pyo3(name = "getValues")]
fn get_values(&self) -> PyResult<Vec<Vec<PyExpr>>> {
self.values
.values
.iter()
.map(|e| py_expr_list(&self.plan, e))
.collect()
}
}
impl TryFrom<LogicalPlan> for PyValues {
type Error = PyErr;
fn try_from(logical_plan: LogicalPlan) -> Result<Self, Self::Error> {
match logical_plan {
LogicalPlan::Values(values) => Ok(PyValues {
plan: Arc::new(LogicalPlan::Values(values.clone())),
values,
}),
_ => Err(py_type_err("unexpected plan")),
}
}
}