ProtobufInputFormat   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
dl 0
loc 51
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toArray() 0 12 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\InputFormats;
5
6
class ProtobufInputFormat implements InputFormatInterface
7
{
8
    /**
9
     * @var array<string,string>
10
     */
11
    protected array $protoBytesDecoder;
12
13
    protected ?FlattenSpec $flattenSpec;
14
15
    /**
16
     *
17
     * @param array<string,string> $protoBytesDecoder Specifies how to decode bytes to Protobuf record. See below for
18
     *                                                an example.
19
     * @param FlattenSpec|null     $flattenSpec       Define a flattenSpec to extract nested values from a Parquet
20
     *                                                file. Note that only 'path' expression are supported ('jq' is
21
     *                                                unavailable).
22
     *
23
     * Example $protoBytesDecoder value:
24
     * ```
25
     * [
26
     *     "type" => "file",
27
     *     "descriptor" => "file:///tmp/metrics.desc",
28
     *     "protoMessageType" => "Metrics"
29
     * ]
30
     * ```
31
     *
32
     * @see https://druid.apache.org/docs/latest/ingestion/data-formats.html#protobuf
33
     */
34 1
    public function __construct(array $protoBytesDecoder, ?FlattenSpec $flattenSpec = null)
35
    {
36 1
        $this->protoBytesDecoder = $protoBytesDecoder;
37 1
        $this->flattenSpec       = $flattenSpec;
38
    }
39
40
    /**
41
     * Return the ProtobufInputFormat so that it can be used in a druid query.
42
     *
43
     * @return array<string,string|array<string,bool|array<array<string,string>>>|string[]>
44
     */
45 1
    public function toArray(): array
46
    {
47 1
        $result = [
48 1
            'type'              => 'protobuf',
49 1
            'protoBytesDecoder' => $this->protoBytesDecoder,
50 1
        ];
51
52 1
        if ($this->flattenSpec) {
53 1
            $result['flattenSpec'] = $this->flattenSpec->toArray();
54
        }
55
56 1
        return $result;
57
    }
58
}