Skip to content

Commit 9579083

Browse files
committed
MongoDB: Introduce a config flag to determine whether to skip using collation or not when querying
Signed-off-by: Sherif Ayad <[email protected]>
1 parent acc308c commit 9579083

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

docs/src/main/sphinx/connector/mongodb.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ The following configuration properties are available:
4444
| `mongodb.connection-url` | The connection url that the driver uses to connect to a MongoDB deployment |
4545
| `mongodb.schema-collection` | A collection which contains schema information |
4646
| `mongodb.case-insensitive-name-matching` | Match database and collection names case insensitively |
47+
| `mongodb.skip-collation` | Skip using `Collation` when querying the collections |
4748
| `mongodb.min-connections-per-host` | The minimum size of the connection pool per host |
4849
| `mongodb.connections-per-host` | The maximum size of the connection pool per host |
4950
| `mongodb.max-wait-time` | The maximum wait time |
@@ -96,6 +97,12 @@ Match database and collection names case insensitively.
9697

9798
This property is optional; the default is `false`.
9899

100+
### `mongodb.skip-collation`
101+
102+
Skip using `Collation` when querying the collections. For more info check the [official documentation](https://www.mongodb.com/docs/manual/reference/collation/)
103+
104+
This property is optional; the default is `false`.
105+
99106
### `mongodb.min-connections-per-host`
100107

101108
The minimum number of connections per host for this MongoClient instance. Those connections are kept in a pool when idle, and the pool ensures over time that it contains at least this minimum number.

plugin/trino-mongodb/src/main/java/io/trino/plugin/mongodb/MongoClientConfig.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class MongoClientConfig
3131
{
3232
private String schemaCollection = "_schema";
3333
private boolean caseInsensitiveNameMatching;
34+
private boolean skipCollation;
3435
private String connectionUrl;
3536

3637
private int minConnectionsPerHost;
@@ -77,6 +78,18 @@ public MongoClientConfig setCaseInsensitiveNameMatching(boolean caseInsensitiveN
7778
return this;
7879
}
7980

81+
public boolean isSkipCollation()
82+
{
83+
return skipCollation;
84+
}
85+
86+
@Config("mongodb.skip-collation")
87+
public MongoClientConfig setSkipCollation(boolean skipCollation)
88+
{
89+
this.skipCollation = skipCollation;
90+
return this;
91+
}
92+
8093
@NotNull
8194
public @Pattern(message = "Invalid connection URL. Expected mongodb:// or mongodb+srv://", regexp = "^mongodb(\\+srv)?://.*") String getConnectionUrl()
8295
{

plugin/trino-mongodb/src/main/java/io/trino/plugin/mongodb/MongoSession.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public class MongoSession
176176

177177
private final String schemaCollection;
178178
private final boolean caseInsensitiveNameMatching;
179+
private final boolean skipCollation;
179180
private final int cursorBatchSize;
180181

181182
private final Cache<SchemaTableName, MongoTable> tableCache;
@@ -187,6 +188,7 @@ public MongoSession(TypeManager typeManager, MongoClient client, MongoClientConf
187188
this.client = requireNonNull(client, "client is null");
188189
this.schemaCollection = requireNonNull(config.getSchemaCollection(), "config.getSchemaCollection() is null");
189190
this.caseInsensitiveNameMatching = config.isCaseInsensitiveNameMatching();
191+
this.skipCollation = config.isSkipCollation();
190192
this.cursorBatchSize = config.getCursorBatchSize();
191193
this.implicitPrefix = requireNonNull(config.getImplicitRowFieldPrefix(), "config.getImplicitRowFieldPrefix() is null");
192194

@@ -528,7 +530,12 @@ public MongoCursor<Document> execute(MongoTableHandle tableHandle, List<MongoCol
528530

529531
MongoCollection<Document> collection = getCollection(tableHandle.remoteTableName());
530532
Document filter = buildFilter(tableHandle);
531-
FindIterable<Document> iterable = collection.find(filter).projection(projection).collation(SIMPLE_COLLATION);
533+
FindIterable<Document> iterable = collection.find(filter).projection(projection);
534+
535+
if (!skipCollation) {
536+
iterable.collation(SIMPLE_COLLATION);
537+
}
538+
532539
tableHandle.limit().ifPresent(iterable::limit);
533540
log.debug("Find documents: collection: %s, filter: %s, projection: %s", tableHandle.schemaTableName(), filter, projection);
534541

plugin/trino-mongodb/src/test/java/io/trino/plugin/mongodb/TestMongoClientConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public void testDefaults()
3434
.setConnectionUrl(null)
3535
.setSchemaCollection("_schema")
3636
.setCaseInsensitiveNameMatching(false)
37+
.setSkipCollation(false)
3738
.setMinConnectionsPerHost(0)
3839
.setConnectionsPerHost(100)
3940
.setMaxWaitTime(120_000)
@@ -58,6 +59,7 @@ public void testExplicitPropertyMappings()
5859
Map<String, String> properties = ImmutableMap.<String, String>builder()
5960
.put("mongodb.schema-collection", "_my_schema")
6061
.put("mongodb.case-insensitive-name-matching", "true")
62+
.put("mongodb.skip-collation", "true")
6163
.put("mongodb.connection-url", "mongodb://router1.example.com:27017,router2.example2.com:27017,router3.example3.com:27017/")
6264
.put("mongodb.min-connections-per-host", "1")
6365
.put("mongodb.connections-per-host", "99")
@@ -79,6 +81,7 @@ public void testExplicitPropertyMappings()
7981
MongoClientConfig expected = new MongoClientConfig()
8082
.setSchemaCollection("_my_schema")
8183
.setCaseInsensitiveNameMatching(true)
84+
.setSkipCollation(true)
8285
.setConnectionUrl("mongodb://router1.example.com:27017,router2.example2.com:27017,router3.example3.com:27017/")
8386
.setMinConnectionsPerHost(1)
8487
.setConnectionsPerHost(99)

0 commit comments

Comments
 (0)