use datafusion_expr::expr::Like;
use pyo3::prelude::*;
use std::fmt::{self, Display, Formatter};
use crate::expr::PyExpr;
#[pyclass(name = "Like", module = "datafusion.expr", subclass)]
#[derive(Clone)]
pub struct PyLike {
like: Like,
}
impl From<Like> for PyLike {
fn from(like: Like) -> PyLike {
PyLike { like }
}
}
impl From<PyLike> for Like {
fn from(like: PyLike) -> Self {
like.like
}
}
impl Display for PyLike {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(
f,
"Like
Negated: {:?}
Expr: {:?}
Pattern: {:?}
Escape_Char: {:?}",
&self.negated(),
&self.expr(),
&self.pattern(),
&self.escape_char()
)
}
}
#[pymethods]
impl PyLike {
fn negated(&self) -> PyResult<bool> {
Ok(self.like.negated)
}
fn expr(&self) -> PyResult<PyExpr> {
Ok((*self.like.expr).clone().into())
}
fn pattern(&self) -> PyResult<PyExpr> {
Ok((*self.like.pattern).clone().into())
}
fn escape_char(&self) -> PyResult<Option<char>> {
Ok(self.like.escape_char)
}
fn __repr__(&self) -> String {
format!("Like({})", self)
}
}
#[pyclass(name = "ILike", module = "datafusion.expr", subclass)]
#[derive(Clone)]
pub struct PyILike {
like: Like,
}
impl From<Like> for PyILike {
fn from(like: Like) -> PyILike {
PyILike { like }
}
}
impl From<PyILike> for Like {
fn from(like: PyILike) -> Self {
like.like
}
}
impl Display for PyILike {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(
f,
"ILike
Negated: {:?}
Expr: {:?}
Pattern: {:?}
Escape_Char: {:?}",
&self.negated(),
&self.expr(),
&self.pattern(),
&self.escape_char()
)
}
}
#[pymethods]
impl PyILike {
fn negated(&self) -> PyResult<bool> {
Ok(self.like.negated)
}
fn expr(&self) -> PyResult<PyExpr> {
Ok((*self.like.expr).clone().into())
}
fn pattern(&self) -> PyResult<PyExpr> {
Ok((*self.like.pattern).clone().into())
}
fn escape_char(&self) -> PyResult<Option<char>> {
Ok(self.like.escape_char)
}
fn __repr__(&self) -> String {
format!("Like({})", self)
}
}
#[pyclass(name = "SimilarTo", module = "datafusion.expr", subclass)]
#[derive(Clone)]
pub struct PySimilarTo {
like: Like,
}
impl From<Like> for PySimilarTo {
fn from(like: Like) -> PySimilarTo {
PySimilarTo { like }
}
}
impl From<PySimilarTo> for Like {
fn from(like: PySimilarTo) -> Self {
like.like
}
}
impl Display for PySimilarTo {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(
f,
"SimilarTo
Negated: {:?}
Expr: {:?}
Pattern: {:?}
Escape_Char: {:?}",
&self.negated(),
&self.expr(),
&self.pattern(),
&self.escape_char()
)
}
}
#[pymethods]
impl PySimilarTo {
fn negated(&self) -> PyResult<bool> {
Ok(self.like.negated)
}
fn expr(&self) -> PyResult<PyExpr> {
Ok((*self.like.expr).clone().into())
}
fn pattern(&self) -> PyResult<PyExpr> {
Ok((*self.like.pattern).clone().into())
}
fn escape_char(&self) -> PyResult<Option<char>> {
Ok(self.like.escape_char)
}
fn __repr__(&self) -> String {
format!("Like({})", self)
}
}