tkhurana commented on code in PR #1732:
URL: https://github.com/apache/phoenix/pull/1732#discussion_r1385636192
##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/json/JsonFunctionsIT.java:
##########
@@ -344,6 +344,68 @@ public void testJsonExpressionIndexInvalid() {
" (JSON_MODIFY(jsoncol, '$.info.tags[2]', '\"newValue\"'))
include (col)");
}
+ @Test
+ public void testJsonExists() throws SQLException, IOException {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ String tableName = generateUniqueName();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ String ddl = "create table " + tableName + " (pk integer primary
key, col integer, jsoncol json)";
+ conn.createStatement().execute(ddl);
+ PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " +
tableName + " VALUES (?,?,?)");
+ stmt.setInt(1, 1);
+ stmt.setInt(2, 2);
+ stmt.setString(3, basicJson);
+ stmt.execute();
+ stmt.setInt(1, 2);
+ stmt.setInt(2, 3);
+ stmt.setString(3, getJsonString(BASIC_JSON, "$[1]"));
+ stmt.execute();
+ conn.commit();
+
+ String query ="SELECT JSON_VALUE(jsoncol, '$.type'),
JSON_VALUE(jsoncol, '$.info.address.town') " +
+ " FROM " + tableName +
+ " WHERE JSON_EXISTS(jsoncol, '$.info.address.town')";
+ ResultSet rs = conn.createStatement().executeQuery(query);
+ assertTrue(rs.next());
+ assertEquals("Basic", rs.getString(1));
+ assertEquals("Bristol", rs.getString(2));
+ assertTrue(rs.next());
+ assertEquals("Normal", rs.getString(1));
+ assertEquals("Bristol2", rs.getString(2));
+ assertFalse(rs.next());
+
+ query ="SELECT JSON_VALUE(jsoncol, '$.type'), JSON_VALUE(jsoncol,
'$.info.address.town') " +
+ " FROM " + tableName +
+ " WHERE JSON_EXISTS(jsoncol, '$.info.address.exists')";
+ rs = conn.createStatement().executeQuery(query);
+ assertTrue(rs.next());
+ assertEquals("Bristol", rs.getString(2));
+ assertFalse(rs.next());
+
+ query ="SELECT JSON_VALUE(jsoncol, '$.type'), JSON_VALUE(jsoncol,
'$.info.address.town') " +
+ " FROM " + tableName +
+ " WHERE JSON_EXISTS(jsoncol, '$.info.address.name')";
+ rs = conn.createStatement().executeQuery(query);
+ assertFalse(rs.next());
+
+ query ="SELECT JSON_VALUE(jsoncol, '$.type'), JSON_VALUE(jsoncol,
'$.info.address.town') " +
+ " FROM " + tableName +
+ " WHERE JSON_EXISTS(jsoncol, '$.existsFail')";
+ rs = conn.createStatement().executeQuery(query);
+
+ query ="SELECT JSON_VALUE(jsoncol, '$.type'), JSON_VALUE(jsoncol,
'$.info.address.town') " +
+ " FROM " + tableName +
+ " WHERE JSON_EXISTS(jsoncol, '$.existsFail')";
+ rs = conn.createStatement().executeQuery(query);
Review Comment:
Copy paste twice
--
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]