-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Support MongoDB case insensitive collection name #1915
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@prestosql.io. For more information, see https://github.com/prestosql/cla. |
1 similar comment
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@prestosql.io. For more information, see https://github.com/prestosql/cla. |
presto-mongodb/src/main/java/io/prestosql/plugin/mongodb/MongoColumnHandle.java
Outdated
Show resolved
Hide resolved
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@prestosql.io. For more information, see https://github.com/prestosql/cla. |
1 similar comment
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@prestosql.io. For more information, see https://github.com/prestosql/cla. |
@cla-bot check |
The cla-bot has been summoned, and re-checked this pull request! |
@tchunwei could you please rebase on current master and squash commits? Ideally, there should be just one commit after that. |
535e98c
to
98a31de
Compare
@findepi thanks for guiding, has rebased, made it into single commit and force pushed. Kindly let me know if I did it incorrectly, thanks again. |
presto-mongodb/src/main/java/io/prestosql/plugin/mongodb/MongoMetadata.java
Outdated
Show resolved
Hide resolved
presto-mongodb/src/main/java/io/prestosql/plugin/mongodb/MongoMetadata.java
Outdated
Show resolved
Hide resolved
presto-mongodb/src/main/java/io/prestosql/plugin/mongodb/MongoMetadata.java
Show resolved
Hide resolved
presto-mongodb/src/main/java/io/prestosql/plugin/mongodb/MongoMetadata.java
Outdated
Show resolved
Hide resolved
presto-mongodb/src/main/java/io/prestosql/plugin/mongodb/MongoPageSink.java
Outdated
Show resolved
Hide resolved
presto-mongodb/src/main/java/io/prestosql/plugin/mongodb/MongoSession.java
Outdated
Show resolved
Hide resolved
presto-mongodb/src/main/java/io/prestosql/plugin/mongodb/MongoSession.java
Outdated
Show resolved
Hide resolved
presto-mongodb/src/main/java/io/prestosql/plugin/mongodb/MongoSession.java
Outdated
Show resolved
Hide resolved
presto-mongodb/src/main/java/io/prestosql/plugin/mongodb/MongoSession.java
Outdated
Show resolved
Hide resolved
presto-mongodb/src/main/java/io/prestosql/plugin/mongodb/MongoTableHandle.java
Outdated
Show resolved
Hide resolved
presto-mongodb/src/test/java/io/prestosql/plugin/mongodb/TestMongoIntegrationSmokeTest.java
Outdated
Show resolved
Hide resolved
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.
@tchunwei Sorry for my late response. Could you try focusing on the actual issue (case insensitive database & collection name) before starting the detailed review? It seems the current commit contains unrelated changes for that.
98a31de
to
dce64cb
Compare
dce64cb
to
752a175
Compare
752a175
to
7a01fce
Compare
@tchunwei Why was this closed? |
@buffcode that was done unintentionally, was rebasing my code then accidentally wiped my commit, will re-open later |
Thank you @ebyhr for your effort guiding me and reviewing the code. Have updated the code based on the feedback for your further review. |
c2de885
to
17c888d
Compare
17c888d
to
d4a83c4
Compare
d4a83c4
to
089ef94
Compare
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.
Sorry for my late response. Left some comments. The program behavior itself looks fine as you added the test.
MongoClient client = new MongoClient(server.getAddress().getHost(), server.getAddress().getPort()); | ||
MongoCollection<Document> collection = client.getDatabase("CamelDB").getCollection("camelTable"); | ||
|
||
collection.insertOne(new Document(ImmutableMap.of("Name", "asdf", "Value", 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.
TestMongoIntegrationSmokeTest already has MongoClient object. Please move this body to testCaseInsensitive. Also, I would recommend renaming Camel
to TestCaseInsensitive
or something.
assertQuery("SELECT name, value FROM cameldb.cameltable", "SELECT 'asdf', 1"); | ||
assertUpdate("INSERT INTO cameldb.cameltable VALUES('qwer', 2)", 1); | ||
|
||
assertQuery("SELECT value FROM cameldb.cameltable where name = 'qwer'", "SELECT 2"); |
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.
Add drop table in Presto and drop collection in MongoDB.
private final List<MongoColumnHandle> columns; | ||
|
||
@JsonCreator | ||
public MongoInsertTableHandle( | ||
@JsonProperty("schemaTableName") SchemaTableName schemaTableName, | ||
@JsonProperty("table") MongoTableHandle table, |
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 String schemaName (case sensitive) and String tableName (case sensitive) instead of MongoTableHandle. MongoInsertTableHandle is also the same.
@@ -215,17 +217,16 @@ public boolean usesLegacyTableLayouts() | |||
} | |||
|
|||
@Override | |||
public ConnectorTableProperties getTableProperties(ConnectorSession session, ConnectorTableHandle table) | |||
public ConnectorTableProperties getTableProperties(ConnectorSession session, ConnectorTableHandle tableHandle) |
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.
Revert
continue; | ||
} | ||
|
||
builder.add(name.toLowerCase(ENGLISH)); |
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.
Revert and add .map(name -> name.toLowerCase(ENGLISH))
.
return databaseName; | ||
} | ||
|
||
private String getTableName(String databaseName, String 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.
This method is unused in this commit. I suppose this should be called from loadTable
method.
private String getTableName(String databaseName, String tableName) | |
private String getCaseSensitiveTableName(String databaseName, String tableName) |
private final TupleDomain<ColumnHandle> constraint; | ||
|
||
public MongoTableHandle(SchemaTableName schemaTableName) | ||
public MongoTableHandle(SchemaTableName table) |
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.
Let's change the argument to (String databaseName, String tableName)
. Otherwise, the above comment about case sensitivity is a little misleading.
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return schemaTableName.toString(); | ||
return String.format("%s.%s", databaseName, collectionName); |
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.
nit: Consistency as ConnectorTableHandle class. Basically, using String.format
function to concatinate string is the right choice. Also, we can use static import for String.format
.
return String.format("%s.%s", databaseName, collectionName); | |
return databaseName + ":" + collectionName; |
@@ -35,8 +35,8 @@ | |||
|
|||
public class TestMongoSession | |||
{ | |||
private static final MongoColumnHandle COL1 = new MongoColumnHandle("col1", BIGINT, false); | |||
private static final MongoColumnHandle COL2 = new MongoColumnHandle("col2", createUnboundedVarcharType(), false); | |||
private static final MongoColumnHandle COL1 = new MongoColumnHandle("Col1", BIGINT, false); |
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.
Let's keep col1
as a lowercase.
@@ -26,11 +26,13 @@ | |||
@Test | |||
public void testRoundTrip() | |||
{ | |||
MongoTableHandle expected = new MongoTableHandle(new SchemaTableName("schema", "table")); | |||
MongoTableHandle expected = new MongoTableHandle("Schema", "Table", TupleDomain.all()); |
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.
Let's call another constructor. Also, it would be better to add a test case instead of replacement to avoid unexpected regression.
any updated about this? |
Any updates of this? |
Covered by #3453 |
Fixes #1102
Currently any MongoDB collection with uppercase name like "Hello" could not be queried.
This PR makes it possible by supporting case insensitivity for collection name, providing solution for case 2 mentioned here #1102 (comment), it doesn't help case 1 though.