ranganathg commented on code in PR #1904:
URL: https://github.com/apache/phoenix/pull/1904#discussion_r1648442847


##########
phoenix-core-client/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java:
##########
@@ -842,11 +851,27 @@ public MutationPlan compile(UpsertStatement upsert) 
throws SQLException {
                         expression.getDataType(), column.getDataType(), 
"expression: "
                                 + expression.toString() + " in column " + 
column);
             }
+            if (!SchemaUtil.isPKColumn(column) && !isJsonNode(valueNode)) {
+                nonPKColumns.add(
+                        new 
Pair<>(ColumnName.caseSensitiveColumnName(column.getName().getString()),
+                                valueNode));
+            }
+            if (isJsonNode(valueNode)) {
+                jsonExpressions.add(
+                        new 
Pair<>(ColumnName.caseSensitiveColumnName(column.getName().getString()),
+                                valueNode));
+                jsonExpressions.addAll(nonPKColumns);
+                nonPKColumns = Lists.newArrayList();

Review Comment:
   Yeah your comment perfectly makes sense



##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/json/JsonFunctionsIT.java:
##########
@@ -749,4 +761,186 @@ public void testJsonWithSetGetObjectAPI() throws 
Exception {
             assertFalse(rs.next());
         }
     }
+
+    @Test
+    public void testSimpleJsonModifyWithAutoCommit() 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 +
+                    " (pk integer primary key, " +
+                    "col integer, " +
+                    "strcol varchar, " +
+                    "strcol1 varchar, " +
+                    "strcol2 varchar, " +
+                    "strcol3 varchar, " +
+                    "strcol4 varchar, " +
+                    "strcol5 varchar, " +
+                    "jsoncol json)";
+            conn.createStatement().execute(ddl);
+            PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + 
tableName + " (pk,col,strcol,jsoncol) VALUES (?,?,?,?)");
+            stmt.setInt(1, 1);
+            stmt.setInt(2, 2);
+            stmt.setString(3, "");
+            stmt.setString(4, basicJson);
+            stmt.execute();
+            String upsert = "UPSERT INTO " + tableName + 
"(pk,col,strcol,jsoncol) VALUES(1,2,JSON_VALUE(jsoncol, 
'$.info.address.town'),JSON_MODIFY(jsoncol, '$.info.address.town', 
'\"Manchester\"')) ";

Review Comment:
   I will create a separate JIRA to handle nested JSON Functions.



##########
phoenix-core-client/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java:
##########
@@ -842,11 +851,27 @@ public MutationPlan compile(UpsertStatement upsert) 
throws SQLException {
                         expression.getDataType(), column.getDataType(), 
"expression: "
                                 + expression.toString() + " in column " + 
column);
             }
+            if (!SchemaUtil.isPKColumn(column) && !isJsonNode(valueNode)) {
+                nonPKColumns.add(
+                        new 
Pair<>(ColumnName.caseSensitiveColumnName(column.getName().getString()),

Review Comment:
   Got it. Will add an IT to test these and add appropriate tests.



-- 
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: issues-unsubscr...@phoenix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to