@@ -32,12 +32,7 @@ use crate::utils::normalize_ident;
3232use arrow_schema:: { DataType , Fields } ;
3333use datafusion_common:: error:: _plan_err;
3434use datafusion_common:: parsers:: CompressionTypeVariant ;
35- use datafusion_common:: {
36- exec_err, not_impl_err, plan_datafusion_err, plan_err, schema_err,
37- unqualified_field_not_found, Column , Constraint , Constraints , DFSchema , DFSchemaRef ,
38- DataFusionError , Result , ScalarValue , SchemaError , SchemaReference , TableReference ,
39- ToDFSchema ,
40- } ;
35+ use datafusion_common:: { exec_err, internal_err, not_impl_err, plan_datafusion_err, plan_err, schema_err, unqualified_field_not_found, Column , Constraint , Constraints , DFSchema , DFSchemaRef , DataFusionError , Result , ScalarValue , SchemaError , SchemaReference , TableReference , ToDFSchema } ;
4136use datafusion_expr:: dml:: { CopyTo , InsertOp } ;
4237use datafusion_expr:: expr_rewriter:: normalize_col_with_schemas_and_ambiguity_check;
4338use datafusion_expr:: logical_plan:: builder:: project;
@@ -204,7 +199,6 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
204199 statement : Statement ,
205200 planner_context : & mut PlannerContext ,
206201 ) -> Result < LogicalPlan > {
207- let sql = Some ( statement. to_string ( ) ) ;
208202 match statement {
209203 Statement :: ExplainTable {
210204 describe_alias : DescribeAlias :: Describe , // only parse 'DESCRIBE table_name' and not 'EXPLAIN table_name'
@@ -518,6 +512,34 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
518512 return not_impl_err ! ( "To not supported" ) ?;
519513 }
520514
515+ // put the statement back together temporarily to get the SQL
516+ // string representation
517+ let stmt = Statement :: CreateView {
518+ or_replace,
519+ materialized,
520+ name,
521+ columns,
522+ query,
523+ options : CreateTableOptions :: None ,
524+ cluster_by,
525+ comment,
526+ with_no_schema_binding,
527+ if_not_exists,
528+ temporary,
529+ to,
530+ } ;
531+ let sql = stmt. to_string ( ) ;
532+ let Statement :: CreateView {
533+ name,
534+ columns,
535+ query,
536+ or_replace,
537+ temporary,
538+ ..
539+ } = stmt else {
540+ return internal_err ! ( "Unreachable code in create view" )
541+ } ;
542+
521543 let columns = columns
522544 . into_iter ( )
523545 . map ( |view_column_def| {
@@ -538,7 +560,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
538560 name : self . object_name_to_table_reference ( name) ?,
539561 input : Arc :: new ( plan) ,
540562 or_replace,
541- definition : sql,
563+ definition : Some ( sql) ,
542564 temporary,
543565 } ) ) )
544566 }
@@ -1123,8 +1145,8 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
11231145 } ,
11241146 ) ) )
11251147 }
1126- _ => {
1127- not_impl_err ! ( "Unsupported SQL statement: {sql:? }" )
1148+ stmt => {
1149+ not_impl_err ! ( "Unsupported SQL statement: {stmt }" )
11281150 }
11291151 }
11301152 }
0 commit comments