From afe2160e1b8ed46533ab284bad6c1c23b4a7559a Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Mon, 5 Dec 2022 21:12:41 +0900 Subject: [PATCH] Fix NPE when column name contains uppercase in MongoDB query function --- .../java/io/trino/plugin/mongodb/MongoMetadata.java | 2 +- .../trino/plugin/mongodb/TestMongoConnectorTest.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plugin/trino-mongodb/src/main/java/io/trino/plugin/mongodb/MongoMetadata.java b/plugin/trino-mongodb/src/main/java/io/trino/plugin/mongodb/MongoMetadata.java index 6b91ac588616..a49830247ad0 100644 --- a/plugin/trino-mongodb/src/main/java/io/trino/plugin/mongodb/MongoMetadata.java +++ b/plugin/trino-mongodb/src/main/java/io/trino/plugin/mongodb/MongoMetadata.java @@ -168,7 +168,7 @@ public Map getColumnHandles(ConnectorSession session, Conn ImmutableMap.Builder columnHandles = ImmutableMap.builder(); for (MongoColumnHandle columnHandle : columns) { - columnHandles.put(columnHandle.getName(), columnHandle); + columnHandles.put(columnHandle.getName().toLowerCase(ENGLISH), columnHandle); } return columnHandles.buildOrThrow(); } diff --git a/plugin/trino-mongodb/src/test/java/io/trino/plugin/mongodb/TestMongoConnectorTest.java b/plugin/trino-mongodb/src/test/java/io/trino/plugin/mongodb/TestMongoConnectorTest.java index c655cc831c30..da556e121bf0 100644 --- a/plugin/trino-mongodb/src/test/java/io/trino/plugin/mongodb/TestMongoConnectorTest.java +++ b/plugin/trino-mongodb/src/test/java/io/trino/plugin/mongodb/TestMongoConnectorTest.java @@ -782,6 +782,18 @@ public void testNativeQueryProjection() .matches("SELECT name FROM region"); } + @Test + public void testNativeQueryCaseNonLowercaseColumn() + { + String tableName = "test_non_lowercase_column" + randomNameSuffix(); + client.getDatabase("test").getCollection(tableName) + .insertOne(new Document("TestColumn", 1)); + + assertQuery( + "SELECT * FROM TABLE(mongodb.system.query(database => 'test', collection => '" + tableName + "', filter => '{\"TestColumn\": 1}'))", + "VALUES 1"); + } + @Test public void testNativeQueryInvalidArgument() {