1 | <?php |
||||||
2 | declare(strict_types=1); |
||||||
3 | |||||||
4 | namespace Level23\Druid\Tasks; |
||||||
5 | |||||||
6 | use Level23\Druid\Types\Granularity; |
||||||
7 | use Level23\Druid\Context\TaskContext; |
||||||
8 | use Level23\Druid\TuningConfig\TuningConfig; |
||||||
9 | use Level23\Druid\Interval\IntervalInterface; |
||||||
10 | use Level23\Druid\TuningConfig\TuningConfigInterface; |
||||||
11 | |||||||
12 | class CompactTask implements TaskInterface |
||||||
13 | { |
||||||
14 | protected string $dataSource; |
||||||
15 | |||||||
16 | protected IntervalInterface $interval; |
||||||
17 | |||||||
18 | protected ?Granularity $segmentGranularity; |
||||||
19 | |||||||
20 | protected ?TuningConfigInterface $tuningConfig; |
||||||
21 | |||||||
22 | protected ?TaskContext $context; |
||||||
23 | |||||||
24 | protected ?int $targetCompactionSizeBytes; |
||||||
25 | |||||||
26 | protected ?string $taskId; |
||||||
27 | |||||||
28 | /** |
||||||
29 | * CompactTask constructor. |
||||||
30 | * |
||||||
31 | * This compaction task reads all segments of the interval 2017-01-01/2018-01-01 and results in new segments. Since |
||||||
32 | * both segmentGranularity and keepSegmentGranularity are null, the original segment granularity will be remained |
||||||
33 | * and not changed after compaction. To control the number of result segments per time chunk, you can set |
||||||
34 | * maxRowsPerSegment or numShards. Please note that you can run multiple compactionTasks at the same time. For |
||||||
35 | * example, you can run 12 compactionTasks per month instead of running a single task for the entire year. |
||||||
36 | * |
||||||
37 | * A compaction task internally generates an index task spec for performing compaction work with some fixed |
||||||
38 | * parameters. For example, its firehose is always the ingestSegmentSpec, and dimensionsSpec and metricsSpec |
||||||
39 | * include all dimensions and metrics of the input segments by default. |
||||||
40 | * |
||||||
41 | * Compaction tasks will exit with a failure status code, without doing anything, if the interval you specify has |
||||||
42 | * no data segments loaded in it (or if the interval you specify is empty). |
||||||
43 | * |
||||||
44 | * @param string $dataSource |
||||||
45 | * @param \Level23\Druid\Interval\IntervalInterface $interval |
||||||
46 | * @param string|Granularity|null $segmentGranularity |
||||||
47 | * @param \Level23\Druid\TuningConfig\TuningConfig|null $tuningConfig |
||||||
48 | * @param \Level23\Druid\Context\TaskContext|null $context |
||||||
49 | * @param int|null $targetCompactionSizeBytes |
||||||
50 | * @param string|null $taskId |
||||||
51 | */ |
||||||
52 | 10 | public function __construct( |
|||||
53 | string $dataSource, |
||||||
54 | IntervalInterface $interval, |
||||||
55 | string|Granularity|null $segmentGranularity = null, |
||||||
56 | ?TuningConfig $tuningConfig = null, |
||||||
57 | ?TaskContext $context = null, |
||||||
58 | ?int $targetCompactionSizeBytes = null, |
||||||
59 | ?string $taskId = null |
||||||
60 | ) { |
||||||
61 | 10 | $this->dataSource = $dataSource; |
|||||
62 | 10 | $this->interval = $interval; |
|||||
63 | 10 | $this->segmentGranularity = is_string($segmentGranularity) ? Granularity::from(strtolower($segmentGranularity)) : $segmentGranularity; |
|||||
64 | 10 | $this->tuningConfig = $tuningConfig; |
|||||
65 | 10 | $this->context = $context; |
|||||
66 | 10 | $this->targetCompactionSizeBytes = $targetCompactionSizeBytes; |
|||||
67 | 10 | $this->taskId = $taskId; |
|||||
68 | } |
||||||
69 | |||||||
70 | /** |
||||||
71 | * Return the task in a format so that we can send it to druid. |
||||||
72 | * |
||||||
73 | * @return array<string,int|null|string|array<string,string|int|bool|array<string,string|int>>> |
||||||
74 | */ |
||||||
75 | 6 | public function toArray(): array |
|||||
76 | { |
||||||
77 | 6 | $result = [ |
|||||
78 | 6 | 'type' => 'compact', |
|||||
79 | 6 | 'dataSource' => $this->dataSource, |
|||||
80 | 6 | 'ioConfig' => [ |
|||||
81 | 6 | 'type' => 'compact', |
|||||
82 | 6 | 'inputSpec' => [ |
|||||
83 | 6 | 'type' => 'interval', |
|||||
84 | 6 | 'interval' => $this->interval->getInterval(), |
|||||
85 | 6 | ], |
|||||
86 | 6 | ], |
|||||
87 | 6 | ]; |
|||||
88 | |||||||
89 | 6 | if ($this->targetCompactionSizeBytes !== null && $this->targetCompactionSizeBytes > 0) { |
|||||
90 | 1 | $result['targetCompactionSizeBytes'] = $this->targetCompactionSizeBytes; |
|||||
91 | } |
||||||
92 | |||||||
93 | 6 | if ($this->taskId) { |
|||||
94 | 3 | $result['id'] = $this->taskId; |
|||||
95 | } |
||||||
96 | |||||||
97 | 6 | if ($this->segmentGranularity) { |
|||||
98 | 6 | $result['segmentGranularity'] = $this->segmentGranularity->value; |
|||||
99 | } |
||||||
100 | |||||||
101 | 6 | if ($this->tuningConfig instanceof TuningConfig) { |
|||||
102 | 5 | $this->tuningConfig->setType('index'); |
|||||
0 ignored issues
–
show
The method
setType() does not exist on Level23\Druid\TuningConfig\TuningConfigInterface . Since it exists in all sub-types, consider adding an abstract or default implementation to Level23\Druid\TuningConfig\TuningConfigInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
103 | 5 | $result['tuningConfig'] = $this->tuningConfig->toArray(); |
|||||
104 | } |
||||||
105 | |||||||
106 | 6 | $context = $this->context ? $this->context->toArray() : []; |
|||||
107 | 6 | if (count($context) > 0) { |
|||||
108 | 2 | $result['context'] = $context; |
|||||
109 | } |
||||||
110 | |||||||
111 | 6 | return $result; |
|||||
112 | } |
||||||
113 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.