public final class SqlParserUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
SqlParserUtil.Format
Pre-initialized
DateFormat objects, to be used within the current
thread, because DateFormat is not thread-safe. |
private static class |
SqlParserUtil.OldTokenSequenceImpl
Implementation of
SqlSpecialOperator.TokenSequence. |
static class |
SqlParserUtil.ParsedCollation
The components of a collation definition, per the SQL standard.
|
static class |
SqlParserUtil.StringAndPos
Contains a string, the offset of a token within the string, and a parser
position containing the beginning and end line number.
|
private static class |
SqlParserUtil.TokenSequenceImpl
Implementation of
SqlSpecialOperator.TokenSequence
based on an existing parser. |
static class |
SqlParserUtil.ToTreeListItem
Class that holds a
SqlOperator and a SqlParserPos. |
| Modifier and Type | Field and Description |
|---|---|
(package private) static org.slf4j.Logger |
LOGGER |
| Modifier | Constructor and Description |
|---|---|
private |
SqlParserUtil() |
| 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 void |
checkDateFormat(String pattern)
Checks if the date/time format is valid
|
static char |
checkUnicodeEscapeChar(String s)
Checks a UESCAPE string for validity, and returns the escape character if
no exception is thrown.
|
private static SqlNode |
convert(PrecedenceClimbingParser.Token token) |
static SqlParserUtil.StringAndPos |
findPos(String sql)
Looks for one or two carets in a SQL string, and if present, converts
them into a parser position.
|
static String |
getCharacterSet(String s) |
static 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,
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 SqlNode[] |
toNodeArray(List<SqlNode> list) |
static SqlNode[] |
toNodeArray(SqlNodeList list) |
static String[] |
toStringArray(List<String> list)
Deprecated.
|
static 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 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, String startQuote, String endQuote, String escape, org.apache.calcite.avatica.util.Casing casing)
public static String trim(String s, String chars)
trim("aBaac123AabC","abBcC") returns "123A".public static SqlParserUtil.StringAndPos findPos(String sql)
Examples:
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)
@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 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.private static SqlNode convert(PrecedenceClimbingParser.Token token)
public static char checkUnicodeEscapeChar(String s)
s - UESCAPE string to checkCopyright © 2012–2018 The Apache Software Foundation. All rights reserved.