| Total Complexity | 3 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class VirtualColumn implements VirtualColumnInterface |
||
| 9 | { |
||
| 10 | protected string $name; |
||
| 11 | |||
| 12 | protected string $expression; |
||
| 13 | |||
| 14 | protected DataType $outputType; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * VirtualColumn constructor. |
||
| 18 | * |
||
| 19 | * @param string $expression An druid expression |
||
| 20 | * @param string $as |
||
| 21 | * @param string|DataType $outputType |
||
| 22 | * |
||
| 23 | * @see https://druid.apache.org/docs/latest/misc/math-expr.html |
||
| 24 | */ |
||
| 25 | 23 | public function __construct(string $expression, string $as, string|DataType $outputType = DataType::FLOAT) |
|
| 26 | { |
||
| 27 | 23 | $this->name = $as; |
|
| 28 | 23 | $this->expression = $expression; |
|
| 29 | 23 | $this->outputType = is_string($outputType) ? DataType::from(strtolower($outputType)) : $outputType; |
|
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Return the virtual column as it can be used in a druid query. |
||
| 34 | * |
||
| 35 | * @return array<string,string> |
||
| 36 | */ |
||
| 37 | 8 | public function toArray(): array |
|
| 44 | 8 | ]; |
|
| 45 | } |
||
| 47 |