|
56 | 56 | import org.bson.BsonString; |
57 | 57 | import org.bson.Document; |
58 | 58 | import org.bson.RawBsonDocument; |
| 59 | +import org.junit.Assert; |
59 | 60 | import org.junit.Assume; |
60 | 61 | import org.junit.Test; |
61 | 62 | import org.junit.experimental.categories.Category; |
@@ -505,6 +506,45 @@ public void testBsonValueFunctionWithBSONType() throws Exception { |
505 | 506 | } |
506 | 507 | } |
507 | 508 |
|
| 509 | + @Test |
| 510 | + public void testBsonReturnValueWithEmptyUpdateExpression() throws Exception { |
| 511 | + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); |
| 512 | + String tableName = generateUniqueName(); |
| 513 | + try (Connection conn = DriverManager.getConnection(getUrl(), props)) { |
| 514 | + conn.setAutoCommit(true); |
| 515 | + conn.createStatement().execute("CREATE TABLE " + tableName + " (" + |
| 516 | + " hk VARCHAR NOT NULL, " + |
| 517 | + " sk VARCHAR NOT NULL, " + |
| 518 | + " col BSON, " + |
| 519 | + " CONSTRAINT pk PRIMARY KEY (hk, sk))"); |
| 520 | + |
| 521 | + RawBsonDocument bsonDoc = RawBsonDocument.parse("{\"a\":1,\"b\":2}"); |
| 522 | + |
| 523 | + PreparedStatement p = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?,?,?)"); |
| 524 | + p.setString(1, "h1"); |
| 525 | + p.setString(2, "s1"); |
| 526 | + p.setObject(3, bsonDoc); |
| 527 | + p.execute(); |
| 528 | + |
| 529 | + p = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?,?) ON DUPLICATE KEY UPDATE\n" + |
| 530 | + " COL = BSON_UPDATE_EXPRESSION(COL,'{}')"); |
| 531 | + p.setString(1, "h1"); |
| 532 | + p.setString(2, "s1"); |
| 533 | + Pair<Integer, ResultSet> resultPair = p.unwrap(PhoenixPreparedStatement.class).executeAtomicUpdateReturnRow(); |
| 534 | + Assert.assertEquals(1, resultPair.getFirst().intValue()); |
| 535 | + Assert.assertEquals(bsonDoc, resultPair.getSecond().getObject(3)); |
| 536 | + |
| 537 | + p = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?,?) ON DUPLICATE KEY UPDATE\n" + |
| 538 | + " COL = BSON_UPDATE_EXPRESSION(COL,?)"); |
| 539 | + p.setString(1, "h1"); |
| 540 | + p.setString(2, "s1"); |
| 541 | + p.setObject(3, new BsonDocument()); |
| 542 | + resultPair = p.unwrap(PhoenixPreparedStatement.class).executeAtomicUpdateReturnRow(); |
| 543 | + Assert.assertEquals(1, resultPair.getFirst().intValue()); |
| 544 | + Assert.assertEquals(bsonDoc, resultPair.getSecond().getObject(3)); |
| 545 | + } |
| 546 | + } |
| 547 | + |
508 | 548 | @Test |
509 | 549 | public void testConditionalUpsertReturnRow() throws Exception { |
510 | 550 | Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); |
|
0 commit comments