virajjasani commented on code in PR #2141:
URL: https://github.com/apache/phoenix/pull/2141#discussion_r2078099263
##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/Bson4IT.java:
##########
@@ -426,6 +428,127 @@ public void testConditionalUpsertReturnRow() throws
Exception {
}
}
+ @Test
+ public void testBsonPk() throws Exception {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ String tableName = generateUniqueName();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ conn.setAutoCommit(true);
+ String ddl = "CREATE TABLE " + tableName
+ + " (PK1 BSON NOT NULL, C1 VARCHAR"
+ + " CONSTRAINT pk PRIMARY KEY(PK1))";
+ conn.createStatement().execute(ddl);
+
+ String sample1 = getJsonString("json/sample_01.json");
+ String sample2 = getJsonString("json/sample_02.json");
+ String sample3 = getJsonString("json/sample_03.json");
+ BsonDocument bsonDocument1 = RawBsonDocument.parse(sample1);
+ BsonDocument bsonDocument2 = RawBsonDocument.parse(sample2);
+ BsonDocument bsonDocument3 = RawBsonDocument.parse(sample3);
+
+ upsertRowsWithBsonPkCol(conn, tableName, bsonDocument1, bsonDocument2,
bsonDocument3);
+
+ String conditionExpression =
+ "press = :press AND track[0].shot[2][0].city.standard[5] =
:softly";
+
+ BsonDocument conditionDoc = new BsonDocument();
+ conditionDoc.put("$EXPR", new BsonString(conditionExpression));
+ conditionDoc.put("$VAL", new BsonDocument()
+ .append(":press", new BsonString("beat"))
+ .append(":softly", new BsonString("softly")));
+
+ String query = "SELECT * FROM " + tableName +
+ " WHERE PK1 = ?";
+ PreparedStatement pst = conn.prepareStatement(query);
+ pst.setObject(1, bsonDocument1);
+ ResultSet rs = pst.executeQuery(query);
+
+ assertTrue(rs.next());
+ assertEquals("0002", rs.getString(2));
+ BsonDocument document1 = (BsonDocument) rs.getObject(1);
+ assertEquals(bsonDocument1, document1);
+
+ assertFalse(rs.next());
+
+ validateExplainPlan(pst, tableName, "POINT LOOKUP ON 1 KEY ");
+
+ query = "SELECT * FROM " + tableName +
+ " WHERE PK1 = CAST('" + sample2 + "' AS BSON)";
+ Statement stmt = conn.createStatement();
+ rs = stmt.executeQuery(query);
+
+ assertTrue(rs.next());
+ assertEquals("1010", rs.getString(2));
+ BsonDocument document2 = (BsonDocument) rs.getObject(1);
+ assertEquals(bsonDocument2, document2);
+
+ assertFalse(rs.next());
+
+ // TODO : Fix this separately, using CAST with PK column results into
full table scan due
+ // to bug.
+ // validateExplainPlan(stmt, query, tableName, "POINT LOOKUP ON 1 KEY ");
Review Comment:
This is an existing bug with using CAST against pk column, it turns out to
be full table scan. I will file separate Jira to fix this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]