Class AntlrParser

java.lang.Object
org.pgcodekeeper.core.parsers.antlr.base.AntlrParser

public final class AntlrParser extends Object
Utility class for creating and managing ANTLR parsers for different SQL dialects. Provides methods for parsing SQL, Microsoft SQL, and ClickHouse SQL with error handling.
  • Method Details

    • createIgnoreListParser

      public static IgnoreListParser createIgnoreListParser(Path listFile) throws IOException
      Creates a parser for ignore list files.
      Parameters:
      listFile - path to the ignore list file
      Returns:
      configured IgnoreListParser instance
      Throws:
      IOException - if there's an error reading the file
    • createPrivilegesParser

      public static PrivilegesParser createPrivilegesParser(String aclArrayAsString)
      Creates a parser for PostgreSQL privilege strings.
      Parameters:
      aclArrayAsString - privilege string to parse
      Returns:
      configured PrivilegesParser instance
    • createSQLParser

      public static SQLParser createSQLParser(String sql, String parsedObjectName, List<Object> errors)
      Creates a PostgreSQL SQL parser from string input.
      Parameters:
      sql - SQL string to parse
      parsedObjectName - name of the object being parsed (for error reporting)
      errors - list to collect parsing errors
      Returns:
      configured SQLParser instance
    • createSQLParser

      public static SQLParser createSQLParser(String sql, String parsedObjectName, List<Object> errors, org.antlr.v4.runtime.Token start)
      Creates a PostgreSQL SQL parser from string input with position offset.
      Parameters:
      sql - SQL string to parse
      parsedObjectName - name of the object being parsed (for error reporting)
      errors - list to collect parsing errors
      start - token providing position offset information
      Returns:
      configured SQLParser instance
    • createSQLParser

      public static SQLParser createSQLParser(InputStream is, String charset, String parsedObjectName, List<Object> errors) throws IOException
      Creates a PostgreSQL SQL parser from input stream.
      Parameters:
      is - input stream containing SQL
      charset - character encoding of the stream
      parsedObjectName - name of the object being parsed (for error reporting)
      errors - list to collect parsing errors
      Returns:
      configured SQLParser instance
      Throws:
      IOException - if there's an error reading the stream
    • createTSQLParser

      public static TSQLParser createTSQLParser(String sql, String parsedObjectName, List<Object> errors)
      Creates a Microsoft SQL parser from string input.
      Parameters:
      sql - T-SQL string to parse
      parsedObjectName - name of the object being parsed (for error reporting)
      errors - list to collect parsing errors
      Returns:
      configured TSQLParser instance
    • createTSQLParser

      public static TSQLParser createTSQLParser(InputStream is, String charset, String parsedObjectName, List<Object> errors) throws IOException
      Creates a Microsoft SQL parser from input stream.
      Parameters:
      is - input stream containing T-SQL
      charset - character encoding of the stream
      parsedObjectName - name of the object being parsed (for error reporting)
      errors - list to collect parsing errors
      Returns:
      configured TSQLParser instance
      Throws:
      IOException - if there's an error reading the stream
    • createCHParser

      public static CHParser createCHParser(String sql, String parsedObjectName, List<Object> errors)
      Creates a ClickHouse SQL parser from string input.
      Parameters:
      sql - ClickHouse SQL string to parse
      parsedObjectName - name of the object being parsed (for error reporting)
      errors - list to collect parsing errors
      Returns:
      configured CHParser instance
    • createCHParser

      public static CHParser createCHParser(InputStream is, String charset, String parsedObjectName, List<Object> errors) throws IOException
      Creates a ClickHouse SQL parser from input stream.
      Parameters:
      is - input stream containing ClickHouse SQL
      charset - character encoding of the stream
      parsedObjectName - name of the object being parsed
      errors - list to collect parsing errors
      Returns:
      configured CHParser instance
      Throws:
      IOException - if there's an error reading the stream
    • parseSqlStream

      public static void parseSqlStream(InputStreamProvider inputStream, String charsetName, String parsedObjectName, List<Object> errors, IMonitor mon, int monitoringLevel, SqlContextProcessor listener, Queue<AntlrTask<?>> antlrTasks)
      Parses PostgreSQL SQL stream asynchronously.
      Parameters:
      inputStream - provider of the input stream
      charsetName - character encoding of the stream
      parsedObjectName - name of the object being parsed
      errors - list to collect parsing errors
      mon - progress monitor for cancellation support
      monitoringLevel - level of parse tree monitoring
      listener - processor for the parsed content
      antlrTasks - queue for parser tasks
    • parseTSqlStream

      public static void parseTSqlStream(InputStreamProvider inputStream, String charsetName, String parsedObjectName, List<Object> errors, IMonitor mon, int monitoringLevel, TSqlContextProcessor listener, Queue<AntlrTask<?>> antlrTasks)
      Parses Microsoft SQL stream asynchronously.
      Parameters:
      inputStream - provider of the input stream
      charsetName - character encoding of the stream
      parsedObjectName - name of the object being parsed
      errors - list to collect parsing errors
      mon - progress monitor for cancellation support
      monitoringLevel - level of parse tree monitoring
      listener - processor for the parsed content
      antlrTasks - queue for parser tasks
    • parseChSqlStream

      public static void parseChSqlStream(InputStreamProvider inputStream, String charsetName, String parsedObjectName, List<Object> errors, IMonitor mon, int monitoringLevel, ChSqlContextProcessor listener, Queue<AntlrTask<?>> antlrTasks)
      Parses ClickHouse SQL stream asynchronously.
      Parameters:
      inputStream - provider of the input stream
      charsetName - character encoding of the stream
      parsedObjectName - name of the object being parsed
      errors - list to collect parsing errors
      mon - progress monitor for cancellation support
      monitoringLevel - level of parse tree monitoring
      listener - processor for the parsed content
      antlrTasks - queue for parser tasks
    • cleanCacheOfAllParsers

      public static void cleanCacheOfAllParsers()
      Clears the parser cache for all database types that have been used.
    • checkToClean

      public static void checkToClean(long cleaningInterval)
      Checks if parser caches need cleaning based on last usage time.
      Parameters:
      cleaningInterval - time interval in milliseconds after which cache should be cleaned