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

Decoding and path problems on windows #84

Open
gijzelaerr opened this issue Aug 21, 2020 · 8 comments
Open

Decoding and path problems on windows #84

gijzelaerr opened this issue Aug 21, 2020 · 8 comments
Assignees
Labels
Milestone

Comments

@gijzelaerr
Copy link
Collaborator

gijzelaerr commented Aug 21, 2020

When running this script on Windows:

https://github.com/MonetDBSolutions/monetdbe-examples/blob/master/python/taxi.py

we see the error:

ParseException:SQLparser:42000!COPY INTO: filename must have absolute path: "C:ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\020\016`>g\002"
Traceback (most recent call last):
  File "taxi.py", line 156, in <module>
    loaddb(path)
  File "taxi.py", line 54, in loaddb
    cursor.execute("""
  File "C:\Python38\lib\site-packages\monetdbe\cursor.py", line 152, in execute
    self.result, self.rowcount = self.connection.lowlevel.query(formatted, make_result=True)  # type: ignore
  File "C:\Python38\lib\site-packages\monetdbe\_cffi.py", line 244, in query
    check_error(lib.monetdbe_query(self._connection, query.encode(), p_result, affected_rows))
  File "C:\Python38\lib\site-packages\monetdbe\_cffi.py", line 82, in check_error
    raise exception(msg)
monetdbe.exceptions.OperationalError: COPY INTO: filename must have absolute path: "C:ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\020\016`>g\002"

The script issues a COPY INTO command, but the path is not properly escaped. When the script is modified with:

path = os.getcwd().replace("\\", "\\\\") + '\\\\..\\\\'

Above error is not properly decoded by monetdbe though:

Traceback (most recent call last):
  File "taxi.py", line 156, in <module>
    loaddb(path)
  File "taxi.py", line 54, in loaddb
    cursor.execute("""
  File "C:\Python38\lib\site-packages\monetdbe\cursor.py", line 152, in execute
    self.result, self.rowcount = self.connection.lowlevel.query(formatted, make_result=True)  # type: ignore
  File "C:\Python38\lib\site-packages\monetdbe\_cffi.py", line 244, in query
    check_error(lib.monetdbe_query(self._connection, query.encode(), p_result, affected_rows))
  File "C:\Python38\lib\site-packages\monetdbe\_cffi.py", line 69, in check_error
    decoded = ffi.string(msg).decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcd in position 79: invalid continuation byte

Monetdbe-Python assumes the error strings returned by monetdb are UTF-8, but in this case the are somehow latin-1. If we change the decoding of the monetdbe errors to to latin-1 we get the proper error.

@gijzelaerr gijzelaerr changed the title Problems on windows Decoding and path problems on windows Aug 21, 2020
@gijzelaerr
Copy link
Collaborator Author

@njnes can you give your opinion about this issue? :)

@njnes
Copy link
Member

njnes commented Aug 28, 2020

monetdbe (and server) expect input 2 be utf8, ie how could monetdbe generate latin-1?

@gijzelaerr
Copy link
Collaborator Author

I think the issue was misdiagnosed, and the path is containing illegal characters.

@gijzelaerr gijzelaerr added this to the 0.9 milestone Sep 11, 2020
@gijzelaerr
Copy link
Collaborator Author

This is still an issue, If I run the query:

COPY OFFSET 2 INTO yellow_tripdata_2016_01 FROM 'C:\Users\gijs\Code\monetdbe-examples\data\yellow_tripdata_2016-01.csv' delimiters ',','

I get the error:

monetdbe.exceptions.OperationalError: COPY INTO: filename must have absolute path: "C:"

@njnes
Copy link
Member

njnes commented Oct 9, 2020

the string passed to the c level should be
COPY OFFSET 2 INTO yellow_tripdata_2016_01 FROM 'C:\Users\gijs\Code\monetdbe-examples\data\yellow_tripdata_2016-01.csv' delimiters ',','

@gijzelaerr
Copy link
Collaborator Author

0.9 has been release, i just didn't manage to test this on Windows yet, so we still have to see if that is resolved.

@gijzelaerr
Copy link
Collaborator Author

This now gives a ParseException:SQLparser:42000!NULL byte in string on all platforms, double escaped or not.

@gijzelaerr gijzelaerr modified the milestones: 0.9, 0.10 Dec 4, 2020
@gijzelaerr
Copy link
Collaborator Author

All these give the same errors:

con = connect()
q1 = "COPY OFFSET 2 INTO t FROM 'C:\\does\\not\\exist.csv' delimiters ',','"
con.execute(q1)
q2 = "COPY OFFSET 2 INTO t FROM 'C:\\\\does\\\\not\\\\exist.csv' delimiters ',','"
con.execute(q1)
q13= r"COPY OFFSET 2 INTO t FROM 'C:\does\not\exist.csv' delimiters ',','"
con.execute(q1)

@gijzelaerr gijzelaerr modified the milestones: 0.10, 0.11 Apr 9, 2021
@gijzelaerr gijzelaerr modified the milestones: 0.11, 0.12 Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants