ClickHouse/Diff/Index.pm

filter: Statementstmt 100% 48 / 48 Branchbran 100% 6 / 6 Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 15 / 15 Podpod 100% 4 / 4 totaltotal 90.5% 77 / 85 CC 9 SCAR 8.9
CC
9
Cov
94%
diff
5.2
changed_index
3.0
as_sql
3.0
CRAP 2.4
« ClickHouse/Storage/TxnScopeGuard.pm ↑ Summary ClickHouse/Diff.pm »
1 package DBIO::ClickHouse::Diff::Index;
2 # ABSTRACT: Diff operations for ClickHouse data-skipping indexes
3  
4 38 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 38 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 38 our $VERSION = '0.900007';
8  
9 38 ▶use base 'DBIO::Diff::Op';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 38 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 38 ▶use DBIO::Diff::Op ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 38 ▶use DBIO::Diff::Compare qw(norm);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 38 ▶use DBIO::ClickHouse::DDL::Emit qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
16 index_def alter_table_add_index alter_table_drop_index
17 38 );
18  
19 38 our @EXPORT_OK = qw(changed_index);
20  
21 38 __PACKAGE__->mk_diff_accessors(qw/table_name index_name index_info storage/);
22  
23  
24  
25 15 ▶sub changed_index {
Subroutine changed_index: called CC=3 SCAR=11.0
Pod documented
26 15 my ($old, $new) = @_;
27  
28 15 my @changed;
29 15 for my $field (qw/expr type_full granularity/) {
30 45 ▶ push @changed, $field if norm($old->{$field}) ne norm($new->{$field});
Branch: 1 branch
BranchTrueFalseTotal
if norm($old->{$field}) ne norm($new->{$field}) 5 40 45
31 }
32 15 return @changed;
33 }
34  
35  
36 89 ▶sub diff {
Subroutine diff: called CC=5 SCAR=16.5
Pod documented
37 89 my ($class, $source, $target, $source_tables, $target_tables, $storage) = @_;
38 89 ▶ $source ||= {};
Condition50%1/2
$source ||= {}
l!l
890
MC/DC0%0/1
$source ||= {}
$source
Truth table50%1/2
A
A= $source
Aresult
11
00
39 89 ▶ $target ||= {};
Condition50%1/2
$target ||= {}
l!l
890
MC/DC0%0/1
$target ||= {}
$target
Truth table50%1/2
A
A= $target
Aresult
11
00
40  
41 return $class->diff_nested($source, $target,
42 scope => 'both',
43 source_tables => $source_tables || {},
44 target_tables => $target_tables || {},
45 15 ▶ changed_when => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
46 15 my ($old, $new) = @_;
47 15 scalar changed_index($old, $new);
48 },
49 5 ▶ on_new => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
50 5 my ($table_name, $name, $new) = @_;
51 5 $class->new(
52 action => 'add',
53 table_name => $table_name,
54 index_name => $name,
55 index_info => $new,
56 storage => $storage,
57 );
58 },
59 5 ▶ on_changed => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
60 5 my ($table_name, $name, $old, $new) = @_;
61 # No ALTER INDEX in ClickHouse: the old summary has to go before the new
62 # definition can take the name.
63 return (
64 5 $class->new(
65 action => 'drop', table_name => $table_name,
66 index_name => $name, index_info => $old,
67 storage => $storage,
68 ),
69 $class->new(
70 action => 'add', table_name => $table_name,
71 index_name => $name, index_info => $new,
72 storage => $storage,
73 ),
74 );
75 },
76 6 ▶ on_gone => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
77 6 my ($table_name, $name, $old) = @_;
78 6 $class->new(
79 action => 'drop',
80 table_name => $table_name,
81 index_name => $name,
82 index_info => $old,
83 storage => $storage,
84 );
85 },
86 89 ▶ );
Condition50%2/4
$source_tables || {}
l!l
890
$target_tables || {}
l!l
890
MC/DC0%0/1
$source_tables || {}
$source_tables
MC/DC0%0/1
$target_tables || {}
$target_tables
Truth table50%1/2
A
A= $source_tables
Aresult
11
00
Truth table50%1/2
A
A= $target_tables
Aresult
11
00
87 }
88  
89  
90 14 ▶sub as_sql {
Subroutine as_sql: called CC=3 SCAR=11.0
Pod documented
91 14 my ($self) = @_;
92  
93 14 ▶ my $if_guard = DBIO::Diff::Op::should_emit_if_exists($self->storage) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
DBIO::Diff::Op::should_emit_if_exists($self->storage) ? : 3 11 14
94  
95 14 ▶ return alter_table_drop_index(
Branch: 1 branch
BranchTrueFalseTotal
if $self->action eq "drop" 7 7 14
96 table => $self->table_name,
97 name => $self->index_name,
98 if_exists => $if_guard,
99 ) if $self->action eq 'drop';
100  
101 7 return alter_table_add_index(
102 table => $self->table_name,
103 definition => index_def($self->index_info),
104 if_not_exists => $if_guard,
105 );
106 }
107  
108  
109 1 ▶sub summary {
Subroutine summary: called CC=1 SCAR=0.0
Pod documented
110 1 my ($self) = @_;
111 1 return sprintf ' %sskipping index: %s on %s',
112 $self->summary_prefix, $self->index_name, $self->table_name;
113 }
114  
115  
116 38 1;
117  
118 __END__
« ClickHouse/Storage/TxnScopeGuard.pm ↑ Summary ClickHouse/Diff.pm »