Skip to content

Commit 9024e7b

Browse files
author
rotten
committed
work on operator functions started
1 parent 59d42da commit 9024e7b

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

rethinkdb-multicorn-fdw.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
11
## This is the implementation of the Multicorn ForeignDataWrapper class that does all of the work in RethinkDB
22
## R.Otten - 2014
33

4+
import operator
5+
46
from multicorn import ForeignDataWrapper
57
from multicorn.utils import log_to_postgres, ERROR, WARNING, DEBUG
68

79
import rethinkdb as r
810

11+
12+
## Translate a string with an operator in it (eg. ">=") into a function.
13+
# hint from here: http://stackoverflow.com/questions/1740726/python-turn-string-into-operator
14+
# Things that might come from PostgreSQL: http://www.postgresql.org/docs/9.3/static/functions-comparison.html
15+
def getOperatorFunction(opr):
16+
17+
'<': operator.lt
18+
'>': operator.gt
19+
'<=': operator.le
20+
'>=': operator.ge
21+
'=': operator.eq
22+
'<>': operator.ne
23+
'!=': operator.ne
24+
'@>': operator.contains
25+
'<@':
26+
'<<':
27+
'>>':
28+
'&<':
29+
'>&':
30+
'&&':
31+
'is':
32+
'~':
33+
'~*':
34+
'!~':
35+
'!~*':
36+
'~~':
37+
'like':
38+
'~~*':
39+
'ilike':
40+
'similar to':
41+
# I'm not sure we'll get "between" so it isn't implemented for now.
42+
# I'm not sure 'OR' will get through either as an operator.
43+
# We are not going to try to support Geometric object operators at this time.
44+
# Nor will we support the Network Address operators yet.
45+
# There aren't any json specific comparison operators yet (if there were, we would want to try to implement them)
46+
47+
## The Foreign Data Wrapper Class:
948
class RethinkdbFDW(ForeignDataWrapper):
1049

1150
"""
@@ -51,8 +90,8 @@ def execute(self, quals, columns):
5190

5291
for qual in quals:
5392

54-
## -- this isn't right yet.
55-
myQuery = myQuery.filter(qual.field_name + ' ' + qual.operator + ' ' + qual.value)
93+
operatorFunction = getOperatorFunction(qual.operator)
94+
myQuery = myQuery.filter(operatorFunction(r.row[qual.field_name], qual.value))
5695

5796
return _run_rethinkdb_action(action=myQuery)
5897

0 commit comments

Comments
 (0)