|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eigenbase.sql.SqlUtil
public abstract class SqlUtil
Contains utility functions related to SQL parsing, all static.
Nested Class Summary | |
---|---|
static class |
SqlUtil.DatabaseMetaDataInvocationHandler
Handles particular DatabaseMetaData methods; invocations of other
methods will fall through to the base class, BarfingInvocationHandler , which will throw an error. |
Field Summary | |
---|---|
static SqlDialect |
dummyDialect
A SqlDialect useful for generating generic SQL. |
static SqlDialect |
eigenbaseDialect
A SqlDialect useful for generating SQL which can be parsed by the
Eigenbase parser, but not much else. |
Constructor Summary | |
---|---|
SqlUtil()
|
Method Summary | |
---|---|
(package private) static SqlNode |
andExpressions(SqlNode node1,
SqlNode node2)
|
static SqlLiteral |
concatenateLiterals(SqlLiteral[] lits)
Concatenates string literals. |
static RelDataType |
createNlsStringType(RelDataTypeFactory typeFactory,
NlsString str)
Creates the type of an NlsString . |
static String |
deriveAliasFromOrdinal(int ordinal)
|
private static DatabaseMetaData |
dummyDatabaseMetaData(String databaseProductName,
String identifierQuoteString)
Creates a DatabaseMetaData object good enough to create a SqlDialect object with, but not good for much else. |
private static void |
filterRoutinesByParameterCount(List<SqlFunction> routines,
RelDataType[] argTypes)
|
private static void |
filterRoutinesByParameterType(List<SqlFunction> routines,
RelDataType[] argTypes)
|
private static void |
filterRoutinesByTypePrecedence(List<SqlFunction> routines,
RelDataType[] argTypes)
|
(package private) static ArrayList<SqlNode> |
flatten(SqlNode node)
|
private static void |
flatten(SqlNode node,
ArrayList<SqlNode> list)
|
static String |
getAliasedSignature(SqlOperator op,
String opName,
List<? extends Object> typeList)
Constructs an operator signature from a type list, substituting an alias for the operator name. |
static SqlNode |
getFromNode(SqlSelect query,
int ordinal)
Returns the n th (0-based) input to a join expression. |
static String |
getOperatorSignature(SqlOperator op,
List<? extends Object> typeList)
Constructs an operator signature from a type list. |
static SqlNode |
getSelectListItem(SqlNode query,
int i)
Returns the i th select-list item of a query. |
static boolean |
isCallTo(SqlNode node,
SqlOperator operator)
Returns whether a node is a call to a
given operator . |
static boolean |
isLiteral(SqlNode node)
Returns whether a node is a literal. |
static boolean |
isLiteralChain(SqlNode node)
Returns whether a node is a literal chain which is used to represent a continued string literal. |
static boolean |
isNull(SqlNode node)
Returns whether a node represents the NULL value or a series of nested CAST(NULL as For Example: isNull(CAST(CAST(NULL as INTEGER) AS VARCHAR(1))) returns true |
static boolean |
isNullLiteral(SqlNode node,
boolean allowCast)
Returns whether a node represents the NULL value. |
static SqlFunction |
lookupRoutine(SqlOperatorTable opTab,
SqlIdentifier funcName,
RelDataType[] argTypes,
SqlFunctionCategory category)
Looks up a (possibly overloaded) routine based on name and argument types. |
static List<SqlFunction> |
lookupSubjectRoutines(SqlOperatorTable opTab,
SqlIdentifier funcName,
RelDataType[] argTypes,
SqlFunctionCategory category)
Looks up all subject routines matching the given name and argument types. |
private static List<SqlFunction> |
lookupSubjectRoutinesByName(SqlOperatorTable opTab,
SqlIdentifier funcName,
SqlFunctionCategory category)
|
static SqlCall |
makeCall(SqlOperatorTable opTab,
SqlIdentifier id)
If an identifier is a legitimate call to a function which has no arguments and requires no parentheses (for example "CURRENT_USER"), returns a call to that function, otherwise returns null. |
static boolean |
matchRoutinesByParameterCount(SqlOperatorTable opTab,
SqlIdentifier funcName,
RelDataType[] argTypes,
SqlFunctionCategory category)
Determine if there is a routine matching the given name and number of arguments. |
static EigenbaseException |
newContextException(int line,
int col,
int endLine,
int endCol,
Throwable e)
Wraps an exception with context. |
static EigenbaseException |
newContextException(SqlParserPos pos,
Throwable e)
Wraps an exception with context. |
static EigenbaseException |
newContextException(SqlParserPos pos,
Throwable e,
String inputText)
Wraps an exception with context. |
static SqlNodeList |
toNodeList(SqlNode[] operands)
Converts an SqlNode array to a SqlNodeList |
static String |
translateCharacterSetName(String name)
Translates a character set name from a SQL-level name into a Java-level name. |
static void |
unparseBinarySyntax(SqlOperator operator,
SqlNode[] operands,
SqlWriter writer,
int leftPrec,
int rightPrec)
|
static void |
unparseFunctionSyntax(SqlOperator operator,
SqlWriter writer,
SqlNode[] operands,
boolean emptyParens,
SqlLiteral quantifier)
Unparses a call to an operator which has function syntax. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final SqlDialect dummyDialect
SqlDialect
useful for generating generic SQL. If you need to do
something database-specific like quoting identifiers, don't rely on this
dialect to do what you want.
public static final SqlDialect eigenbaseDialect
SqlDialect
useful for generating SQL which can be parsed by the
Eigenbase parser, but not much else.
Constructor Detail |
---|
public SqlUtil()
Method Detail |
---|
static SqlNode andExpressions(SqlNode node1, SqlNode node2)
static ArrayList<SqlNode> flatten(SqlNode node)
public static SqlNode getFromNode(SqlSelect query, int ordinal)
n
th (0-based) input to a join expression.
private static void flatten(SqlNode node, ArrayList<SqlNode> list)
public static SqlNodeList toNodeList(SqlNode[] operands)
public static boolean isNullLiteral(SqlNode node, boolean allowCast)
Examples:
SqlLiteral
Unknown, returns false.
CAST(NULL AS type)
, returns true if
allowCast
is true, false otherwise.
CAST(CAST(NULL AS type) AS type))
,
returns false.
public static boolean isNull(SqlNode node)
public static boolean isLiteral(SqlNode node)
Many constructs which require literals also accept CAST(NULL AS
type)
. This method does not accept casts, so you should
call isNullLiteral(org.eigenbase.sql.SqlNode, boolean)
first.
node
- The node, never null.
public static boolean isLiteralChain(SqlNode node)
node
- The node, never null.
public static void unparseFunctionSyntax(SqlOperator operator, SqlWriter writer, SqlNode[] operands, boolean emptyParens, SqlLiteral quantifier)
operator
- The operatorwriter
- Writeroperands
- List of 0 or more operandsemptyParens
- Whether to print parentheses if there are 0 operandsquantifier
- public static void unparseBinarySyntax(SqlOperator operator, SqlNode[] operands, SqlWriter writer, int leftPrec, int rightPrec)
private static DatabaseMetaData dummyDatabaseMetaData(String databaseProductName, String identifierQuoteString)
DatabaseMetaData
object good enough to create a SqlDialect
object with, but not good for much else.
databaseProductName
- Database product nameidentifierQuoteString
- Identifier quote stringpublic static SqlLiteral concatenateLiterals(SqlLiteral[] lits)
This method takes an array of arguments, since pairwise concatenation means too much string copying.
lits
- an array of SqlLiteral
, not empty, all of the same
class
SqlLiteral
, of that same class, whose value is the
string concatenation of the values of the literals
ClassCastException
- if the lits are not homogeneous.
ArrayIndexOutOfBoundsException
- if lits is an empty array.public static SqlFunction lookupRoutine(SqlOperatorTable opTab, SqlIdentifier funcName, RelDataType[] argTypes, SqlFunctionCategory category)
opTab
- operator table to searchfuncName
- name of function being invokedargTypes
- argument typescategory
- whether a function or a procedure. (If a procedure is
being invoked, the overload rules are simpler.)
public static List<SqlFunction> lookupSubjectRoutines(SqlOperatorTable opTab, SqlIdentifier funcName, RelDataType[] argTypes, SqlFunctionCategory category)
opTab
- operator table to searchfuncName
- name of function being invokedargTypes
- argument typescategory
- category of routine to look up
public static boolean matchRoutinesByParameterCount(SqlOperatorTable opTab, SqlIdentifier funcName, RelDataType[] argTypes, SqlFunctionCategory category)
opTab
- operator table to searchfuncName
- name of function being invokedargTypes
- argument typescategory
- category of routine to look up
private static List<SqlFunction> lookupSubjectRoutinesByName(SqlOperatorTable opTab, SqlIdentifier funcName, SqlFunctionCategory category)
private static void filterRoutinesByParameterCount(List<SqlFunction> routines, RelDataType[] argTypes)
private static void filterRoutinesByParameterType(List<SqlFunction> routines, RelDataType[] argTypes)
private static void filterRoutinesByTypePrecedence(List<SqlFunction> routines, RelDataType[] argTypes)
public static SqlNode getSelectListItem(SqlNode query, int i)
i
th select-list item of a query.
public static SqlCall makeCall(SqlOperatorTable opTab, SqlIdentifier id)
public static String deriveAliasFromOrdinal(int ordinal)
public static String getOperatorSignature(SqlOperator op, List<? extends Object> typeList)
op
- operatortypeList
- list of types to use for operands. Types may be
represented as String
, SqlTypeFamily
, or any object with
a valid Object.toString()
method.
public static String getAliasedSignature(SqlOperator op, String opName, List<? extends Object> typeList)
op
- operatoropName
- name to use for operatortypeList
- list of SqlTypeName
or String
to use for
operands
public static EigenbaseException newContextException(SqlParserPos pos, Throwable e, String inputText)
public static EigenbaseException newContextException(SqlParserPos pos, Throwable e)
public static EigenbaseException newContextException(int line, int col, int endLine, int endCol, Throwable e)
public static boolean isCallTo(SqlNode node, SqlOperator operator)
node
is a call
to a
given operator
.
public static RelDataType createNlsStringType(RelDataTypeFactory typeFactory, NlsString str)
NlsString
.
The type inherits the The NlsString's Charset
and SqlCollation
, if they are set, otherwise it gets the system defaults.
typeFactory
- Type factorystr
- String
public static String translateCharacterSetName(String name)
name
- SQL-level name
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |