line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Presto; |
2
|
3
|
|
|
3
|
|
31233
|
use Moo; |
|
3
|
|
|
|
|
32270
|
|
|
3
|
|
|
|
|
19
|
|
3
|
3
|
|
|
3
|
|
4628
|
use Furl; |
|
3
|
|
|
|
|
64802
|
|
|
3
|
|
|
|
|
88
|
|
4
|
3
|
|
|
3
|
|
19
|
use Carp qw(confess); |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
147
|
|
5
|
3
|
|
|
3
|
|
13
|
use Scalar::Util qw(blessed); |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
179
|
|
6
|
3
|
|
|
3
|
|
1716
|
use JSON::XS; |
|
3
|
|
|
|
|
11972
|
|
|
3
|
|
|
|
|
189
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
957
|
use Net::Presto::Statement; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
1863
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has protocol => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
isa => sub { die "Unsupported protocol: $_[0]" unless $_[0] =~ /\Ahttps?\z/ }, |
15
|
|
|
|
|
|
|
default => sub { 'http' }, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has path => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
default => sub { '/v1/statement' }, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has server => ( |
24
|
|
|
|
|
|
|
is => 'ro', |
25
|
|
|
|
|
|
|
required => 1, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has catalog => ( |
29
|
|
|
|
|
|
|
is => 'ro', |
30
|
|
|
|
|
|
|
required => 1, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has schema => ( |
34
|
|
|
|
|
|
|
is => 'ro', |
35
|
|
|
|
|
|
|
required => 1, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has user => ( |
39
|
|
|
|
|
|
|
is => 'ro', |
40
|
|
|
|
|
|
|
required => 1, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has time_zone => ( |
44
|
|
|
|
|
|
|
is => 'ro', |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has language => ( |
48
|
|
|
|
|
|
|
is => 'ro', |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has properties => ( |
52
|
|
|
|
|
|
|
is => 'ro', |
53
|
|
|
|
|
|
|
isa => sub { die "properties is not a HashRef" unless ref $_[0] eq 'HASH' }, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
has furl => ( |
57
|
|
|
|
|
|
|
is => 'ro', |
58
|
|
|
|
|
|
|
isa => sub { die "furl is not a Furl object" unless blessed $_[0] && $_[0]->isa('Furl') }, |
59
|
|
|
|
|
|
|
default => sub { |
60
|
|
|
|
|
|
|
my $self = shift; |
61
|
|
|
|
|
|
|
Furl->new( |
62
|
|
|
|
|
|
|
agent => $self->source, |
63
|
|
|
|
|
|
|
timeout => 180, |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
}, |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
has source => ( |
69
|
|
|
|
|
|
|
is => 'ro', |
70
|
|
|
|
|
|
|
default => sub { join('/', __PACKAGE__, $VERSION) }, |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub execute { |
74
|
0
|
|
|
0
|
1
|
|
my ($self, $query) = @_; |
75
|
0
|
0
|
|
|
|
|
confess 'No query specified' unless defined $query; |
76
|
0
|
|
|
|
|
|
my $url = sprintf '%s://%s%s', $self->protocol, $self->server, $self->path; |
77
|
0
|
|
|
|
|
|
my $headers = [ |
78
|
|
|
|
|
|
|
'X-Presto-User' => $self->user, |
79
|
|
|
|
|
|
|
'X-Presto-Source' => $self->source, |
80
|
|
|
|
|
|
|
'X-Presto-Catalog' => $self->catalog, |
81
|
|
|
|
|
|
|
'X-Presto-Schema' => $self->schema, |
82
|
|
|
|
|
|
|
$self->time_zone ? ('X-Presto-Time-Zone' => $self->time_zone) : (), |
83
|
|
|
|
|
|
|
$self->language ? ('X-Presto-Language' => $self->language) : (), |
84
|
|
|
|
|
|
|
$self->properties ? ( |
85
|
|
|
|
|
|
|
map { |
86
|
0
|
|
|
|
|
|
('X-Presto-Session' => join('=', $_, $self->properties->{$_})) # need to validate? |
87
|
0
|
0
|
|
|
|
|
} keys %{$self->properties} |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
88
|
|
|
|
|
|
|
) : (), |
89
|
|
|
|
|
|
|
]; |
90
|
0
|
|
|
|
|
|
my $response = $self->furl->post($url, $headers, $query); |
91
|
0
|
0
|
|
|
|
|
confess $response->status_line unless $response->is_success; |
92
|
0
|
|
|
|
|
|
my $res = decode_json $response->content; |
93
|
0
|
|
|
|
|
|
Net::Presto::Statement->create( |
94
|
|
|
|
|
|
|
furl => $self->furl, |
95
|
|
|
|
|
|
|
headers => $headers, |
96
|
|
|
|
|
|
|
res => $res, |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub do { |
101
|
0
|
|
|
0
|
1
|
|
my ($self, $query) = @_; |
102
|
0
|
|
|
|
|
|
my $st = $self->execute($query); |
103
|
0
|
|
|
|
|
|
$st->wait_for_completion; |
104
|
0
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub select_one { |
108
|
0
|
|
|
0
|
1
|
|
my ($self, $query) = @_; |
109
|
0
|
|
|
|
|
|
my $st = $self->execute($query); |
110
|
0
|
|
|
|
|
|
my $rows = $st->fetch; |
111
|
0
|
|
|
|
|
|
$st->wait_for_completion; |
112
|
0
|
|
|
|
|
|
$rows->[0]->[0]; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub select_row { |
116
|
0
|
|
|
0
|
1
|
|
my ($self, $query) = @_; |
117
|
0
|
|
|
|
|
|
my $st = $self->execute($query); |
118
|
0
|
|
|
|
|
|
my $rows = $st->fetch_hashref; |
119
|
0
|
|
|
|
|
|
$st->wait_for_completion; |
120
|
0
|
|
|
|
|
|
$rows->[0]; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub select_all { |
124
|
0
|
|
|
0
|
1
|
|
my ($self, $query) = @_; |
125
|
0
|
|
|
|
|
|
my $st = $self->execute($query); |
126
|
0
|
|
|
|
|
|
my @rows; |
127
|
0
|
|
|
|
|
|
while (my $rows = $st->fetch_hashref) { |
128
|
0
|
|
|
|
|
|
push @rows, @$rows; |
129
|
|
|
|
|
|
|
} |
130
|
0
|
|
|
|
|
|
\@rows; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |
134
|
|
|
|
|
|
|
__END__ |