Skip to content

Add builder API for CreateExternalTable to reduce redundancy and make the code easier to understand #19039

@alamb

Description

@alamb

Is your feature request related to a problem or challenge?

While reviewing #18971. I noticed many examples like this over the codbase

          let cmd = CreateExternalTable {
              name,
              location,
              file_type: "parquet".to_string(),
              schema: Arc::new(DFSchema::empty()),
              table_partition_cols: vec![],
              if_not_exists: false,
              or_replace: false,
              temporary: false,
              definition: None,
              order_exprs: vec![],
              unbounded: false,
              options: HashMap::new(),
              constraints: Constraints::default(),
              column_defaults: HashMap::new(),
          };

This is non ideal for several reasons:

  1. It is verbose (most of the fields are the defaults)
  2. It makes it hard to see what fields are actually overridden vs which are the defaults

Describe the solution you'd like

instead of having to provide values for all fields, most of which are the default values, I think it would be nice to have a well commented builder API

Describe alternatives you've considered

I suggest adding a CrateExternalTableBuilder and replace the above code it with something like this

  let cmd = CreateExternalTable::builder()
    .with_name(name)
    .with_location(location)
    .with_file_type("parquet")
    .with_schema(schema)
    .build()?

It may make sense to have required parameters be verified by the compiler like this

  let cmd = CreateExternalTable::builder(name, location, "parquet", schema)
    .build()?

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions