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

NameError: name 'message' is not defined #419

Closed
oualib opened this issue Oct 9, 2021 · 2 comments
Closed

NameError: name 'message' is not defined #419

oualib opened this issue Oct 9, 2021 · 2 comments
Labels
bug protocol requires Vertica protocol knowledge

Comments

@oualib
Copy link
Member

oualib commented Oct 9, 2021

I am trying to load a file:

CREATE TABLE "public"."test3"("pclass" Integer, "survived" Integer, "name" Varchar(164), "sex" Varchar(20), "age" Numeric(8,4), "sibsp" Integer, "parch" Integer, "ticket" Varchar(36), "fare" Numeric(11,6), "cabin" Varchar(30), "embarked" Varchar(20), "boat" Varchar(100), "body" Varchar(100), "home.dest" Varchar(100));
COPY "public"."test3"("pclass", 
                      "survived", 
                      "name", 
                      "sex", 
                      "age", 
                      "sibsp", 
                      "parch", 
                      "ticket", 
                      "fare", 
                      "cabin", 
                      "embarked", 
                      "boat", 
                      "body", 
                      "home.dest") FROM LOCAL 'titanic_test.csv' 
DELIMITER ',' NULL '' ESCAPE AS '\' SKIP 1 ABORT ON ERROR;

After checking with vsql, the error message is clear. There is a 'quote' problem in the file.
This is the python message:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-3-740b48eb7b6c> in <module>()
----> 1 get_ipython().run_cell_magic('sql', '', 'DROP TABLE IF EXISTS "public"."test3";\nCREATE TABLE "public"."test3"("pclass" Integer, "survived" Integer, "name" Varchar(164), "sex" Varchar(20), "age" Numeric(8,4), "sibsp" Integer, "parch" Integer, "ticket" Varchar(36), "fare" Numeric(11,6), "cabin" Varchar(30), "embarked" Varchar(20), "boat" Varchar(100), "body" Varchar(100), "home.dest" Varchar(100));\nCOPY "public"."test3"("pclass", \n                      "survived", \n                      "name", \n                      "sex", \n                      "age", \n                      "sibsp", \n                      "parch", \n                      "ticket", \n                      "fare", \n                      "cabin", \n                      "embarked", \n                      "boat", \n                      "body", \n                      "home.dest") FROM LOCAL \'titanic_test.csv\' \nDELIMITER \',\' NULL \'\' ESCAPE AS \'\\\' SKIP 1 ABORT ON ERROR;')

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
   2129             magic_arg_s = self.var_expand(line, stack_depth)
   2130             with self.builtin_trap:
-> 2131                 result = fn(magic_arg_s, cell)
   2132             return result
   2133 

~/Library/Python/3.6/lib/python/site-packages/verticapy/sql.py in sql(line, cell, local_ns)
    171                 cursor.copy(query, fs)
    172         elif (i < n - 1) or ((i == n - 1) and (query_type.lower() not in ("select", "with", "undefined"))):
--> 173             cursor.execute(query)
    174             if verticapy.options["print_info"]:
    175                 print(query_type)

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/vertica_python/vertica/cursor.py in execute(self, operation, parameters, use_prepared_statements, copy_stdin, buffer_size)
    220             if parameters:
    221                 operation = self.format_operation_with_parameters(operation, parameters)
--> 222             self._execute_simple_query(operation)
    223 
    224         return self

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/vertica_python/vertica/cursor.py in _execute_simple_query(self, query)
    613                 raise errors.QueryError.from_error_response(self._message, query)
    614             elif isinstance(self._message, messages.VerifyFiles):
--> 615                 self._handle_copy_local_protocol()
    616 
    617     def _handle_copy_local_protocol(self):

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/vertica_python/vertica/cursor.py in _handle_copy_local_protocol(self)
    674                 while True:
    675                     self._send_copy_file_data()
--> 676                     if not self._read_copy_data_response():
    677                         break
    678         except Exception as e:

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/vertica_python/vertica/cursor.py in _read_copy_data_response(self, is_stdin_copy)
    751             return True
    752         elif not isinstance(self._message, messages.CopyDoneResponse):
--> 753             raise errors.MessageError('Unexpected COPY-LOCAL message: {0}'.format(message))
    754         return False
    755 

NameError: name 'message' is not defined

My guess is to define the variable 'message' in the file cursor.py (line 753).
My vertica_python version is 1.0.1.

@sitingren sitingren added the bug label Oct 9, 2021
@sitingren
Copy link
Member

@oualib Thank you for reporting this issue. Would you please provide the file content to reproduce this issue? The vsql error message would also be helpful.

@oualib
Copy link
Member Author

oualib commented Oct 9, 2021

@sitingren Just sent you a mail.

sitingren added a commit to sitingren/vertica-python that referenced this issue Oct 11, 2021
@sitingren sitingren added the protocol requires Vertica protocol knowledge label Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug protocol requires Vertica protocol knowledge
Projects
None yet
Development

No branches or pull requests

2 participants