Class AntlrParser
java.lang.Object
org.pgcodekeeper.core.parsers.antlr.base.AntlrParser
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 Summary
Modifier and TypeMethodDescriptionstatic voidcheckToClean(long cleaningInterval) Checks if parser caches need cleaning based on last usage time.static voidClears the parser cache for all database types that have been used.static CHParsercreateCHParser(InputStream is, String charset, String parsedObjectName, List<Object> errors) Creates a ClickHouse SQL parser from input stream.static CHParsercreateCHParser(String sql, String parsedObjectName, List<Object> errors) Creates a ClickHouse SQL parser from string input.static IgnoreListParsercreateIgnoreListParser(Path listFile) Creates a parser for ignore list files.static PrivilegesParsercreatePrivilegesParser(String aclArrayAsString) Creates a parser for PostgreSQL privilege strings.static SQLParsercreateSQLParser(InputStream is, String charset, String parsedObjectName, List<Object> errors) Creates a PostgreSQL SQL parser from input stream.static SQLParsercreateSQLParser(String sql, String parsedObjectName, List<Object> errors) Creates a PostgreSQL SQL parser from string input.static SQLParsercreateSQLParser(String sql, String parsedObjectName, List<Object> errors, org.antlr.v4.runtime.Token start) Creates a PostgreSQL SQL parser from string input with position offset.static TSQLParsercreateTSQLParser(InputStream is, String charset, String parsedObjectName, List<Object> errors) Creates a Microsoft SQL parser from input stream.static TSQLParsercreateTSQLParser(String sql, String parsedObjectName, List<Object> errors) Creates a Microsoft SQL parser from string input.static voidparseChSqlStream(InputStreamProvider inputStream, String charsetName, String parsedObjectName, List<Object> errors, IMonitor mon, int monitoringLevel, ChSqlContextProcessor listener, Queue<AntlrTask<?>> antlrTasks) Parses ClickHouse SQL stream asynchronously.static voidparseSqlStream(InputStreamProvider inputStream, String charsetName, String parsedObjectName, List<Object> errors, IMonitor mon, int monitoringLevel, SqlContextProcessor listener, Queue<AntlrTask<?>> antlrTasks) Parses PostgreSQL SQL stream asynchronously.static voidparseTSqlStream(InputStreamProvider inputStream, String charsetName, String parsedObjectName, List<Object> errors, IMonitor mon, int monitoringLevel, TSqlContextProcessor listener, Queue<AntlrTask<?>> antlrTasks) Parses Microsoft SQL stream asynchronously.
-
Method Details
-
createIgnoreListParser
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
Creates a parser for PostgreSQL privilege strings.- Parameters:
aclArrayAsString- privilege string to parse- Returns:
- configured PrivilegesParser instance
-
createSQLParser
Creates a PostgreSQL SQL parser from string input.- Parameters:
sql- SQL string to parseparsedObjectName- 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 parseparsedObjectName- name of the object being parsed (for error reporting)errors- list to collect parsing errorsstart- 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 SQLcharset- character encoding of the streamparsedObjectName- 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
Creates a Microsoft SQL parser from string input.- Parameters:
sql- T-SQL string to parseparsedObjectName- 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-SQLcharset- character encoding of the streamparsedObjectName- 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
Creates a ClickHouse SQL parser from string input.- Parameters:
sql- ClickHouse SQL string to parseparsedObjectName- 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 SQLcharset- character encoding of the streamparsedObjectName- name of the object being parsederrors- 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 streamcharsetName- character encoding of the streamparsedObjectName- name of the object being parsederrors- list to collect parsing errorsmon- progress monitor for cancellation supportmonitoringLevel- level of parse tree monitoringlistener- processor for the parsed contentantlrTasks- 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 streamcharsetName- character encoding of the streamparsedObjectName- name of the object being parsederrors- list to collect parsing errorsmon- progress monitor for cancellation supportmonitoringLevel- level of parse tree monitoringlistener- processor for the parsed contentantlrTasks- 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 streamcharsetName- character encoding of the streamparsedObjectName- name of the object being parsederrors- list to collect parsing errorsmon- progress monitor for cancellation supportmonitoringLevel- level of parse tree monitoringlistener- processor for the parsed contentantlrTasks- 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
-