Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions x-pack/plugin/esql/qa/testFixtures/src/main/resources/math.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -266,38 +266,30 @@ d: double | s:double
;

log10ofNegative
row d = -1.0 | eval s = is_nan(log10(d));
row d = -1.0 | eval s = log10(d);
warning:Line 1:25: evaluation of [log10(d)] failed, treating result as null. Only first 20 failures recorded.
warning:java.lang.ArithmeticException: Log of non-positive number

d:double | s:boolean
-1.0 | true
;

log10ofNan
row d = 0.0/0.0 | eval s = is_nan(log10(d));

d:double | s:boolean
NaN | true
d:double | s:double
-1.0 | null
;

log10ofZero
row d = 0.0 |eval s = is_infinite(log10(d));
row d = 0.0 | eval s = log10(d);
warning:Line 1:24: evaluation of [log10(d)] failed, treating result as null. Only first 20 failures recorded.
warning:java.lang.ArithmeticException: Log of non-positive number

d:double | s:boolean
0.0 | true
d:double | s:double
0.0 | null
;

log10ofNegativeZero
row d = -0.0 |eval s = is_infinite(log10(d));

d:double | s:boolean
-0.0 | true
;
row d = -0.0 | eval s = log10(d);
warning:Line 1:25: evaluation of [log10(d)] failed, treating result as null. Only first 20 failures recorded.
warning:java.lang.ArithmeticException: Log of non-positive number

log10ofInfinite
row d = 1/0.0 | eval s = is_infinite(log10(d));

d:double | s:boolean
Infinity | true
d:double | s:double
-0.0 | null
;

log10ofLong
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@
// 2.0.
package org.elasticsearch.xpack.esql.expression.function.scalar.math;

import java.lang.ArithmeticException;
import java.lang.Override;
import java.lang.String;
import org.elasticsearch.compute.data.Block;
import org.elasticsearch.compute.data.DoubleBlock;
import org.elasticsearch.compute.data.DoubleVector;
import org.elasticsearch.compute.data.Page;
import org.elasticsearch.compute.operator.EvalOperator;
import org.elasticsearch.xpack.esql.expression.function.Warnings;
import org.elasticsearch.xpack.ql.tree.Source;

/**
* {@link EvalOperator.ExpressionEvaluator} implementation for {@link Log10}.
* This class is generated. Do not edit it.
*/
public final class Log10DoubleEvaluator implements EvalOperator.ExpressionEvaluator {
private final Warnings warnings;

private final EvalOperator.ExpressionEvaluator val;

public Log10DoubleEvaluator(EvalOperator.ExpressionEvaluator val) {
public Log10DoubleEvaluator(Source source, EvalOperator.ExpressionEvaluator val) {
this.warnings = new Warnings(source);
this.val = val;
}

Expand All @@ -34,7 +40,7 @@ public Block eval(Page page) {
if (valVector == null) {
return eval(page.getPositionCount(), valBlock);
}
return eval(page.getPositionCount(), valVector).asBlock();
return eval(page.getPositionCount(), valVector);
}

public DoubleBlock eval(int positionCount, DoubleBlock valBlock) {
Expand All @@ -44,15 +50,25 @@ public DoubleBlock eval(int positionCount, DoubleBlock valBlock) {
result.appendNull();
continue position;
}
result.appendDouble(Log10.process(valBlock.getDouble(valBlock.getFirstValueIndex(p))));
try {
result.appendDouble(Log10.process(valBlock.getDouble(valBlock.getFirstValueIndex(p))));
} catch (ArithmeticException e) {
warnings.registerException(e);
result.appendNull();
}
}
return result.build();
}

public DoubleVector eval(int positionCount, DoubleVector valVector) {
DoubleVector.Builder result = DoubleVector.newVectorBuilder(positionCount);
public DoubleBlock eval(int positionCount, DoubleVector valVector) {
DoubleBlock.Builder result = DoubleBlock.newBlockBuilder(positionCount);
position: for (int p = 0; p < positionCount; p++) {
result.appendDouble(Log10.process(valVector.getDouble(p)));
try {
result.appendDouble(Log10.process(valVector.getDouble(p)));
} catch (ArithmeticException e) {
warnings.registerException(e);
result.appendNull();
}
}
return result.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,29 @@
// 2.0.
package org.elasticsearch.xpack.esql.expression.function.scalar.math;

import java.lang.ArithmeticException;
import java.lang.Override;
import java.lang.String;
import org.elasticsearch.compute.data.Block;
import org.elasticsearch.compute.data.DoubleBlock;
import org.elasticsearch.compute.data.DoubleVector;
import org.elasticsearch.compute.data.IntBlock;
import org.elasticsearch.compute.data.IntVector;
import org.elasticsearch.compute.data.Page;
import org.elasticsearch.compute.operator.EvalOperator;
import org.elasticsearch.xpack.esql.expression.function.Warnings;
import org.elasticsearch.xpack.ql.tree.Source;

/**
* {@link EvalOperator.ExpressionEvaluator} implementation for {@link Log10}.
* This class is generated. Do not edit it.
*/
public final class Log10IntEvaluator implements EvalOperator.ExpressionEvaluator {
private final Warnings warnings;

private final EvalOperator.ExpressionEvaluator val;

public Log10IntEvaluator(EvalOperator.ExpressionEvaluator val) {
public Log10IntEvaluator(Source source, EvalOperator.ExpressionEvaluator val) {
this.warnings = new Warnings(source);
this.val = val;
}

Expand All @@ -36,7 +41,7 @@ public Block eval(Page page) {
if (valVector == null) {
return eval(page.getPositionCount(), valBlock);
}
return eval(page.getPositionCount(), valVector).asBlock();
return eval(page.getPositionCount(), valVector);
}

public DoubleBlock eval(int positionCount, IntBlock valBlock) {
Expand All @@ -46,15 +51,25 @@ public DoubleBlock eval(int positionCount, IntBlock valBlock) {
result.appendNull();
continue position;
}
result.appendDouble(Log10.process(valBlock.getInt(valBlock.getFirstValueIndex(p))));
try {
result.appendDouble(Log10.process(valBlock.getInt(valBlock.getFirstValueIndex(p))));
} catch (ArithmeticException e) {
warnings.registerException(e);
result.appendNull();
}
}
return result.build();
}

public DoubleVector eval(int positionCount, IntVector valVector) {
DoubleVector.Builder result = DoubleVector.newVectorBuilder(positionCount);
public DoubleBlock eval(int positionCount, IntVector valVector) {
DoubleBlock.Builder result = DoubleBlock.newBlockBuilder(positionCount);
position: for (int p = 0; p < positionCount; p++) {
result.appendDouble(Log10.process(valVector.getInt(p)));
try {
result.appendDouble(Log10.process(valVector.getInt(p)));
} catch (ArithmeticException e) {
warnings.registerException(e);
result.appendNull();
}
}
return result.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,29 @@
// 2.0.
package org.elasticsearch.xpack.esql.expression.function.scalar.math;

import java.lang.ArithmeticException;
import java.lang.Override;
import java.lang.String;
import org.elasticsearch.compute.data.Block;
import org.elasticsearch.compute.data.DoubleBlock;
import org.elasticsearch.compute.data.DoubleVector;
import org.elasticsearch.compute.data.LongBlock;
import org.elasticsearch.compute.data.LongVector;
import org.elasticsearch.compute.data.Page;
import org.elasticsearch.compute.operator.EvalOperator;
import org.elasticsearch.xpack.esql.expression.function.Warnings;
import org.elasticsearch.xpack.ql.tree.Source;

/**
* {@link EvalOperator.ExpressionEvaluator} implementation for {@link Log10}.
* This class is generated. Do not edit it.
*/
public final class Log10LongEvaluator implements EvalOperator.ExpressionEvaluator {
private final Warnings warnings;

private final EvalOperator.ExpressionEvaluator val;

public Log10LongEvaluator(EvalOperator.ExpressionEvaluator val) {
public Log10LongEvaluator(Source source, EvalOperator.ExpressionEvaluator val) {
this.warnings = new Warnings(source);
this.val = val;
}

Expand All @@ -36,7 +41,7 @@ public Block eval(Page page) {
if (valVector == null) {
return eval(page.getPositionCount(), valBlock);
}
return eval(page.getPositionCount(), valVector).asBlock();
return eval(page.getPositionCount(), valVector);
}

public DoubleBlock eval(int positionCount, LongBlock valBlock) {
Expand All @@ -46,15 +51,25 @@ public DoubleBlock eval(int positionCount, LongBlock valBlock) {
result.appendNull();
continue position;
}
result.appendDouble(Log10.process(valBlock.getLong(valBlock.getFirstValueIndex(p))));
try {
result.appendDouble(Log10.process(valBlock.getLong(valBlock.getFirstValueIndex(p))));
} catch (ArithmeticException e) {
warnings.registerException(e);
result.appendNull();
}
}
return result.build();
}

public DoubleVector eval(int positionCount, LongVector valVector) {
DoubleVector.Builder result = DoubleVector.newVectorBuilder(positionCount);
public DoubleBlock eval(int positionCount, LongVector valVector) {
DoubleBlock.Builder result = DoubleBlock.newBlockBuilder(positionCount);
position: for (int p = 0; p < positionCount; p++) {
result.appendDouble(Log10.process(valVector.getLong(p)));
try {
result.appendDouble(Log10.process(valVector.getLong(p)));
} catch (ArithmeticException e) {
warnings.registerException(e);
result.appendNull();
}
}
return result.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,29 @@
// 2.0.
package org.elasticsearch.xpack.esql.expression.function.scalar.math;

import java.lang.ArithmeticException;
import java.lang.Override;
import java.lang.String;
import org.elasticsearch.compute.data.Block;
import org.elasticsearch.compute.data.DoubleBlock;
import org.elasticsearch.compute.data.DoubleVector;
import org.elasticsearch.compute.data.LongBlock;
import org.elasticsearch.compute.data.LongVector;
import org.elasticsearch.compute.data.Page;
import org.elasticsearch.compute.operator.EvalOperator;
import org.elasticsearch.xpack.esql.expression.function.Warnings;
import org.elasticsearch.xpack.ql.tree.Source;

/**
* {@link EvalOperator.ExpressionEvaluator} implementation for {@link Log10}.
* This class is generated. Do not edit it.
*/
public final class Log10UnsignedLongEvaluator implements EvalOperator.ExpressionEvaluator {
private final Warnings warnings;

private final EvalOperator.ExpressionEvaluator val;

public Log10UnsignedLongEvaluator(EvalOperator.ExpressionEvaluator val) {
public Log10UnsignedLongEvaluator(Source source, EvalOperator.ExpressionEvaluator val) {
this.warnings = new Warnings(source);
this.val = val;
}

Expand All @@ -36,7 +41,7 @@ public Block eval(Page page) {
if (valVector == null) {
return eval(page.getPositionCount(), valBlock);
}
return eval(page.getPositionCount(), valVector).asBlock();
return eval(page.getPositionCount(), valVector);
}

public DoubleBlock eval(int positionCount, LongBlock valBlock) {
Expand All @@ -46,15 +51,25 @@ public DoubleBlock eval(int positionCount, LongBlock valBlock) {
result.appendNull();
continue position;
}
result.appendDouble(Log10.processUnsignedLong(valBlock.getLong(valBlock.getFirstValueIndex(p))));
try {
result.appendDouble(Log10.processUnsignedLong(valBlock.getLong(valBlock.getFirstValueIndex(p))));
} catch (ArithmeticException e) {
warnings.registerException(e);
result.appendNull();
}
}
return result.build();
}

public DoubleVector eval(int positionCount, LongVector valVector) {
DoubleVector.Builder result = DoubleVector.newVectorBuilder(positionCount);
public DoubleBlock eval(int positionCount, LongVector valVector) {
DoubleBlock.Builder result = DoubleBlock.newBlockBuilder(positionCount);
position: for (int p = 0; p < positionCount; p++) {
result.appendDouble(Log10.processUnsignedLong(valVector.getLong(p)));
try {
result.appendDouble(Log10.processUnsignedLong(valVector.getLong(p)));
} catch (ArithmeticException e) {
warnings.registerException(e);
result.appendNull();
}
}
return result.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,50 @@ public Supplier<EvalOperator.ExpressionEvaluator> toEvaluator(
var eval = field.get();

if (fieldType == DataTypes.DOUBLE) {
return () -> new Log10DoubleEvaluator(eval);
return () -> new Log10DoubleEvaluator(source(), eval);
}
if (fieldType == DataTypes.INTEGER) {
return () -> new Log10IntEvaluator(eval);
return () -> new Log10IntEvaluator(source(), eval);
}
if (fieldType == DataTypes.LONG) {
return () -> new Log10LongEvaluator(eval);
return () -> new Log10LongEvaluator(source(), eval);
}
if (fieldType == DataTypes.UNSIGNED_LONG) {
return () -> new Log10UnsignedLongEvaluator(eval);
return () -> new Log10UnsignedLongEvaluator(source(), eval);
}

throw EsqlIllegalArgumentException.illegalDataType(fieldType);
}

@Evaluator(extraName = "Double")
@Evaluator(extraName = "Double", warnExceptions = ArithmeticException.class)
static double process(double val) {
if (val <= 0d) {
throw new ArithmeticException("Log of non-positive number");
}
return Math.log10(val);
}

@Evaluator(extraName = "Long")
@Evaluator(extraName = "Long", warnExceptions = ArithmeticException.class)
static double process(long val) {
if (val <= 0L) {
throw new ArithmeticException("Log of non-positive number");
}
return Math.log10(val);
}

@Evaluator(extraName = "UnsignedLong")
@Evaluator(extraName = "UnsignedLong", warnExceptions = ArithmeticException.class)
static double processUnsignedLong(long val) {
if (val == NumericUtils.ZERO_AS_UNSIGNED_LONG) {
throw new ArithmeticException("Log of non-positive number");
}
return Math.log10(NumericUtils.unsignedLongToDouble(val));
}

@Evaluator(extraName = "Int")
@Evaluator(extraName = "Int", warnExceptions = ArithmeticException.class)
static double process(int val) {
if (val <= 0) {
throw new ArithmeticException("Log of non-positive number");
}
return Math.log10(val);
}

Expand Down
Loading