It turns out PostgreSQL supports LN(exp) and LOG(exp) in double precision, but not LOG(base, exp). So we're adding an explicit LOG10. I wonder how useful the two-argument one is... maybe we should delete it.
This commit is contained in:
@@ -68,7 +68,8 @@ public class Funs
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an expression that computes the natural logarithm of the supplied expression.
|
||||
* Creates an expression that computes the natural logarithm of the supplied expression,
|
||||
* which may be double-precision.
|
||||
*/
|
||||
public static Ln ln (SQLExpression exp)
|
||||
{
|
||||
@@ -76,16 +77,18 @@ public class Funs
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an expression that computes the base-10 logarithm of the supplied expression.
|
||||
* Creates an expression that computes the base-10 logarithm of the supplied expression,
|
||||
* which may be double-precision.
|
||||
*/
|
||||
public static LogN log10 (SQLExpression value)
|
||||
public static Log10 log10 (SQLExpression value)
|
||||
{
|
||||
return new LogN(Exps.value(10), value);
|
||||
return new Log10(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an expression that computes the logarithm of the supplied value expression
|
||||
* in the supplied base expression.
|
||||
* in the supplied base expression. Note: Under PostgreSQL, this must evaluate to a simple
|
||||
* numerical, not double precision.
|
||||
*/
|
||||
public static LogN logN (SQLExpression base, SQLExpression value)
|
||||
{
|
||||
|
||||
@@ -70,6 +70,15 @@ public abstract class NumericalFun
|
||||
}
|
||||
}
|
||||
|
||||
public static class Log10 extends OneArgFun {
|
||||
public Log10 (SQLExpression value) {
|
||||
super(value);
|
||||
}
|
||||
public Object accept (ExpressionVisitor<?> visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LogN extends TwoArgFun {
|
||||
public LogN (SQLExpression base, SQLExpression value) {
|
||||
super(base, value);
|
||||
|
||||
@@ -68,6 +68,7 @@ import com.samskivert.depot.function.NumericalFun.Ceil;
|
||||
import com.samskivert.depot.function.NumericalFun.Exp;
|
||||
import com.samskivert.depot.function.NumericalFun.Floor;
|
||||
import com.samskivert.depot.function.NumericalFun.Ln;
|
||||
import com.samskivert.depot.function.NumericalFun.Log10;
|
||||
import com.samskivert.depot.function.NumericalFun.LogN;
|
||||
import com.samskivert.depot.function.NumericalFun.Pi;
|
||||
import com.samskivert.depot.function.NumericalFun.Power;
|
||||
@@ -617,6 +618,11 @@ public abstract class BuildVisitor implements ExpressionVisitor<Void>
|
||||
return appendFunctionCall("ln", exp.getArg());
|
||||
}
|
||||
|
||||
public Void visit (Log10 exp)
|
||||
{
|
||||
return appendFunctionCall("log", exp.getArg());
|
||||
}
|
||||
|
||||
public Void visit (LogN exp)
|
||||
{
|
||||
return appendFunctionCall("log", exp.getBase(), exp.getValue());
|
||||
|
||||
@@ -51,6 +51,7 @@ import com.samskivert.depot.function.NumericalFun.Ceil;
|
||||
import com.samskivert.depot.function.NumericalFun.Exp;
|
||||
import com.samskivert.depot.function.NumericalFun.Floor;
|
||||
import com.samskivert.depot.function.NumericalFun.Ln;
|
||||
import com.samskivert.depot.function.NumericalFun.Log10;
|
||||
import com.samskivert.depot.function.NumericalFun.LogN;
|
||||
import com.samskivert.depot.function.NumericalFun.Pi;
|
||||
import com.samskivert.depot.function.NumericalFun.Power;
|
||||
@@ -123,6 +124,7 @@ public interface ExpressionVisitor<T>
|
||||
public T visit (Exp exp);
|
||||
public T visit (Floor exp);
|
||||
public T visit (Ln exp);
|
||||
public T visit (Log10 exp);
|
||||
public T visit (LogN exp);
|
||||
public T visit (Pi exp);
|
||||
public T visit (Power exp);
|
||||
|
||||
@@ -86,7 +86,8 @@ public class PostgreSQLBuilder
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public Void visit (DatePart exp) {
|
||||
@Override public Void visit (DatePart exp)
|
||||
{
|
||||
return appendFunctionCall(
|
||||
"date_part", Exps.value(translateDatePart(exp.getPart())), exp.getArg());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user