|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Level23\Druid\Lookups; |
|
5
|
|
|
|
|
6
|
|
|
use Level23\Druid\Lookups\ParseSpecs\ParseSpecInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @see https://druid.apache.org/docs/latest/querying/lookups-cached-global#uri-lookup |
|
10
|
|
|
*/ |
|
11
|
|
|
class UriPrefixLookup implements LookupInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @param ParseSpecInterface $parseSpec |
|
15
|
|
|
* @param string $uriPrefix |
|
16
|
|
|
* @param string|null $fileRegex |
|
17
|
|
|
* @param string|null $pollPeriod The pollPeriod value specifies the period in ISO 8601 format |
|
18
|
|
|
* between checks for replacement data for the lookup. For example |
|
19
|
|
|
* PT15M. When not given, it is only once. If the source of the |
|
20
|
|
|
* lookup is capable of providing a timestamp, the lookup will only |
|
21
|
|
|
* be updated if it has changed since the prior tick of pollPeriod. |
|
22
|
|
|
* A value of 0, an absent parameter, or null all mean populate once |
|
23
|
|
|
* and do not attempt to look for new data later. Whenever an poll |
|
24
|
|
|
* occurs, the updating system will look for a file with the most |
|
25
|
|
|
* recent timestamp and assume that one with the most recent data |
|
26
|
|
|
* set, replacing the local cache of the lookup data. |
|
27
|
|
|
* @param int|null $maxHeapPercentage |
|
28
|
|
|
* @param bool $injective If the underlying map is injective (keys and values are unique) |
|
29
|
|
|
* then optimizations can occur internally by setting this to true |
|
30
|
|
|
* @param int $firstCacheTimeoutMs How long to wait (in ms) for the first run of the cache to |
|
31
|
|
|
* populate. 0 indicates to not wait |
|
32
|
|
|
* |
|
33
|
|
|
*/ |
|
34
|
1 |
|
public function __construct( |
|
35
|
|
|
protected ParseSpecInterface $parseSpec, |
|
36
|
|
|
protected string $uriPrefix, |
|
37
|
|
|
protected ?string $fileRegex = null, |
|
38
|
|
|
protected ?string $pollPeriod = null, |
|
39
|
|
|
protected ?int $maxHeapPercentage = null, |
|
40
|
|
|
protected bool $injective = false, |
|
41
|
|
|
protected int $firstCacheTimeoutMs = 0 |
|
42
|
|
|
) { |
|
43
|
|
|
|
|
44
|
1 |
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
public function toArray(): array |
|
47
|
|
|
{ |
|
48
|
1 |
|
$response = [ |
|
49
|
1 |
|
'type' => 'uri', |
|
50
|
1 |
|
'uriPrefix' => $this->uriPrefix, |
|
51
|
1 |
|
'namespaceParseSpec' => $this->parseSpec->toArray(), |
|
52
|
1 |
|
]; |
|
53
|
|
|
|
|
54
|
1 |
|
if ($this->fileRegex !== null) { |
|
55
|
1 |
|
$response['fileRegex'] = $this->fileRegex; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
if ($this->pollPeriod !== null) { |
|
59
|
1 |
|
$response['pollPeriod'] = $this->pollPeriod; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
if ($this->maxHeapPercentage !== null) { |
|
63
|
1 |
|
$response['maxHeapPercentage'] = $this->maxHeapPercentage; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
1 |
|
return [ |
|
67
|
1 |
|
'type' => 'cachedNamespace', |
|
68
|
1 |
|
'extractionNamespace' => $response, |
|
69
|
1 |
|
'injective' => $this->injective, |
|
70
|
1 |
|
'firstCacheTimeout' => $this->firstCacheTimeoutMs, |
|
71
|
1 |
|
]; |
|
72
|
|
|
} |
|
73
|
|
|
} |