Skip to content
This repository has been archived by the owner on Sep 22, 2021. It is now read-only.

Problem with filtering #24

Open
philippejuhel opened this issue May 20, 2014 · 4 comments
Open

Problem with filtering #24

philippejuhel opened this issue May 20, 2014 · 4 comments
Labels

Comments

@philippejuhel
Copy link

I use a simple CSV file named data.csv :

name,firstname,age
bidule,marcel,45
machin,joseph,34
truc,paul,12

When I do :
http://timmy.icam-toulouse.fr/i48/?source=http://timmy.icam-toulouse.fr/eleve/data.csv&format=json
I get :
[{"nom":"bidule","prenom":"marcel","age":"45"},{"nom":"machin","prenom":"joseph","age":"34"},{"nom":"truc","prenom":"paul","age":"12"}]

OK

When I do :
http://timmy.icam-toulouse.fr/i48/?source=http://timmy.icam-toulouse.fr/eleve/data.csv&format=json&age=45 (filter age=45, the fisrt row)
I get :
[{"nom":"bidule","prenom":"marcel","age":"45"}]

OK

When I do :
http://timmy.icam-toulouse.fr/i48/?source=http://timmy.icam-toulouse.fr/eleve/data.csv&format=json&age=12 (filter age=12, the third row)
I get :
{"2":{"nom":"truc","prenom":"paul","age":"12"}}

BAD.
Why do I have {“2”: … and not [{"nom":"truc","prenom":"paul","age":"12"}] as I can expect?

@waldoj
Copy link
Contributor

waldoj commented May 21, 2014

I have no idea of what's going on here. But I did explore some more and found that it's part of a larger pattern. For example, if I filter not by age, but by last name.

http://timmy.icam-toulouse.fr/i48/?source=http://timmy.icam-toulouse.fr/eleve/data.csv&format=json&prenom=paul:

{"2":{"nom":"truc","prenom":"paul","age":"12"}}

So that's prefixed with 2. Then if I perform the same filter, but for joseph instead of paul:

http://timmy.icam-toulouse.fr/i48/?source=http://timmy.icam-toulouse.fr/eleve/data.csv&format=json&prenom=joseph:

{"1":{"nom":"machin","prenom":"joseph","age":"34"}}

It's notable that these prefixes correspond to their positions in the master CSV file—2, and 1. But if I filter based on prenom=marcel, I don't get a prefix of 0, as would be expected. So there's even a bug within this bug.

I don't have the time to fix this just now, but I do want to get some more information recorded about the bug here, for when I have the time, or somebody else might be able to identify and fix the problem.

@philippejuhel
Copy link
Author

Thank you for your two replies.

For the problem of filtering, I duplicate the first line of data in the CSV file so in my program, I only care about the line 2, 3, …

It’s a workaround but it’s OK.

Regards,

Philippe JUHEL

  • Edit - removing earlier messages duplicated below -GB *

@gbinal gbinal added the bug label Nov 3, 2014
@eydelrivero
Copy link

I know there is no activity on this thread since two years now, but it might be helpful for someone in the future to know that the issue is caused by the line 1349 in class.csv-to-api.php saying:

$filtered[$key] = $obj;

It is enough to say:

$filtered[] = $obj;

That will fix the problem.

@thesneakattack
Copy link

I know there is no activity on this thread since two years now, but it might be helpful for someone in the future to know that the issue is caused by the line 1349 in class.csv-to-api.php saying:

$filtered[$key] = $obj;

It is enough to say:

$filtered[] = $obj;

That will fix the problem.

Can we confirm that this is resolved?

ajlb added a commit to ajlb/csv-to-api that referenced this issue Aug 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants