Commit a803c38
committed
[SPARK-55716][SQL][FOLLOWUP] Simplify NOT NULL preservation by skipping asNullable in resolveRelation
### What changes were proposed in this pull request?
Followup to #54517. Simplifies NOT NULL constraint preservation per [review feedback](#54517 (comment)).
Instead of calling `dataSchema.asNullable` in `resolveRelation()` and then restoring nullability with recursive `restoreNullability`/`restoreDataTypeNullability` helpers in `CreateDataSourceTableCommand`, this PR:
1. Adds a `forceNullable` parameter to `DataSource.resolveRelation()` (default `true`, preserving existing behavior)
2. Passes `forceNullable = !enforceNotNull` from `CreateDataSourceTableCommand`, so `asNullable` is skipped only when the config is enabled
3. Removes `restoreNullability` and `restoreDataTypeNullability` helper methods entirely
**Data flow:**
- **Config OFF** (default): `forceNullable = true` → `asNullable` runs → same behavior as before SPARK-55716
- **Config ON**: `forceNullable = false` → `asNullable` skipped → catalog stores NOT NULL → `PreprocessTableInsertion` enforces at insert time
### Why are the changes needed?
Addresses review feedback: "is it simpler to not do `dataSchema.asNullable` if the flag is on?"
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Existing SPARK-55716 tests (7 tests in InsertSuite) and ShowCreateTableSuite (30 tests) all pass.
### Was this patch authored or co-authored using generative AI tooling?
Yes, co-authored with GitHub Copilot.
Closes #54597 from yaooqinn/SPARK-55716.
Authored-by: Kent Yao <kentyao@microsoft.com>
Signed-off-by: Kent Yao <kentyao@microsoft.com>1 parent 93ab196 commit a803c38
4 files changed
Lines changed: 14 additions & 51 deletions
File tree
- sql
- core/src
- main/scala/org/apache/spark/sql/execution
- command
- datasources
- test/scala/org/apache/spark/sql/execution/command/v1
- hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver
Lines changed: 6 additions & 44 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | | - | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
82 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
83 | 86 | | |
84 | 87 | | |
85 | 88 | | |
| |||
107 | 110 | | |
108 | 111 | | |
109 | 112 | | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | 113 | | |
120 | | - | |
| 114 | + | |
121 | 115 | | |
122 | 116 | | |
123 | 117 | | |
| |||
132 | 126 | | |
133 | 127 | | |
134 | 128 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | 129 | | |
168 | 130 | | |
169 | 131 | | |
| |||
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
365 | | - | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
366 | 369 | | |
367 | 370 | | |
368 | 371 | | |
| |||
436 | 439 | | |
437 | 440 | | |
438 | 441 | | |
439 | | - | |
| 442 | + | |
440 | 443 | | |
441 | 444 | | |
442 | 445 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | | - | |
| 188 | + | |
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
| |||
Lines changed: 2 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
343 | | - | |
344 | | - | |
| 343 | + | |
345 | 344 | | |
346 | 345 | | |
347 | | - | |
348 | | - | |
| 346 | + | |
349 | 347 | | |
350 | 348 | | |
351 | 349 | | |
| |||
0 commit comments