Search code examples
rethinkdbrethinkdb-python

rethinkDB eq(0) return value is not built-in boolean type?


Can anyone help me?? Why the return value of row['TimeInBucket1'].eq(0) is not True or False???? I

Here is the code in python

def map1(row):
    flgTB1 = row['TimeInBucket1'].eq(0)

    return {'nMX1Pop': 0 if flgTB1 else 1 ,
          'meanMX1Pop':0.0 if flgTB1 else row['MX1'],
          'varMX1Pop': 0.0 if flgTB1 else row['MX1']*row['MX1']
          }

cursor = r.db(dbName).table(tableName).map(map1).run(connection)

Solution

  • You're using Python's if/else, which is evaluated on the client. You need to use r.branch to do that on the server (so r.branch(flgTB1, 0, 1) instead of 0 if flgTB1 else 1).