I don't know what your want to do, could you make a clear explanation?
No function can accept table
as parameter, the parameters must have certain type, String, Int or others. So constants
and columns
can be used as parameters. If your meaning is the table name as a parameter, the sql should be as follows:
SELECT MYTEST22(a), MYTEST(a), MYTEST1(a), COUNT(*)
FROM alisis.table1
WHERE a=max_dt('alisis.table1')
GROUP BY MYTEST22(a),MYTEST(a),MYTEST1(a)
As I known, all functions Calcite (version is 1.11) supported are defined at SqlStdOperatorTable
. If you want to support other functions, you can implement a class that extends SqlStdOperatorTable
, for example:
public class TestOperatorTable extends SqlStdOperatorTable {
private static volatile TestOperatorTable instance;
public static TestOperatorTable instance() {
if (instance == null) {
synchronized(TestOperatorTable.class) {
if (instance == null) {
instance = new TestOperatorTable();
// Use reflection to register the expressions stored in public fields.
instance.init();
}
}
}
return instance;
}
/** Follow add your functions */
public static SqlFunction LTRIM = new SqlTrimFunction("LTRIM");
}
SqlTrimFunction
as follows:
public class SqlTrimFunction extends SqlFunction {
public SqlTrimFunction(String funcName) {
super(
funcName,
SqlKind.OTHER_FUNCTION,
ReturnTypes.VARCHAR_2000, // return type is String
InferTypes.FIRST_KNOWN,
OperandTypes.STRING, // parameter type is String
SqlFunctionCategory.STRING
);
}
}
When you create a SqlValidator, for example SqlValidatorImpl
, you should use TestOperatorTable
as its first parameter.