Repository navigation
Commit c808a0a
fix(snowflake): correct alter order when dropping a clustered column and replacing the key
Snowflake rejects DROP COLUMN while the column is still in the clustering key,
and also rejects CLUSTER BY on a column that has not been added yet. The
previous fix placed a single clustering statement at the position of the first
affected drop, which worked for the drop-key case but was wrong when the key
changes: CLUSTER BY (new_col) before ADD COLUMN new_col also fails, and emitting
CLUSTER BY (remaining_col) before DROP COLUMN old_col leaves the old key active
during the drop.
The correct Snowflake sequence when the current key names a column being dropped:
1. DROP CLUSTERING KEY — before any drop of a column the old key still names.
2. Column changes (drops and adds) — in their existing schema-diff order.
3. CLUSTER BY — after all column changes, if the target table is clustered.
When no column being dropped belongs to the current key the historical position
is kept: column changes first, then the clustering change at the end. BigQuery
and StarRocks are unaffected; they continue to use the base mixin which appends
the clustering change after all column changes.
The mixin now calls _apply_clustering_operation() instead of computing a single
insert position. SnowflakeEngineAdapter overrides that hook to emit up to two
clustering statements (DROP CLUSTERING KEY early; CLUSTER BY at the end) when
needed, while every other ClusteredByMixin engine keeps the one-statement append.
Signed-off-by: Nick Muoh <nickspirit3+github@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent a596f5d commit c808a0a
3 files changed
Lines changed: 112 additions & 53 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
| 401 | + | |
405 | 402 | | |
406 | 403 | | |
407 | 404 | | |
408 | | - | |
| 405 | + | |
409 | 406 | | |
410 | 407 | | |
| 408 | + | |
411 | 409 | | |
412 | | - | |
413 | | - | |
| 410 | + | |
| 411 | + | |
414 | 412 | | |
415 | | - | |
416 | | - | |
417 | | - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
418 | 417 | | |
419 | | - | |
| 418 | + | |
420 | 419 | | |
421 | 420 | | |
422 | 421 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
693 | 695 | | |
694 | 696 | | |
695 | 697 | | |
696 | | - | |
| 698 | + | |
697 | 699 | | |
698 | 700 | | |
| 701 | + | |
699 | 702 | | |
700 | | - | |
701 | | - | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
702 | 713 | | |
703 | | - | |
704 | | - | |
705 | | - | |
| 714 | + | |
| 715 | + | |
706 | 716 | | |
707 | 717 | | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
724 | 743 | | |
725 | 744 | | |
726 | 745 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1277 | 1277 | | |
1278 | 1278 | | |
1279 | 1279 | | |
1280 | | - | |
| 1280 | + | |
1281 | 1281 | | |
1282 | 1282 | | |
1283 | 1283 | | |
1284 | | - | |
1285 | | - | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
1286 | 1287 | | |
1287 | 1288 | | |
1288 | 1289 | | |
| |||
1296 | 1297 | | |
1297 | 1298 | | |
1298 | 1299 | | |
1299 | | - | |
1300 | | - | |
| 1300 | + | |
| 1301 | + | |
1301 | 1302 | | |
1302 | | - | |
| 1303 | + | |
1303 | 1304 | | |
1304 | 1305 | | |
1305 | | - | |
1306 | | - | |
| 1306 | + | |
| 1307 | + | |
1307 | 1308 | | |
| 1309 | + | |
1308 | 1310 | | |
1309 | 1311 | | |
1310 | 1312 | | |
| |||
1366 | 1368 | | |
1367 | 1369 | | |
1368 | 1370 | | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
1369 | 1408 | | |
1370 | 1409 | | |
1371 | 1410 | | |
| |||
1436 | 1475 | | |
1437 | 1476 | | |
1438 | 1477 | | |
1439 | | - | |
1440 | | - | |
| 1478 | + | |
| 1479 | + | |
1441 | 1480 | | |
1442 | 1481 | | |
1443 | 1482 | | |
| |||
1449 | 1488 | | |
1450 | 1489 | | |
1451 | 1490 | | |
| 1491 | + | |
1452 | 1492 | | |
1453 | | - | |
| 1493 | + | |
1454 | 1494 | | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
1455 | 1499 | | |
1456 | | - | |
1457 | | - | |
1458 | | - | |
1459 | | - | |
1460 | | - | |
1461 | | - | |
1462 | | - | |
1463 | | - | |
1464 | | - | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
1465 | 1506 | | |
1466 | 1507 | | |
1467 | 1508 | | |
| |||
0 commit comments