fn wrap_query(
    query: &mut Query,
    projection: Vec<SelectItem>,
    selection: Option<Expr>,
    tmp_tab_name: &str,
) -> Statement {
    let with = query.with.clone();
    query.with = None;
    let alias = if tmp_tab_name.is_empty() {
        None
    } else {
        Some(TableAlias {
            name: Ident {
                value: tmp_tab_name.into(),
                quote_style: None,
            },
            columns: vec![],
        })
    };
    Statement::Query(Box::new(Query {
        with,
        body: SetExpr::Select(Box::new(Select {
            distinct: false,
            top: None,
            projection,
            from: vec![TableWithJoins {
                relation: TableFactor::Derived {
                    lateral: false,
                    subquery: Box::new(query.clone()),
                    alias,
                },
                joins: vec![],
            }],
            lateral_views: vec![],
            selection,
            group_by: vec![],
            cluster_by: vec![],
            distribute_by: vec![],
            sort_by: vec![],
            having: None,
        })),
        order_by: vec![],
        limit: None,
        offset: None,
        fetch: None,
    }))
}
// wrap a query into a derived table
wrap a query into a derived table
wrap a query into a derived table
fn wrap_query(
    query: &mut Query,
    projection: Vec<SelectItem>,
    selection: Option<Expr>,
    tmp_tab_name: &str,
) -> Statement {
    let with = query.with.clone();
    query.with = None;
    let alias = if tmp_tab_name.is_empty() {
        None
    } else {
        Some(TableAlias {
            name: Ident {
                value: tmp_tab_name.into(),
                quote_style: None,
            },
            columns: vec![],
        })
    };
    Statement::Query(Box::new(Query {
        with,
        body: SetExpr::Select(Box::new(Select {
            distinct: false,
            top: None,
            projection,
            from: vec![TableWithJoins {
                relation: TableFactor::Derived {
                    lateral: false,
                    subquery: Box::new(query.clone()),
                    alias,
                },
                joins: vec![],
            }],
            lateral_views: vec![],
            selection,
            group_by: vec![],
            cluster_by: vec![],
            distribute_by: vec![],
            sort_by: vec![],
            having: None,
        })),
        order_by: vec![],
        limit: None,
        offset: None,
        fetch: None,
    }))
}
fn wrap_query ( query : & mut Query , projection : Vec < SelectItem > , selection : Option < Expr > , tmp_tab_name : & str , ) -> Statement { let with = query . with . clone ( ) ; query . with = None ; let alias = if tmp_tab_name . is_empty ( ) { None } else { Some ( TableAlias { name : Ident { value : tmp_tab_name . into ( ) , quote_style : None , } , columns : vec ! [ ] , } ) } ; Statement :: Query ( Box :: new ( Query { with , body : SetExpr :: Select ( Box :: new ( Select { distinct : false , top : None , projection , from : vec ! [ TableWithJoins { relation TableFactor Derived { lateral false subquery Box new ( query clone ( ) ) alias } joins vec [ ] } ] , lateral_views : vec ! [ ] , selection , group_by : vec ! [ ] , cluster_by : vec ! [ ] , distribute_by : vec ! [ ] , sort_by : vec ! [ ] , having : None , } ) ) , order_by : vec ! [ ] , limit : None , offset : None , fetch : None , } ) ) }
wrap a query into a derived table
wrap a query into a derived table
query
&mut Query
projection
Vec<SelectItem>
selection
Option<Expr>
tmp_tab_name
&str
query
&mut Query
projection
Vec<SelectItem>
selection
Option<Expr>
tmp_tab_name
&str