Package com.databricks.jdbc.common.util
Class SqlCommentParser
- java.lang.Object
-
- com.databricks.jdbc.common.util.SqlCommentParser
-
public class SqlCommentParser extends Object
Utility class for parsing out comments from SQL strings
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSqlCommentParser.SqlCharConsumerstatic classSqlCommentParser.State
-
Constructor Summary
Constructors Constructor Description SqlCommentParser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidforEachNonCommentChar(String sql, SqlCommentParser.SqlCharConsumer consumer)Iterates over each character in the SQL string while keeping track of comment, string literal, and identifier state.static StringstripCommentsAndWhitespaces(String sql)Removes all comments and extra whitespace from the SQL string.
-
-
-
Method Detail
-
forEachNonCommentChar
public static void forEachNonCommentChar(String sql, SqlCommentParser.SqlCharConsumer consumer)
Iterates over each character in the SQL string while keeping track of comment, string literal, and identifier state. Each character that is not part of a comment calls the consumer with the current state and character. Emits a ' ' character after each comment to avoid token fusion.- Parameters:
sql- the SQL string to parseconsumer- called for each visible character with its parsing state
-
stripCommentsAndWhitespaces
public static String stripCommentsAndWhitespaces(String sql)
Removes all comments and extra whitespace from the SQL string.- Parameters:
sql- the SQL string to remove comments and extra whitespace from- Returns:
- the SQL string with all comments and extra whitespace removed
-
-