Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Import from CSV into table creates empty row of nulls for header row #136
(Sorry to be raising so many issues in such a short timespan. I absolutely love nanoSQL and want to create a wrapper library so it can be used in Google Dart, and I'm discovering issues as part of my unit testing of that wrapper. I hope it's not too annoying!)
Consider the following script using 2.2.2, which imports five identically-shaped CSV files into a table.
(The sample data is attached to #132 .)
Each of the five files contains a header row and then 100 data rows, for a total of 101 rows. The documentation at https://nanosql.gitbook.io/docs/query/import-and-export#import-csv stipulates that there must be a header row in the file.
Since each file contains 100 data rows, the total number of rows in the database after import should be 500. Since no data row contains any null values, the total number of rows in the database matching a SELECT ... WHERE on a NULL should be zero.
The results of the script show (a) that there are 505 rows, not 500; and (b) there are five rows containing null values, not zero.
My guess is that the header rows in the CSV files are being transformed into rows of nulls in the database.
Additionally - and this is more of a question - I wasn't sure how to query on NULL in a SQL-like manner, which is why I used a closure in this specific case. None of the following possibilities returned a valid result:
Is there a way to query for a null value other than by closure?
Absolutely no problem with these many issues, I can't express how grateful I am that you take the time to not only report the issues but provide full examples to test the issues with. It's extremely helpful!
It looks like the issue is actually the empty line at the bottom of your CSV files. I'm still using the example CSVs provided in the
This will be taken care of with a release later today of
The proper way to test for null is like this:
.where(["forename", "=", "NULL"])
Oh yes! That makes much more sense (a redundant \n at the end of each CSV file) than the header row being mishandled. Thank you for checking.
I tried your WHERE syntax in the test file and I couldn't get it to work; it returns an empty array for me, rather than the five rows containing nulls. The exact query I am using is:
Ah, the issue is you're requesting a NULL value for a secondary index.
Secondary indexes bypass the standard query path and use an optimized one that isn't intended to handle NULL. I'll add some code to handle NULL and have