Return a `format`able structure with the a human readable description of this LogicalPlan node per node, not including children. For example: ```text Projection: id ``` ``` use arrow::datatypes::{DataType, Field, Schema}; use datafusion_expr::{col, lit, logical_plan::table_scan, LogicalPlanBuilder}; let schema = Schema::new(vec![Field::new("id", DataType::Int32, false)]); let plan = table_scan(So
(&self)
| 1848 | /// assert_eq!("TableScan: t1", display_string); |
| 1849 | /// ``` |
| 1850 | pub fn display(&self) -> impl Display + '_ { |
| 1851 | // Boilerplate structure to wrap LogicalPlan with something |
| 1852 | // that that can be formatted |
| 1853 | struct Wrapper<'a>(&'a LogicalPlan); |
| 1854 | impl Display for Wrapper<'_> { |
| 1855 | fn fmt(&self, f: &mut Formatter) -> fmt::Result { |
| 1856 | match self.0 { |
| 1857 | LogicalPlan::EmptyRelation(EmptyRelation { |
| 1858 | produce_one_row, |
| 1859 | schema: _, |
| 1860 | }) => { |
| 1861 | let rows = if *produce_one_row { 1 } else { 0 }; |
| 1862 | write!(f, "EmptyRelation: rows={rows}") |
| 1863 | } |
| 1864 | LogicalPlan::RecursiveQuery(RecursiveQuery { |
| 1865 | is_distinct, .. |
| 1866 | }) => { |
| 1867 | write!(f, "RecursiveQuery: is_distinct={is_distinct}") |
| 1868 | } |
| 1869 | LogicalPlan::Values(Values { values, .. }) => { |
| 1870 | let str_values: Vec<_> = values |
| 1871 | .iter() |
| 1872 | // limit to only 5 values to avoid horrible display |
| 1873 | .take(5) |
| 1874 | .map(|row| { |
| 1875 | let item = row |
| 1876 | .iter() |
| 1877 | .map(|expr| expr.to_string()) |
| 1878 | .collect::<Vec<_>>() |
| 1879 | .join(", "); |
| 1880 | format!("({item})") |
| 1881 | }) |
| 1882 | .collect(); |
| 1883 | |
| 1884 | let eclipse = if values.len() > 5 { "..." } else { "" }; |
| 1885 | write!(f, "Values: {}{}", str_values.join(", "), eclipse) |
| 1886 | } |
| 1887 | |
| 1888 | LogicalPlan::TableScan(TableScan { |
| 1889 | source, |
| 1890 | table_name, |
| 1891 | projection, |
| 1892 | filters, |
| 1893 | fetch, |
| 1894 | .. |
| 1895 | }) => { |
| 1896 | let projected_fields = match projection { |
| 1897 | Some(indices) => { |
| 1898 | let schema = source.schema(); |
| 1899 | let names: Vec<&str> = indices |
| 1900 | .iter() |
| 1901 | .map(|i| schema.field(*i).name().as_str()) |
| 1902 | .collect(); |
| 1903 | format!(" projection=[{}]", names.join(", ")) |
| 1904 | } |
| 1905 | _ => "".to_string(), |
| 1906 | }; |
| 1907 |