Skip to content

Convert SqlToRel::statement_to_pan to take ownership rather than references. #1469

Closed

Description

@alamb

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
While working on some other code, I noticed that SqlToRel::statement_to_plan takes a reference to the parse tree -- this results in having to clone() many values (identifiers, etc) while converting a parsed SQL query to a LogicalPlan

The only callsite I could find throws away the parsed query immediately; Doing this would likely save lots of cloning internal to SqlToRel

Describe the solution you'd like

If someone wanted a fun project, they could convert SqlToRel::statement_to_pan to take ownership rather than references.
https://github.com/apache/arrow-datafusion/blob/0052667afae33ba9e549256d0d5d47e2f45e6ffb/datafusion/src/sql/planner.rs#L121

Specifically, change:

    pub fn statement_to_plan(&self, statement: &DFStatement) -> Result<LogicalPlan> {

To

    pub fn statement_to_plan(&self, statement: DFStatement) -> Result<LogicalPlan> {

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
This would be a software engineering exercise -- it wouldn't really require much in the way of knowledge of the guts of DataFusion

Activity

  1. xudong963 commented on Dec 21, 2021

    @xudong963
    Member

    @alamb good catch!

    Here I give a specific example to omit clone

        pub fn external_table_to_plan(
            &self,
            statement: &CreateExternalTable,
        ) -> Result<LogicalPlan> {
            let CreateExternalTable {
                name,
                columns,
                file_type,
                has_header,
                location,
            } = statement;
    
            ...
    
            Ok(LogicalPlan::CreateExternalTable(PlanCreateExternalTable {
                schema: schema.to_dfschema_ref()?,
                name: name.clone(),
                location: location.clone(),
                file_type: *file_type,
                has_header: *has_header,
            }))
        }

    to

        pub fn external_table_to_plan(
            &self,
            statement: CreateExternalTable,
        ) -> Result<LogicalPlan> {
            let CreateExternalTable {
                name,
                columns,
                file_type,
                has_header,
                location,
            } = statement;
    
           ...
    
            Ok(LogicalPlan::CreateExternalTable(PlanCreateExternalTable {
                schema: schema.to_dfschema_ref()?,
                name,
                location,
                file_type: *file_type,
                has_header: *has_header,
            }))
        }

    BTW, I think it's better to add a good first issue

  2. doki23 commented on Feb 28, 2022

    @doki23
    Contributor

    I wanna take this issue, can I? @alamb

  3. alamb commented on Feb 28, 2022

    @alamb
    ContributorAuthor

    Please do @doki23 !

  4. added a commit that references this issue on May 13, 2026
  5. added a commit that references this issue on May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions