Class ChDiffUtils

java.lang.Object
org.pgcodekeeper.core.database.ch.utils.ChDiffUtils

public class ChDiffUtils extends Object
Utility class for handling quoting and unquoting of identifiers and literals in ClickHouse.
  • Method Details

    • getQuotedName

      public static String getQuotedName(String name)
      Returns the name quoted with backticks (`) if it's not a valid identifier. If name is 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

      public static String quoteName(String name)
      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

      public static String quoteLiteralName(String name)
      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

      public static boolean isValidId(String id, boolean allowCaps)
      Checks if the given string is a valid ClickHouse identifier.
      Parameters:
      id - the identifier to validate
      allowCaps - 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 check
      allowCaps - whether to allow uppercase letters
      allowDigits - whether to allow digits
      Returns:
      true if character is valid for ClickHouse identifiers, false otherwise
    • unQuoteName

      public static String unQuoteName(String name)
      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

      public static String unQuoteLiteralName(String name)
      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

      public static boolean isSystemSchema(String schema)
      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