Repository navigation
Multipath - Add MGET backward compatibility #497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -159,8 +159,8 @@ def testMGetCommand(env): | |
| """Test REJSON.MGET command""" | ||
| r = env | ||
| # Test mget with multi paths | ||
| r.assertOk(r.execute_command('JSON.SET', 'doc1', '$', '{"a":1, "b": 2, "nested": {"a": 3}, "c": null, "nested2": {"a": null}} ')) | ||
| r.assertOk(r.execute_command('JSON.SET', 'doc2', '$', '{"a":4, "b": 5, "nested": {"a": 6}, "c": null, "nested2": {"a": [null]}}')) | ||
| r.assertOk(r.execute_command('JSON.SET', 'doc1', '$', '{"a":1, "b": 2, "nested1": {"a": 3}, "c": null, "nested2": {"a": null}}')) | ||
| r.assertOk(r.execute_command('JSON.SET', 'doc2', '$', '{"a":4, "b": 5, "nested3": {"a": 6}, "c": null, "nested4": {"a": [null]}}')) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain this change?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wanted a path that would match only one of the keys (for the missing path/key scenario) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So why change an existing test and not add a new one?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This had no impact on existing tests (just names of internal paths) |
||
| # Compare also to single JSON.GET | ||
| res1 = r.execute_command('JSON.GET', 'doc1', '$..a') | ||
| res2 = r.execute_command('JSON.GET', 'doc2', '$..a') | ||
|
|
@@ -172,14 +172,38 @@ def testMGetCommand(env): | |
| r.assertEqual([res1], res) | ||
| # Test mget with multi path | ||
| res = r.execute_command('JSON.MGET', 'doc1', 'doc2', '$..a') | ||
| r.assertEqual(res, [res1,res2]) | ||
| r.assertEqual(res, [res1, res2]) | ||
|
|
||
| # Test missing key | ||
| # Test missing key/path | ||
| res = r.execute_command('JSON.MGET', 'doc1', 'missing_doc', '$..a') | ||
| r.assertEqual(res, [res1, None]) | ||
| res = r.execute_command('JSON.MGET', 'doc1', 'doc2', 'missing_doc', '$.nested1.a') | ||
| r.assertEqual(res, [json.dumps([json.loads(res1)[1]]), '[]', None]) | ||
| res = r.execute_command('JSON.MGET', 'missing_doc1', 'missing_doc2', '$..a') | ||
| r.assertEqual(res, [None, None]) | ||
|
|
||
| # Test missing path | ||
| res = r.execute_command('JSON.MGET', 'doc1', 'missing_doc2', '$..niente') | ||
| r.assertEqual(res, ['[]', None]) | ||
|
|
||
| # Test legacy (for each path only the first value is returned as a json string) | ||
| # Test mget with single path | ||
| res = r.execute_command('JSON.MGET', 'doc1', '..a') | ||
| r.assertEqual(res, [json.dumps(json.loads(res1)[0])]) | ||
| # Test mget with multi path | ||
| res = r.execute_command('JSON.MGET', 'doc1', 'doc2', '..a') | ||
| r.assertEqual(res, [json.dumps(json.loads(res1)[0]), json.dumps(json.loads(res2)[0])]) | ||
|
|
||
| # Test missing key/path | ||
| res = r.execute_command('JSON.MGET', 'doc1', 'doc2', 'missing_doc', '.nested1.a') | ||
| r.assertEqual(res, [json.dumps(json.loads(res1)[1]), None, None]) | ||
| res = r.execute_command('JSON.MGET', 'missing_doc1', 'missing_doc2', '..a') | ||
| r.assertEqual(res, [None, None]) | ||
|
|
||
| # Test missing path | ||
| res = r.execute_command('JSON.MGET', 'doc1', 'missing_doc2', '.niente') | ||
| r.assertEqual(res, [None, None]) | ||
|
|
||
|
|
||
| def testNumByCommands(env): | ||
| """ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this reverts the tests changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the previous change ignored the previous behavior. Since the path here starts with a
., the old behavior is now kept.