This is an automated email from the ASF dual-hosted git repository. palashc pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/master by this push: new 6c4cb77ad6 PHOENIX-7691 : Handle empty bson doc in bson update expression function (#2277) 6c4cb77ad6 is described below commit 6c4cb77ad65b072761144ec592dee749160e6874 Author: Palash Chauhan <palashc...@gmail.com> AuthorDate: Fri Aug 22 10:09:24 2025 -0700 PHOENIX-7691 : Handle empty bson doc in bson update expression function (#2277) Co-authored-by: Palash Chauhan <p.chau...@pchauha-ltmgv47.internal.salesforce.com> --- .../function/BsonUpdateExpressionFunction.java | 2 +- .../java/org/apache/phoenix/end2end/Bson4IT.java | 40 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/BsonUpdateExpressionFunction.java b/phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/BsonUpdateExpressionFunction.java index a86a523794..373cd5042e 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/BsonUpdateExpressionFunction.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/BsonUpdateExpressionFunction.java @@ -95,7 +95,7 @@ public class BsonUpdateExpressionFunction extends ScalarFunction { updateExpressionBsonDoc = RawBsonDocument.parse(updateExpression); } else { updateExpressionBsonDoc = (RawBsonDocument) PBson.INSTANCE.toObject(ptr); - if (updateExpressionBsonDoc == null || updateExpressionBsonDoc.isEmpty()) { + if (updateExpressionBsonDoc == null) { return true; } } diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/Bson4IT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/Bson4IT.java index f8884472ab..0c0d8bc471 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/Bson4IT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/Bson4IT.java @@ -56,6 +56,7 @@ import org.bson.BsonNull; import org.bson.BsonString; import org.bson.Document; import org.bson.RawBsonDocument; +import org.junit.Assert; import org.junit.Assume; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -505,6 +506,45 @@ public class Bson4IT extends ParallelStatsDisabledIT { } } + @Test + public void testBsonReturnValueWithEmptyUpdateExpression() throws Exception { + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + String tableName = generateUniqueName(); + try (Connection conn = DriverManager.getConnection(getUrl(), props)) { + conn.setAutoCommit(true); + conn.createStatement().execute("CREATE TABLE " + tableName + " (" + + " hk VARCHAR NOT NULL, " + + " sk VARCHAR NOT NULL, " + + " col BSON, " + + " CONSTRAINT pk PRIMARY KEY (hk, sk))"); + + RawBsonDocument bsonDoc = RawBsonDocument.parse("{\"a\":1,\"b\":2}"); + + PreparedStatement p = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?,?,?)"); + p.setString(1, "h1"); + p.setString(2, "s1"); + p.setObject(3, bsonDoc); + p.execute(); + + p = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?,?) ON DUPLICATE KEY UPDATE\n" + + " COL = BSON_UPDATE_EXPRESSION(COL,'{}')"); + p.setString(1, "h1"); + p.setString(2, "s1"); + Pair<Integer, ResultSet> resultPair = p.unwrap(PhoenixPreparedStatement.class).executeAtomicUpdateReturnRow(); + Assert.assertEquals(1, resultPair.getFirst().intValue()); + Assert.assertEquals(bsonDoc, resultPair.getSecond().getObject(3)); + + p = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?,?) ON DUPLICATE KEY UPDATE\n" + + " COL = BSON_UPDATE_EXPRESSION(COL,?)"); + p.setString(1, "h1"); + p.setString(2, "s1"); + p.setObject(3, new BsonDocument()); + resultPair = p.unwrap(PhoenixPreparedStatement.class).executeAtomicUpdateReturnRow(); + Assert.assertEquals(1, resultPair.getFirst().intValue()); + Assert.assertEquals(bsonDoc, resultPair.getSecond().getObject(3)); + } + } + @Test public void testConditionalUpsertReturnRow() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);