| 1 | package DBIO::ClickHouse::Test::Conformance; | ||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Answers the shared conformance case table for the ClickHouse driver | ||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 4 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use base 'DBIO::Test::Conformance'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use DBI (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use DBIO::Exception (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use DBIO::ClickHouse::Introspect (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use DBIO::ClickHouse::Deploy (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use DBIO::ClickHouse::DDL (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use DBIO::ClickHouse::DDL::Emit qw(create_database drop_database split_table_name quote_ident); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 4 | my $SEQ = 0; | |||||||||||||||||||||||||||||||
| 20 | # schema class => the name of its case's database | ||||||||||||||||||||||||||||||||
| 21 | 4 | my %NAMESPACE; | |||||||||||||||||||||||||||||||
| 22 | # schema class => 1 when this run created the database | ||||||||||||||||||||||||||||||||
| 23 | my %CREATED; | ||||||||||||||||||||||||||||||||
| 24 | # schema class => { 'database.table' => 1 }: the tables this run made in other databases | ||||||||||||||||||||||||||||||||
| 25 | 4 | my %QUALIFIED; | |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub _env { $ENV{"DBIO_TEST_CLICKHOUSE_$_[0]"} // '' } | ||||||||||||||||||||||||||||||
|
Subroutine
_env: not called CC=2 SCAR=17.9
Condition0%0/2
$ENV{"DBIO_TEST_CLICKHOUSE_$_[0]"} // ""
MC/DC0%0/1
$ENV{"DBIO_TEST_CLICKHOUSE_$_[0]"} // ""
$ENV{"DBIO_TEST_CLICKHOUSE_$_[0]"}
Truth table0%0/2
A
A= $ENV{"DBIO_TEST_CLICKHOUSE_$_[0]"}
| |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | # The DSN of the case: the one of the environment, naming the database of the | ||||||||||||||||||||||||||||||||
| 30 | # case. | ||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub _case_dsn { | ||||||||||||||||||||||||||||||
|
Subroutine
_case_dsn: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 32 | 0 | my ($name) = @_; | |||||||||||||||||||||||||||||||
| 33 | 0 | my $dsn = $ENV{DBIO_TEST_CLICKHOUSE_DSN}; | |||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | $dsn =~ s/\b(?:database|dbname)=[^;]*/database=$name/i | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 35 | or $dsn .= ";database=$name"; | ||||||||||||||||||||||||||||||||
| 36 | 0 | return $dsn; | |||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub _attrs { | ||||||||||||||||||||||||||||||
|
Subroutine
_attrs: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 40 | 0 | my ($dsn) = @_; | |||||||||||||||||||||||||||||||
| 41 | 0 | my %attrs = ( AutoCommit => 1, RaiseError => 1, PrintError => 0, PrintWarn => 0 ); | |||||||||||||||||||||||||||||||
| 42 | # DBD::mysql hands text back as bytes unless asked; DBD::MariaDB decodes | ||||||||||||||||||||||||||||||||
| 43 | # unconditionally and refuses the attribute (see DBIO::ClickHouse::Test). | ||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $attrs{mysql_enable_utf8mb4} = 1 if $dsn =~ /\Adbi:mysql:/i; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 45 | 0 | return \%attrs; | |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | # A connection of its own to the database named in the DSN, for the statements | ||||||||||||||||||||||||||||||||
| 49 | # that create and drop the database of a case. | ||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub _admin_connect { | ||||||||||||||||||||||||||||||
|
Subroutine
_admin_connect: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 51 | return DBI->connect($ENV{DBIO_TEST_CLICKHOUSE_DSN}, | ||||||||||||||||||||||||||||||||
| 52 | 0 | _env('DBUSER'), _env('DBPASS'), _attrs($ENV{DBIO_TEST_CLICKHOUSE_DSN})); | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 3 | ▶ | sub conformance_live_available { | ||||||||||||||||||||||||||||||
|
Subroutine
conformance_live_available: called CC=4 SCAR=22.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 57 | 3 | ▶ | my ($driver) = ($ENV{DBIO_TEST_CLICKHOUSE_DSN} // '') =~ /\Adbi:(\w+):/i | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$ENV{"DBIO_TEST_CLICKHOUSE_DSN"} // ""
MC/DC0%0/1
$ENV{"DBIO_TEST_CLICKHOUSE_DSN"} // ""
$ENV{"DBIO_TEST_CLICKHOUSE_DSN"}
Truth table50%1/2
A
A= $ENV{"DBIO_TEST_CLICKHOUSE_DSN"}
| |||||||||||||||||||||||||||||||||
| 58 | or return 0; | ||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | return eval { require "DBD/$driver.pm"; 1 } ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub conformance_connect { | ||||||||||||||||||||||||||||||
|
Subroutine
conformance_connect: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 64 | 0 | my ($class, $schema_class) = @_; | |||||||||||||||||||||||||||||||
| 65 | 0 | my $name = sprintf 'dbio_cf_%d_%d', $$, ++$SEQ; | |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 0 | my $admin = _admin_connect(); | |||||||||||||||||||||||||||||||
| 68 | 0 | $admin->do(create_database(name => $name)); | |||||||||||||||||||||||||||||||
| 69 | 0 | $admin->disconnect; | |||||||||||||||||||||||||||||||
| 70 | 0 | $NAMESPACE{$schema_class} = $name; | |||||||||||||||||||||||||||||||
| 71 | 0 | $CREATED{$schema_class} = 1; | |||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 0 | $schema_class->load_components('ClickHouse'); | |||||||||||||||||||||||||||||||
| 74 | 0 | my $dsn = _case_dsn($name); | |||||||||||||||||||||||||||||||
| 75 | 0 | return $schema_class->connect($dsn, _env('DBUSER'), _env('DBPASS'), _attrs($dsn)); | |||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub _namespace_of { | ||||||||||||||||||||||||||||||
|
Subroutine
_namespace_of: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 79 | 0 | my ($class, $schema) = @_; | |||||||||||||||||||||||||||||||
| 80 | 0 | my $name = $NAMESPACE{ ref $schema }; | |||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | DBIO::Exception->throw('conformance: this schema was not connected through ' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 82 | . 'conformance_connect') unless defined $name; | ||||||||||||||||||||||||||||||||
| 83 | 0 | return $name; | |||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub conformance_namespace { | ||||||||||||||||||||||||||||||
|
Subroutine
conformance_namespace: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 88 | 0 | my ($class, $schema, $case) = @_; | |||||||||||||||||||||||||||||||
| 89 | 0 | my $name = $class->_namespace_of($schema); | |||||||||||||||||||||||||||||||
| 90 | 0 | my ($n) = $schema->storage->dbh->selectrow_array( | |||||||||||||||||||||||||||||||
| 91 | 'SELECT count() FROM system.tables WHERE database = ?', undef, $name); | ||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | DBIO::Exception->throw("conformance: the database '$name' is not empty") | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 93 | if $n; | ||||||||||||||||||||||||||||||||
| 94 | 0 | return { name => $name }; | |||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub conformance_install { | ||||||||||||||||||||||||||||||
|
Subroutine
conformance_install: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 99 | 0 | my ($class, $schema, $case) = @_; | |||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | 0 | my @qualified = DBIO::ClickHouse::DDL->qualified_tables($schema); | |||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if (@qualified) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 103 | 0 | my $dbh = _admin_connect(); | |||||||||||||||||||||||||||||||
| 104 | 0 | for my $pair (@qualified) { | |||||||||||||||||||||||||||||||
| 105 | 0 | my ($table, $database) = @$pair; | |||||||||||||||||||||||||||||||
| 106 | 0 | my (undef, $short) = split_table_name($table); | |||||||||||||||||||||||||||||||
| 107 | 0 | my ($there) = $dbh->selectrow_array( | |||||||||||||||||||||||||||||||
| 108 | 'SELECT count() FROM system.tables WHERE database = ? AND name = ?', | ||||||||||||||||||||||||||||||||
| 109 | undef, $database, $short); | ||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | DBIO::Exception->throw("conformance: the table '$table' is on the server " | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 111 | . 'already; it is not the run\'s to use or drop') if $there; | ||||||||||||||||||||||||||||||||
| 112 | 0 | $QUALIFIED{ ref $schema }{$table} = 1; | |||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||
| 114 | 0 | $dbh->disconnect; | |||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | 0 | DBIO::ClickHouse::Deploy->new(schema => $schema)->install; | |||||||||||||||||||||||||||||||
| 118 | 0 | return; | |||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub conformance_cleanup { | ||||||||||||||||||||||||||||||
|
Subroutine
conformance_cleanup: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 123 | 0 | my ($class, $schema, $case, $namespace) = @_; | |||||||||||||||||||||||||||||||
| 124 | 0 | my $created = delete $CREATED{ ref $schema }; | |||||||||||||||||||||||||||||||
| 125 | 0 | my $name = delete $NAMESPACE{ ref $schema }; | |||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | my $qualified = delete $QUALIFIED{ ref $schema } || {}; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $QUALIFIED{ref $schema} || {}
MC/DC0%0/1
delete $QUALIFIED{ref $schema} || {}
delete $QUALIFIED{ref $schema}
Truth table0%0/2
A
A= delete $QUALIFIED{ref $schema}
| |||||||||||||||||||||||||||||||||
| 127 | 0 | eval { $schema->storage->disconnect }; | |||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if (my @tables = sort keys %$qualified) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 130 | 0 | my $dbh = _admin_connect(); | |||||||||||||||||||||||||||||||
| 131 | 0 | for my $table (@tables) { | |||||||||||||||||||||||||||||||
| 132 | 0 | my ($database, $short) = split_table_name($table); | |||||||||||||||||||||||||||||||
| 133 | 0 | $dbh->do('DROP TABLE IF EXISTS ' . quote_ident($database) . '.' . quote_ident($short)); | |||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||
| 135 | 0 | $dbh->disconnect; | |||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if ($created && defined $name) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$created and defined $name
MC/DC0%0/2
$created and defined $name
$created
defined $name
Truth table0%0/3
A and B
A= $createdB= defined $name
| |||||||||||||||||||||||||||||||||
| 139 | 0 | my $dbh = _admin_connect(); | |||||||||||||||||||||||||||||||
| 140 | 0 | $dbh->do(drop_database(name => $name, if_exists => 1)); | |||||||||||||||||||||||||||||||
| 141 | 0 | $dbh->disconnect; | |||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||
| 143 | 0 | return; | |||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub conformance_diff_is_empty { | ||||||||||||||||||||||||||||||
|
Subroutine
conformance_diff_is_empty: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 148 | 0 | my ($class, $schema, $case) = @_; | |||||||||||||||||||||||||||||||
| 149 | 0 | my $diff = DBIO::ClickHouse::Deploy->new(schema => $schema)->diff; | |||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | return $diff->has_changes ? 0 : 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | sub conformance_upgrade { | ||||||||||||||||||||||||||||||
|
Subroutine
conformance_upgrade: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 155 | 0 | my ($class, $schema, $to_class, $case) = @_; | |||||||||||||||||||||||||||||||
| 156 | 0 | my $name = $class->_namespace_of($schema); | |||||||||||||||||||||||||||||||
| 157 | 0 | my $to = $class->_connect_target($to_class, $name); | |||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | 0 | my $ok = eval { DBIO::ClickHouse::Deploy->new(schema => $to)->upgrade(allow_destructive => 1); 1 }; | |||||||||||||||||||||||||||||||
| 160 | 0 | my $err = $@; | |||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | unless ($ok) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 162 | 0 | eval { $to->storage->disconnect }; | |||||||||||||||||||||||||||||||
| 163 | 0 | die $err; | |||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | 0 | $class->_hand_over_namespace($schema, $to_class, $name); | |||||||||||||||||||||||||||||||
| 167 | 0 | return $to; | |||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub conformance_deploy { | ||||||||||||||||||||||||||||||
|
Subroutine
conformance_deploy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 172 | 0 | my ($class, $schema, $to_class, $case) = @_; | |||||||||||||||||||||||||||||||
| 173 | 0 | my $name = $class->_namespace_of($schema); | |||||||||||||||||||||||||||||||
| 174 | 0 | my $to = $class->_connect_target($to_class, $name); | |||||||||||||||||||||||||||||||
| 175 | 0 | $class->_hand_over_namespace($schema, $to_class, $name); | |||||||||||||||||||||||||||||||
| 176 | 0 | return DBIO::ClickHouse::Deploy->new(schema => $to); | |||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | # The target class, connected to the database of the installed schema. | ||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | sub _connect_target { | ||||||||||||||||||||||||||||||
|
Subroutine
_connect_target: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 181 | 0 | my ($class, $to_class, $name) = @_; | |||||||||||||||||||||||||||||||
| 182 | 0 | $to_class->load_components('ClickHouse'); | |||||||||||||||||||||||||||||||
| 183 | 0 | my $dsn = _case_dsn($name); | |||||||||||||||||||||||||||||||
| 184 | 0 | return $to_class->connect($dsn, _env('DBUSER'), _env('DBPASS'), _attrs($dsn)); | |||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | # The database now belongs to the target's class: the runner cleans up through | ||||||||||||||||||||||||||||||||
| 188 | # the schema it gets back, and closes $schema itself afterwards. | ||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | sub _hand_over_namespace { | ||||||||||||||||||||||||||||||
|
Subroutine
_hand_over_namespace: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 190 | 0 | my ($class, $schema, $to_class, $name) = @_; | |||||||||||||||||||||||||||||||
| 191 | 0 | $NAMESPACE{$to_class} = $name; | |||||||||||||||||||||||||||||||
| 192 | 0 | $CREATED{$to_class} = delete $CREATED{ ref $schema }; | |||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | $QUALIFIED{$to_class} = delete $QUALIFIED{ ref $schema } if $QUALIFIED{ ref $schema }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 194 | 0 | delete $NAMESPACE{ ref $schema }; | |||||||||||||||||||||||||||||||
| 195 | 0 | return; | |||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | 6 | ▶ | sub conformance_answered_through { { DDL => 2, Diff => 4, Bind => 1 } } | ||||||||||||||||||||||||||||||
|
Subroutine
conformance_answered_through: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||
| 202 | 3 | ▶ | sub conformance_refusals { | ||||||||||||||||||||||||||||||
|
Subroutine
conformance_refusals: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 203 | 3 | my ($class) = @_; | |||||||||||||||||||||||||||||||
| 204 | 3 | my $fk = qr/is a foreign key constraint, which ClickHouse cannot create/; | |||||||||||||||||||||||||||||||
| 205 | 3 | my $unique = qr/unique constraint .* cannot be enforced/; | |||||||||||||||||||||||||||||||
| 206 | 3 | my $auto = qr/is auto-increment, which ClickHouse cannot build/; | |||||||||||||||||||||||||||||||
| 207 | 3 | my $refusals = { | |||||||||||||||||||||||||||||||
| 208 | 'ddl-unique-constraint' => { kind => 'server', reason => $unique }, | ||||||||||||||||||||||||||||||||
| 209 | 'ddl-unique-not-null-without-pk' => { kind => 'server', reason => $unique }, | ||||||||||||||||||||||||||||||||
| 210 | 'ddl-foreign-key' => { kind => 'server', reason => $fk }, | ||||||||||||||||||||||||||||||||
| 211 | 'ddl-fk-actions' => { kind => 'server', reason => $fk }, | ||||||||||||||||||||||||||||||||
| 212 | 'ddl-fk-two-rels-one-column' => { kind => 'server', reason => $fk }, | ||||||||||||||||||||||||||||||||
| 213 | 'ddl-fk-table-order' => { kind => 'server', reason => $fk }, | ||||||||||||||||||||||||||||||||
| 214 | 'ddl-index-on-unique-columns' => { kind => 'server', reason => $unique }, | ||||||||||||||||||||||||||||||||
| 215 | 'ddl-auto-increment' => { kind => 'server', reason => $auto }, | ||||||||||||||||||||||||||||||||
| 216 | 'diff-auto-increment-kept' => { kind => 'server', reason => $auto }, | ||||||||||||||||||||||||||||||||
| 217 | 'bind-lob-row-operations' => { kind => 'server', reason => $auto }, | ||||||||||||||||||||||||||||||||
| 218 | 'ddl-type-size-bit' => { | ||||||||||||||||||||||||||||||||
| 219 | kind => 'server', | ||||||||||||||||||||||||||||||||
| 220 | reason => qr/size '8' on type 'bit' is refused: ClickHouse has no BIT type/, | ||||||||||||||||||||||||||||||||
| 221 | }, | ||||||||||||||||||||||||||||||||
| 222 | 'ddl-type-size-char' => { | ||||||||||||||||||||||||||||||||
| 223 | kind => 'deviation', | ||||||||||||||||||||||||||||||||
| 224 | fact => qr/column_size of Sized\.c: expected '10', the server shows NULL; Sized: the server accepted a row it must reject/, | ||||||||||||||||||||||||||||||||
| 225 | reason => 'ClickHouse has no CHAR(n) with a character limit: the portable ' | ||||||||||||||||||||||||||||||||
| 226 | . 'character(10) is a String of any length, stored whole and read ' | ||||||||||||||||||||||||||||||||
| 227 | . 'back without a size; the only bounded string, FixedString(N), ' | ||||||||||||||||||||||||||||||||
| 228 | . 'counts bytes (not characters) and pads with NUL bytes, which ' | ||||||||||||||||||||||||||||||||
| 229 | . 'is not what CHAR(n) means anywhere else, so the driver ' | ||||||||||||||||||||||||||||||||
| 230 | . 'offers it only as opt-in extra->{fixed_string} and adds no ' | ||||||||||||||||||||||||||||||||
| 231 | . 'CHECK for the length ' | ||||||||||||||||||||||||||||||||
| 232 | . '(https://clickhouse.com/docs/sql-reference/data-types/fixedstring)', | ||||||||||||||||||||||||||||||||
| 233 | }, | ||||||||||||||||||||||||||||||||
| 234 | 'diff-column-type-change' => { | ||||||||||||||||||||||||||||||||
| 235 | kind => 'deviation', | ||||||||||||||||||||||||||||||||
| 236 | fact => qr/column_size of Num\.n: expected '20', the server shows NULL/, | ||||||||||||||||||||||||||||||||
| 237 | reason => 'the varchar(20) the column is changed to is a String, which ' | ||||||||||||||||||||||||||||||||
| 238 | . 'has no length and reads back without a size ' | ||||||||||||||||||||||||||||||||
| 239 | . '(https://clickhouse.com/docs/sql-reference/data-types/string); ' | ||||||||||||||||||||||||||||||||
| 240 | . 'the type change itself and the rows are right', | ||||||||||||||||||||||||||||||||
| 241 | }, | ||||||||||||||||||||||||||||||||
| 242 | 'bind-numeric-exact' => { | ||||||||||||||||||||||||||||||||
| 243 | kind => 'deviation', | ||||||||||||||||||||||||||||||||
| 244 | fact => qr/read back '-?1234567890123456\.789'/, | ||||||||||||||||||||||||||||||||
| 245 | reason => 'the value is stored exactly in Decimal(38, 4); the server ' | ||||||||||||||||||||||||||||||||
| 246 | . 'formats it without trailing fractional zeros, so ' | ||||||||||||||||||||||||||||||||
| 247 | . '1234567890123456.7890 reads back as 1234567890123456.789 ' | ||||||||||||||||||||||||||||||||
| 248 | . '(the same number, a shorter spelling: ' | ||||||||||||||||||||||||||||||||
| 249 | . 'https://clickhouse.com/docs/sql-reference/data-types/decimal)', | ||||||||||||||||||||||||||||||||
| 250 | }, | ||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||
| 252 | # The Diff list. A case whose declaration carries a foreign key or a | ||||||||||||||||||||||||||||||||
| 253 | # unique constraint is refused when the declaration is installed or built | ||||||||||||||||||||||||||||||||
| 254 | # into the scratch database, as above. | ||||||||||||||||||||||||||||||||
| 255 | 'diff-table-added-complete' => { kind => 'server', reason => $fk }, | ||||||||||||||||||||||||||||||||
| 256 | 'diff-indexed-column-dropped' => { kind => 'server', reason => $unique }, | ||||||||||||||||||||||||||||||||
| 257 | 'diff-fk-dropped' => { kind => 'server', reason => $fk }, | ||||||||||||||||||||||||||||||||
| 258 | 'diff-fk-added-to-new-unique' => { kind => 'server', reason => $fk }, | ||||||||||||||||||||||||||||||||
| 259 | 'diff-constraint-changed' => { kind => 'server', reason => $fk }, | ||||||||||||||||||||||||||||||||
| 260 | 'diff-fk-action-changed' => { kind => 'server', reason => $fk }, | ||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||
| 262 | # The two cases the engine would "apply" by writing something nobody | ||||||||||||||||||||||||||||||||
| 263 | # wrote. The upgrade reads the table first and refuses before the first | ||||||||||||||||||||||||||||||||
| 264 | # statement (Deploy::_check_before_apply). | ||||||||||||||||||||||||||||||||
| 265 | 'diff-column-added-not-null-populated' => { | ||||||||||||||||||||||||||||||||
| 266 | kind => 'server', | ||||||||||||||||||||||||||||||||
| 267 | reason => qr/NOT NULL without a default to a table that holds rows/, | ||||||||||||||||||||||||||||||||
| 268 | }, | ||||||||||||||||||||||||||||||||
| 269 | 'diff-not-null-over-nulls' => { | ||||||||||||||||||||||||||||||||
| 270 | kind => 'server', | ||||||||||||||||||||||||||||||||
| 271 | reason => qr/is Nullable and holds \d+ NULL row/, | ||||||||||||||||||||||||||||||||
| 272 | }, | ||||||||||||||||||||||||||||||||
| 273 | }; | ||||||||||||||||||||||||||||||||
| 274 | 3 | ▶ | $refusals->{'ddl-qualified-source-name'} = { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$class->conformance_live_available and not $class->_database_exists("other")
MC/DC0%0/2
$class->conformance_live_available and not $class->_database_exists("other")
$class->conformance_live_available
not $class->_database_exists("other")
Truth table33%1/3
A and not(B)
A= $class->conformance_live_availableB= not $class->_database_exists("other")
| |||||||||||||||||||||||||||||||||
| 275 | kind => 'server', | ||||||||||||||||||||||||||||||||
| 276 | reason => qr/the database other does not exist/, | ||||||||||||||||||||||||||||||||
| 277 | } if $class->conformance_live_available && !$class->_database_exists('other'); | ||||||||||||||||||||||||||||||||
| 278 | 3 | return $refusals; | |||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||
| 281 | # Whether the server has a database of exactly that name; asked once per name | ||||||||||||||||||||||||||||||||
| 282 | # and process, and read only. | ||||||||||||||||||||||||||||||||
| 283 | 4 | my %DATABASE_EXISTS; | |||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | sub _database_exists { | ||||||||||||||||||||||||||||||
|
Subroutine
_database_exists: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 285 | 0 | my ($class, $name) = @_; | |||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | return $DATABASE_EXISTS{$name} //= do { | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$DATABASE_EXISTS{$name} //= do {
my $dbh = _admin_connect();
my($found) = $dbh->selectrow_array("SELECT count() FROM system.databases WHERE name = ?", undef, $name);
$dbh->disconnect;
$found ? 1 : 0
}
MC/DC0%0/2
$DATABASE_EXISTS{$name} //= do {
my $dbh = _admin_connect();
my($found) = $dbh->selectrow_array("SELECT count() FROM system.databases WHERE name = ?", undef, $name);
$dbh->disconnect;
$found ? 1 : 0
}
$DATABASE_EXISTS{$name}
do {
my $dbh = _admin_connect();
my($found) = $dbh->selectrow_array("SELECT count() FROM system.databases WHERE name = ?", undef, $name);
$dbh->disconnect;
$found ? 1 : 0
}
Truth table0%0/3
A //= B
A= $DATABASE_EXISTS{$name}B= do {
my $dbh = _admin_connect();
my($found) = $dbh->selectrow_array("SELECT count() FROM system.databases WHERE name = ?", undef, $name);
$dbh->disconnect;
$found ? 1 : 0
}
| |||||||||||||||||||||||||||||||||
| 287 | 0 | my $dbh = _admin_connect(); | |||||||||||||||||||||||||||||||
| 288 | 0 | my ($found) = $dbh->selectrow_array( | |||||||||||||||||||||||||||||||
| 289 | 'SELECT count() FROM system.databases WHERE name = ?', undef, $name); | ||||||||||||||||||||||||||||||||
| 290 | 0 | $dbh->disconnect; | |||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | $found ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 292 | }; | ||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | sub conformance_fact { | ||||||||||||||||||||||||||||||
|
Subroutine
conformance_fact: not called CC=25 SCAR=64.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 297 | 0 | my ($class, $schema, $name, $args) = @_; | |||||||||||||||||||||||||||||||
| 298 | 0 | my $dbh = $schema->storage->dbh; | |||||||||||||||||||||||||||||||
| 299 | 0 | my $table = $args->{table}; | |||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | if ($name eq 'table_in_namespace') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 302 | my ($n) = $dbh->selectrow_array( | ||||||||||||||||||||||||||||||||
| 303 | 'SELECT count() FROM system.tables WHERE database = ? AND name = ?', | ||||||||||||||||||||||||||||||||
| 304 | 0 | undef, $args->{namespace}, $args->{unqualified}); | |||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | return $n ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||
| 308 | 0 | my $model = DBIO::ClickHouse::Introspect->new(dbh => $dbh)->model; | |||||||||||||||||||||||||||||||
| 309 | 0 | my $entry = $model->{tables}{$table}; | |||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | if ($name eq 'object_kind') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | return $entry ? $entry->{kind} : undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | if ($name eq 'table_name') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | return $entry ? $entry->{table_name} : undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | my $columns = $model->{columns}{$table} || []; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$model->{'columns'}{$table} || []
MC/DC0%0/1
$model->{'columns'}{$table} || []
$model->{'columns'}{$table}
Truth table0%0/2
A
A= $model->{'columns'}{$table}
| |||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | if ($name eq 'column_names') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 320 | 0 | return [ map { $_->{column_name} } @$columns ]; | |||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | if ($name eq 'column_size') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 323 | 0 | my ($col) = grep { $_->{column_name} eq $args->{column} } @$columns; | |||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | return undef unless $col; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 325 | 0 | return DBIO::ClickHouse::Introspect::Util->normalize_type($col->{data_type})->{size}; | |||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | if ($name eq 'column_auto_increment') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 328 | # no identity column exists; the only generated key is a UUID default | ||||||||||||||||||||||||||||||||
| 329 | 0 | my ($col) = grep { $_->{column_name} eq $args->{column} } @$columns; | |||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | return $col && ($col->{default_value} // '') =~ /generateUUIDv4/ ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$col and ($col->{"default_value"} // "") =~ /generateUUIDv4/
$col->{"default_value"} // ""
MC/DC0%0/2
$col and ($col->{"default_value"} // "") =~ /generateUUIDv4/
$col
$col->{"default_value"}
Truth table0%0/3
A and B
A= $colB= $col->{"default_value"}
| |||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | if ($name eq 'primary_key_columns') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | return $entry ? [ @{ $entry->{primary_key_columns} } ] : []; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | if ($name eq 'unique_exists') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 336 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | if ($name eq 'foreign_key_count') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 339 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | if ($name eq 'index_count') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | my @want = @{ $args->{columns} || [] }; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'columns'} || []
MC/DC0%0/1
$args->{'columns'} || []
$args->{'columns'}
Truth table0%0/2
A
A= $args->{'columns'}
| |||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | my $indexes = $model->{data_skipping_indexes}{$table} || []; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$model->{'data_skipping_indexes'}{$table} || []
MC/DC0%0/1
$model->{'data_skipping_indexes'}{$table} || []
$model->{'data_skipping_indexes'}{$table}
Truth table0%0/2
A
A= $model->{'data_skipping_indexes'}{$table}
| |||||||||||||||||||||||||||||||||
| 344 | return scalar grep { | ||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | my $got = $_->{columns} || []; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$_->{'columns'} || []
MC/DC0%0/1
$_->{'columns'} || []
$_->{'columns'}
Truth table0%0/2
A
A= $_->{'columns'}
| |||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | @$got == @want and join("\0", @$got) eq join("\0", @want); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@$got == @want && join("\000", @$got) eq join("\000", @want)
MC/DC0%0/2
@$got == @want && join("\000", @$got) eq join("\000", @want)
@$got == @want
join("\000", @$got) eq join("\000", @want)
Truth table0%0/3
A && B
A= @$got == @wantB= join("\000", @$got) eq join("\000", @want)
| |||||||||||||||||||||||||||||||||
| 347 | } ref $indexes eq 'HASH' ? values %$indexes : @$indexes; | ||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||
| 350 | 0 | DBIO::Exception->throw("unknown conformance fact '$name'"); | |||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||
| 353 | 4 | 1; | |||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||
| 355 | __END__ | ||||||||||||||||||||||||||||||||