ClickHouse/Diff/Column.pm

filter: Statementstmt 99.3% 153 / 154 Branchbran 89.7% 79 / 88 Conditioncond 65.9% 62 / 94 MC/DCmcdc 42.5% 23 / 54 Subroutinesub 100% 28 / 28 Podpod 100% 12 / 12 totaltotal 83.0% 357 / 430 CC 83 SCAR 25.4
CC
83
Cov
88%
lossy
31.4
_sized_info
14.0
as_sql
9.1
CRAP 12.6
« ClickHouse/Result.pm ↑ Summary ClickHouse/Diff/View.pm »
1 package DBIO::ClickHouse::Diff::Column;
2 # ABSTRACT: Diff operations for ClickHouse columns
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(changed_fields column_change_lossy);
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 column_def quote_ident
17 alter_table_add_column alter_table_modify_column alter_table_drop_column
18 alter_table_remove_default
19 38 );
20  
21 38 our @EXPORT_OK = qw(changed_column norm_clickhouse_type is_nullable_type);
22  
23 38 __PACKAGE__->mk_diff_accessors(qw/table_name column_name old_info new_info storage/);
24  
25  
26  
27 412 ▶sub norm_clickhouse_type {
Subroutine norm_clickhouse_type: called CC=2 SCAR=7.0
Pod documented
28 412 my ($type) = @_;
29 412 ▶ return '' unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 412 412
30 412 $type =~ s/\s+/ /g;
31 412 $type =~ s/\A\s+//;
32 412 $type =~ s/\s+\z//;
33 412 return $type;
34 }
35  
36  
37 93 ▶sub changed_column {
Subroutine changed_column: called CC=8 SCAR=20.9
Pod documented
38 93 my ($old, $new) = @_;
39 93 ▶ $old ||= {};
Condition50%1/2
$old ||= {}
l!l
930
MC/DC0%0/1
$old ||= {}
$old
Truth table50%1/2
A
A= $old
Aresult
11
00
40 93 ▶ $new ||= {};
Condition50%1/2
$new ||= {}
l!l
930
MC/DC0%0/1
$new ||= {}
$new
Truth table50%1/2
A
A= $new
Aresult
11
00
41  
42 93 ▶ return () if _is_unmanaged_computed($old, $new);
Branch: 1 branch
BranchTrueFalseTotal
if _is_unmanaged_computed($old, $new) 2 91 93
43  
44 91 my @changed;
45 push @changed, 'data_type'
46 if defined $new->{data_type}
47 91 ▶ && norm_clickhouse_type($old->{data_type}) ne norm_clickhouse_type($new->{data_type});
Branch: 1 branch
BranchTrueFalseTotal
if defined $new->{"data_type"} and norm_clickhouse_type($old->{"data_type"}) ne norm_clickhouse_type($new->{"data_type"}) 15 76 91
Condition66%2/3
defined $new->{"data_type"} and norm_clickhouse_type($old->{"data_type"}) ne norm_clickhouse_type($new->{"data_type"})
!ll&&!rl&&r
07615
MC/DC50%1/2
defined $new->{"data_type"} and norm_clickhouse_type($old->{"data_type"}) ne norm_clickhouse_type($new->{"data_type"})
defined $new->{"data_type"} norm_clickhouse_type($old->{"data_type"}) ne norm_clickhouse_type($new->{"data_type"})
Truth table66%2/3
A and B
A= defined $new->{"data_type"}B= norm_clickhouse_type($old->{"data_type"}) ne norm_clickhouse_type($new->{"data_type"})
ABresult
0X0
100
111
48  
49 91 push @changed, changed_fields($old, $new, scalar => ['default_value']);
50  
51 # Both sides are introspected from a server, so an undef default on the
52 # target is "the schema declares none", not "the schema has no opinion":
53 # the live default is removed (karr k43).
54 push @changed, 'default_value'
55 91 ▶ if !grep({ $_ eq 'default_value' } @changed) && _removes_default($old, $new);
Branch: 1 branch
BranchTrueFalseTotal
if not grep({$_ eq "default_value";} @changed) and _removes_default($old, $new) 2 89 91
Condition100%3/3
not grep({$_ eq "default_value";} @changed) and _removes_default($old, $new)
!ll&&!rl&&r
1882
MC/DC100%2/2
not grep({$_ eq "default_value";} @changed) and _removes_default($old, $new)
not grep({$_ eq "default_value";} @changed) _removes_default($old, $new)
Truth table100%3/3
not(A) and B
A= not grep({$_ eq "default_value";} @changed)B= _removes_default($old, $new)
ABresult
0X0
100
111
56  
57 91 return @changed;
58 }
59  
60  
61 19 ▶sub is_nullable_type {
Subroutine is_nullable_type: called CC=3 SCAR=11.0
Pod documented
62 19 my ($type) = @_;
63 19 ▶ return 0 unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 1 18 19
64 18 ▶ return norm_clickhouse_type($type) =~ /\A(?:LowCardinality\()?Nullable\(/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
norm_clickhouse_type($type) =~ /\A(?:LowCardinality\()?Nullable\(/ ? : 8 10 18
65 }
66  
67 # The live column has a plain DEFAULT, the target none.
68 104 ▶sub _removes_default {
Subroutine _removes_default: called CC=5 SCAR=16.3
69 104 my ($old, $new) = @_;
70 return defined $old->{default_value} && !defined $new->{default_value}
71 104 ▶ && uc($old->{default_kind} // 'DEFAULT') eq 'DEFAULT' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $old->{'default_value'} && !defined($new->{'default_value'}) && uc($old->{'default_kind'} // 'DEFAULT') eq 'DEFAULT' ? : 4 100 104
Condition75%6/8
defined $old->{"default_value"} and not defined $new->{"default_value"} and uc($old->{"default_kind"} // "DEFAULT") eq "DEFAULT"
!ll&&!rl&&r
10004
defined $old->{"default_value"} and not defined $new->{"default_value"}
!ll&&!rl&&r
9464
$old->{"default_kind"} // "DEFAULT"
l!l
40
MC/DC66%2/3
defined $old->{"default_value"} and not defined $new->{"default_value"} and uc($old->{"default_kind"} // "DEFAULT") eq "DEFAULT"
defined $old->{"default_value"} not defined $new->{"default_value"} $old->{"default_kind"}
Truth table75%3/4
A and not(B) and C
A= defined $old->{"default_value"}B= not defined $new->{"default_value"}C= $old->{"default_kind"}
ABCresult
0XX0
10X0
1100
1111
72 }
73  
74 93 ▶sub _is_unmanaged_computed {
Subroutine _is_unmanaged_computed: called CC=4 SCAR=13.9
75 93 my ($old, $new) = @_;
76 93 ▶ my $old_kind = uc($old->{default_kind} // 'DEFAULT');
Condition100%2/2
$old->{"default_kind"} // "DEFAULT"
l!l
687
MC/DC100%1/1
$old->{"default_kind"} // "DEFAULT"
$old->{"default_kind"}
Truth table100%2/2
A
A= $old->{"default_kind"}
Aresult
11
00
77 93 ▶ return 0 if $old_kind eq 'DEFAULT';
Branch: 1 branch
BranchTrueFalseTotal
if $old_kind eq "DEFAULT" 91 2 93
78 2 ▶ return 0 if defined $new->{default_kind};
Branch: 1 branch
BranchTrueFalseTotal
if defined $new->{"default_kind"} 0 2 2
79 2 return 1;
80 }
81  
82  
83 89 ▶sub diff {
Subroutine diff: called CC=1 SCAR=0.0
Pod documented
84 89 my ($class, $source, $target, $source_tables, $target_tables, $storage) = @_;
85  
86 return $class->diff_nested($source, $target,
87 index_by => 'column_name',
88 scope => 'both',
89 source_tables => $source_tables,
90 target_tables => $target_tables,
91 93 ▶ changed_when => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
92 93 my ($old, $new) = @_;
93 93 scalar changed_column($old, $new);
94 },
95 8 ▶ on_new => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
96 8 my ($table_name, $col_name, $new) = @_;
97 8 $class->new(
98 action => 'add',
99 table_name => $table_name,
100 column_name => $col_name,
101 new_info => $new,
102 storage => $storage,
103 );
104 },
105 17 ▶ on_changed => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
106 17 my ($table_name, $col_name, $old, $new) = @_;
107 17 $class->new(
108 action => 'alter',
109 table_name => $table_name,
110 column_name => $col_name,
111 old_info => $old,
112 new_info => $new,
113 storage => $storage,
114 );
115 },
116 4 ▶ on_gone => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
117 4 my ($table_name, $col_name, $old) = @_;
118 4 $class->new(
119 action => 'drop',
120 table_name => $table_name,
121 column_name => $col_name,
122 old_info => $old,
123 storage => $storage,
124 );
125 },
126 89 );
127 }
128  
129  
130 25 ▶sub as_sql {
Subroutine as_sql: called CC=9 SCAR=22.1
Pod documented
131 25 my ($self) = @_;
132  
133 25 ▶ 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) ? : 4 21 25
134  
135 25 ▶ return alter_table_drop_column(
Branch: 1 branch
BranchTrueFalseTotal
if $self->action eq "drop" 4 21 25
136 table => $self->table_name,
137 name => $self->column_name,
138 if_exists => $if_guard,
139 ) if $self->action eq 'drop';
140  
141 21 ▶ my $info = $self->new_info // {};
Condition50%1/2
$self->new_info // {}
l!l
210
MC/DC0%0/1
$self->new_info // {}
$self->new_info
Truth table50%1/2
A
A= $self->new_info
Aresult
11
00
142 my $def = column_def(
143 name => $self->column_name,
144 type => ($info->{data_type} // 'String'),
145 default => $info->{default_value}
146 21 ▶ );
Condition50%1/2
$info->{"data_type"} // "String"
l!l
210
MC/DC0%0/1
$info->{"data_type"} // "String"
$info->{"data_type"}
Truth table50%1/2
A
A= $info->{"data_type"}
Aresult
11
00
147  
148 21 ▶ return alter_table_add_column(
Branch: 1 branch
BranchTrueFalseTotal
if $self->action eq "add" 7 14 21
149 table => $self->table_name,
150 definition => $def,
151 if_not_exists => $if_guard,
152 ) if $self->action eq 'add';
153  
154 # A default the schema no longer declares goes first, so the old expression
155 # is not checked against the new type; a type change follows as a statement
156 # of its own (REMOVE DEFAULT takes no type beside it).
157 14 ▶ if ($self->removes_default) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->removes_default) 2 12 14
158 2 my @sql = alter_table_remove_default(table => $self->table_name, name => $self->column_name);
159 push @sql, alter_table_modify_column(table => $self->table_name, definition => $def)
160 if norm_clickhouse_type(($self->old_info // {})->{data_type})
161 2 ▶ ne norm_clickhouse_type($info->{data_type});
Branch: 1 branch
BranchTrueFalseTotal
if norm_clickhouse_type(+($self->old_info // {})->{"data_type"}) ne norm_clickhouse_type($info->{"data_type"}) 1 1 2
Condition50%1/2
$self->old_info // {}
l!l
20
MC/DC0%0/1
$self->old_info // {}
$self->old_info
Truth table50%1/2
A
A= $self->old_info
Aresult
11
00
162 2 return join "\n", @sql;
163 }
164  
165 # MODIFY COLUMN does not accept the flag: ClickHouse has no such guard
166 # (t/38), and alter_table_modify_column in Emit croaks if the flag is
167 # passed. The capability helper returns 1 here for the same storage, but
168 # the alter_table_modify_column path ignores storage entirely -- that is
169 # by design, not a leak.
170 12 return alter_table_modify_column(table => $self->table_name, definition => $def);
171 }
172  
173  
174 14 ▶sub removes_default {
Subroutine removes_default: called CC=4 SCAR=15.2
Pod documented
175 14 my ($self) = @_;
176 14 ▶ return 0 unless $self->action eq 'alter';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->action eq "alter" 0 14 14
177 14 ▶ return _removes_default($self->old_info // {}, $self->new_info // {});
Condition50%2/4
$self->old_info // {}
l!l
140
$self->new_info // {}
l!l
140
MC/DC0%0/1
$self->old_info // {}
$self->old_info
MC/DC0%0/1
$self->new_info // {}
$self->new_info
Truth table50%1/2
A
A= $self->old_info
Aresult
11
00
Truth table50%1/2
A
A= $self->new_info
Aresult
11
00
178 }
179  
180  
181 38 our %LOSSLESS_PAIRS;
182 {
183 38 for my $ladder ([qw(int8 int16 int32 int64 int128 int256)],
184 [qw(uint8 uint16 uint32 uint64 uint128 uint256)]) {
185 76 for my $from (0 .. $#$ladder - 1) {
186 380 $LOSSLESS_PAIRS{"$ladder->[$from]->$ladder->[$_]"} = 1 for $from + 1 .. $#$ladder;
187 }
188 }
189 38 $LOSSLESS_PAIRS{'date->date32'} = 1;
190 38 $LOSSLESS_PAIRS{'datetime->datetime64'} = 1;
191 38 $LOSSLESS_PAIRS{'enum8->enum16'} = 1;
192 }
193  
194 38 my %DECIMAL_PRECISION = (decimal32 => 9, decimal64 => 18, decimal128 => 38, decimal256 => 76);
195  
196 # The parts of a native type string: wrappers off, base name, the parameters.
197 102 ▶sub _parse_type {
Subroutine _parse_type: called CC=3 SCAR=11.0
198 102 my ($type) = @_;
199 102 my $t = norm_clickhouse_type($type);
200 102 my %p = (nullable => 0, raw => $t);
201 102 ▶ while ($t =~ /\A(LowCardinality|Nullable)\((.*)\)\z/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t =~ /\A(LowCardinality|Nullable)\((.*)\)\z/s) 12 102 114
202 12 $p{ lc $1 } = 1;
203 12 $t = $2;
204 }
205 102 $p{inner} = $t;
206 102 ▶ my ($name, $args) = $t =~ /\A(\w+)(?:\((.*)\))?\z/s ? ($1, $2) : ($t, undef);
Branch: 1 branch
BranchTrueFalseTotal
$t =~ /\A(\w+)(?:\((.*)\))?\z/s ? : 102 0 102
207 102 @p{qw(name args)} = (lc $name, $args);
208 102 return \%p;
209 }
210  
211 # The info as column_change_lossy reads it, or undef for a type whose
212 # parameters are not understood (they must then be equal).
213 78 ▶sub _sized_info {
Subroutine _sized_info: called CC=13 SCAR=26.4
214 78 my ($p) = @_;
215 78 my ($name, $args) = @{$p}{qw(name args)};
216 78 ▶ return { data_type => $name } unless defined $args;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args 50 28 78
217  
218 28 ▶ if ($name eq 'decimal' && $args =~ /\A\s*(\d+)\s*,\s*(\d+)\s*\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "decimal" and $args =~ /\A\s*(\d+)\s*,\s*(\d+)\s*\z/) 7 21 28
Condition66%2/3
$name eq "decimal" and $args =~ /\A\s*(\d+)\s*,\s*(\d+)\s*\z/
!ll&&!rl&&r
2107
MC/DC50%1/2
$name eq "decimal" and $args =~ /\A\s*(\d+)\s*,\s*(\d+)\s*\z/
$name eq "decimal" $args =~ /\A\s*(\d+)\s*,\s*(\d+)\s*\z/
Truth table66%2/3
A and B
A= $name eq "decimal"B= $args =~ /\A\s*(\d+)\s*,\s*(\d+)\s*\z/
ABresult
0X0
100
111
219 7 return { data_type => 'decimal', size => [ $1, $2 ] };
220 }
221 21 ▶ if ($DECIMAL_PRECISION{$name} && $args =~ /\A\s*(\d+)\s*\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DECIMAL_PRECISION{$name} and $args =~ /\A\s*(\d+)\s*\z/) 2 19 21
Condition66%2/3
$DECIMAL_PRECISION{$name} and $args =~ /\A\s*(\d+)\s*\z/
!ll&&!rl&&r
1902
MC/DC50%1/2
$DECIMAL_PRECISION{$name} and $args =~ /\A\s*(\d+)\s*\z/
$DECIMAL_PRECISION{$name} $args =~ /\A\s*(\d+)\s*\z/
Truth table66%2/3
A and B
A= $DECIMAL_PRECISION{$name}B= $args =~ /\A\s*(\d+)\s*\z/
ABresult
0X0
100
111
222 2 return { data_type => 'decimal', size => [ $DECIMAL_PRECISION{$name}, $1 ] };
223 }
224 19 ▶ if ($name eq 'fixedstring' && $args =~ /\A\s*(\d+)\s*\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "fixedstring" and $args =~ /\A\s*(\d+)\s*\z/) 6 13 19
Condition66%2/3
$name eq "fixedstring" and $args =~ /\A\s*(\d+)\s*\z/
!ll&&!rl&&r
1306
MC/DC50%1/2
$name eq "fixedstring" and $args =~ /\A\s*(\d+)\s*\z/
$name eq "fixedstring" $args =~ /\A\s*(\d+)\s*\z/
Truth table66%2/3
A and B
A= $name eq "fixedstring"B= $args =~ /\A\s*(\d+)\s*\z/
ABresult
0X0
100
111
225 6 return { data_type => $name, size => $1 };
226 }
227 13 ▶ if ($name eq 'datetime64' && $args =~ /\A\s*(\d+)\s*(?:,\s*'((?:[^'\\]|\\.)*)')?\s*\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "datetime64" and $args =~ /\A\s*(\d+)\s*(?:,\s*'((?:[^'\\]|\\.)*)')?\s*\z/) 9 4 13
Condition66%2/3
$name eq "datetime64" and $args =~ /\A\s*(\d+)\s*(?:,\s*'((?:[^'\\]|\\.)*)')?\s*\z/
!ll&&!rl&&r
409
MC/DC50%1/2
$name eq "datetime64" and $args =~ /\A\s*(\d+)\s*(?:,\s*'((?:[^'\\]|\\.)*)')?\s*\z/
$name eq "datetime64" $args =~ /\A\s*(\d+)\s*(?:,\s*'((?:[^'\\]|\\.)*)')?\s*\z/
Truth table66%2/3
A and B
A= $name eq "datetime64"B= $args =~ /\A\s*(\d+)\s*(?:,\s*'((?:[^'\\]|\\.)*)')?\s*\z/
ABresult
0X0
100
111
228 9 ▶ return { data_type => $name, size => $1, tz => $2 // '' };
Condition100%2/2
$2 // ""
l!l
45
MC/DC100%1/1
$2 // ""
$2
Truth table100%2/2
A
A= $2
Aresult
11
00
229 }
230 4 ▶ if ($name eq 'datetime' && $args =~ /\A\s*'((?:[^'\\]|\\.)*)'\s*\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "datetime" and $args =~ /\A\s*'((?:[^'\\]|\\.)*)'\s*\z/) 0 4 4
Condition33%1/3
$name eq "datetime" and $args =~ /\A\s*'((?:[^'\\]|\\.)*)'\s*\z/
!ll&&!rl&&r
400
MC/DC0%0/2
$name eq "datetime" and $args =~ /\A\s*'((?:[^'\\]|\\.)*)'\s*\z/
$name eq "datetime" $args =~ /\A\s*'((?:[^'\\]|\\.)*)'\s*\z/
Truth table33%1/3
A and B
A= $name eq "datetime"B= $args =~ /\A\s*'((?:[^'\\]|\\.)*)'\s*\z/
ABresult
0X0
100
111
231 0 return { data_type => $name, tz => $1 };
232 }
233 4 return undef;
234 }
235  
236 8 ▶sub _enum_elements {
Subroutine _enum_elements: called CC=2 SCAR=6.9
237 8 my ($args) = @_;
238 8 my @el;
239 8 ▶ while ($args =~ /'((?:[^'\\]|\\.)*)'\s*=\s*(-?\d+)/g) { push @el, [ $1, $2 ] }
Branch: 1 branch
BranchTrueFalseTotal
if ($args =~ /'((?:[^'\\]|\\.)*)'\s*=\s*(-?\d+)/g) 15 8 23
240 8 return \@el;
241 }
242  
243  
244 60 ▶sub lossy {
Subroutine lossy: called CC=28 SCAR=34.5
Pod documented
245 60 my ($self) = @_;
246 60 ▶ return 0 unless $self->action eq 'alter';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->action eq "alter" 7 53 60
247 53 ▶ my ($old, $new) = ($self->old_info // {}, $self->new_info // {});
Condition50%2/4
$self->old_info // {}
l!l
530
$self->new_info // {}
l!l
530
MC/DC0%0/1
$self->old_info // {}
$self->old_info
MC/DC0%0/1
$self->new_info // {}
$self->new_info
Truth table50%1/2
A
A= $self->old_info
Aresult
11
00
Truth table50%1/2
A
A= $self->new_info
Aresult
11
00
248  
249 # a target without a type prescribes none
250 53 ▶ return 0 unless defined $new->{data_type};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $new->{"data_type"} 0 53 53
251 53 ▶ return 0 if norm_clickhouse_type($old->{data_type}) eq norm_clickhouse_type($new->{data_type});
Branch: 1 branch
BranchTrueFalseTotal
if norm_clickhouse_type($old->{"data_type"}) eq norm_clickhouse_type($new->{"data_type"}) 2 51 53
252  
253 51 my ($po, $pn) = (_parse_type($old->{data_type}), _parse_type($new->{data_type}));
254 51 ▶ return 1 if $po->{nullable} && !$pn->{nullable};
Branch: 1 branch
BranchTrueFalseTotal
if $po->{"nullable"} and not $pn->{"nullable"} 3 48 51
Condition100%3/3
$po->{"nullable"} and not $pn->{"nullable"}
!ll&&!rl&&r
4623
MC/DC100%2/2
$po->{"nullable"} and not $pn->{"nullable"}
$po->{"nullable"} not $pn->{"nullable"}
Truth table100%3/3
A and not(B)
A= $po->{"nullable"}B= not $pn->{"nullable"}
ABresult
0X0
100
111
255  
256 # the same base type with the same spelling: only the wrappers changed
257 48 ▶ return 0 if $po->{inner} eq $pn->{inner};
Branch: 1 branch
BranchTrueFalseTotal
if $po->{"inner"} eq $pn->{"inner"} 4 44 48
258  
259 44 ▶ if ($po->{name} =~ /\Aenum(?:8|16)\z/ || $pn->{name} =~ /\Aenum(?:8|16)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($po->{"name"} =~ /\Aenum(?:8|16)\z/ or $pn->{"name"} =~ /\Aenum(?:8|16)\z/) 5 39 44
Condition66%2/3
$po->{"name"} =~ /\Aenum(?:8|16)\z/ or $pn->{"name"} =~ /\Aenum(?:8|16)\z/
l!l&&r!l&&!r
5039
MC/DC50%1/2
$po->{"name"} =~ /\Aenum(?:8|16)\z/ or $pn->{"name"} =~ /\Aenum(?:8|16)\z/
$po->{"name"} =~ /\Aenum(?:8|16)\z/ $pn->{"name"} =~ /\Aenum(?:8|16)\z/
Truth table66%2/3
A or B
A= $po->{"name"} =~ /\Aenum(?:8|16)\z/B= $pn->{"name"} =~ /\Aenum(?:8|16)\z/
ABresult
1X1
011
000
260 5 ▶ return 1 unless $po->{name} =~ /\Aenum(?:8|16)\z/ && $pn->{name} =~ /\Aenum(?:8|16)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $po->{"name"} =~ /\Aenum(?:8|16)\z/ and $pn->{"name"} =~ /\Aenum(?:8|16)\z/ 0 5 5
Condition33%1/3
$po->{"name"} =~ /\Aenum(?:8|16)\z/ and $pn->{"name"} =~ /\Aenum(?:8|16)\z/
!ll&&!rl&&r
005
MC/DC0%0/2
$po->{"name"} =~ /\Aenum(?:8|16)\z/ and $pn->{"name"} =~ /\Aenum(?:8|16)\z/
$po->{"name"} =~ /\Aenum(?:8|16)\z/ $pn->{"name"} =~ /\Aenum(?:8|16)\z/
Truth table33%1/3
A and B
A= $po->{"name"} =~ /\Aenum(?:8|16)\z/B= $pn->{"name"} =~ /\Aenum(?:8|16)\z/
ABresult
0X0
100
111
261 5 ▶ return 1 if $po->{name} eq 'enum16' && $pn->{name} eq 'enum8';
Branch: 1 branch
BranchTrueFalseTotal
if $po->{"name"} eq "enum16" and $pn->{"name"} eq "enum8" 1 4 5
Condition66%2/3
$po->{"name"} eq "enum16" and $pn->{"name"} eq "enum8"
!ll&&!rl&&r
401
MC/DC50%1/2
$po->{"name"} eq "enum16" and $pn->{"name"} eq "enum8"
$po->{"name"} eq "enum16" $pn->{"name"} eq "enum8"
Truth table66%2/3
A and B
A= $po->{"name"} eq "enum16"B= $pn->{"name"} eq "enum8"
ABresult
0X0
100
111
262 4 ▶ my @was = @{ _enum_elements($po->{args} // '') };
Condition50%1/2
$po->{"args"} // ""
l!l
40
MC/DC0%0/1
$po->{"args"} // ""
$po->{"args"}
Truth table50%1/2
A
A= $po->{"args"}
Aresult
11
00
263 4 ▶ my %now = map { ($_->[0] => $_->[1]) } @{ _enum_elements($pn->{args} // '') };
Condition50%1/2
$pn->{"args"} // ""
l!l
40
MC/DC0%0/1
$pn->{"args"} // ""
$pn->{"args"}
Truth table50%1/2
A
A= $pn->{"args"}
Aresult
11
00
264 4 ▶ return 1 unless @was;
Branch: 1 branch
BranchTrueFalseTotal
unless @was 0 4 4
265 4 ▶ return 1 if grep { !defined $now{ $_->[0] } || $now{ $_->[0] } != $_->[1] } @was;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $now{$_->[0]} or $now{$_->[0]} != $_->[1];} @was 2 2 4
Condition100%3/3
!defined($now{$_->[0]}) || $now{$_->[0]} != $_->[1]
l!l&&r!l&&!r
124
MC/DC100%2/2
!defined($now{$_->[0]}) || $now{$_->[0]} != $_->[1]
!defined($now{$_->[0]}) $now{$_->[0]} != $_->[1]
Truth table100%3/3
not(A) || B
A= !defined($now{$_->[0]})B= $now{$_->[0]} != $_->[1]
ABresult
1X1
011
000
266 2 return 0;
267 }
268  
269 39 my ($io, $in) = (_sized_info($po), _sized_info($pn));
270 # compound types and the like: only a change of wrappers is known to be safe
271 39 ▶ return 1 unless $io && $in;
Branch: 1 branch
BranchTrueFalseTotal
unless $io and $in 2 37 39
Condition66%2/3
$io and $in
!ll&&!rl&&r
2037
MC/DC50%1/2
$io and $in
$io $in
Truth table66%2/3
A and B
A= $ioB= $in
ABresult
0X0
100
111
272  
273 37 ▶ if ($io->{data_type} =~ /\Adatetime(?:64)?\z/ && $in->{data_type} =~ /\Adatetime(?:64)?\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($io->{"data_type"} =~ /\Adatetime(?:64)?\z/ and $in->{"data_type"} =~ /\Adatetime(?:64)?\z/) 5 32 37
Condition66%2/3
$io->{"data_type"} =~ /\Adatetime(?:64)?\z/ and $in->{"data_type"} =~ /\Adatetime(?:64)?\z/
!ll&&!rl&&r
3205
MC/DC50%1/2
$io->{"data_type"} =~ /\Adatetime(?:64)?\z/ and $in->{"data_type"} =~ /\Adatetime(?:64)?\z/
$io->{"data_type"} =~ /\Adatetime(?:64)?\z/ $in->{"data_type"} =~ /\Adatetime(?:64)?\z/
Truth table66%2/3
A and B
A= $io->{"data_type"} =~ /\Adatetime(?:64)?\z/B= $in->{"data_type"} =~ /\Adatetime(?:64)?\z/
ABresult
0X0
100
111
274 5 ▶ return 1 if ($io->{tz} // '') ne ($in->{tz} // '');
Branch: 1 branch
BranchTrueFalseTotal
if ($io->{"tz"} // "") ne ($in->{"tz"} // "") 1 4 5
Condition75%3/4
$io->{"tz"} // ""
l!l
41
$in->{"tz"} // ""
l!l
50
MC/DC100%1/1
$io->{"tz"} // ""
$io->{"tz"}
MC/DC0%0/1
$in->{"tz"} // ""
$in->{"tz"}
Truth table100%2/2
A
A= $io->{"tz"}
Aresult
11
00
Truth table50%1/2
A
A= $in->{"tz"}
Aresult
11
00
275 }
276  
277 36 ▶ return column_change_lossy($io, $in, \%LOSSLESS_PAIRS) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
column_change_lossy($io, $in, \%DBIO::ClickHouse::Diff::Column::LOSSLESS_PAIRS) ? : 20 16 36
278 }
279  
280  
281 10 ▶sub needs_row_check {
Subroutine needs_row_check: called CC=6 SCAR=18.0
Pod documented
282 10 my ($self) = @_;
283 10 ▶ return 0 unless $self->action eq 'add';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->action eq "add" 4 6 10
284 6 ▶ my $info = $self->new_info // {};
Condition50%1/2
$self->new_info // {}
l!l
60
MC/DC0%0/1
$self->new_info // {}
$self->new_info
Truth table50%1/2
A
A= $self->new_info
Aresult
11
00
285 6 ▶ return 0 if defined $info->{default_value} || defined $info->{default_kind};
Branch: 1 branch
BranchTrueFalseTotal
if defined $info->{"default_value"} or defined $info->{"default_kind"} 2 4 6
Condition66%2/3
defined $info->{"default_value"} or defined $info->{"default_kind"}
l!l&&r!l&&!r
204
MC/DC50%1/2
defined $info->{"default_value"} or defined $info->{"default_kind"}
defined $info->{"default_value"} defined $info->{"default_kind"}
Truth table66%2/3
A or B
A= defined $info->{"default_value"}B= defined $info->{"default_kind"}
ABresult
1X1
011
000
286 4 ▶ return is_nullable_type($info->{data_type}) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
is_nullable_type($info->{'data_type'}) ? : 1 3 4
287 }
288  
289  
290 3 ▶sub row_check_sql {
Subroutine row_check_sql: called CC=1 SCAR=0.0
Pod documented
291 3 my ($self) = @_;
292 3 return sprintf 'SELECT 1 FROM %s LIMIT 1', quote_ident($self->table_name);
293 }
294  
295  
296 11 ▶sub needs_null_check {
Subroutine needs_null_check: called CC=6 SCAR=18.1
Pod documented
297 11 my ($self) = @_;
298 11 ▶ return 0 unless $self->action eq 'alter';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->action eq "alter" 5 6 11
299 return is_nullable_type(($self->old_info // {})->{data_type})
300 6 ▶ && !is_nullable_type(($self->new_info // {})->{data_type}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
is_nullable_type(+($self->old_info // {})->{'data_type'}) && !is_nullable_type(+($self->new_info // {})->{'data_type'}) ? : 3 3 6
Condition71%5/7
is_nullable_type(+($self->old_info // {})->{"data_type"}) and not is_nullable_type(+($self->new_info // {})->{"data_type"})
!ll&&!rl&&r
213
$self->old_info // {}
l!l
60
$self->new_info // {}
l!l
40
MC/DC100%2/2
is_nullable_type(+($self->old_info // {})->{"data_type"}) and not is_nullable_type(+($self->new_info // {})->{"data_type"})
is_nullable_type(+($self->old_info // {})->{"data_type"}) not is_nullable_type(+($self->new_info // {})->{"data_type"})
MC/DC0%0/1
$self->old_info // {}
$self->old_info
MC/DC0%0/1
$self->new_info // {}
$self->new_info
Truth table100%3/3
A and not(B)
A= is_nullable_type(+($self->old_info // {})->{"data_type"})B= not is_nullable_type(+($self->new_info // {})->{"data_type"})
ABresult
0X0
100
111
Truth table50%1/2
A
A= $self->old_info
Aresult
11
00
Truth table50%1/2
A
A= $self->new_info
Aresult
11
00
301 }
302  
303  
304 3 ▶sub null_check_sql {
Subroutine null_check_sql: called CC=1 SCAR=0.0
Pod documented
305 3 my ($self) = @_;
306 3 return sprintf 'SELECT count() FROM %s WHERE %s IS NULL',
307 quote_ident($self->table_name), quote_ident($self->column_name);
308 }
309  
310  
311 4 ▶sub summary {
Subroutine summary: called CC=3 SCAR=11.7
Pod documented
312 4 my ($self) = @_;
313 4 ▶ my $type = $self->new_info ? sprintf(' (%s)', $self->new_info->{data_type} // '') : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->new_info ? : 4 0 4
Condition50%1/2
$self->new_info->{"data_type"} // ""
l!l
40
MC/DC0%0/1
$self->new_info->{"data_type"} // ""
$self->new_info->{"data_type"}
Truth table50%1/2
A
A= $self->new_info->{"data_type"}
Aresult
11
00
314 4 return sprintf ' %scolumn: %s.%s%s',
315 $self->summary_prefix, $self->table_name, $self->column_name, $type;
316 }
317  
318  
319 38 1;
320  
321 __END__
« ClickHouse/Result.pm ↑ Summary ClickHouse/Diff/View.pm »