Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delimiter_detect and the $limit behavior #366

Closed
Sharptsa opened this issue Dec 13, 2019 · 0 comments
Closed

delimiter_detect and the $limit behavior #366

Sharptsa opened this issue Dec 13, 2019 · 0 comments

Comments

@Sharptsa
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants