1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Level23\Druid\Responses; |
5
|
|
|
|
6
|
|
|
class SelectQueryResponse extends QueryResponse |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Return the last known paging identifier known by a select query. (If any is executed). |
10
|
|
|
* If no paging identifier is known, an empty array is returned. |
11
|
|
|
* |
12
|
|
|
* The paging identifier will be something like this: |
13
|
|
|
* ``` |
14
|
|
|
* Array( |
15
|
|
|
* 'wikipedia_2015-09-12T00:00:00.000Z_2015-09-13T00:00:00.000Z_2019-09-12T14:15:44.694Z' => 19, |
16
|
|
|
* ) |
17
|
|
|
* ``` |
18
|
|
|
* |
19
|
|
|
* @return array<string,int> |
20
|
|
|
*/ |
21
|
2 |
|
public function pagingIdentifier(): array |
22
|
|
|
{ |
23
|
|
|
/** @var array<string,array<string,int>> $row */ |
24
|
2 |
|
$row = $this->getResultRow(); |
25
|
|
|
|
26
|
2 |
|
return $row['pagingIdentifiers'] ?? []; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Return the data in a "normalized" way, so we can easily iterate over it |
31
|
|
|
* |
32
|
|
|
* @return array<mixed> |
33
|
|
|
*/ |
34
|
2 |
|
public function data(): array |
35
|
|
|
{ |
36
|
|
|
/** @var array<string,array<string,array<mixed>>> $resultRow */ |
37
|
2 |
|
$resultRow = $this->getResultRow(); |
38
|
|
|
|
39
|
2 |
|
return array_map(function ($row) { |
40
|
|
|
/** @var array<string, array<mixed>> $row */ |
41
|
1 |
|
return $row['event']; |
42
|
2 |
|
}, $resultRow['events'] ?? []); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return array<string,array<mixed>> |
47
|
|
|
*/ |
48
|
2 |
|
protected function getResultRow(): array |
49
|
|
|
{ |
50
|
|
|
/** @var null|array<string,array<string,array<mixed>>> $row */ |
51
|
2 |
|
$row = $this->response[0] ?? null; |
52
|
2 |
|
if ($row === null) { |
53
|
1 |
|
return []; |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
return $row['result'] ?? []; |
57
|
|
|
} |
58
|
|
|
} |