line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Environ::ClickHouse::Proxy; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.5'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
571
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
45
|
|
7
|
1
|
|
|
1
|
|
10
|
use v5.10; |
|
1
|
|
|
|
|
3
|
|
8
|
1
|
|
|
1
|
|
5
|
use utf8; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
390
|
use App::Environ; |
|
1
|
|
|
|
|
580
|
|
|
1
|
|
|
|
|
25
|
|
11
|
1
|
|
|
1
|
|
351
|
use App::Environ::Config; |
|
1
|
|
|
|
|
14351
|
|
|
1
|
|
|
|
|
26
|
|
12
|
1
|
|
|
1
|
|
5
|
use Carp qw( carp croak ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
13
|
1
|
|
|
1
|
|
5
|
use Cpanel::JSON::XS; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
39
|
|
14
|
1
|
|
|
1
|
|
460
|
use IO::Socket; |
|
1
|
|
|
|
|
15394
|
|
|
1
|
|
|
|
|
3
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $INSTANCE; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $JSON = Cpanel::JSON::XS->new->utf8; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
App::Environ::Config->register(qw(clickhouse_proxy.yml)); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub instance { |
23
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
24
|
|
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
|
unless ($INSTANCE) { |
26
|
0
|
|
|
|
|
|
my $config = App::Environ::Config->instance; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $sock = IO::Socket::INET->new( |
29
|
|
|
|
|
|
|
Proto => 'udp', |
30
|
|
|
|
|
|
|
PeerAddr => $config->{clickhouse_proxy}{host}, |
31
|
|
|
|
|
|
|
PeerPort => $config->{clickhouse_proxy}{port}, |
32
|
0
|
0
|
|
|
|
|
) or croak("Could not create socket: $!"); |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
$INSTANCE = bless { sock => $sock }, $class; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
return $INSTANCE; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub send { |
41
|
0
|
|
|
0
|
0
|
|
my __PACKAGE__ $self = shift; |
42
|
0
|
|
|
|
|
|
my $query = shift; |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
1
|
|
539
|
no warnings 'numeric'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
138
|
|
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my @types; |
47
|
0
|
|
|
|
|
|
foreach (@_) { |
48
|
0
|
0
|
0
|
|
|
|
if ( defined($_) |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
49
|
|
|
|
|
|
|
&& length( ( my $dummy = '' ) & $_ ) |
50
|
|
|
|
|
|
|
&& 0 + $_ eq $_ |
51
|
|
|
|
|
|
|
&& $_ * 0 == 0 ) |
52
|
|
|
|
|
|
|
{ |
53
|
0
|
0
|
|
|
|
|
if (/^[+-]?\d+\z/) { |
54
|
0
|
|
|
|
|
|
push @types, 'int'; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else { |
57
|
0
|
|
|
|
|
|
push @types, 'float'; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else { |
61
|
0
|
|
|
|
|
|
push @types, 'string'; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
1
|
|
6
|
use warnings 'numeric'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
123
|
|
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my %val = ( |
68
|
|
|
|
|
|
|
query => $query, |
69
|
|
|
|
|
|
|
data => \@_, |
70
|
|
|
|
|
|
|
types => \@types, |
71
|
|
|
|
|
|
|
version => 1, |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
$self->{sock}->send( $JSON->encode( \%val ) ) or carp("Send error: $!"); |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |