|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Level23\Druid\InputFormats; |
|
5
|
|
|
|
|
6
|
|
|
class TsvInputFormat extends CsvInputFormat |
|
7
|
|
|
{ |
|
8
|
|
|
protected ?string $delimiter; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @param array<string>|null $columns Specifies the columns of the data. The columns should be in the |
|
12
|
|
|
* same order with the columns of your data. |
|
13
|
|
|
* @param string|null $delimiter A custom delimiter for data values. |
|
14
|
|
|
* @param string|null $listDelimiter A custom delimiter for multi-value dimensions. |
|
15
|
|
|
* @param bool|null $findColumnsFromHeader If this is set, the task will find the column names from the |
|
16
|
|
|
* header row. Note that skipHeaderRows will be applied before |
|
17
|
|
|
* finding column names from the header. For example, if you set |
|
18
|
|
|
* skipHeaderRows to 2 and findColumnsFromHeader to true, the task |
|
19
|
|
|
* will skip the first two lines and then extract column |
|
20
|
|
|
* information from the third line. columns will be ignored if |
|
21
|
|
|
* this is set to true. |
|
22
|
|
|
* @param int $skipHeaderRows If this is set, the task will skip the first skipHeaderRows |
|
23
|
|
|
* rows. |
|
24
|
|
|
*/ |
|
25
|
7 |
|
public function __construct( |
|
26
|
|
|
array $columns = null, |
|
27
|
|
|
string $delimiter = null, |
|
28
|
|
|
string $listDelimiter = null, |
|
29
|
|
|
bool $findColumnsFromHeader = null, |
|
30
|
|
|
int $skipHeaderRows = 0 |
|
31
|
|
|
) { |
|
32
|
7 |
|
$this->delimiter = $delimiter; |
|
33
|
7 |
|
parent::__construct($columns, $listDelimiter, $findColumnsFromHeader, $skipHeaderRows); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Return the TsvInputFormat so that it can be used in a druid query. |
|
38
|
|
|
* |
|
39
|
|
|
* @return array<string,string|string[]|bool|int> |
|
40
|
|
|
*/ |
|
41
|
7 |
|
public function toArray(): array |
|
42
|
|
|
{ |
|
43
|
7 |
|
$result = parent::toArray(); |
|
44
|
7 |
|
$result['type'] = 'tsv'; |
|
45
|
|
|
|
|
46
|
7 |
|
if ($this->delimiter !== null) { |
|
47
|
3 |
|
$result['delimiter'] = $this->delimiter; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
7 |
|
return $result; |
|
51
|
|
|
} |
|
52
|
|
|
} |