| 102 | |
| 103 | impl Unparser<'_> { |
| 104 | pub fn plan_to_sql(&self, plan: &LogicalPlan) -> Result<ast::Statement> { |
| 105 | let mut plan = normalize_union_schema(plan)?; |
| 106 | if !self.dialect.supports_qualify() { |
| 107 | plan = rewrite_qualify(plan)?; |
| 108 | } |
| 109 | |
| 110 | match plan { |
| 111 | LogicalPlan::Projection(_) |
| 112 | | LogicalPlan::Filter(_) |
| 113 | | LogicalPlan::Window(_) |
| 114 | | LogicalPlan::Aggregate(_) |
| 115 | | LogicalPlan::Sort(_) |
| 116 | | LogicalPlan::Join(_) |
| 117 | | LogicalPlan::Repartition(_) |
| 118 | | LogicalPlan::Union(_) |
| 119 | | LogicalPlan::TableScan(_) |
| 120 | | LogicalPlan::EmptyRelation(_) |
| 121 | | LogicalPlan::Subquery(_) |
| 122 | | LogicalPlan::SubqueryAlias(_) |
| 123 | | LogicalPlan::Limit(_) |
| 124 | | LogicalPlan::Statement(_) |
| 125 | | LogicalPlan::Values(_) |
| 126 | | LogicalPlan::Distinct(_) => self.select_to_sql_statement(&plan), |
| 127 | LogicalPlan::Dml(_) => self.dml_to_sql(&plan), |
| 128 | LogicalPlan::Extension(extension) => { |
| 129 | self.extension_to_statement(extension.node.as_ref()) |
| 130 | } |
| 131 | LogicalPlan::Explain(_) |
| 132 | | LogicalPlan::Analyze(_) |
| 133 | | LogicalPlan::Ddl(_) |
| 134 | | LogicalPlan::Copy(_) |
| 135 | | LogicalPlan::DescribeTable(_) |
| 136 | | LogicalPlan::RecursiveQuery(_) |
| 137 | | LogicalPlan::Unnest(_) => not_impl_err!("Unsupported plan: {plan:?}"), |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /// Try to unparse a [UserDefinedLogicalNode] to a SQL statement. |
| 142 | /// If multiple unparsers are registered for the same [UserDefinedLogicalNode], |