Jackie-Jiang commented on a change in pull request #7511:
URL: https://github.com/apache/pinot/pull/7511#discussion_r723598335



##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/query/optimizer/statement/JsonStatementOptimizer.java
##########
@@ -384,13 +383,34 @@ private static void optimizeJsonPredicate(Expression 
expression, @Nullable Table
   }
 
   /**
-   *  @return A string array containing all the parts of an identifier. An 
identifier may have one or more parts that
-   *  are joined together using <DOT>. For example the identifier 
"testTable.jsonColumn.name.first" consists up of
-   *  "testTable" (name of table), "jsonColumn" (name of column), "name" (json 
path), and "first" (json path). The last
-   *  two parts when joined together (name.first) represent a JSON path 
expression.
+   * @return A two element String array where the first element is the column 
name and second element is the JSON
+   * path expression. If column name is not suffixed by JSON path expression, 
then array will contain only a single
+   * element representing the column name. For example:
+   * 1) Identifier "jsonColumn.name.first" -> {"jsonColumn", "name.first"}
+   * 2) Identifier "jsonColumn[0]" -> {"jsonColumn", "[0]"}
+   * 3) Identifier "jsonColumn" -> {"jsonColumn"}
    */
   private static String[] getIdentifierParts(Identifier identifier) {
-    return StringUtils.split(identifier.getName(), '.');
+    String name = identifier.getName();
+    int dotIndex = name.indexOf('.');
+    int openBracketIndex = name.indexOf('[');
+
+    // column name followed by top-level array expression.
+    if (openBracketIndex != -1) {
+      // name has an '[', check if this path expression refers to a top-level 
JSON array.
+      if (dotIndex == -1 || openBracketIndex < dotIndex) {
+        // This path expression refers to a top-level JSON array.
+        return new String[]{name.substring(0, openBracketIndex), 
name.substring(openBracketIndex)};
+      }
+    }
+
+    // column name followed by all other JSON path expression
+    if (dotIndex != -1) {
+      return new String[] {name.substring(0, dotIndex), 
name.substring(dotIndex + 1)};

Review comment:
       ```suggestion
         return new String[] {name.substring(0, dotIndex), 
name.substring(dotIndex)};
   ```

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/query/optimizer/statement/JsonStatementOptimizer.java
##########
@@ -407,8 +427,10 @@ private static String getJsonPath(String[] parts, boolean 
applyDoubleQuote) {
     }
 
     builder.append("$");
-    for (int i = 1; i < parts.length; i++) {
-      builder.append(".").append(parts[i]);
+    if (parts[1].charAt(0) == '[') {
+      builder.append(parts[1]);
+    } else {
+      builder.append(".").append(parts[1]);

Review comment:
       ```suggestion
       builder.append(parts[1]);
   ```




-- 
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]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to