Bug #84585 Invalid operator in expression
Submitted: 20 Jan 2017 13:27 Modified: 9 Mar 2017 18:47
Reporter: William Chiquito Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S2 (Serious)
Version:2.2.2 m3 OS:Any
Assigned to: CPU Architecture:Any
Tags: expression, operators, python, XDevAPI

[20 Jan 2017 13:27] William Chiquito
Description:
Doesn't seem to parse correctly the expression.

Error:

Traceback (most recent call last):
  File "test.py", line 24, in <module>
    .bind('{"country": "Mexico", "gnp": 12345}') \
  File "/usr/local/lib/python2.7/dist-packages/mysqlx/statement.py", line 516, in execute
    return self._connection.find(self)
  File "/usr/local/lib/python2.7/dist-packages/mysqlx/connection.py", line 123, in wrapper
    return func(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/mysqlx/connection.py", line 201, in find
    return DocResult(self) if statement._doc_based else RowResult(self)
  File "/usr/local/lib/python2.7/dist-packages/mysqlx/result.py", line 834, in __init__
    super(DocResult, self).__init__(connection)
  File "/usr/local/lib/python2.7/dist-packages/mysqlx/result.py", line 706, in __init__
    self._init_result()
  File "/usr/local/lib/python2.7/dist-packages/mysqlx/result.py", line 709, in _init_result
    self._columns = self._connection.get_column_metadata(self)
  File "/usr/local/lib/python2.7/dist-packages/mysqlx/connection.py", line 123, in wrapper
    return func(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/mysqlx/connection.py", line 242, in get_column_metadata
    return self.protocol.get_column_metadata(result)
  File "/usr/local/lib/python2.7/dist-packages/mysqlx/protocol.py", line 318, in get_column_metadata
    msg = self._read_message(rs)
  File "/usr/local/lib/python2.7/dist-packages/mysqlx/protocol.py", line 302, in _read_message
    raise OperationalError(msg.msg)
mysqlx.errors.OperationalError: Invalid operator AND

How to repeat:
'''
Using:
    * Python: 2.7.12
    * MySQL: 5.7.17
    * Schema: world_x http://downloads.mysql.com/docs/world_x-db.zip
    * Connector/Python: 2.2.2 m3 https://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.2.2.tar.gz
'''

import os
import mysqlx
import string

session = mysqlx.get_session({
    'host': 'localhost',
    'port': 33060,
    'user': os.environ['user'],
    'password': os.environ['password']
})

schema = session.get_schema('world_x')
collection = schema.get_collection('countryinfo')

''' Work
print "Find Mexico***\n"
result = collection.find('Name = :country') \
                   .bind('{ "country": "Mexico" }') \
                   .execute()
'''
# Not work
result = collection.find('Name = :country and GNP = :gnp') \
                   .bind('{ "country": "Mexico", "gnp": 414972 }') \
                   .execute()

row = result.fetch_all()

for i, data in enumerate(row):
    print "{iteration}: {data}".format(iteration = i, data = data)

session.close()
[23 Jan 2017 12:39] Chiranjeevi Battula
Hello William Chiquito,

Thank you for the bug report.

Thanks,
Chiranjeevi.
[9 Mar 2017 18:47] Paul DuBois
Posted by developer:
 
Noted in 2.2.3 changelog.

The Collection.find() method failed to work with several operators.
Support was added for these operators:

Nullary Operators:
   *

Unary Operators:
   !, not, +, -, ~

Binary Operators:
   and, &&, or, ||, xor, <>, ^
   is not, not regexp, not like, cast, not in

Ternary Operators:
   not between

Also the arrow notation to access JSON columns is now functional (schema.table.column->'$.document field').