|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Level23\Druid\Filters; |
|
5
|
|
|
|
|
6
|
|
|
use Level23\Druid\Types\DataType; |
|
7
|
|
|
|
|
8
|
|
|
class EqualityFilter implements FilterInterface |
|
9
|
|
|
{ |
|
10
|
|
|
protected string $column; |
|
11
|
|
|
|
|
12
|
|
|
protected string|int|float $value; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var \Level23\Druid\Types\DataType |
|
16
|
|
|
*/ |
|
17
|
|
|
protected DataType $matchValueType; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Equality Filter constructor. |
|
21
|
|
|
* |
|
22
|
|
|
* @param string $column Input column or virtual column name to filter. |
|
23
|
|
|
* @param string|int|float $value Value to match, must not be null. |
|
24
|
|
|
* @param \Level23\Druid\Types\DataType|null $matchValueType The type of value to match. When not given, we will |
|
25
|
|
|
* auto-detect the value based on the given value. |
|
26
|
|
|
*/ |
|
27
|
19 |
|
public function __construct( |
|
28
|
|
|
string $column, |
|
29
|
|
|
string|int|float $value, |
|
30
|
|
|
DataType $matchValueType = null |
|
31
|
|
|
) { |
|
32
|
19 |
|
if (is_null($matchValueType)) { |
|
33
|
|
|
|
|
34
|
19 |
|
if (is_int($value)) { |
|
35
|
3 |
|
$matchValueType = DataType::LONG; |
|
36
|
17 |
|
} elseif (is_float($value)) { |
|
37
|
4 |
|
$matchValueType = DataType::DOUBLE; |
|
38
|
|
|
} else { |
|
39
|
15 |
|
$matchValueType = DataType::STRING; |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
19 |
|
$this->value = $value; |
|
44
|
19 |
|
$this->matchValueType = $matchValueType; |
|
45
|
19 |
|
$this->column = $column; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Return the filter as it can be used in the druid query. |
|
50
|
|
|
* |
|
51
|
|
|
* @return array<string,string|int|float|array<string,string|int|bool|array<mixed>>> |
|
52
|
|
|
*/ |
|
53
|
10 |
|
public function toArray(): array |
|
54
|
|
|
{ |
|
55
|
10 |
|
return [ |
|
56
|
10 |
|
'type' => 'equals', |
|
57
|
10 |
|
'column' => $this->column, |
|
58
|
10 |
|
'matchValueType' => $this->matchValueType->value, |
|
59
|
10 |
|
'matchValue' => $this->value, |
|
60
|
10 |
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
} |