Commit efb574a
authored
[spanner-to-sourcedb] DELETEs: Error fetching shard id column (#3024)
[b/458068271](https://b.corp.google.com/issues/458068271)
[b/458070941](https://b.corp.google.com/issues/458070941)
## Problem:
Whenever a row has column with NULL value, the reverse replication fails with the following error messages:
1. AssignShardId step in dataflow: ```Error fetching shard Id column: Illegal call to getter of null value```
2. DLQ entry: ```"error_message":"No shard identified for the record"```
## Fix:
marshalSpannerValues calls getter functions to get value of the column, but these function throw a NullPointerException when the value is NULL. This is handled incorrectly and causes the above error. So the fix is to catch a NULL value at the beginning of the function itself.
## Tests:
1. Unit test updated - failed without the fix with the expected error and passed with it.
2. Integration test updated to include NULL values in the row.
### Dataflow job with container built on fixed code.
Template Container built in gs://ea-functional-tests/templates/flex/Spanner_to_SourceDb
Ran [dataflow job](https://pantheon.corp.google.com/dataflow/jobs/us-central1/2025-11-26_02_33_03-2924712538454216688;graphView=0?project=span-cloud-ck-testing-external&e=PangolinKitchenLaunch::PangolinKitchenEnabled&mods=logs_tg_staging&pageState=(%22dfTime%22:(%22l%22:%22dfJobMaxTime%22))) with above container.
#### 1. double datatype
SQL Query: column skill of type double is kept NULL, column variance of type double is non-NULL
```
INSERT INTO ut_scl_squad (ddrKey, gameSpaceId, ownerPersId, teammateIndex, teammatePersId, `variance`, lastUpdateTime) VALUES (3002, 17613, 172377253, 202, 1269841562, 1234.56, 2720290009);
DELETE FROM ut_scl_squad WHERE ddrKey = 3002 AND gameSpaceId = 17613 AND ownerPersId = 172377253;
```
#### 2. timestamp datatype
SQL Query:
- column createdTime of type timestamp is kept non-NULL, column squadName of type varchar is NULL
```
INSERT INTO ut_showoff (ddrkey, showoffId, userId, createdTime, `count`) VALUES (2002, 2002, -285444577, TIMESTAMP('2025-01-01T12:00:00Z'), 2444035295);
DELETE FROM ut_showoff WHERE ddrkey = 2002 AND showoffId = 2002;
```
- column createdTime of type timestamp is kept NULL
```
INSERT INTO ut_showoff (ddrkey, showoffId, userId) VALUES (202, 202, -28577);
DELETE FROM ut_showoff WHERE ddrkey = 202 AND showoffId = 202;
```
#### 3. Reserved Keywords
SQL Query: column content of type varbinary is kept NULL
```
INSERT INTO sedges (ddrkey, created, `from`, `to`, `type`, `value`, flags) VALUES (2001, 2001, 'nodeA', 'nodeB', 'edgeType1', 'edgeValue1', -1326272220);
DELETE FROM sedges WHERE ddrkey = 2001 AND created = 2001;
```
#### 4. INTERLEAVING
- INTERLEAVE IN PARENT ON DELETE CASCADE: on deleting parent on spanner, both parent and child records from sql were also deleted.
- INTERLEAVE IN: on deleting parent on spanner, the parent row was also deleted from sql.
#### 5. Regression testing: Custom sharding logic
- Flow when theres no migration_shard_id column and pipeline uses ddrkey value to compute shard is not affected by this change.1 parent a73e0f0 commit efb574a
File tree
6 files changed
+378
-16
lines changed- v2/spanner-to-sourcedb/src
- main/java/com/google/cloud/teleport/v2/templates/transforms
- test
- java/com/google/cloud/teleport/v2/templates
- transforms
- resources/SpannerToSourceDbDatatypeIT
6 files changed
+378
-16
lines changedLines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
340 | 345 | | |
341 | 346 | | |
342 | 347 | | |
| |||
Lines changed: 28 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
263 | 281 | | |
264 | 282 | | |
265 | 283 | | |
| |||
423 | 441 | | |
424 | 442 | | |
425 | 443 | | |
426 | | - | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
427 | 454 | | |
428 | 455 | | |
Lines changed: 29 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
109 | 110 | | |
| 111 | + | |
110 | 112 | | |
111 | 113 | | |
| 114 | + | |
112 | 115 | | |
113 | 116 | | |
114 | 117 | | |
| |||
119 | 122 | | |
120 | 123 | | |
121 | 124 | | |
| 125 | + | |
122 | 126 | | |
123 | 127 | | |
124 | 128 | | |
| |||
129 | 133 | | |
130 | 134 | | |
131 | 135 | | |
| 136 | + | |
132 | 137 | | |
133 | 138 | | |
| 139 | + | |
| 140 | + | |
134 | 141 | | |
135 | 142 | | |
136 | 143 | | |
| |||
224 | 231 | | |
225 | 232 | | |
226 | 233 | | |
227 | | - | |
| 234 | + | |
228 | 235 | | |
229 | 236 | | |
230 | 237 | | |
| |||
264 | 271 | | |
265 | 272 | | |
266 | 273 | | |
267 | | - | |
| 274 | + | |
268 | 275 | | |
269 | 276 | | |
270 | 277 | | |
| |||
806 | 813 | | |
807 | 814 | | |
808 | 815 | | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
809 | 820 | | |
810 | 821 | | |
811 | 822 | | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
812 | 826 | | |
813 | 827 | | |
814 | 828 | | |
| |||
824 | 838 | | |
825 | 839 | | |
826 | 840 | | |
827 | | - | |
828 | | - | |
829 | | - | |
830 | | - | |
831 | | - | |
832 | | - | |
833 | | - | |
834 | | - | |
835 | | - | |
836 | | - | |
| 841 | + | |
837 | 842 | | |
838 | 843 | | |
839 | 844 | | |
| |||
848 | 853 | | |
849 | 854 | | |
850 | 855 | | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
851 | 859 | | |
852 | 860 | | |
853 | 861 | | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
854 | 871 | | |
855 | 872 | | |
856 | 873 | | |
| |||
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
31 | 40 | | |
32 | 41 | | |
33 | 42 | | |
| |||
0 commit comments