| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright (C) 2022 Horimoto Yasuhiro |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify |
|
4
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by |
|
5
|
|
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
|
6
|
|
|
|
|
|
|
# (at your option) any later version. |
|
7
|
|
|
|
|
|
|
# |
|
8
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
|
9
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11
|
|
|
|
|
|
|
# GNU General Public License for more details. |
|
12
|
|
|
|
|
|
|
# |
|
13
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
|
14
|
|
|
|
|
|
|
# along with this program. If not, see . |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package Groonga::Commands::Load; |
|
17
|
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
7
|
use JSON; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
5
|
|
|
19
|
1
|
|
|
1
|
|
79
|
use Carp 'croak'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
34
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
15
|
|
|
22
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
18
|
|
|
23
|
1
|
|
|
1
|
|
4
|
use Data::Dumper; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
320
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $groonga_http_client = undef; |
|
26
|
|
|
|
|
|
|
my $command_args = ""; |
|
27
|
|
|
|
|
|
|
my $n_loaded_records = undef; |
|
28
|
|
|
|
|
|
|
my @records; |
|
29
|
|
|
|
|
|
|
my $use_drilldown = 0; |
|
30
|
|
|
|
|
|
|
my @load_arguments = ( |
|
31
|
|
|
|
|
|
|
'table', |
|
32
|
|
|
|
|
|
|
'values' |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub new { |
|
36
|
0
|
|
|
0
|
0
|
|
my ($class, %args) = @_; |
|
37
|
0
|
|
|
|
|
|
my $self = {%args}; |
|
38
|
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
$groonga_http_client = $self->{client}; |
|
40
|
0
|
|
|
|
|
|
$command_args = _parse_arguments($self); |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return bless $self, $class; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _is_valid_arguments { |
|
46
|
0
|
|
|
0
|
|
|
my $args = shift; |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
while (my ($key, $value) = each %{$args}) { |
|
|
0
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if ($key eq 'client') { |
|
50
|
0
|
|
|
|
|
|
next; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
0
|
0
|
|
|
|
|
if (!(grep {$_ eq $key} @load_arguments)) { |
|
|
0
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
croak "Invalid arguments: ${key}"; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
return 1; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _parse_arguments { |
|
61
|
0
|
|
|
0
|
|
|
my $args = shift; |
|
62
|
0
|
|
|
|
|
|
my %parsed_arguments = (); |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
_is_valid_arguments($args); |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if (exists($args->{'table'})) { |
|
67
|
0
|
|
|
|
|
|
$parsed_arguments{'table'} = $args->{'table'}; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
0
|
|
|
|
|
|
$parsed_arguments{'values'} = encode_json($args->{'values'}); |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return \%parsed_arguments; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _parse_result { |
|
75
|
0
|
|
|
0
|
|
|
my $result = shift; |
|
76
|
0
|
|
|
|
|
|
my %result_set = (); |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$result_set{'n_loaded_records'} = $result; |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
return \%result_set; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub execute { |
|
84
|
0
|
0
|
|
0
|
0
|
|
if (defined $groonga_http_client) { |
|
85
|
|
|
|
|
|
|
return _parse_result($groonga_http_client->send_post( |
|
86
|
|
|
|
|
|
|
'load', |
|
87
|
|
|
|
|
|
|
"?table=$command_args->{'table'}", |
|
88
|
0
|
|
|
|
|
|
$command_args->{'values'} |
|
89
|
|
|
|
|
|
|
) |
|
90
|
|
|
|
|
|
|
); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
0
|
|
|
|
|
|
return; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |