libAtoms / abcd

2 stars 4 forks source link

Warning for query with wrong order (e.g. `-q "0.01>E_CC_MP2_2B"`) #54

Open eszter137 opened 5 years ago

eszter137 commented 5 years ago

The problem is with the ordering of the relation in the above query; -q "E_CC_MP2_2B<0.01" would work. Current error message:


Traceback (most recent call last):
  File "/Users/es732/anaconda3/bin/abcd", line 10, in <module>
    sys.exit(main())
  File "/Users/es732/anaconda3/lib/python3.7/site-packages/abcd/frontends/cli/parser.py", line 101, in main
    return callback_func(**kwargs)
  File "/Users/es732/anaconda3/lib/python3.7/site-packages/abcd/frontends/cli/decorators.py", line 32, in wrapper
    func(*args, config=config, **kwargs)
  File "/Users/es732/anaconda3/lib/python3.7/site-packages/abcd/frontends/cli/decorators.py", line 52, in wrapper
    func(*args, db=db, query=q, **kwargs)
  File "/Users/es732/anaconda3/lib/python3.7/site-packages/abcd/frontends/cli/decorators.py", line 23, in wrapper
    func(*args, style=style, **kwargs)
  File "/Users/es732/anaconda3/lib/python3.7/site-packages/abcd/frontends/cli/commands.py", line 174, in summary
    data = db.hist('arrays.' + p, query=query, bins=bins, truncate=truncate)
  File "/Users/es732/anaconda3/lib/python3.7/site-packages/abcd/backends/atoms_mongoengine.py", line 628, in hist
    data = self.property(name, query)
  File "/Users/es732/anaconda3/lib/python3.7/site-packages/abcd/backends/atoms_mongoengine.py", line 485, in property
    return [val['data'] for val in AtomsModel.objects.query(query).aggregate(*pipeline)]
  File "/Users/es732/anaconda3/lib/python3.7/site-packages/mongoengine/queryset/base.py", line 1212, in aggregate
    return self._collection.aggregate(pipeline, cursor={}, **kwargs)
  File "/Users/es732/anaconda3/lib/python3.7/site-packages/pymongo/collection.py", line 2411, in aggregate
    **kwargs)
  File "/Users/es732/anaconda3/lib/python3.7/site-packages/pymongo/collection.py", line 2318, in _aggregate
    user_fields={'cursor': {'firstBatch': 1}})
  File "/Users/es732/anaconda3/lib/python3.7/site-packages/pymongo/pool.py", line 584, in command
    user_fields=user_fields)
  File "/Users/es732/anaconda3/lib/python3.7/site-packages/pymongo/network.py", line 158, in command
    parse_write_concern_error=parse_write_concern_error)
  File "/Users/es732/anaconda3/lib/python3.7/site-packages/pymongo/helpers.py", line 155, in _check_command_response
    raise OperationFailure(msg % errmsg, code, response)
pymongo.errors.OperationFailure: $or/$and/$nor entries need to be full objects```
fekad commented 5 years ago

@gabor1 Do you want to support when you have "{value}{operator}{key}" or you want to catch the error? We would have a more complex parser for recognising what "0.01>E_CC_MP2_2B" means at all?

gabor1 commented 5 years ago

well binary operators like that work both ways in any programming language, so it would be strange not to support that, no?

fekad commented 5 years ago

No, it is more like a filter where you have syntax like: {labels} {operators} {values}. Like in a dictionary you have a specific structure (keys and values) and you cannot switch the order. I mean in special cases you can but that will be a completly different object.

In the case of the programing language, it is easier because you can evaluate the whole expression.

Here have to figure out which one is the label: "0.01" or "E_CC_MP2_2B":

atoms.info["0.01"] > "E_CC_MP2_2B"

vs

atoms.info["E_CC_MP2_2B"] < 0.01
gabor1 commented 5 years ago

fine. we'll call it an enhancement and so push it down the priority list ;-)

fekad commented 5 years ago

To implement this issue there could cause a big performance decrease because we have to handle all labels in the query as a regex. I would estimate feature needs more than 2 weeks to implement it properly.

gabor1 commented 5 years ago

This was discussed, and we decided that once strings values are indicated with quotes, it should be no problem to have either order around a binary operator.