1

My rethinkdb stores data in the following format.

data = [{
      'appName': "app1",
      'startTime': "Mon, 14 Feb 2017 05:10:00 GMT",
      'endTime': "Mon, 14 Feb 2017 05:15:00 GMT",
      'status': "SUCCESS"
    },
    {
      'appName': "app1",
      'startTime': "Mon, 13 Feb 2017 05:10:00 GMT",
      'endTime': "Mon, 13 Feb 2017 05:15:00 GMT",
      'status': "FAILED"
    },
    {
      'appName': "app2",
      'startTime': "Mon, 13 Feb 2017 05:10:00 GMT",
      'endTime': "Mon, 13 Feb 2017 05:15:00 GMT",
      'status': "RUNNING"
    }]

I need to fetch the latest information for all apps.

r.table('apps').group('appName').max('startTime').run()

But since my startTime is stored as a string, I can not do a max operation.

I tried updating the values in the table as follows,

r.table('apps').update({'startTimeDate': pytz.timezone('Europe/Rome').localize(datetime.strptime(r.row['startTime'], '%a, %d %b %Y %H:%M:%S GMT'))}).run()

I receive an error:

TypeError: must be string, not Bracket

How do I persist startTime and endTime as date in rethinkdb from string?

1 Answer 1

0

RethinkDB only supports dates formatted as ISO8601 or as a number of seconds since the UNIX epoch.

Your update query has the right idea, but it tries to use python functions inside the update, where row['startTime'] is a query fragment and not a string.

Something like this might work instead:

for app in r.table('apps').run():
  date = (pytz.timezone('Europe/Rome')
              .localize(datetime.strptime(app['startTime'],
                                          '%a, %d %b %Y %H:%M:%S GMT'))
  (r.table('apps')
    .get(app['id'])
    .update({'startTimeDate': date},
            durability='soft')
  ).run()
r.table('apps').sync()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.