public final class SqlParserUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
SqlParserUtil.ParsedCollation
The components of a collation definition, per the SQL standard.
|
static class |
SqlParserUtil.ToTreeListItem
Class that holds a
SqlOperator and a SqlParserPos. |
| Modifier and Type | Method and Description |
|---|---|
static String |
addCarets(String sql,
int line,
int col,
int endLine,
int endCol)
Converts a string to a string with one or two carets in it.
|
static boolean |
allowsIdentifier(String[] tokenImage,
int[][] expectedTokenSequences)
Returns whether the reported ParseException tokenImage
allows SQL identifier.
|
static void |
checkDateFormat(String pattern)
Checks if the date/time format is valid, throws if not.
|
static char |
checkUnicodeEscapeChar(String s)
Checks a UESCAPE string for validity, and returns the escape character if
no exception is thrown.
|
static StringAndPos |
findPos(String sql)
Deprecated.
|
static @Nullable String |
getCharacterSet(String s)
Returns the character-set prefix of a SQL string literal; returns null if
there is none.
|
static @Nullable String |
getTokenVal(String token) |
static int[] |
indexToLineCol(String sql,
int i)
Returns the (1-based) line and column corresponding to a particular
(0-based) offset in a string.
|
static long |
intervalToMillis(SqlIntervalLiteral.IntervalValue interval)
Converts the interval value into a millisecond representation.
|
static long |
intervalToMillis(String literal,
SqlIntervalQualifier intervalQualifier) |
static long |
intervalToMonths(SqlIntervalLiteral.IntervalValue interval)
Converts the interval value into a months representation.
|
static long |
intervalToMonths(String literal,
SqlIntervalQualifier intervalQualifier) |
static int |
lineColToIndex(String sql,
int line,
int column)
Finds the position (0-based) in a string which corresponds to a given
line and column (1-based).
|
static int |
nextLine(String sql,
int j) |
static byte[] |
parseBinaryString(String s)
Deprecated.
|
static SqlParserUtil.ParsedCollation |
parseCollation(String in)
Extracts the values from a collation name.
|
static Date |
parseDate(String s)
Deprecated.
this method is not localized for Farrago standards
|
static SqlDateLiteral |
parseDateLiteral(String s,
SqlParserPos pos) |
static BigDecimal |
parseDecimal(String s) |
static BigDecimal |
parseInteger(String s) |
static SqlIntervalLiteral |
parseIntervalLiteral(SqlParserPos pos,
int sign,
String s,
SqlIntervalQualifier intervalQualifier) |
static int |
parsePositiveInt(String value)
Parses a positive int.
|
static String |
parseString(String s)
Converts the contents of an sql quoted string literal into the
corresponding Java string representation (removing leading and trailing
quotes and unescaping internal doubled quotes).
|
static Time |
parseTime(String s)
Deprecated.
Does not parse SQL:99 milliseconds
|
static SqlTimeLiteral |
parseTimeLiteral(String s,
SqlParserPos pos) |
static Timestamp |
parseTimestamp(String s)
Deprecated.
this method is not localized for Farrago standards
|
static SqlTimestampLiteral |
parseTimestampLiteral(String s,
SqlParserPos pos) |
static <T> void |
replaceSublist(List<T> list,
int start,
int end,
T o)
Replaces a range of elements in a list with a single element.
|
static String |
rightTrim(String s,
char c)
Deprecated.
|
static String |
strip(String s,
@Nullable String startQuote,
@Nullable String endQuote,
@Nullable String escape,
org.apache.calcite.avatica.util.Casing casing)
Converts a quoted identifier, unquoted identifier, or quoted string to a
string of its contents.
|
static String |
stripQuotes(String s,
String startQuote,
String endQuote,
String escape,
org.apache.calcite.avatica.util.Casing casing)
Unquotes a quoted string, using different quotes for beginning and end.
|
static SqlNodeList |
stripRow(SqlNode n)
Converts "ROW (1, 2)" to "(1, 2)"
and "3" to "(3)".
|
static String |
toCase(String s,
org.apache.calcite.avatica.util.Casing casing)
Converts an identifier to a particular casing.
|
static SqlNode[] |
toNodeArray(List<SqlNode> list) |
static SqlNode[] |
toNodeArray(SqlNodeList list) |
static String[] |
toStringArray(List<String> list)
Deprecated.
|
static @Nullable SqlNode |
toTree(List<Object> list)
Converts a list of {expression, operator, expression, ...} into a tree,
taking operator precedence and associativity into account.
|
static SqlNode |
toTreeEx(SqlSpecialOperator.TokenSequence list,
int start,
int minPrec,
SqlKind stopperKind)
Converts a list of {expression, operator, expression, ...} into a tree,
taking operator precedence and associativity into account.
|
static String |
trim(String s,
String chars)
Trims a string for given characters from left and right.
|
public static @Nullable String getCharacterSet(String s)
public static String parseString(String s)
public static BigDecimal parseDecimal(String s)
public static BigDecimal parseInteger(String s)
@Deprecated public static Date parseDate(String s)
@Deprecated public static Time parseTime(String s)
@Deprecated public static Timestamp parseTimestamp(String s)
public static SqlDateLiteral parseDateLiteral(String s, SqlParserPos pos)
public static SqlTimeLiteral parseTimeLiteral(String s, SqlParserPos pos)
public static SqlTimestampLiteral parseTimestampLiteral(String s, SqlParserPos pos)
public static SqlIntervalLiteral parseIntervalLiteral(SqlParserPos pos, int sign, String s, SqlIntervalQualifier intervalQualifier)
public static void checkDateFormat(String pattern)
pattern - SimpleDateFormat patternpublic static long intervalToMillis(SqlIntervalLiteral.IntervalValue interval)
interval - Intervalpublic static long intervalToMillis(String literal, SqlIntervalQualifier intervalQualifier)
public static long intervalToMonths(SqlIntervalLiteral.IntervalValue interval)
interval - Intervalpublic static long intervalToMonths(String literal, SqlIntervalQualifier intervalQualifier)
public static int parsePositiveInt(String value)
NumberFormatException - if invalid number or leading '-'Integer.parseInt(String)@Deprecated public static byte[] parseBinaryString(String s)
public static String strip(String s, @Nullable String startQuote, @Nullable String endQuote, @Nullable String escape, org.apache.calcite.avatica.util.Casing casing)
First, if startQuote is provided, endQuote and
escape must also be provided, and this method removes quotes.
Finally, converts the string to the provided casing.
public static String stripQuotes(String s, String startQuote, String endQuote, String escape, org.apache.calcite.avatica.util.Casing casing)
public static String toCase(String s, org.apache.calcite.avatica.util.Casing casing)
public static String trim(String s, String chars)
trim("aBaac123AabC","abBcC") returns "123A".@Deprecated public static StringAndPos findPos(String sql)
public static int[] indexToLineCol(String sql, int i)
Converse of lineColToIndex(String, int, int).
public static int nextLine(String sql, int j)
public static int lineColToIndex(String sql, int line, int column)
Converse of indexToLineCol(String, int).
public static String addCarets(String sql, int line, int col, int endLine, int endCol)
addCarets("values (foo)", 1, 9, 1, 12) yields "values
(^foo^)".public static SqlParserUtil.ParsedCollation parseCollation(String in)
Collation names are on the form charset$locale$strength.
in - The collation nameSqlParserUtil.ParsedCollation@Deprecated public static String[] toStringArray(List<String> list)
public static SqlNode[] toNodeArray(SqlNodeList list)
public static SqlNodeList stripRow(SqlNode n)
@Deprecated public static String rightTrim(String s, char c)
public static <T> void replaceSublist(List<T> list, int start, int end, T o)
{A, B, C, D, E} then
replaceSublist(list, X, 1, 4) returns {A, X, E}.public static @Nullable SqlNode toTree(List<Object> list)
public static SqlNode toTreeEx(SqlSpecialOperator.TokenSequence list, int start, int minPrec, SqlKind stopperKind)
list - List of operands and operators. This list is modified as
expressions are reduced.start - Position of first operand in the list. Anything to the
left of this (besides the immediately preceding operand)
is ignored. Generally use value 1.minPrec - Minimum precedence to consider. If the method encounters
an operator of lower precedence, it doesn't reduce any
further.stopperKind - If not SqlKind.OTHER, stop reading the list if
we encounter a token of this kind.public static char checkUnicodeEscapeChar(String s)
s - UESCAPE string to checkpublic static boolean allowsIdentifier(String[] tokenImage, int[][] expectedTokenSequences)
tokenImage - The allowed tokens from the ParseExceptionexpectedTokenSequences - Expected token sequencesCopyright © 2012-2022 Apache Software Foundation. All Rights Reserved.