-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Make [non] nullable struct fields easier to create (#646)
## What changes are proposed in this pull request? A lot of code (especially in tests) calls `StructField::new` with literal values of the `nullable: bool` argument. Booleans are easy to misinterpret (which value means non-null field?) -- and it's hard to read when the third arg is split to its own line in nested expressions such as: ```rust StructField::new( "fileConstantValues", StructType::new([StructField::new( "partitionValues", MapType::new(DataType::STRING, DataType::STRING, true), false, )]), true, ), ``` To improve readability and make the code less error-prone, define two new helper methods/constructors for `StructField`: `nullable` and `not_null`, which create struct fields having the corresponding nullability. ## How was this change tested? No new functionality, and all existing unit tests still pass. To minimize the risk of unfaithful refactoring, the change was made in four steps: 1. Use a multi-file regexp search/replace to convert simple code such like this: ```rust StructField::new("a", DataType::LONG, true) ``` to this: ```rust StructField::nullable("a", DataType::LONG) ``` The exact expression used was: `StructField::new(\([^()]*\), true) → StructField::nullable(\1)`, which ignores any constructor call containing parentheses, to avoid ambiguity. 2. Use the multi-file regexp search/replace `StructField::new(\([^()]*\), false) → StructField::not_null(\1)`, to convert simple use `not_null` call sites (see above for details). 3. Use an interactive multi-file search/replace `StructField::new → StructField::nullable`, relying on IDE parentheses matching to identify calls that pass the literal `true` (first pass). As a safety measure, the resulting code is compiled; all changed call sites fail to compile because of the (now unrecognized) third arg, which can then be deleted after verifying it is the literal `true`. 4. Use the same two-pass process for `StructField::new → StructField::not_null` with literal `false`. Each step is its own commit, for easier verification.
- Loading branch information
Showing
18 changed files
with
258 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.