|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eigenbase.sql.parser.SqlParserUtil
public final class SqlParserUtil
Utility methods relating to parsing SQL.
Nested Class Summary | |
---|---|
static class |
SqlParserUtil.ParsedCollation
|
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. |
static class |
SqlParserUtil.ToTreeListItem
Class that holds a SqlOperator and a SqlParserPos . |
Field Summary | |
---|---|
static String |
DateFormatStr
|
static List |
emptyList
|
static String[] |
emptyStringArray
|
static String |
PrecisionTimeFormatStr
|
static String |
PrecisionTimestampFormatStr
|
static String |
TimeFormatStr
|
static String |
TimestampFormatStr
|
(package private) static Logger |
tracer
|
Constructor Summary | |
---|---|
private |
SqlParserUtil()
|
Method Summary | ||
---|---|---|
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. |
|
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 byte[] |
parseBinaryString(String s)
Parses a Binary string. |
|
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 BigDecimal |
parseDecimal(String s)
|
|
static BigDecimal |
parseInteger(String s)
|
|
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 Timestamp |
parseTimestamp(String s)
Deprecated. this method is not localized for Farrago standards |
|
static
|
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)
|
|
static String |
strip(String s,
String quote)
Unquotes a quoted string. |
|
static SqlNode[] |
toNodeArray(List<SqlNode> list)
|
|
static SqlNode[] |
toNodeArray(SqlNodeList list)
|
|
static String[] |
toStringArray(List<String> list)
|
|
static SqlNode |
toTree(List list)
Converts a list of {expression, operator, expression, ...} into a tree, taking operator precedence and associativity into account. |
|
static SqlNode |
toTreeEx(List<Object> 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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static final Logger tracer
public static final String[] emptyStringArray
public static final List emptyList
public static final String DateFormatStr
public static final String TimeFormatStr
public static final String PrecisionTimeFormatStr
public static final String TimestampFormatStr
public static final String PrecisionTimestampFormatStr
Constructor Detail |
---|
private SqlParserUtil()
Method Detail |
---|
public static String getCharacterSet(String s)
public static String parseString(String s)
public static BigDecimal parseDecimal(String s)
public static BigDecimal parseInteger(String s)
public static Date parseDate(String s)
public static Time parseTime(String s)
public static Timestamp parseTimestamp(String s)
public static void checkDateFormat(String pattern)
pattern
- SimpleDateFormat
patternpublic static long intervalToMillis(SqlIntervalLiteral.IntervalValue interval)
interval
- Interval
public static long intervalToMillis(String literal, SqlIntervalQualifier intervalQualifier)
public static long intervalToMonths(SqlIntervalLiteral.IntervalValue interval)
interval
- Interval
public static long intervalToMonths(String literal, SqlIntervalQualifier intervalQualifier)
public static int parsePositiveInt(String value) throws NumberFormatException
NumberFormatException
Integer.parseInt(String)
public static byte[] parseBinaryString(String s)
public static String strip(String s, String quote)
strip("'it''s got
quotes'")
returns "it's got quotes"
.
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 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 String getTokenVal(String token)
public static SqlParserUtil.ParsedCollation parseCollation(String in)
Collation names are on the form charset$locale$strength.
in
- The collation name
SqlParserUtil.ParsedCollation
public static String[] toStringArray(List<String> list)
public static SqlNode[] toNodeArray(List<SqlNode> list)
public static SqlNode[] toNodeArray(SqlNodeList list)
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 list)
public static SqlNode toTreeEx(List<Object> 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 check
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |