line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Class::Helper::TableSample; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Add support for tablesample clauses |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
195840
|
use v5.10.1; |
|
1
|
|
|
|
|
3
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use parent 'DBIx::Class::ResultSet'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
497
|
use Ref::Util qw/ is_plain_arrayref is_plain_hashref is_plain_scalarref /; |
|
1
|
|
|
|
|
3638
|
|
|
1
|
|
|
|
|
74
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# RECOMMEND PREREQ: Ref::Util::XS |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
6
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = 'v0.3.2'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _resolved_attrs { |
22
|
9
|
|
|
9
|
|
852648
|
my $rs = $_[0]; |
23
|
|
|
|
|
|
|
|
24
|
9
|
|
|
|
|
57
|
$rs->next::method; |
25
|
|
|
|
|
|
|
|
26
|
9
|
|
|
|
|
1653
|
my $attrs = $rs->{_attrs}; |
27
|
|
|
|
|
|
|
|
28
|
9
|
50
|
|
|
|
37
|
if ( my $conf = delete $attrs->{tablesample} ) { |
29
|
|
|
|
|
|
|
|
30
|
9
|
|
|
|
|
20
|
my $from = $attrs->{from}; |
31
|
|
|
|
|
|
|
|
32
|
9
|
50
|
33
|
|
|
66
|
$rs->throw_exception('tablesample on joins is not supported') |
33
|
|
|
|
|
|
|
if is_plain_arrayref($from) && @$from > 1; |
34
|
|
|
|
|
|
|
|
35
|
9
|
100
|
|
|
|
35
|
$conf = { fraction => $conf } unless is_plain_hashref($conf); |
36
|
|
|
|
|
|
|
|
37
|
9
|
50
|
|
|
|
26
|
$rs->throw_exception('tablesample must be a hashref') |
38
|
|
|
|
|
|
|
unless is_plain_hashref($conf); |
39
|
|
|
|
|
|
|
|
40
|
9
|
|
|
|
|
50
|
my $sqla = $rs->result_source->storage->sql_maker; |
41
|
|
|
|
|
|
|
|
42
|
9
|
|
|
|
|
815
|
my $part_sql = " tablesample"; |
43
|
|
|
|
|
|
|
|
44
|
9
|
100
|
100
|
|
|
65
|
if (my $type = ($conf->{method} // $conf->{type})) { |
45
|
4
|
|
|
|
|
21
|
$part_sql .= " $type"; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
9
|
|
|
|
|
24
|
my $arg = $conf->{fraction}; |
49
|
9
|
100
|
|
|
|
28
|
$arg = $$arg if is_plain_scalarref($arg); |
50
|
9
|
|
|
|
|
66
|
$part_sql .= "($arg)"; |
51
|
|
|
|
|
|
|
|
52
|
9
|
100
|
|
|
|
28
|
if ( defined $conf->{repeatable} ) { |
53
|
2
|
|
|
|
|
5
|
my $seed = $conf->{repeatable}; |
54
|
2
|
100
|
|
|
|
7
|
$seed = $$seed if is_plain_scalarref($seed); |
55
|
2
|
|
|
|
|
15
|
$part_sql .= sprintf( ' repeatable (%s)', $seed ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
9
|
50
|
|
|
|
23
|
if (is_plain_arrayref($from)) { |
59
|
9
|
|
|
|
|
66
|
my $sql = $sqla->_from_chunk_to_sql($from->[0]) . $sqla->_sqlcase($part_sql); |
60
|
9
|
|
|
|
|
979
|
$from->[0] = \$sql; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else { |
63
|
0
|
|
|
|
|
0
|
my $sql = $sqla->_from_chunk_to_sql($from) . $sqla->_sqlcase($part_sql); |
64
|
0
|
|
|
|
|
0
|
$attrs->{from} = \$sql; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
9
|
|
|
|
|
66
|
return $attrs; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |