Class ChDiffUtils
java.lang.Object
org.pgcodekeeper.core.database.ch.utils.ChDiffUtils
Utility class for handling quoting and unquoting of identifiers and literals in ClickHouse.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetQuotedName(String name) Returns the name quoted with backticks (`) if it's not a valid identifier.static booleanisSystemSchema(String schema) Checks if a schema is a ClickHouse system schema.static booleanChecks if the given string is a valid ClickHouse identifier.static booleanisValidIdChar(char c, boolean allowCaps, boolean allowDigits) Checks if character is valid for ClickHouse identifiers.static StringquoteLiteralName(String name) Quotes a string literal with single quotes (') if unquoted.static StringWraps the name in backticks (`) if not already quoted.static StringunQuoteLiteralName(String name) Unquotes a single-quoted string literal.static StringunQuoteName(String name) Unquotes a backtick-quoted identifier.
-
Method Details
-
getQuotedName
Returns the name quoted with backticks (`) if it's not a valid identifier. Ifnameis already valid, it is returned unchanged.- Parameters:
name- the name to check and quote if needed- Returns:
- the original name (if valid) or a backtick-quoted version
-
quoteName
Wraps the name in backticks (`) if not already quoted.- Parameters:
name- the name to quote- Returns:
- the quoted name, or original if already quoted
-
quoteLiteralName
Quotes a string literal with single quotes (') if unquoted.- Parameters:
name- the string to quote (e.g., a SQL value)- Returns:
- the quoted string, or original if already quoted
-
isValidId
Checks if the given string is a valid ClickHouse identifier.- Parameters:
id- the identifier to validateallowCaps- whether to allow uppercase letters in the identifier- Returns:
- true if the identifier is valid, false otherwise
-
isValidIdChar
public static boolean isValidIdChar(char c, boolean allowCaps, boolean allowDigits) Checks if character is valid for ClickHouse identifiers.- Parameters:
c- the character to checkallowCaps- whether to allow uppercase lettersallowDigits- whether to allow digits- Returns:
- true if character is valid for ClickHouse identifiers, false otherwise
-
unQuoteName
Unquotes a backtick-quoted identifier. Handles escaped backticks (``) by converting them to single backticks.- Parameters:
name- the quoted identifier to unquote- Returns:
- the unquoted identifier
-
unQuoteLiteralName
Unquotes a single-quoted string literal. Handles escaped single quotes ('') by converting them to single quotes.- Parameters:
name- the quoted string to unquote- Returns:
- the unquoted string
-
isSystemSchema
Checks if a schema is a ClickHouse system schema.- Parameters:
schema- the schema name to check- Returns:
- true if the schema is 'system' or 'information_schema', false otherwise
-