Passed
Pull Request — master (#38)
by Teye
05:43
created

OrcInputFormat::toArray()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 10
cc 3
nc 4
nop 0
crap 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\InputFormats;
5
6
class OrcInputFormat implements InputFormatInterface
7
{
8
    protected ?FlattenSpec $flattenSpec;
9
10
    protected ?bool $binaryAsString;
11
12
    /**
13
     * @param FlattenSpec|null $flattenSpec    Specifies flattening configuration for nested ORC data. See flattenSpec
14
     *                                         for more info.
15
     * @param bool|null        $binaryAsString Specifies if the binary orc column which is not logically marked as a
16
     *                                         string should be treated as a UTF-8 encoded string. Default is false.
17
     */
18 2
    public function __construct(FlattenSpec $flattenSpec = null, bool $binaryAsString = null)
19
    {
20 2
        $this->flattenSpec    = $flattenSpec;
21 2
        $this->binaryAsString = $binaryAsString;
22
    }
23
24
    /**
25
     * Return the OrcInputFormat so that it can be used in a druid query.
26
     *
27
     * @return array<string,string|array<string,bool|array<array<string,string>>>|bool>
28
     */
29 2
    public function toArray(): array
30
    {
31 2
        $result = ['type' => 'orc'];
32
33 2
        if (!empty($this->flattenSpec)) {
34 2
            $result['flattenSpec'] = $this->flattenSpec->toArray();
35
        }
36
37 2
        if ($this->binaryAsString !== null) {
38 2
            $result['binaryAsString'] = $this->binaryAsString;
39
        }
40
41 2
        return $result;
42
    }
43
}