Jackie-Jiang commented on code in PR #19327:
URL: https://github.com/apache/pinot/pull/19327#discussion_r3837362029
##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/builder/TableNameBuilder.java:
##########
@@ -117,6 +118,47 @@ public static boolean isRealtimeTableResource(String
resourceName) {
return REALTIME.tableHasTypeSuffix(resourceName);
}
+ /// Quotes a typed table name for use as a SQL identifier. When the table
name is database-qualified, the database
+ /// and table components are quoted separately. Embedded double quotes are
escaped by doubling them.
+ ///
+ /// @param tableNameWithType Table name ending in `_OFFLINE` or `_REALTIME`,
optionally prefixed with a database name
+ /// @return Table name quoted for use in a SQL statement
+ /// @throws IllegalArgumentException If the table name is not a valid typed
table resource
+ public static String quoteTableNameWithType(String tableNameWithType) {
+ if (tableNameWithType == null || containsWhitespace(tableNameWithType)) {
+ throw new IllegalArgumentException("Invalid table name with type");
+ }
+
+ int separatorIndex = tableNameWithType.indexOf('.');
+ if (separatorIndex < 0) {
+ validateTableResourceName(tableNameWithType);
+ return StringUtil.quoteSqlIdentifier(tableNameWithType);
+ }
+ if (separatorIndex == 0 || separatorIndex !=
tableNameWithType.lastIndexOf('.')) {
+ throw new IllegalArgumentException("Invalid table name with type");
+ }
+
+ String tableResourceName = tableNameWithType.substring(separatorIndex + 1);
+ validateTableResourceName(tableResourceName);
+ return StringUtil.quoteSqlIdentifier(tableNameWithType.substring(0,
separatorIndex)) + "."
+ + StringUtil.quoteSqlIdentifier(tableResourceName);
+ }
+
+ private static void validateTableResourceName(String tableResourceName) {
Review Comment:
`tableResourceName` is the same as `tableNameWithType`. Suggest making the
names consistent
##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/StringUtil.java:
##########
@@ -36,6 +36,15 @@ public static String join(String separator, String... keys) {
return StringUtils.join(keys, separator);
}
+ /// Quotes one SQL identifier component with double quotes, escaping
embedded double quotes by doubling them.
+ /// Qualified names must be split by the caller so that each component is
quoted separately.
+ ///
+ /// @param identifier SQL identifier component
+ /// @return Identifier quoted for use in a SQL statement
+ public static String quoteSqlIdentifier(String identifier) {
Review Comment:
I don't think this belongs to this util. Please create a sql util if none
exists
--
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]