diff --git a/src/catalog.rs b/src/catalog.rs index 900960607..4dd431fcb 100644 --- a/src/catalog.rs +++ b/src/catalog.rs @@ -81,6 +81,13 @@ impl PyCatalog { ))), } } + + fn __repr__(&self) -> PyResult { + Ok(format!( + "Catalog(schema_names=[{}])", + self.names().join(";") + )) + } } #[pymethods] @@ -97,6 +104,13 @@ impl PyDatabase { } } + fn __repr__(&self) -> PyResult { + Ok(format!( + "Database(table_names=[{}])", + Vec::from_iter(self.names()).join(";") + )) + } + // register_table // deregister_table } @@ -119,6 +133,11 @@ impl PyTable { } } + fn __repr__(&self) -> PyResult { + let kind = self.kind(); + Ok(format!("Table(kind={kind})")) + } + // fn scan // fn statistics // fn has_exact_statistics diff --git a/src/config.rs b/src/config.rs index d5d577765..228f95a0b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -72,6 +72,14 @@ impl PyConfig { } Ok(dict.into()) } + + fn __repr__(&mut self, py: Python) -> PyResult { + let dict = self.get_all(py); + match dict { + Ok(result) => Ok(format!("Config({result})")), + Err(err) => Ok(format!("Error: {:?}", err.to_string())), + } + } } /// Convert a python object to a ScalarValue diff --git a/src/context.rs b/src/context.rs index 3990a4c37..915ac4573 100644 --- a/src/context.rs +++ b/src/context.rs @@ -460,6 +460,14 @@ impl PySessionContext { }; Ok(PyDataFrame::new(df)) } + + fn __repr__(&self) -> PyResult { + let id = self.session_id(); + match id { + Ok(value) => Ok(format!("SessionContext(session_id={value})")), + Err(err) => Ok(format!("Error: {:?}", err.to_string())), + } + } } impl PySessionContext { diff --git a/src/dataframe.rs b/src/dataframe.rs index c6162e4e4..3dd8210e0 100644 --- a/src/dataframe.rs +++ b/src/dataframe.rs @@ -66,6 +66,16 @@ impl PyDataFrame { }) } + fn __repr__(&self, py: Python) -> PyResult { + let df = self.df.as_ref().clone().limit(0, Some(10))?; + let batches = wait_for_future(py, df.collect())?; + let batches_as_string = pretty::pretty_format_batches(&batches); + match batches_as_string { + Ok(batch) => Ok(format!("DataFrame()\n{batch}")), + Err(err) => Ok(format!("Error: {:?}", err.to_string())), + } + } + /// Returns the schema from the logical plan fn schema(&self) -> PyArrowType { PyArrowType(self.df.schema().into()) diff --git a/src/expression.rs b/src/expression.rs index 2e8fb801c..1eb7813ed 100644 --- a/src/expression.rs +++ b/src/expression.rs @@ -57,8 +57,8 @@ impl PyExpr { expr.into() } - fn __str__(&self) -> PyResult { - Ok(format!("{}", self.expr)) + fn __repr__(&self) -> PyResult { + Ok(format!("Expr({})", self.expr)) } fn __add__(&self, rhs: PyExpr) -> PyResult { diff --git a/src/udaf.rs b/src/udaf.rs index 863d8d799..a623de6b0 100644 --- a/src/udaf.rs +++ b/src/udaf.rs @@ -141,4 +141,8 @@ impl PyAggregateUDF { let args = args.iter().map(|e| e.expr.clone()).collect(); Ok(self.function.call(args).into()) } + + fn __repr__(&self) -> PyResult { + Ok(format!("AggregateUDF({})", self.function.name)) + } } diff --git a/src/udf.rs b/src/udf.rs index 4804f999e..10a8782b2 100644 --- a/src/udf.rs +++ b/src/udf.rs @@ -92,4 +92,8 @@ impl PyScalarUDF { let args = args.iter().map(|e| e.expr.clone()).collect(); Ok(self.function.call(args).into()) } + + fn __repr__(&self) -> PyResult { + Ok(format!("ScalarUDF({})", self.function.name)) + } }