Commit 4aea018
authored
feat(duckdb): Add transpilation support for nanoseconds used in date/time functions. (#6617)
* feat(duckdb): Add transpilation support for nanoseconds used in date/time functions
* Address review comments: remove redundant casting and fix test cases
- Remove redundant TIMESTAMP_NS casting in _timediff_sql (lines 268-271)
* Previously cast to TIMESTAMP_NS before calling _handle_nanosecond_diff
* _handle_nanosecond_diff already handles casting via exp.cast (which avoids recasting)
* Now passes expressions directly, matching _date_diff_sql pattern
- Fix TIMEDIFF test case to use valid Snowflake syntax
* Changed from TIME literal '10:00:00.000000000'
* To TIMESTAMP with CAST: CAST('2023-01-01 10:00:00.000000000' AS TIMESTAMP)
* TIME literals don't work with TIMEDIFF in Snowflake
- Fix TIMEADD test case to use valid Snowflake syntax
* Changed from TIME literal '10:00:00.000000000'
* To TIMESTAMP with CAST: CAST('2023-01-01 10:00:00.000000000' AS TIMESTAMP)
* TIME literals don't work with TIMEADD in Snowflake
Addresses review comments from VaggelisD on PR #6617
* Address review comments: simplify code and improve clarity
- Use expression.unit property accessor instead of expression.args.get('unit')
* Updated in _timediff_sql, date_delta_to_binary_interval_op, _date_diff_sql
* More concise and idiomatic
- Remove unnecessary docstring from _is_nanosecond_unit
* Function name is self-explanatory
- Keep _unwrap_cast helper function
* Necessary to avoid nested casts like CAST(CAST(x AS TIMESTAMP) AS TIMESTAMP_NS)
* exp.cast only avoids recasting to SAME type, not DIFFERENT types
* Example: CAST('2023-01-01' AS TIMESTAMP) → without unwrap → CAST(CAST(...) AS TIMESTAMP_NS)
* With unwrap: extracts '2023-01-01' → CAST('2023-01-01' AS TIMESTAMP_NS)
- cast parameter not needed for NANOSECOND handling
* NANOSECOND operations require EPOCH_NS/make_timestamp_ns
* These functions require TIMESTAMP_NS type
* Must always cast regardless of cast parameter
* cast parameter only applies to base implementation's interval operations
Addresses review comments from georgesittas on PR #6617
* feat(duckdb): Remove the unwrapping logic and remove the corresponding tests for simplicity1 parent fc5800d commit 4aea018
2 files changed
+132
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | | - | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
142 | 143 | | |
143 | 144 | | |
144 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
145 | 182 | | |
146 | 183 | | |
147 | 184 | | |
| |||
215 | 252 | | |
216 | 253 | | |
217 | 254 | | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
218 | 260 | | |
219 | 261 | | |
220 | 262 | | |
| |||
223 | 265 | | |
224 | 266 | | |
225 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
226 | 289 | | |
227 | 290 | | |
228 | 291 | | |
| |||
439 | 502 | | |
440 | 503 | | |
441 | 504 | | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
442 | 510 | | |
443 | 511 | | |
444 | | - | |
445 | 512 | | |
446 | 513 | | |
447 | 514 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2489 | 2489 | | |
2490 | 2490 | | |
2491 | 2491 | | |
| 2492 | + | |
| 2493 | + | |
| 2494 | + | |
| 2495 | + | |
| 2496 | + | |
| 2497 | + | |
| 2498 | + | |
| 2499 | + | |
| 2500 | + | |
| 2501 | + | |
| 2502 | + | |
| 2503 | + | |
| 2504 | + | |
| 2505 | + | |
| 2506 | + | |
| 2507 | + | |
| 2508 | + | |
| 2509 | + | |
| 2510 | + | |
| 2511 | + | |
| 2512 | + | |
| 2513 | + | |
| 2514 | + | |
| 2515 | + | |
| 2516 | + | |
| 2517 | + | |
| 2518 | + | |
| 2519 | + | |
| 2520 | + | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
| 2527 | + | |
| 2528 | + | |
| 2529 | + | |
| 2530 | + | |
| 2531 | + | |
| 2532 | + | |
| 2533 | + | |
| 2534 | + | |
| 2535 | + | |
| 2536 | + | |
| 2537 | + | |
| 2538 | + | |
| 2539 | + | |
| 2540 | + | |
| 2541 | + | |
| 2542 | + | |
| 2543 | + | |
| 2544 | + | |
| 2545 | + | |
| 2546 | + | |
| 2547 | + | |
| 2548 | + | |
| 2549 | + | |
| 2550 | + | |
| 2551 | + | |
| 2552 | + | |
| 2553 | + | |
| 2554 | + | |
2492 | 2555 | | |
2493 | 2556 | | |
2494 | 2557 | | |
| |||
0 commit comments