Fix bug of mongo_fdw in Mar-2022#159
Open
khieuvm wants to merge 2 commits intoEnterpriseDB:masterfrom
Open
Conversation
**Describe the bug**
The value of int64 is bigger than int32, but check this value in the range of int32 type
**To Reproduce**
1. Run make check
2. See result of select file:
SELECT a FROM f_test_tbl7 ORDER BY 1;
ERROR: value "9999999999" is out of range for type integer
**Expected behavior**
SELECT a FROM f_test_tbl7 ORDER BY 1;
a
------------
0
25
25
25
1410065407
(5 rows)
**Solution**
Change check this value in the range of int32 type to int64 type
**Describe the bug**
NAMEOID does not support UTF8 bson type, the result will be null.
**To Reproduce**
1. Create foreign table:
CREATE FOREIGN TABLE f_test_name (_id name, c1 INTEGER, c2 name, c3 name)
SERVER mongo_server OPTIONS (database 'mongo_fdw_regress', collection 'test_tbl2');
2. SELECT:
SELECT * from f_test_name;
3. Actual:
SELECT * from f_test_name;
_id | c1 | c2 | c3
--------------------------+----+----+----
6242b41661829e26825ce3b5 | 10 | |
6242b41661829e26825ce3b6 | 20 | |
6242b41661829e26825ce3b7 | 30 | |
6242b41661829e26825ce3b8 | 40 | |
(4 rows)
**Expected behavior**
SELECT * from f_test_name;
_id | c1 | c2 | c3
--------------------------+----+----------------+----------
6242b41661829e26825ce3b5 | 10 | DEVELOPMENT | PUNE
6242b41661829e26825ce3b6 | 20 | ADMINISTRATION | BANGLORE
6242b41661829e26825ce3b7 | 30 | SALES | MUMBAI
6242b41661829e26825ce3b8 | 40 | HR | NAGPUR
(4 rows)
**Solution**
Check UTF8 bson type and convert it.
Collaborator
|
On Tue, Mar 29, 2022 at 1:19 PM Vu Manh Khieu ***@***.***> wrote:
We have fix 2 bugs of your repository. I'd like to create a PR to
contribute them to your repository.
- Fix convert UTF8 bson type to name postgres type
<khieuvm@e80a5a7>
Why do you think that UTF8 bson type should be mapped to the name type at
the PostgreSQL side? Can you please explain the same?
We map UTF8 bson type to TEXT type which seems more correct.
- Fix check range value of int64 type
<khieuvm@0d5cc05>
We can't assign a > int32 value to an int32 variable. And thus throwing an
error is the correct way.
Storing a wrong overflow value is NOT good.
…
------------------------------
You can view, comment on, or merge this pull request online at:
#159
Commit Summary
- 0d5cc05
<0d5cc05>
Fix check range value of int64 type
- e80a5a7
<e80a5a7>
Fix convert UTF8 bson type to name postgres type
File Changes
(4 files <https://github.com/EnterpriseDB/mongo_fdw/pull/159/files>)
- *M* expected/select.out
<https://github.com/EnterpriseDB/mongo_fdw/pull/159/files#diff-f367be6b780968d3eae8f3e8efd1c6d0e57d58ad45878e8c67b693904024ca5c>
(10)
- *M* mongo_fdw.c
<https://github.com/EnterpriseDB/mongo_fdw/pull/159/files#diff-9cb479006ae28d4734f487aa9a4d85f844ffaa102d9b938cec3f72fc937d7aba>
(32)
- *M* mongo_wrapper.c
<https://github.com/EnterpriseDB/mongo_fdw/pull/159/files#diff-d9456d13da4041407744b677dce21375c824f45a338309894fc07e18fcda0e88>
(4)
- *M* mongo_wrapper_meta.c
<https://github.com/EnterpriseDB/mongo_fdw/pull/159/files#diff-caa26f9ea947479915bfded686d0730fb5f4f9ad6e13fa90f3d2f7133223383f>
(4)
Patch Links:
- https://github.com/EnterpriseDB/mongo_fdw/pull/159.patch
- https://github.com/EnterpriseDB/mongo_fdw/pull/159.diff
—
Reply to this email directly, view it on GitHub
<#159>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/APOVKLPJVS4BS5BBBYTTCMLVCKYXVANCNFSM5R5QUFUA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
Jeevan Chalke
*Senior Staff SDE, Database Architect and Manager,Product Development*
edbpostgres.com
|
Author
Following the commit log, when I debug with name type, your code does not process if type is UTF8. You can reprocedure it follow my commit log.
We get value by: |
Collaborator
|
On Tue, Mar 29, 2022 at 2:09 PM Vu Manh Khieu ***@***.***> wrote:
Why do you think that UTF8 bson type should be mapped to the name type at
the PostgreSQL side? Can you please explain the same?
Following the commit log, when I debug with name type, your code does not
process if type is UTF8. You can reprocedure it follow my commit log.
Yes.
The name type is mapped ONLY with ObjectId BSON type and UTF8 BSON type is
mapped to TEXT type. So you need to define a foreign table with text type
if you have UTF8 data on the mongo side. Supporting such cross types needs
a detailed study and not just allowing utf8 data with name.
We can't assign a > int32 value to an int32 variable. And thus throwing an
error is the correct way.
We get value by: int64 val = bson_iter_int64(it);, so I think we need to
compare it with INT64 type, why we compare it with INT32 type?
The foreign table column type is int32. How can you store value greater
than int32 into it?
… —
Reply to this email directly, view it on GitHub
<#159 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/APOVKLOA4Q2CZLOWIYDWXQ3VCK6UFANCNFSM5R5QUFUA>
.
You are receiving this because you commented.Message ID:
***@***.***>
--
Jeevan Chalke
*Senior Staff SDE, Database Architect and Manager,Product Development*
edbpostgres.com
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We have fix 2 bugs of your repository. I'd like to create a PR to contribute them to your repository.