Skip to content

Commit

Permalink
[Feat](Nereids) add numeric functions (apache#40744)
Browse files Browse the repository at this point in the history
add fold constant on fe of numeric functions:
Coalesce, Round, Ceil, Floor, Exp, Ln, Log, Log10, Log2, Sqrt, Power,
Sin, Cos, Tan, Acos, Asin, Atan, Atan2, Sign, Bin, BitCount, BitLength,
Cbrt, Cosh, Tanh, Dexp, Dlog10, Dlog1, Dpow, Dsqrt, Fmod, Fpow, Radians,
Degrees, Xor, Pi, E, Conv, Truncate, CountEqual, Pmod.

---------

Co-authored-by: libinfeng <[email protected]>
  • Loading branch information
LiBinfeng-01 and LiBinfeng-01 authored Sep 30, 2024
1 parent b419278 commit 2926cdb
Show file tree
Hide file tree
Showing 14 changed files with 1,201 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ public String getStringValueInFe(FormatOptions options) {
String timeStr = getStringValue();
return timeStr.substring(1, timeStr.length() - 1);
} else {
if (Double.isInfinite(getValue())) {
return Double.toString(getValue());
}
return BigDecimal.valueOf(getValue()).toPlainString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
package org.apache.doris.nereids.trees.expressions;

import org.apache.doris.catalog.Env;
import org.apache.doris.nereids.exceptions.NotSupportedException;
import org.apache.doris.nereids.trees.expressions.functions.BoundFunction;
import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction;
import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeAcquire;
import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeArithmetic;
import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeExtractAndTransform;
import org.apache.doris.nereids.trees.expressions.functions.executable.ExecutableFunctions;
import org.apache.doris.nereids.trees.expressions.functions.executable.NumericArithmetic;
import org.apache.doris.nereids.trees.expressions.functions.executable.StringArithmetic;
import org.apache.doris.nereids.trees.expressions.functions.executable.TimeRoundSeries;
Expand Down Expand Up @@ -105,20 +105,24 @@ private Expression invoke(Expression expression, String fnName) {
Class<?> componentType = parameterType.getComponentType();
Object varArgs = Array.newInstance(componentType, inputSize - fixedArgsSize);
for (int i = fixedArgsSize; i < inputSize; i++) {
if (!(expression.children().get(i) instanceof NullLiteral)) {
Array.set(varArgs, i - fixedArgsSize, expression.children().get(i));
}
Array.set(varArgs, i - fixedArgsSize, expression.children().get(i));
}
Object[] objects = new Object[fixedArgsSize + 1];
for (int i = 0; i < fixedArgsSize; i++) {
objects[i] = expression.children().get(i);
}
objects[fixedArgsSize] = varArgs;

return (Literal) method.invoke(null, varArgs);
return (Literal) method.invoke(null, objects);
}
return (Literal) method.invoke(null, expression.children().toArray());
} catch (InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof NotSupportedException) {
throw new NotSupportedException(e.getTargetException().getMessage());
} else {
return expression;
}
} catch (IllegalAccessException | IllegalArgumentException e) {
return expression;
}
}
Expand Down Expand Up @@ -192,7 +196,6 @@ private void registerFunctions() {
List<Class<?>> classes = ImmutableList.of(
DateTimeAcquire.class,
DateTimeExtractAndTransform.class,
ExecutableFunctions.class,
DateLiteral.class,
DateTimeArithmetic.class,
NumericArithmetic.class,
Expand Down

This file was deleted.

Loading

0 comments on commit 2926cdb

Please sign in to comment.