Browse Source

Multiget fixed:

Loop in function _build_multiget_uri lost keys when current url became too long.
dtcyganov 4 years ago
parent
commit
1326bc3137
2 changed files with 28 additions and 4 deletions
  1. 2 3
      lib/HBase/JSONRest.pm
  2. 26 1
      t/uri_gen.t

+ 2 - 3
lib/HBase/JSONRest.pm

@ -542,8 +542,7 @@ sub _build_multiget_uri {
542 542
    my $keys  = $query->{where}->{key_in};
543 543
    my $table = $query->{table};
544 544
545
    my $route_base = '/' . $table . '/multiget?';
546
    my $uri_base = $route_base;
545
    my $uri_base = '/' . $table . '/multiget?';
547 546
548 547
    my @multiget_urls = ();
549 548
    my $current_url = undef;
@ -558,7 +557,7 @@ sub _build_multiget_uri {
558 557
            }
559 558
            else {
560 559
                push @multiget_urls, { url => $current_url, len => length($current_url) };
561
                $current_url = undef;
560
                $current_url = $uri_base . "row=" . uri_escape($key);
562 561
            }
563 562
        }
564 563
    }

+ 26 - 1
t/uri_gen.t

@ -2,7 +2,7 @@
2 2
use strict;
3 3
use warnings;
4 4
5
use Test::More tests => 9;
5
use Test::More tests => 10;
6 6
7 7
use HBase::JSONRest;
8 8
use HBase::JSONRest::Scanner;
@ -152,3 +152,28 @@ ok(
152 152
    q|Test startrow scan|
153 153
);
154 154
155
# 10. multiget: long keys
156
is_deeply(
157
    [
158
        map { $_->{url} }
159
        @{ HBase::JSONRest::_build_multiget_uri({
160
            'table' => 'my_table',
161
            'where' => {
162
                'key_in' => [
163
                    1 x 1600,
164
                    2 x 1600,
165
                    3 x 800,
166
                    4 x 800,
167
                    5 x 800,
168
                ]
169
            },
170
        }) }
171
    ],
172
    [
173
        '/my_table/multiget?row=' . ( 1 x 1600 ),
174
        '/my_table/multiget?row=' . ( 2 x 1600 ),
175
        '/my_table/multiget?row=' . ( 3 x 800 ) . '&row=' . (4 x 800),
176
        '/my_table/multiget?row=' . ( 5 x 800 ),
177
    ],
178
    q|Test multiget with long ids|
179
);