Package com.databricks.jdbc.common.util
Class StringUtil
- java.lang.Object
-
- com.databricks.jdbc.common.util.StringUtil
-
public class StringUtil extends Object
-
-
Constructor Summary
Constructors Constructor Description StringUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancheckPrefixMatch(String prefix, String fileName, boolean caseSensitive)Function to check if the given prefix exists in the fileNamestatic StringconvertJdbcEscapeSequences(String sql)static StringescapeStringLiteral(String str)Escape sql string literal which is enclosed in a single quote, it replaces single quote with doubled single quotes.static StringgetBaseNameFromPath(String path)Function to return the base name from the pathstatic StringgetFolderNameFromPath(String path)Function to return the folder name from the pathstatic StringgetVolumePath(String catalog, String schema, String volume)Building the volume path using the provided catalog, schema and volumestatic Set<Integer>parseIntegerSet(String input)Parses a comma-separated string of integers into a Set.static StringremoveRedundantEscapeClause(String sql)Removes empty ESCAPE clauses from SQL statements to work around Databricks SQL parser limitations.static List<String>split(String value)
-
-
-
Method Detail
-
escapeStringLiteral
public static String escapeStringLiteral(String str)
Escape sql string literal which is enclosed in a single quote, it replaces single quote with doubled single quotes.Please always use prepareStatement to bind variables if possible, only use it when prepareStatement is not applicable, e.g. some DDL statement
-
checkPrefixMatch
public static boolean checkPrefixMatch(String prefix, String fileName, boolean caseSensitive)
Function to check if the given prefix exists in the fileName
-
getFolderNameFromPath
public static String getFolderNameFromPath(String path)
Function to return the folder name from the path
-
getBaseNameFromPath
public static String getBaseNameFromPath(String path)
Function to return the base name from the path
-
getVolumePath
public static String getVolumePath(String catalog, String schema, String volume)
Building the volume path using the provided catalog, schema and volume
-
removeRedundantEscapeClause
public static String removeRedundantEscapeClause(String sql)
Removes empty ESCAPE clauses from SQL statements to work around Databricks SQL parser limitations.All other ESCAPE clauses, including custom escape characters (e.g.,
ESCAPE '#'), are preserved unchanged.- Parameters:
sql- The SQL statement to process- Returns:
- SQL with empty ESCAPE clauses removed, or null if input is null
-
parseIntegerSet
public static Set<Integer> parseIntegerSet(String input)
Parses a comma-separated string of integers into a Set.- Parameters:
input- comma-separated string of integers (e.g., "500, 503, 504")- Returns:
- Set of parsed integers, or empty set if input is null/empty or all values are invalid
- Throws:
NumberFormatException- if any value cannot be parsed as an integer (after validation)
-
-