public abstract class SqlUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
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. |
| Constructor and Description |
|---|
SqlUtil() |
| Modifier and Type | Method and Description |
|---|---|
static SqlLiteral |
concatenateLiterals(List<SqlLiteral> lits)
Concatenates string literals.
|
static RelDataType |
createNlsStringType(RelDataTypeFactory typeFactory,
NlsString str)
Creates the type of an
NlsString. |
static String |
deriveAliasFromOrdinal(int ordinal) |
static String |
getAliasedSignature(SqlOperator op,
String opName,
List<?> typeList)
Constructs an operator signature from a type list, substituting an alias
for the operator name.
|
static com.google.common.collect.ImmutableList<SqlNode> |
getAncestry(SqlNode root,
com.google.common.base.Predicate<SqlNode> predicate,
com.google.common.base.Predicate<SqlNode> postPredicate)
Returns a list of ancestors of
predicate within a given
SqlNode tree. |
static SqlNode |
getFromNode(SqlSelect query,
int ordinal)
Returns the
nth (0-based) input to a join expression. |
static String |
getOperatorSignature(SqlOperator op,
List<?> typeList)
Constructs an operator signature from a type list.
|
static SqlNode |
getSelectListItem(SqlNode query,
int i)
Returns the
ith select-list item of a query. |
static boolean |
isCallTo(SqlNode node,
SqlOperator 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 type) calls. |
static boolean |
isNullLiteral(SqlNode node,
boolean allowCast)
Returns whether a node represents the NULL value.
|
static SqlFunction |
lookupRoutine(SqlOperatorTable opTab,
SqlIdentifier funcName,
List<RelDataType> argTypes,
SqlFunctionCategory category)
Looks up a (possibly overloaded) routine based on name and argument
types.
|
static List<SqlFunction> |
lookupSubjectRoutines(SqlOperatorTable opTab,
SqlIdentifier funcName,
List<RelDataType> argTypes,
SqlFunctionCategory category)
Looks up all subject routines matching the given name and argument types.
|
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,
List<RelDataType> argTypes,
SqlFunctionCategory category)
Determine if there is a routine matching the given name and number of
arguments.
|
static CalciteContextException |
newContextException(int line,
int col,
int endLine,
int endCol,
Resources.ExInst<?> e)
Wraps an exception with context.
|
static CalciteContextException |
newContextException(SqlParserPos pos,
Resources.ExInst<?> e)
Wraps an exception with context.
|
static CalciteException |
newContextException(SqlParserPos pos,
Resources.ExInst<?> e,
String inputText)
Wraps an exception with context.
|
static SqlNode |
stripAs(SqlNode node)
If a node is "AS", returns the underlying expression; otherwise returns
the node.
|
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,
SqlCall call,
SqlWriter writer,
int leftPrec,
int rightPrec) |
static void |
unparseFunctionSyntax(SqlOperator operator,
SqlWriter writer,
SqlCall call)
Unparses a call to an operator which has function syntax.
|
public static SqlNode getFromNode(SqlSelect query, int ordinal)
nth (0-based) input to a join expression.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)
CAST(NULL AS type) calls. For example:
isNull(CAST(CAST(NULL as INTEGER) AS VARCHAR(1)))
returns true.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.apache.calcite.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, SqlCall call)
operator - The operatorwriter - Writercall - List of 0 or more operandspublic static void unparseBinarySyntax(SqlOperator operator, SqlCall call, SqlWriter writer, int leftPrec, int rightPrec)
public static SqlLiteral concatenateLiterals(List<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
classSqlLiteral, of that same class, whose value is the
string concatenation of the values of the literalsClassCastException - if the lits are not homogeneous.ArrayIndexOutOfBoundsException - if lits is an empty array.public static SqlFunction lookupRoutine(SqlOperatorTable opTab, SqlIdentifier funcName, List<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, List<RelDataType> argTypes, SqlFunctionCategory category)
opTab - operator table to searchfuncName - name of function being invokedargTypes - argument typescategory - category of routine to look uppublic static boolean matchRoutinesByParameterCount(SqlOperatorTable opTab, SqlIdentifier funcName, List<RelDataType> argTypes, SqlFunctionCategory category)
opTab - operator table to searchfuncName - name of function being invokedargTypes - argument typescategory - category of routine to look uppublic static SqlNode getSelectListItem(SqlNode query, int i)
ith 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<?> 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<?> typeList)
op - operatoropName - name to use for operatortypeList - list of SqlTypeName or String to use for
operandspublic static CalciteException newContextException(SqlParserPos pos, Resources.ExInst<?> e, String inputText)
public static CalciteContextException newContextException(SqlParserPos pos, Resources.ExInst<?> e)
public static CalciteContextException newContextException(int line, int col, int endLine, int endCol, Resources.ExInst<?> e)
public static boolean isCallTo(SqlNode node, SqlOperator 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 - Stringpublic static String translateCharacterSetName(String name)
name - SQL-level namepublic static SqlNode stripAs(SqlNode node)
public static com.google.common.collect.ImmutableList<SqlNode> getAncestry(SqlNode root, com.google.common.base.Predicate<SqlNode> predicate, com.google.common.base.Predicate<SqlNode> postPredicate)
predicate within a given
SqlNode tree.
The first element of the list is root, and the last is
the node that matched predicate. Throws if no node matches.
Copyright © 2012–2015 The Apache Software Foundation. All rights reserved.