8000 update PyAlias to wrap upstream Alias · apache/datafusion-python@ac4ba9c · GitHub
[go: up one dir, main page]

Skip to content

Commit ac4ba9c

Browse files
update PyAlias to wrap upstream Alias
1 parent 7a023d4 commit ac4ba9c

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl PyExpr {
122122
/// Return the specific expression
123123
fn to_variant(&self, py: Python) -> PyResult<PyObject> {
124124
Python::with_gil(|_| match &self.expr {
125-
Expr::Alias(alias) => Ok(PyAlias::new(&alias.expr, &alias.name).into_py(py)),
125+
Expr::Alias(alias) => Ok(PyAlias::from(alias.clone()).into_py(py)),
126126
Expr::Column(col) => Ok(PyColumn::from(col.clone()).into_py(py)),
127127
Expr::ScalarVariable(data_type, variables) => {
128128
Ok(PyScalarVariable::new(data_type, variables).into_py(py))

src/expr/alias.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,24 @@ use crate::expr::PyExpr;
1919
use pyo3::prelude::*;
2020
use std::fmt::{self, Display, Formatter};
2121

22-
use datafusion_expr::Expr;
22+
use datafusion_expr::expr::Alias;
2323

2424
#[pyclass(name = "Alias", module = "datafusion.expr", subclass)]
2525
#[derive(Clone)]
2626
pub struct PyAlias {
27-
expr: PyExpr,
28-
alias_name: String,
27+
alias: Alias,
28+
}
29+
30+
impl From<Alias> for PyAlias {
31+
fn from(alias: Alias) -> Self {
32+
Self { alias }
33+
}
34+
}
35+
36+
impl From<PyAlias> for Alias {
37+
fn from(py_alias: PyAlias) -> Self {
38+
py_alias.alias
39+
}
2940
}
3041

3142
impl Display for PyAlias {
@@ -35,29 +46,20 @@ impl Display for PyAlias {
3546
"Alias
3647
\nExpr: `{:?}`
3748
\nAlias Name: `{}`",
38-
&self.expr, &self.alias_name
49+
&self.alias.expr, &self.alias.name
3950
)
4051
}
4152
}
4253

43-
impl PyAlias {
44-
pub fn new(expr: &Expr, alias_name: &String) -> Self {
45-
Self {
46-
expr: expr.clone().into(),
47-
alias_name: alias_name.to_owned(),
48-
}
49-
}
50-
}
51-
5254
#[pymethods]
5355
impl PyAlias {
5456
/// Retrieve the "name" of the alias
5557
fn alias(&self) -> PyResult<String> {
56-
Ok(self.alias_name.clone())
58+
Ok(self.alias.name.clone())
5759
}
5860

5961
fn expr(&self) -> PyResult<PyExpr> {
60-
Ok(self.expr.clone())
62+
Ok((*self.alias.expr.clone()).into())
6163
}
6264

6365
/// Get a String representation of this column

0 commit comments

Comments
 (0)
0