Package org.apache.calcite.sql
Class SqlJdbcFunctionCall
- java.lang.Object
-
- org.apache.calcite.sql.SqlOperator
-
- org.apache.calcite.sql.SqlFunction
-
- org.apache.calcite.sql.SqlJdbcFunctionCall
-
public class SqlJdbcFunctionCall extends SqlFunction
ASqlJdbcFunctionCall
is a node of a parse tree which represents a JDBC function call. A JDBC call is of the form{fn NAME(arg0, arg1, ...)}
.See Sun's documentation for writers of JDBC drivers.*
Supported JDBC functions Function Name Function Returns
NUMERIC FUNCTIONS
ABS(number) Absolute value of number ACOS(float) Arccosine, in radians, of float ASIN(float) Arcsine, in radians, of float ATAN(float) Arctangent, in radians, of float ATAN2(float1, float2) Arctangent, in radians, of float2 / float1 CEILING(number) Smallest integer >= number COS(float) Cosine of float radians COT(float) Cotangent of float radians DEGREES(number) Degrees in number radians EXP(float) Exponential function of float FLOOR(number) Largest integer <= number LOG(float) Base e logarithm of float LOG10(float) Base 10 logarithm of float MOD(integer1, integer2) Rh3ainder for integer1 / integer2 PI() The constant pi POWER(number, power) number raised to (integer) power RADIANS(number) Radians in number degrees RAND(integer) Random floating point for seed integer ROUND(number, places) number rounded to places places SIGN(number) -1 to indicate number is < 0; 0 to indicate number is = 0; 1 to indicate number is > 0 SIN(float) Sine of float radians SQRT(float) Square root of float TAN(float) Tangent of float radians TRUNCATE(number, places) number truncated to places places
STRING FUNCTIONS
ASCII(string) Integer representing the ASCII code value of the leftmost character in string CHAR(code) Character with ASCII code value code, where code is between 0 and 255 CONCAT(string1, string2) Character string formed by appending string2 to string1; if a string is null, the result is DBMS-dependent DIFFERENCE(string1, string2) Integer indicating the difference between the values returned by the function SOUNDEX for string1 and string2 INSERT(string1, start, length, string2) A character string formed by deleting length characters from string1 beginning at start, and inserting string2 into string1 at start LCASE(string) Converts all uppercase characters in string to lowercase LEFT(string, count) The count leftmost characters from string LENGTH(string) Number of characters in string, excluding trailing blanks LOCATE(string1, string2[, start]) Position in string2 of the first occurrence of string1, searching from the beginning of string2; if start is specified, the search begins from position start. 0 is returned if string2 does not contain string1. Position 1 is the first character in string2. LTRIM(string) Characters of string with leading blank spaces rh3oved REPEAT(string, count) A character string formed by repeating string count times REPLACE(string1, string2, string3) Replaces all occurrences of string2 in string1 with string3 RIGHT(string, count) The count rightmost characters in string RTRIM(string) The characters of string with no trailing blanks SOUNDEX(string) A character string, which is data source-dependent, representing the sound of the words in string; this could be a four-digit SOUNDEX code, a phonetic representation of each word, etc. SPACE(count) A character string consisting of count spaces SUBSTRING(string, start, length) A character string formed by extracting length characters from string beginning at start UCASE(string) Converts all lowercase characters in string to uppercase
TIME and DATE FUNCTIONS
CURDATE() The current date as a date value CURTIME() The current local time as a time value DAYNAME(date) A character string representing the day component of date; the name for the day is specific to the data source DAYOFMONTH(date) An integer from 1 to 31 representing the day of the month in date DAYOFWEEK(date) An integer from 1 to 7 representing the day of the week in date; 1 represents Sunday DAYOFYEAR(date) An integer from 1 to 366 representing the day of the year in date HOUR(time) An integer from 0 to 23 representing the hour component of time MINUTE(time) An integer from 0 to 59 representing the minute component of time MONTH(date) An integer from 1 to 12 representing the month component of date MONTHNAME(date) A character string representing the month component of date; the name for the month is specific to the data source NOW() A timestamp value representing the current date and time QUARTER(date) An integer from 1 to 4 representing the quarter in date; 1 represents January 1 through March 31 SECOND(time) An integer from 0 to 59 representing the second component of time TIMESTAMPADD(interval,count, timestamp) A timestamp calculated by adding count number of interval(s) to timestamp; interval may be one of the following: SQL_TSI_FRAC_SECOND, SQL_TSI_SECOND, SQL_TSI_MINUTE, SQL_TSI_HOUR, SQL_TSI_DAY, SQL_TSI_WEEK, SQL_TSI_MONTH, SQL_TSI_QUARTER, or SQL_TSI_YEAR TIMESTAMPDIFF(interval,timestamp1, timestamp2) An integer representing the number of interval(s) by which timestamp2 is greater than timestamp1; interval may be one of the following: SQL_TSI_FRAC_SECOND, SQL_TSI_SECOND, SQL_TSI_MINUTE, SQL_TSI_HOUR, SQL_TSI_DAY, SQL_TSI_WEEK, SQL_TSI_MONTH, SQL_TSI_QUARTER, or SQL_TSI_YEAR WEEK(date) An integer from 1 to 53 representing the week of the year in date YEAR(date) An integer representing the year component of date
SYSTEM FUNCTIONS
DATABASE() Name of the database IFNULL(expression, value) value if expression is null; expression if expression is not null USER() User name in the DBMS
CONVERSION FUNCTIONS
CONVERT(value, SQLtype) value converted to SQLtype where SQLtype may be one of the following SQL types: BIGINT, BINARY, BIT, CHAR, DATE, DECIMAL, DOUBLE, FLOAT, INTEGER, LONGVARBINARY, LONGVARCHAR, REAL, SMALLINT, TIME, TIMESTAMP, TINYINT, VARBINARY, or VARCHAR
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
SqlJdbcFunctionCall.JdbcToInternalLookupTable
Lookup table between JDBC functions and internal representationprivate static interface
SqlJdbcFunctionCall.MakeCall
Converts a call to a JDBC function to a call to a regular function.private static class
SqlJdbcFunctionCall.PermutingMakeCall
Implementation ofSqlJdbcFunctionCall.MakeCall
that can re-order or ignore operands.static class
SqlJdbcFunctionCall.SimpleMakeCall
Converter that calls a built-in function with the same arguments.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
jdbcName
private SqlCall
lookupCall
private SqlJdbcFunctionCall.MakeCall
lookupMakeCallObj
private static java.lang.String
NUMERIC_FUNCTIONS
List of all numeric function names defined by JDBC.private static java.lang.String
STRING_FUNCTIONS
List of all string function names defined by JDBC.private static java.lang.String
SYSTEM_FUNCTIONS
List of all system function names defined by JDBC.private SqlNode[]
thisOperands
private static java.lang.String
TIME_DATE_FUNCTIONS
List of all time/date function names defined by JDBC.-
Fields inherited from class org.apache.calcite.sql.SqlOperator
kind, MDX_PRECEDENCE, NL
-
-
Constructor Summary
Constructors Constructor Description SqlJdbcFunctionCall(java.lang.String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.String
constructFuncList(java.lang.String... functionNames)
SqlCall
createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands)
Creates a call to this operand with an array of operands.RelDataType
deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call)
Derives the type of a call to this operator.java.lang.String
getAllowedSignatures(java.lang.String name)
Returns a string describing the expected operand types of a call, e.g.SqlCall
getLookupCall()
static java.lang.String
getNumericFunctions()
static java.lang.String
getStringFunctions()
static java.lang.String
getSystemFunctions()
static java.lang.String
getTimeDateFunctions()
RelDataType
inferReturnType(SqlOperatorBinding opBinding)
Infers the return type of an invocation of this operator; only called after the number and types of operands have already been validated.SqlNode
rewriteCall(SqlValidator validator, SqlCall call)
Rewrites a call to this operator.void
unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec)
Writes a SQL representation of a call to this operator to a writer, including parentheses if the operators on either side are of greater precedence.-
Methods inherited from class org.apache.calcite.sql.SqlFunction
getFunctionType, getNameAsId, getParamNames, getParamTypes, getSqlIdentifier, getSyntax, isQuantifierAllowed, validateCall, validateQuantifier
-
Methods inherited from class org.apache.calcite.sql.SqlOperator
acceptCall, acceptCall, adjustType, allowsFraming, argumentMustBeScalar, checkOperandCount, checkOperandTypes, constructArgNameList, constructArgTypeList, constructOperandList, createCall, createCall, createCall, equals, getAllowedSignatures, getKind, getLeftPrec, getMonotonicity, getMonotonicity, getName, getOperandCountRange, getOperandTypeChecker, getOperandTypeInference, getReturnTypeInference, getRightPrec, getSignatureTemplate, hashCode, inferReturnType, isAggregator, isDeterministic, isDynamicFunction, isGroup, isGroupAuxiliary, isName, leftPrec, needsSpace, preValidateCall, requiresDecimalExpansion, requiresOrder, requiresOver, rightPrec, toString, unparseListClause, unparseListClause, validateOperands, validRexOperands
-
-
-
-
Field Detail
-
NUMERIC_FUNCTIONS
private static final java.lang.String NUMERIC_FUNCTIONS
List of all numeric function names defined by JDBC.
-
STRING_FUNCTIONS
private static final java.lang.String STRING_FUNCTIONS
List of all string function names defined by JDBC.
-
TIME_DATE_FUNCTIONS
private static final java.lang.String TIME_DATE_FUNCTIONS
List of all time/date function names defined by JDBC.
-
SYSTEM_FUNCTIONS
private static final java.lang.String SYSTEM_FUNCTIONS
List of all system function names defined by JDBC.
-
jdbcName
private final java.lang.String jdbcName
-
lookupMakeCallObj
private final SqlJdbcFunctionCall.MakeCall lookupMakeCallObj
-
lookupCall
private SqlCall lookupCall
-
thisOperands
private SqlNode[] thisOperands
-
-
Method Detail
-
constructFuncList
private static java.lang.String constructFuncList(java.lang.String... functionNames)
-
createCall
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands)
Description copied from class:SqlOperator
Creates a call to this operand with an array of operands.The position of the resulting call is the union of the
pos
and the positions of all of the operands.- Overrides:
createCall
in classSqlOperator
- Parameters:
functionQualifier
- function qualifier (e.g. "DISTINCT"), may bepos
- parser position of the identifier of the calloperands
- array of operands
-
rewriteCall
public SqlNode rewriteCall(SqlValidator validator, SqlCall call)
Description copied from class:SqlOperator
Rewrites a call to this operator. Some operators are implemented as trivial rewrites (e.g. NULLIF becomes CASE). However, we don't do this at createCall time because we want to preserve the original SQL syntax as much as possible; instead, we do this before the call is validated (so the trivial operator doesn't need its own implementation of type derivation methods). The default implementation is to just return the original call without any rewrite.- Overrides:
rewriteCall
in classSqlOperator
- Parameters:
validator
- Validatorcall
- Call to be rewritten- Returns:
- rewritten call
-
getLookupCall
public SqlCall getLookupCall()
-
getAllowedSignatures
public java.lang.String getAllowedSignatures(java.lang.String name)
Description copied from class:SqlOperator
Returns a string describing the expected operand types of a call, e.g. "SUBSTRING(VARCHAR, INTEGER, INTEGER)" where the name (SUBSTRING in this example) can be replaced by a specified name.- Overrides:
getAllowedSignatures
in classSqlOperator
-
deriveType
public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call)
Description copied from class:SqlOperator
Derives the type of a call to this operator.This method is an intrinsic part of the validation process so, unlike
SqlOperator.inferReturnType(org.apache.calcite.sql.SqlOperatorBinding)
, specific operators would not typically override this method.- Overrides:
deriveType
in classSqlFunction
- Parameters:
validator
- Validatorscope
- Scope of validationcall
- Call to this operator- Returns:
- Type of call
-
inferReturnType
public RelDataType inferReturnType(SqlOperatorBinding opBinding)
Description copied from class:SqlOperator
Infers the return type of an invocation of this operator; only called after the number and types of operands have already been validated. Subclasses must either override this method or supply an instance ofSqlReturnTypeInference
to the constructor.- Overrides:
inferReturnType
in classSqlOperator
- Parameters:
opBinding
- description of invocation (not necessarily aSqlCall
)- Returns:
- inferred return type
-
unparse
public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec)
Description copied from class:SqlOperator
Writes a SQL representation of a call to this operator to a writer, including parentheses if the operators on either side are of greater precedence.The default implementation of this method delegates to
SqlSyntax.unparse(org.apache.calcite.sql.SqlWriter, org.apache.calcite.sql.SqlOperator, org.apache.calcite.sql.SqlCall, int, int)
.- Overrides:
unparse
in classSqlFunction
-
getNumericFunctions
public static java.lang.String getNumericFunctions()
- See Also:
DatabaseMetaData.getNumericFunctions()
-
getStringFunctions
public static java.lang.String getStringFunctions()
- See Also:
DatabaseMetaData.getStringFunctions()
-
getTimeDateFunctions
public static java.lang.String getTimeDateFunctions()
- See Also:
DatabaseMetaData.getTimeDateFunctions()
-
getSystemFunctions
public static java.lang.String getSystemFunctions()
- See Also:
DatabaseMetaData.getSystemFunctions()
-
-