This is an automated email from the ASF dual-hosted git repository.
mayanks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
The following commit(s) were added to refs/heads/master by this push:
new d3a2a19 support abs,ceil,exp,floor,ln,log,sqrt math transform
function (#3934)
d3a2a19 is described below
commit d3a2a194ac740b81249ca75be2f073602c5607f7
Author: Xue Yu <[email protected]>
AuthorDate: Tue Jun 11 01:32:14 2019 +0800
support abs,ceil,exp,floor,ln,log,sqrt math transform function (#3934)
* abs,ceil,exp,floor,ln,log,sqrt transform function
* pass array to reduce func calls
* feedback addressed, remove ln,log10
* feedback address
* feedback address
---
.../function/SingleParamMathTransformFunction.java | 185 ++++++++++++
.../function/TransformFunctionFactory.java | 8 +
.../function/BaseTransformFunctionTest.java | 6 +-
.../SingleParamMathTransformFunctionTest.java | 330 +++++++++++++++++++++
4 files changed, 526 insertions(+), 3 deletions(-)
diff --git
a/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/SingleParamMathTransformFunction.java
b/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/SingleParamMathTransformFunction.java
new file mode 100644
index 0000000..5d4bafd
--- /dev/null
+++
b/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/SingleParamMathTransformFunction.java
@@ -0,0 +1,185 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.operator.transform.function;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Nonnull;
+
+import org.apache.pinot.common.data.FieldSpec.DataType;
+import org.apache.pinot.core.common.DataSource;
+import org.apache.pinot.core.operator.blocks.ProjectionBlock;
+import org.apache.pinot.core.operator.transform.TransformResultMetadata;
+import org.apache.pinot.core.plan.DocIdSetPlanNode;
+import org.apache.pinot.core.util.ArrayCopyUtils;
+
+/**
+ * A group of commonly used math transformation which has only one single
parameter,
+ * including abs, exp, ceil, floor, sqrt.
+ */
+public abstract class SingleParamMathTransformFunction extends
BaseTransformFunction {
+ private TransformFunction _transformFunction;
+ protected double[] _results;
+
+ @Override
+ public abstract String getName();
+
+ @Override
+ public void init(@Nonnull List<TransformFunction> arguments, @Nonnull
Map<String, DataSource> dataSourceMap) {
+ // Check that there are exactly 1 argument
+ if (arguments.size() != 1) {
+ throw new IllegalArgumentException("Exactly 1 arguments are required for
" + getName() + " transform function");
+ }
+
+ TransformFunction firstArgument = arguments.get(0);
+ if (firstArgument instanceof LiteralTransformFunction) {
+ throw new IllegalArgumentException("Argument of " + getName() + " should
not be literal");
+ } else {
+ if (!firstArgument.getResultMetadata().isSingleValue()) {
+ throw new IllegalArgumentException("First argument of " + getName() +
" transform function must be single-valued");
+ }
+ _transformFunction = firstArgument;
+ }
+ }
+
+ @Override
+ public TransformResultMetadata getResultMetadata() {
+ return DOUBLE_SV_NO_DICTIONARY_METADATA;
+ }
+
+ @Override
+ public double[] transformToDoubleValuesSV(@Nonnull ProjectionBlock
projectionBlock) {
+ if (_results == null) {
+ _results = new double[DocIdSetPlanNode.MAX_DOC_PER_CALL];
+ }
+
+ int length = projectionBlock.getNumDocs();
+
+ if (_transformFunction.getResultMetadata().getDataType() ==
DataType.STRING) {
+ String[] stringValues =
_transformFunction.transformToStringValuesSV(projectionBlock);
+ ArrayCopyUtils.copy(stringValues, _results, length);
+ applyMathOperator(_results, length);
+ } else {
+ double[] doubleValues =
_transformFunction.transformToDoubleValuesSV(projectionBlock);
+ applyMathOperator(doubleValues, length);
+ }
+
+ return _results;
+ }
+
+ abstract protected void applyMathOperator(double[] values, int length);
+
+ public static class AbsTransformFunction extends
SingleParamMathTransformFunction {
+ public static final String FUNCTION_NAME = "abs";
+
+ @Override
+ public String getName() {
+ return FUNCTION_NAME;
+ }
+
+ @Override
+ protected void applyMathOperator(double[] values, int length) {
+ for (int i = 0; i < length; i++) {
+ _results[i] = Math.abs(values[i]);
+ }
+ }
+ }
+
+ public static class CeilTransformFunction extends
SingleParamMathTransformFunction {
+ public static final String FUNCTION_NAME = "ceil";
+
+ @Override
+ public String getName() {
+ return FUNCTION_NAME;
+ }
+
+ @Override
+ protected void applyMathOperator(double[] values, int length) {
+ for (int i = 0; i < length; i++) {
+ _results[i] = Math.ceil(values[i]);
+ }
+ }
+ }
+
+ public static class ExpTransformFunction extends
SingleParamMathTransformFunction {
+ public static final String FUNCTION_NAME = "exp";
+
+ @Override
+ public String getName() {
+ return FUNCTION_NAME;
+ }
+
+ @Override
+ protected void applyMathOperator(double[] values, int length) {
+ for (int i = 0; i < length; i++) {
+ _results[i] = Math.exp(values[i]);
+ }
+ }
+ }
+
+ public static class FloorTransformFunction extends
SingleParamMathTransformFunction {
+ public static final String FUNCTION_NAME = "floor";
+
+ @Override
+ public String getName() {
+ return FUNCTION_NAME;
+ }
+
+ @Override
+ protected void applyMathOperator(double[] values, int length) {
+ for (int i = 0; i < length; i++) {
+ _results[i] = Math.floor(values[i]);
+ }
+ }
+ }
+
+ public static class LnTransformFunction extends
SingleParamMathTransformFunction {
+ public static final String FUNCTION_NAME = "ln";
+
+ @Override
+ public String getName() {
+ return FUNCTION_NAME;
+ }
+
+ @Override
+ protected void applyMathOperator(double[] values, int length) {
+ for (int i = 0; i < length; i++) {
+ _results[i] = Math.log(values[i]);
+ }
+ }
+ }
+
+ public static class SqrtTransformFunction extends
SingleParamMathTransformFunction {
+ public static final String FUNCTION_NAME = "sqrt";
+
+ @Override
+ public String getName() {
+ return FUNCTION_NAME;
+ }
+
+ @Override
+ protected void applyMathOperator(double[] values, int length) {
+ for (int i = 0; i < length; i++) {
+ _results[i] = Math.sqrt(values[i]);
+ }
+ }
+ }
+}
diff --git
a/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/TransformFunctionFactory.java
b/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/TransformFunctionFactory.java
index 1ba8938..c8c3808 100644
---
a/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/TransformFunctionFactory.java
+++
b/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/TransformFunctionFactory.java
@@ -26,6 +26,7 @@ import java.util.Set;
import javax.annotation.Nonnull;
import org.apache.pinot.common.request.transform.TransformExpressionTree;
import org.apache.pinot.core.common.DataSource;
+import
org.apache.pinot.core.operator.transform.function.SingleParamMathTransformFunction.*;
import org.apache.pinot.core.query.exception.BadQueryRequestException;
@@ -48,6 +49,13 @@ public class TransformFunctionFactory {
put(DateTimeConversionTransformFunction.FUNCTION_NAME.toLowerCase(),
DateTimeConversionTransformFunction.class);
put(ValueInTransformFunction.FUNCTION_NAME.toLowerCase(),
ValueInTransformFunction.class);
+
+ put(AbsTransformFunction.FUNCTION_NAME.toLowerCase(),
AbsTransformFunction.class);
+ put(CeilTransformFunction.FUNCTION_NAME.toLowerCase(),
CeilTransformFunction.class);
+ put(ExpTransformFunction.FUNCTION_NAME.toLowerCase(),
ExpTransformFunction.class);
+ put(FloorTransformFunction.FUNCTION_NAME.toLowerCase(),
FloorTransformFunction.class);
+ put(LnTransformFunction.FUNCTION_NAME.toLowerCase(),
LnTransformFunction.class);
+ put(SqrtTransformFunction.FUNCTION_NAME.toLowerCase(),
SqrtTransformFunction.class);
}
};
diff --git
a/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/BaseTransformFunctionTest.java
b/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/BaseTransformFunctionTest.java
index 70bf0dc..957177e 100644
---
a/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/BaseTransformFunctionTest.java
+++
b/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/BaseTransformFunctionTest.java
@@ -86,9 +86,9 @@ public abstract class BaseTransformFunctionTest {
for (int i = 0; i < NUM_ROWS; i++) {
_intSVValues[i] = RANDOM.nextInt();
_longSVValues[i] = RANDOM.nextLong();
- _floatSVValues[i] = RANDOM.nextFloat();
- _doubleSVValues[i] = RANDOM.nextDouble();
- _stringSVValues[i] = Double.toString(RANDOM.nextDouble());
+ _floatSVValues[i] = _intSVValues[i] * RANDOM.nextFloat();
+ _doubleSVValues[i] = _intSVValues[i] * RANDOM.nextDouble();
+ _stringSVValues[i] = Double.toString(_intSVValues[i] *
RANDOM.nextDouble());
int numValues = 1 + RANDOM.nextInt(MAX_NUM_MULTI_VALUES);
_intMVValues[i] = new int[numValues];
diff --git
a/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/SingleParamMathTransformFunctionTest.java
b/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/SingleParamMathTransformFunctionTest.java
new file mode 100644
index 0000000..0e68356
--- /dev/null
+++
b/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/SingleParamMathTransformFunctionTest.java
@@ -0,0 +1,330 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.operator.transform.function;
+
+import org.apache.pinot.common.request.transform.TransformExpressionTree;
+import
org.apache.pinot.core.operator.transform.function.SingleParamMathTransformFunction.*;
+import org.apache.pinot.core.query.exception.BadQueryRequestException;
+import org.testng.Assert;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+
+public class SingleParamMathTransformFunctionTest extends
BaseTransformFunctionTest {
+
+ @Test
+ public void testAbsTransformFunction() {
+ TransformExpressionTree expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("abs(%s)",
INT_SV_COLUMN));
+ TransformFunction transformFunction =
TransformFunctionFactory.get(expression, _dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof AbsTransformFunction);
+ Assert.assertEquals(transformFunction.getName(),
AbsTransformFunction.FUNCTION_NAME);
+ double[] expectedValues = new double[NUM_ROWS];
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.abs(_intSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("abs(%s)",
LONG_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof AbsTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.abs(_longSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("abs(%s)",
FLOAT_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof AbsTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.abs(_floatSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression = TransformExpressionTree
+ .compileToExpressionTree(String.format("abs(%s)", DOUBLE_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof AbsTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.abs(_doubleSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("abs(%s)",
STRING_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof AbsTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.abs(Double.parseDouble(_stringSVValues[i]));
+ }
+ testTransformFunction(transformFunction, expectedValues);
+ }
+
+ @Test
+ public void testCeilTransformFunction() {
+ TransformExpressionTree expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("ceil(%s)",
INT_SV_COLUMN));
+ TransformFunction transformFunction =
TransformFunctionFactory.get(expression, _dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof CeilTransformFunction);
+ Assert.assertEquals(transformFunction.getName(),
CeilTransformFunction.FUNCTION_NAME);
+ double[] expectedValues = new double[NUM_ROWS];
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.ceil(_intSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("ceil(%s)",
LONG_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof CeilTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.ceil(_longSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("ceil(%s)",
FLOAT_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof CeilTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.ceil(_floatSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression = TransformExpressionTree
+ .compileToExpressionTree(String.format("ceil(%s)", DOUBLE_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof CeilTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.ceil(_doubleSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("ceil(%s)",
STRING_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof CeilTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.ceil(Double.parseDouble(_stringSVValues[i]));
+ }
+ testTransformFunction(transformFunction, expectedValues);
+ }
+
+ @Test
+ public void testExpTransformFunction() {
+ TransformExpressionTree expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("exp(%s)",
INT_SV_COLUMN));
+ TransformFunction transformFunction =
TransformFunctionFactory.get(expression, _dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof ExpTransformFunction);
+ Assert.assertEquals(transformFunction.getName(),
ExpTransformFunction.FUNCTION_NAME);
+ double[] expectedValues = new double[NUM_ROWS];
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.exp(_intSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("exp(%s)",
LONG_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof ExpTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.exp(_longSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("exp(%s)",
FLOAT_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof ExpTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.exp(_floatSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression = TransformExpressionTree
+ .compileToExpressionTree(String.format("exp(%s)", DOUBLE_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof ExpTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.exp(_doubleSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("exp(%s)",
STRING_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof ExpTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.exp(Double.parseDouble(_stringSVValues[i]));
+ }
+ testTransformFunction(transformFunction, expectedValues);
+ }
+
+ @Test
+ public void testFloorTransformFunction() {
+ TransformExpressionTree expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("floor(%s)",
INT_SV_COLUMN));
+ TransformFunction transformFunction =
TransformFunctionFactory.get(expression, _dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof FloorTransformFunction);
+ Assert.assertEquals(transformFunction.getName(),
FloorTransformFunction.FUNCTION_NAME);
+ double[] expectedValues = new double[NUM_ROWS];
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.floor(_intSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("floor(%s)",
LONG_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof FloorTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.floor(_longSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("floor(%s)",
FLOAT_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof FloorTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.floor(_floatSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression = TransformExpressionTree
+ .compileToExpressionTree(String.format("floor(%s)", DOUBLE_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof FloorTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.floor(_doubleSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("floor(%s)",
STRING_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof FloorTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.floor(Double.parseDouble(_stringSVValues[i]));
+ }
+ testTransformFunction(transformFunction, expectedValues);
+ }
+
+ @Test
+ public void testLnTransformFunction() {
+ TransformExpressionTree expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("ln(%s)",
INT_SV_COLUMN));
+ TransformFunction transformFunction =
TransformFunctionFactory.get(expression, _dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof LnTransformFunction);
+ Assert.assertEquals(transformFunction.getName(),
LnTransformFunction.FUNCTION_NAME);
+ double[] expectedValues = new double[NUM_ROWS];
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.log(_intSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("ln(%s)",
LONG_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof LnTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.log(_longSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("ln(%s)",
FLOAT_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof LnTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.log(_floatSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression = TransformExpressionTree
+ .compileToExpressionTree(String.format("ln(%s)", DOUBLE_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof LnTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.log(_doubleSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("ln(%s)",
STRING_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof LnTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.log(Double.parseDouble(_stringSVValues[i]));
+ }
+ testTransformFunction(transformFunction, expectedValues);
+ }
+
+ @Test
+ public void testSqrtTransformFunction() {
+ TransformExpressionTree expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("sqrt(%s)",
INT_SV_COLUMN));
+ TransformFunction transformFunction =
TransformFunctionFactory.get(expression, _dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof SqrtTransformFunction);
+ Assert.assertEquals(transformFunction.getName(),
SqrtTransformFunction.FUNCTION_NAME);
+ double[] expectedValues = new double[NUM_ROWS];
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.sqrt(_intSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("sqrt(%s)",
LONG_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof SqrtTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.sqrt(_longSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("sqrt(%s)",
FLOAT_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof SqrtTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.sqrt(_floatSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression = TransformExpressionTree
+ .compileToExpressionTree(String.format("sqrt(%s)", DOUBLE_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof SqrtTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.sqrt(_doubleSVValues[i]);
+ }
+ testTransformFunction(transformFunction, expectedValues);
+
+ expression =
+
TransformExpressionTree.compileToExpressionTree(String.format("sqrt(%s)",
STRING_SV_COLUMN));
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof SqrtTransformFunction);
+ for (int i = 0; i < NUM_ROWS; i++) {
+ expectedValues[i] = Math.sqrt(Double.parseDouble(_stringSVValues[i]));
+ }
+ testTransformFunction(transformFunction, expectedValues);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]