harelba / q

q - Run SQL directly on delimited files and multi-file sqlite databases
http://harelba.github.io/q/
GNU General Public License v3.0
10.15k stars 419 forks source link

AttributeError("'dict' object has no attribute 'iteritems'") #264

Closed djacob65 closed 2 years ago

djacob65 commented 3 years ago

When I use the options -S dbtmp --save-db-to-disk-method=fast, I obtained this error: AttributeError("'dict' object has no attribute 'iteritems'") whereas without them, the query works fine.

my config: python 3.7 / sqlite3 3.36.0 (compiled from source in order to change the max columns limit) both sqlitebck and six python modules installed q version 2.0.19, running from source (q.py)

djacob65 commented 3 years ago

The method "iteritems" has been removed from python3. We have to replace it by 'items'. So, after replacing it at the line 302 in the function 'store_db_to_disk_fast', the error does not occur anymore.

line 302: table_names_mapping.iteritems() changed by table_names_mapping.items()

However, it still doesn't work with the -S dbtmp.db --save-db-to-disk-method=fast options and I don't know why. I get a message like this: Going to save data into a disk database: dbtmp.db Data has been loaded in 0.043 seconds Saving data to db file dbtmp.db Data has been saved into dbtmp.db . Saving has taken 0.027 seconds

But no data to output :-( Need more investigations

harelba commented 3 years ago

Hi @djacob65 , thanks for reporting this. It's indeed a bug. I'm sorry I can't provide an immediate solution for this, but i'm releasing a new major version of q in the coming weeks, which touches this area as well, and this issue will be fixed in that new version.

djacob65 commented 3 years ago

@harelba thank you for your reply

On my side, I have made more investigations

this command /usr/bin/q -H -O -t -e iso-8859-1 -S dbtmp.db --save-db-to-disk-method=fast "select * from Sample_metadata.txt"; echo $?

returns no data with a zero code error and the message

Going to save data into a disk database: dbtmp.db Data has been loaded in 0.016 seconds Saving data to db file dbtmp.db Data has been saved into dbtmp.db. Saving has taken 0.023 seconds Query to run on the database: select * from Sample_metadata.txt;

and now, this command echo 'select * from "Sample_metadata.txt" f1' | sqlite3 dbtmp.db 1>/dev/null; echo $?

Returns data with a zero code error.

The issue comes from the fact that 1) in the first command, if we put the table name with quote, we get an error 2) in the second command, if we put the table without quote, we get an error

This seriously complicates the generation of SQL queries in programmatic mode as it is the case in my application. But I don't know if it comes from q itself or sqlite3. To be continued ...

harelba commented 3 years ago

Thanks for continuing to analyse this @djacob65

The only reason i'm not rushing into finding the root cause and fixing this is because my current changes (the ones which will go out soon) touch this area specifically, and will probably provide a solution for this use-case and many others in a more seamless way. Also, the packaging for q is not really seamless unfortunately, so getting out a new version just for this fix would take a lot of effort.

I'm aiming for the new version to be released rather soon, a couple of weeks or so, so please forgive me for this. I'm quite confident that the new version would answer your use-case properly.

djacob65 commented 3 years ago

@harelba No worries, I understand. On my side, I've solved my issues. :-)

InCogNiTo124 commented 2 years ago

@harelba Sorry for the bump, but I believe this is now fixed and could be closed

harelba commented 2 years ago

thanks @InCogNiTo124 !