提交 79c12544 authored 作者: Thomas Mueller's avatar Thomas Mueller

Deterministic user defined functions did not work when the parameter was a column.

上级 03e1c25a
......@@ -48,11 +48,13 @@ public class JavaFunction extends Expression implements FunctionCall {
}
public Expression optimize(Session session) throws SQLException {
boolean allConst = isDeterministic();
for (int i = 0; i < args.length; i++) {
Expression e = args[i].optimize(session);
args[i] = e;
allConst &= e.isConstant();
}
if (isEverything(ExpressionVisitor.DETERMINISTIC)) {
if (allConst) {
return ValueExpression.get(getValue(session));
}
return this;
......
......@@ -79,6 +79,12 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals(0, rs.getInt(1));
stat.execute("drop alias getCount");
stat.execute("create alias reverse deterministic for \""+getClass().getName()+".reverse\"");
rs = stat.executeQuery("select reverse(x) from system_range(700, 700)");
rs.next();
assertEquals("007", rs.getString(1));
stat.execute("drop alias reverse");
conn.close();
}
......@@ -558,6 +564,16 @@ public class TestFunctions extends TestBase implements AggregateFunction {
count = newCount;
}
/**
* This method is called via reflection from the database.
*
* @param s the string
* @return the string, reversed
*/
public static String reverse(String s) {
return new StringBuffer(s).reverse().toString();
}
/**
* This method is called via reflection from the database.
*
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论