Skip to content

delimiter_detect and the $limit behavior #366

@Sharptsa

Description

@Sharptsa

Bug Report

Information Description
Version 9.4.1
PHP version 7.2.24

I think there is an issue with the behavior of the $limit parameter in the delimiter_detect function.
Or at least I find it really confusing.

Example with the following csv and call to the function:

foo;bar;hello_world
42;1,2,3,4,5;true
delimiter_detect($reader, [';', ','], 1)

In this case I would expect the function to only take the first line(the header) into account. And so ; would be the delimiter with the highest count.

But it actually returns:

[";" => 4, "," => 6]

It happens because of the record count where condition in the statement

$stmt = (new Statement())->limit($limit)->where(static function (array $record): bool {
    return count($record) > 1;
});

When counting for the , delimiter, it will skip the first line.

It makes so the delimiters are not compared to the same lines.
Because of this behavior it breaks the detection of delimiters on the header only (which is usually more consistent than other lines).

As a workaround I made my own delimiter_detect function, removing the condition on the statement and it works as expected.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions