Commit 2b05b09
feat: Add builder API for CreateExternalTable to reduce verbosity (#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
---------
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>1 parent 482c6b8 commit 2b05b09
File tree
5 files changed
+245
-184
lines changed- datafusion
- catalog/src
- core/src/datasource
- expr/src/logical_plan
- proto/src/logical_plan
- sql/src
5 files changed
+245
-184
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
131 | | - | |
| 130 | + | |
132 | 131 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
146 | 137 | | |
147 | 138 | | |
148 | 139 | | |
| |||
Lines changed: 58 additions & 135 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
234 | | - | |
| 234 | + | |
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
| 248 | + | |
249 | 249 | | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
264 | 256 | | |
265 | 257 | | |
266 | 258 | | |
| |||
286 | 278 | | |
287 | 279 | | |
288 | 280 | | |
289 | | - | |
| 281 | + | |
290 | 282 | | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
305 | 289 | | |
306 | 290 | | |
307 | 291 | | |
| |||
331 | 315 | | |
332 | 316 | | |
333 | 317 | | |
334 | | - | |
| 318 | + | |
335 | 319 | | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
350 | 326 | | |
351 | 327 | | |
352 | 328 | | |
| |||
383 | 359 | | |
384 | 360 | | |
385 | 361 | | |
386 | | - | |
| 362 | + | |
387 | 363 | | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
402 | 370 | | |
403 | 371 | | |
404 | 372 | | |
| |||
427 | 395 | | |
428 | 396 | | |
429 | 397 | | |
430 | | - | |
| 398 | + | |
431 | 399 | | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
446 | 405 | | |
447 | 406 | | |
448 | 407 | | |
| |||
467 | 426 | | |
468 | 427 | | |
469 | 428 | | |
470 | | - | |
| 429 | + | |
471 | 430 | | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
486 | 436 | | |
487 | 437 | | |
488 | 438 | | |
| |||
508 | 458 | | |
509 | 459 | | |
510 | 460 | | |
511 | | - | |
| 461 | + | |
512 | 462 | | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | | - | |
525 | | - | |
526 | | - | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
527 | 468 | | |
528 | 469 | | |
529 | 470 | | |
| |||
558 | 499 | | |
559 | 500 | | |
560 | 501 | | |
561 | | - | |
| 502 | + | |
562 | 503 | | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
577 | 509 | | |
578 | 510 | | |
579 | 511 | | |
| |||
597 | 529 | | |
598 | 530 | | |
599 | 531 | | |
600 | | - | |
| 532 | + | |
601 | 533 | | |
602 | 534 | | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | | - | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
616 | 539 | | |
617 | 540 | | |
618 | 541 | | |
| |||
0 commit comments