-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bug] Use a list instead of a set for index changes to perserve order (…
…#73) Co-authored-by: Colin Rogers <[email protected]>
- Loading branch information
1 parent
6a1897e
commit cf10056
Showing
4 changed files
with
80 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Fixes | ||
body: Replace usage of `Set` with `List` to fix issue with index updates intermittently happening out of order | ||
time: 2024-04-25T13:34:01.018399-04:00 | ||
custom: | ||
Author: mikealfare | ||
Issue: "72" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from copy import deepcopy | ||
|
||
from dbt.adapters.contracts.relation import RelationType | ||
from dbt.adapters.relation_configs.config_change import RelationConfigChangeAction | ||
|
||
from dbt.adapters.postgres.relation import PostgresRelation | ||
from dbt.adapters.postgres.relation_configs import PostgresIndexConfig | ||
|
||
|
||
def test_index_config_changes(): | ||
index_0_old = { | ||
"name": "my_index_0", | ||
"column_names": {"column_0"}, | ||
"unique": True, | ||
"method": "btree", | ||
} | ||
index_1_old = { | ||
"name": "my_index_1", | ||
"column_names": {"column_1"}, | ||
"unique": True, | ||
"method": "btree", | ||
} | ||
index_2_old = { | ||
"name": "my_index_2", | ||
"column_names": {"column_2"}, | ||
"unique": True, | ||
"method": "btree", | ||
} | ||
existing_indexes = frozenset( | ||
PostgresIndexConfig.from_dict(index) for index in [index_0_old, index_1_old, index_2_old] | ||
) | ||
|
||
index_0_new = deepcopy(index_0_old) | ||
index_2_new = deepcopy(index_2_old) | ||
index_2_new.update(method="hash") | ||
index_3_new = { | ||
"name": "my_index_3", | ||
"column_names": {"column_3"}, | ||
"unique": True, | ||
"method": "hash", | ||
} | ||
new_indexes = frozenset( | ||
PostgresIndexConfig.from_dict(index) for index in [index_0_new, index_2_new, index_3_new] | ||
) | ||
|
||
relation = PostgresRelation.create( | ||
database="my_database", | ||
schema="my_schema", | ||
identifier="my_materialized_view", | ||
type=RelationType.MaterializedView, | ||
) | ||
|
||
index_changes = relation._get_index_config_changes(existing_indexes, new_indexes) | ||
|
||
assert isinstance(index_changes, list) | ||
assert len(index_changes) == len(["drop 1", "drop 2", "create 2", "create 3"]) | ||
assert index_changes[0].action == RelationConfigChangeAction.drop | ||
assert index_changes[1].action == RelationConfigChangeAction.drop | ||
assert index_changes[2].action == RelationConfigChangeAction.create | ||
assert index_changes[3].action == RelationConfigChangeAction.create |