-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Avoid populating _schema if the collection is empty in MongoDB connector #21236
base: master
Are you sure you want to change the base?
Conversation
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Mithilesh Wachasunder.
|
@@ -878,7 +878,7 @@ private List<Document> guessTableFields(String schemaName, String tableName) | |||
{ | |||
MongoDatabase db = client.getDatabase(schemaName); | |||
Document doc = db.getCollection(tableName).find().first(); | |||
if (doc == null) { | |||
if (doc == null || doc.isEmpty()) { |
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.
Please add a test to TestMongoConnectorTest. We can use MongoClient
for preparing an empty collection in MongoDB server.
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.
Sure will do.
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Mithilesh Wachasunder.
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Mithilesh Wachasunder.
|
database.getCollection(tableName).insertOne(new Document(ImmutableMap.of("k", "v"))); | ||
MaterializedResult result = getQueryRunner().execute(getSession(), "SELECT * FROM mongodb.test." + tableName); |
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.
We should add another SELECT statement before inserting a document. That's the original scenario we want to fix.
Also, this test doesn't reach doc.isEmpty()
as far as I confirmed.
@Test | ||
public void testEmptyCollection() | ||
{ | ||
String tableName = "test_empty"; |
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.
Please append suffix with randomNameSuffix method.
database.createCollection(tableName); | ||
database.getCollection(tableName).insertOne(new Document(ImmutableMap.of("k", "v"))); | ||
MaterializedResult result = getQueryRunner().execute(getSession(), "SELECT * FROM mongodb.test." + tableName); | ||
assertThat(result.getRowCount()).isEqualTo(1); |
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.
Please drop the table.
@cla-bot check |
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Mithilesh Wachasunder.
|
The cla-bot has been summoned, and re-checked this pull request! |
This pull request has gone a while without any activity. Tagging the Trino developer relations team: @bitsondatadev @colebow @mosabua |
👋 @build2create - are you still interested in progressing this PR? If yes, could you address the comments from @ebyhr and fix any build failures? |
This pull request has gone a while without any activity. Tagging the Trino developer relations team: @bitsondatadev @colebow @mosabua |
Yes sorry its been a while will resume on this. Based on the offline chat with @ebyhr seems like a different behaviour with Mongo Compass and Java Client so the test results are different. |
String tableName = "test_empty"; | ||
MongoDatabase database = client.getDatabase("test"); | ||
database.createCollection(tableName); | ||
database.getCollection(tableName).insertOne(new Document(ImmutableMap.of("k", "v"))); |
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.
#20972 issue can be reproduced once you replace the data with new Document()
.
Description
This PR is to fix the [issue][1]. Whenever a empty collection was created an entry was populated in default collection
_schema
. Further upon populating the collection with documents the fields in_schema
remained empty. So a workaround there is a check introduced to avoid populating_schema
if collection is empty.Fixes #20972
Release notes
(x) This is not user-visible or is docs only, and no release notes are required.