AryanBagade opened a new pull request, #19066:
URL: https://github.com/apache/datafusion/pull/19066

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements and this helps us generate change logs for our releases. You can 
link an issue to this PR using the GitHub syntax. For example `Closes #123` 
indicates that this PR will close issue #123.
   -->
   
   - Closes #19039.
   
   ## Rationale for this change
   
   As per the Issue #19039, many examples of verbose `CreateExternalTable` 
initialization were found throughout the codebase. The current approach 
requires specifying all 14 fields even when most use default values, making it:
   1. Verbose (most fields are defaults)
   2. Hard to see which fields are actually overridden vs defaults
   
   This PR implements a builder API to address these issues.
   
   ## What changes are included in this PR?
   
   - Added `CreateExternalTableBuilder` with required parameters enforced at 
compile-time
   - Constructor takes required fields: `builder(name, location, file_type, 
schema)`
   - Optional fields can be set via `.with_*()` methods (following DataFusion's 
builder conventions)
   - Updated all usages across 5 files to use the new builder API
   - Reduced typical usage from 15 lines to 4-6 lines
   
   Example transformation:
   **Before**
     ```rust
     // Before (15 lines)
     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: Default::default(),
         column_defaults: HashMap::new(),
     }
   ```
   **After**
   ```rust
     // After (4 lines)
     CreateExternalTable::builder(name, location, "parquet",
     schema)
         .build()
   ```
   ## Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are 
they covered by existing tests)?
   -->
   
   Yup, all existing tests pass:
     - cargo test -p datafusion-expr - DDL tests pass
     - cargo test -p datafusion-catalog - Catalog tests pass
     - cargo test -p datafusion - Core tests pass
     - All modified usage sites are in existing test files
   
   ## Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be 
updated before approving the PR.
   -->
   No breaking changes.
   <!--
   If there are any breaking changes to public APIs, please add the `api 
change` label.
   -->
   The builder API is new one and its for internal code cleanup and reducing 
redundancy and verboseness


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to