-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_0031_low_cardinality_index.py
More file actions
38 lines (26 loc) · 1.36 KB
/
Copy pathtest_0031_low_cardinality_index.py
File metadata and controls
38 lines (26 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from __future__ import print_function
from unittest import TestCase
from indexdigest.linters.linter_0031_low_cardinality_index import \
check_low_cardinality_index, get_low_cardinality_indices
from indexdigest.test import DatabaseTestMixin
class TestLinter(TestCase, DatabaseTestMixin):
def test_get_low_cardinality_indices(self):
indices = list(get_low_cardinality_indices(self.connection))
print(indices)
assert len(indices) == 1
assert indices[0][0] == '0020_big_table'
assert indices[0][2]['INDEX_NAME'] == 'num_idx'
assert indices[0][2]['COLUMN_NAME'] == 'num'
assert indices[0][2]['CARDINALITY'] > 1
assert indices[0][2]['CARDINALITY'] < 5
def test_low_cardinality_index(self):
reports = list(check_low_cardinality_index(self.connection))
print(reports, reports[0].context)
assert len(reports) == 1
assert str(reports[0]) == '0020_big_table: "num_idx" index on "num" column ' \
'has low cardinality, check if it is needed'
assert reports[0].table_name == '0020_big_table'
assert reports[0].context['column_name'] == 'num'
assert reports[0].context['index_name'] == 'num_idx'
assert isinstance(reports[0].context['index_cardinality'], int)
assert int(reports[0].context['value_usage']) == 33