Jackie-Jiang commented on code in PR #19352:
URL: https://github.com/apache/pinot/pull/19352#discussion_r3847487273


##########
pinot-common/src/main/java/org/apache/pinot/sql/parsers/ParserUtils.java:
##########
@@ -18,14 +18,41 @@
  */
 package org.apache.pinot.sql.parsers;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
+import java.util.StringJoiner;
 import org.apache.pinot.common.request.Expression;
+import org.apache.pinot.common.request.ExpressionType;
+import org.apache.pinot.spi.utils.SqlUtils;
 
 
 public class ParserUtils {
   private ParserUtils() {
   }
 
+  /// Converts a raw or SQL-quoted identifier into a safe SQL identifier 
fragment. Qualified identifiers are split on
+  /// dots outside quoted components. Valid bare Pinot identifier components 
and wildcards remain bare, while other
+  /// components are double-quoted. Backtick-quoted and double-quoted 
components are normalized to double quotes.
+  ///
+  /// @param identifier Raw or SQL-quoted identifier, optionally qualified
+  /// @return Identifier formatted for use in a SQL statement
+  /// @throws NullPointerException If the identifier is null
+  /// @throws IllegalArgumentException If the identifier is empty or has 
invalid quoted structure
+  public static String sanitizeIdentifier(String identifier) {
+    Objects.requireNonNull(identifier, "identifier cannot be null");

Review Comment:
   (nit) We don't usually do this check, but assume unannotated argument as 
non-null



##########
pinot-common/src/main/java/org/apache/pinot/sql/parsers/ParserUtils.java:
##########
@@ -18,14 +18,41 @@
  */
 package org.apache.pinot.sql.parsers;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
+import java.util.StringJoiner;
 import org.apache.pinot.common.request.Expression;
+import org.apache.pinot.common.request.ExpressionType;
+import org.apache.pinot.spi.utils.SqlUtils;
 
 
 public class ParserUtils {
   private ParserUtils() {
   }
 
+  /// Converts a raw or SQL-quoted identifier into a safe SQL identifier 
fragment. Qualified identifiers are split on
+  /// dots outside quoted components. Valid bare Pinot identifier components 
and wildcards remain bare, while other
+  /// components are double-quoted. Backtick-quoted and double-quoted 
components are normalized to double quotes.
+  ///
+  /// @param identifier Raw or SQL-quoted identifier, optionally qualified
+  /// @return Identifier formatted for use in a SQL statement
+  /// @throws NullPointerException If the identifier is null
+  /// @throws IllegalArgumentException If the identifier is empty or has 
invalid quoted structure
+  public static String sanitizeIdentifier(String identifier) {
+    Objects.requireNonNull(identifier, "identifier cannot be null");
+    String trimmed = identifier.trim();
+    if (trimmed.isEmpty()) {
+      throw new IllegalArgumentException("identifier cannot be empty");
+    }
+
+    StringJoiner result = new StringJoiner(".");

Review Comment:
   Please optimize for the common case where this is no `.` or quote. Same for 
other places. We should only pay overhead for the uncommon case



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