From 0c4c26f31d25da48aad10681092571109e2e8616 Mon Sep 17 00:00:00 2001 From: tarushapptech Date: Sun, 18 Jun 2017 22:41:41 +0530 Subject: [PATCH 1/5] commiting changes for the functions ln, log10, exp --- .../sql/interpreter/BeamSqlFnExecutor.java | 12 ++++ .../operator/math/BeamSqlExpExpression.java | 58 ++++++++++++++++++ .../operator/math/BeamSqlLnExpression.java | 59 ++++++++++++++++++ .../operator/math/BeamSqlLogExpression.java | 58 ++++++++++++++++++ .../math/BeamSqlMathUnaryExpressionTest.java | 61 ++++++++++++++++++- 5 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlExpExpression.java create mode 100644 dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlLnExpression.java create mode 100644 dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlLogExpression.java diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/BeamSqlFnExecutor.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/BeamSqlFnExecutor.java index 091dbf7f5fbe..4e25f868a257 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/BeamSqlFnExecutor.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/BeamSqlFnExecutor.java @@ -54,6 +54,9 @@ import org.apache.beam.dsls.sql.interpreter.operator.logical.BeamSqlNotExpression; import org.apache.beam.dsls.sql.interpreter.operator.logical.BeamSqlOrExpression; import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlAbsExpression; +import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlExpExpression; +import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlLnExpression; +import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlLogExpression; import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlRoundExpression; import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlSqrtExpression; import org.apache.beam.dsls.sql.interpreter.operator.string.BeamSqlCharLengthExpression; @@ -230,6 +233,15 @@ static BeamSqlExpression buildExpression(RexNode rexNode) { case "ROUND": ret = new BeamSqlRoundExpression(subExps); break; + case "LN": + ret = new BeamSqlLnExpression(subExps); + break; + case "LOG10": + ret = new BeamSqlLogExpression(subExps); + break; + case "EXP": + ret = new BeamSqlExpExpression(subExps); + break; // string operators case "||": diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlExpExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlExpExpression.java new file mode 100644 index 000000000000..2675e35101d6 --- /dev/null +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlExpExpression.java @@ -0,0 +1,58 @@ +/* + * 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.beam.dsls.sql.interpreter.operator.math; + +import java.util.List; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; +import org.apache.calcite.runtime.SqlFunctions; +import org.apache.calcite.sql.type.SqlTypeName; + +/** + * {@code BeamSqlMathUnaryExpression} for 'EXP' function. + */ +public class BeamSqlExpExpression extends BeamSqlMathUnaryExpression { + + public BeamSqlExpExpression(List operands) { + super(operands); + } + + @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { + BeamSqlPrimitive result = null; + switch (op.getOutputType()) { + case TINYINT: + case SMALLINT: + case INTEGER: + case BIGINT: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.exp(SqlFunctions.toLong(op.getValue()))); + break; + case FLOAT: + case DOUBLE: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.exp(SqlFunctions.toDouble(op.getValue()))); + break; + case DECIMAL: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.exp(SqlFunctions.toBigDecimal(op.getValue()))); + break; + } + return result; + } +} diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlLnExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlLnExpression.java new file mode 100644 index 000000000000..57f3db86009b --- /dev/null +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlLnExpression.java @@ -0,0 +1,59 @@ +/* + * 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.beam.dsls.sql.interpreter.operator.math; + +import java.util.List; + +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; +import org.apache.calcite.runtime.SqlFunctions; +import org.apache.calcite.sql.type.SqlTypeName; + +/** + * {@code BeamSqlMathUnaryExpression} for 'LN' function. + */ +public class BeamSqlLnExpression extends BeamSqlMathUnaryExpression { + + public BeamSqlLnExpression(List operands) { + super(operands); + } + + @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { + BeamSqlPrimitive result = null; + switch (op.getOutputType()) { + case TINYINT: + case SMALLINT: + case INTEGER: + case BIGINT: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.ln(SqlFunctions.toLong(op.getValue()))); + break; + case FLOAT: + case DOUBLE: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.ln(SqlFunctions.toDouble(op.getValue()))); + break; + case DECIMAL: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.ln(SqlFunctions.toBigDecimal(op.getValue()))); + break; + } + return result; + } +} diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlLogExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlLogExpression.java new file mode 100644 index 000000000000..ff72a7b86f11 --- /dev/null +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlLogExpression.java @@ -0,0 +1,58 @@ +/* + * 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.beam.dsls.sql.interpreter.operator.math; + +import java.util.List; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; +import org.apache.calcite.runtime.SqlFunctions; +import org.apache.calcite.sql.type.SqlTypeName; + +/** + * {@code BeamSqlMathUnaryExpression} for 'Log10' function. + */ +public class BeamSqlLogExpression extends BeamSqlMathUnaryExpression { + + public BeamSqlLogExpression(List operands) { + super(operands); + } + + @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { + BeamSqlPrimitive result = null; + switch (op.getOutputType()) { + case TINYINT: + case SMALLINT: + case INTEGER: + case BIGINT: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.log10(SqlFunctions.toLong(op.getValue()))); + break; + case FLOAT: + case DOUBLE: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.log10(SqlFunctions.toDouble(op.getValue()))); + break; + case DECIMAL: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.log10(SqlFunctions.toBigDecimal(op.getValue()))); + break; + } + return result; + } +} diff --git a/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java b/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java index e3b0d18b7d77..281a7ad0ec78 100644 --- a/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java +++ b/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java @@ -18,8 +18,10 @@ package org.apache.beam.dsls.sql.interpreter.operator.math; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; + import org.apache.beam.dsls.sql.interpreter.BeamSqlFnExecutorTestBase; import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; @@ -27,7 +29,6 @@ import org.junit.Assert; import org.junit.Test; - /** * Test for {@link BeamSqlMathUnaryExpression}. */ @@ -67,4 +68,62 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { .assertEquals(28965734597L, new BeamSqlAbsExpression(operands).evaluate(record).getValue()); } + @Test public void testForLnExpression() { + List operands = new ArrayList<>(); + + // test for LN function with operand type smallint + operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); + Assert.assertEquals(0.6931471805599453, + new BeamSqlLnExpression(operands).evaluate(record).getValue()); + + // test for LN function with operand type double + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 2.4)); + Assert.assertEquals(0.8754687373538999, + new BeamSqlLnExpression(operands).evaluate(record).getValue()); + // test for LN function with operand type decimal + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(2.56))); + Assert.assertEquals(0.9400072584914712, + new BeamSqlLnExpression(operands).evaluate(record).getValue()); + } + + @Test public void testForLog10Expression() { + List operands = new ArrayList<>(); + + // test for log10 function with operand type smallint + operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); + Assert.assertEquals(0.3010299956639812, + new BeamSqlLogExpression(operands).evaluate(record).getValue()); + // test for log10 function with operand type double + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 2.4)); + Assert.assertEquals(0.38021124171160603, + new BeamSqlLogExpression(operands).evaluate(record).getValue()); + // test for log10 function with operand type decimal + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(2.56))); + Assert.assertEquals(0.4082399653118496, + new BeamSqlLogExpression(operands).evaluate(record).getValue()); + } + + @Test public void testForExpExpression() { + List operands = new ArrayList<>(); + + // test for exp function with operand type smallint + operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); + Assert.assertEquals(7.38905609893065, + new BeamSqlExpExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type double + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 2.4)); + Assert.assertEquals(11.023176380641601, + new BeamSqlExpExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type decimal + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(2.56))); + Assert.assertEquals(12.935817315543076, + new BeamSqlExpExpression(operands).evaluate(record).getValue()); + } + } From bd09604329f2f7be3f180982c6985234a1af8368 Mon Sep 17 00:00:00 2001 From: tarushapptech Date: Tue, 20 Jun 2017 14:39:35 +0530 Subject: [PATCH 2/5] commiting changes to corresponding jira ticket Beam-2480 --- .../sql/interpreter/BeamSqlFnExecutor.java | 36 ++++ .../operator/math/BeamSqlACosExpression.java | 58 ++++++ .../operator/math/BeamSqlASinExpression.java | 58 ++++++ .../operator/math/BeamSqlATanExpression.java | 58 ++++++ .../operator/math/BeamSqlCosExpression.java | 58 ++++++ .../operator/math/BeamSqlCotExpression.java | 58 ++++++ .../math/BeamSqlDegreesExpression.java | 58 ++++++ .../math/BeamSqlRadiansExpression.java | 58 ++++++ .../operator/math/BeamSqlSignExpression.java | 61 +++++++ .../operator/math/BeamSqlSinExpression.java | 58 ++++++ .../operator/math/BeamSqlTanExpression.java | 58 ++++++ .../math/BeamSqlMathUnaryExpressionTest.java | 170 ++++++++++++++++++ 12 files changed, 789 insertions(+) create mode 100644 dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlACosExpression.java create mode 100644 dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlASinExpression.java create mode 100644 dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlATanExpression.java create mode 100644 dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlCosExpression.java create mode 100644 dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlCotExpression.java create mode 100644 dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlDegreesExpression.java create mode 100644 dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlRadiansExpression.java create mode 100644 dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlSignExpression.java create mode 100644 dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlSinExpression.java create mode 100644 dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlTanExpression.java diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/BeamSqlFnExecutor.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/BeamSqlFnExecutor.java index 4e25f868a257..9498b1afa81b 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/BeamSqlFnExecutor.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/BeamSqlFnExecutor.java @@ -53,12 +53,21 @@ import org.apache.beam.dsls.sql.interpreter.operator.logical.BeamSqlAndExpression; import org.apache.beam.dsls.sql.interpreter.operator.logical.BeamSqlNotExpression; import org.apache.beam.dsls.sql.interpreter.operator.logical.BeamSqlOrExpression; +import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlACosExpression; +import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlASinExpression; +import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlATanExpression; import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlAbsExpression; +import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlCotExpression; +import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlDegreesExpression; import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlExpExpression; import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlLnExpression; import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlLogExpression; +import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlRadiansExpression; import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlRoundExpression; +import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlSignExpression; +import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlSinExpression; import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlSqrtExpression; +import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlTanExpression; import org.apache.beam.dsls.sql.interpreter.operator.string.BeamSqlCharLengthExpression; import org.apache.beam.dsls.sql.interpreter.operator.string.BeamSqlConcatExpression; import org.apache.beam.dsls.sql.interpreter.operator.string.BeamSqlInitCapExpression; @@ -242,6 +251,33 @@ static BeamSqlExpression buildExpression(RexNode rexNode) { case "EXP": ret = new BeamSqlExpExpression(subExps); break; + case "ACOS": + ret = new BeamSqlACosExpression(subExps); + break; + case "ASIN": + ret = new BeamSqlASinExpression(subExps); + break; + case "ATAN": + ret = new BeamSqlATanExpression(subExps); + break; + case "COT": + ret = new BeamSqlCotExpression(subExps); + break; + case "DEGREES": + ret = new BeamSqlDegreesExpression(subExps); + break; + case "RADIANS": + ret = new BeamSqlRadiansExpression(subExps); + break; + case "SIN": + ret = new BeamSqlSinExpression(subExps); + break; + case "TAN": + ret = new BeamSqlTanExpression(subExps); + break; + case "SIGN": + ret = new BeamSqlSignExpression(subExps); + break; // string operators case "||": diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlACosExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlACosExpression.java new file mode 100644 index 000000000000..4216642eccbf --- /dev/null +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlACosExpression.java @@ -0,0 +1,58 @@ +/* + * 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.beam.dsls.sql.interpreter.operator.math; + +import java.util.List; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; +import org.apache.calcite.runtime.SqlFunctions; +import org.apache.calcite.sql.type.SqlTypeName; + +/** + * {@code BeamSqlMathUnaryExpression} for 'ACOS' function. + */ +public class BeamSqlACosExpression extends BeamSqlMathUnaryExpression { + + public BeamSqlACosExpression(List operands) { + super(operands); + } + + @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { + BeamSqlPrimitive result = null; + switch (op.getOutputType()) { + case TINYINT: + case SMALLINT: + case INTEGER: + case BIGINT: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.acos(SqlFunctions.toLong(op.getValue()))); + break; + case FLOAT: + case DOUBLE: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.acos(SqlFunctions.toDouble(op.getValue()))); + break; + case DECIMAL: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.acos(SqlFunctions.toBigDecimal(op.getValue()))); + break; + } + return result; + } +} diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlASinExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlASinExpression.java new file mode 100644 index 000000000000..d0e61f37f10d --- /dev/null +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlASinExpression.java @@ -0,0 +1,58 @@ +/* + * 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.beam.dsls.sql.interpreter.operator.math; + +import java.util.List; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; +import org.apache.calcite.runtime.SqlFunctions; +import org.apache.calcite.sql.type.SqlTypeName; + +/** + * {@code BeamSqlMathUnaryExpression} for 'ASIN' function. + */ +public class BeamSqlASinExpression extends BeamSqlMathUnaryExpression { + + public BeamSqlASinExpression(List operands) { + super(operands); + } + + @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { + BeamSqlPrimitive result = null; + switch (op.getOutputType()) { + case TINYINT: + case SMALLINT: + case INTEGER: + case BIGINT: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.asin(SqlFunctions.toLong(op.getValue()))); + break; + case FLOAT: + case DOUBLE: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.asin(SqlFunctions.toDouble(op.getValue()))); + break; + case DECIMAL: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.asin(SqlFunctions.toBigDecimal(op.getValue()))); + break; + } + return result; + } +} diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlATanExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlATanExpression.java new file mode 100644 index 000000000000..be0024a055a2 --- /dev/null +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlATanExpression.java @@ -0,0 +1,58 @@ +/* + * 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.beam.dsls.sql.interpreter.operator.math; + +import java.util.List; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; +import org.apache.calcite.runtime.SqlFunctions; +import org.apache.calcite.sql.type.SqlTypeName; + +/** + * {@code BeamSqlMathUnaryExpression} for 'ATAN' function. + */ +public class BeamSqlATanExpression extends BeamSqlMathUnaryExpression { + + public BeamSqlATanExpression(List operands) { + super(operands); + } + + @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { + BeamSqlPrimitive result = null; + switch (op.getOutputType()) { + case TINYINT: + case SMALLINT: + case INTEGER: + case BIGINT: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.atan(SqlFunctions.toLong(op.getValue()))); + break; + case FLOAT: + case DOUBLE: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.atan(SqlFunctions.toDouble(op.getValue()))); + break; + case DECIMAL: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.atan(SqlFunctions.toBigDecimal(op.getValue()))); + break; + } + return result; + } +} diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlCosExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlCosExpression.java new file mode 100644 index 000000000000..d584d72a5f4f --- /dev/null +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlCosExpression.java @@ -0,0 +1,58 @@ +/* + * 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.beam.dsls.sql.interpreter.operator.math; + +import java.util.List; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; +import org.apache.calcite.runtime.SqlFunctions; +import org.apache.calcite.sql.type.SqlTypeName; + +/** + * {@code BeamSqlMathUnaryExpression} for 'COS' function. + */ +public class BeamSqlCosExpression extends BeamSqlMathUnaryExpression { + + public BeamSqlCosExpression(List operands) { + super(operands); + } + + @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { + BeamSqlPrimitive result = null; + switch (op.getOutputType()) { + case TINYINT: + case SMALLINT: + case INTEGER: + case BIGINT: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.cos(SqlFunctions.toLong(op.getValue()))); + break; + case FLOAT: + case DOUBLE: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.cos(SqlFunctions.toDouble(op.getValue()))); + break; + case DECIMAL: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.cos(SqlFunctions.toBigDecimal(op.getValue()))); + break; + } + return result; + } +} diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlCotExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlCotExpression.java new file mode 100644 index 000000000000..0b970258ac04 --- /dev/null +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlCotExpression.java @@ -0,0 +1,58 @@ +/* + * 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.beam.dsls.sql.interpreter.operator.math; + +import java.util.List; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; +import org.apache.calcite.runtime.SqlFunctions; +import org.apache.calcite.sql.type.SqlTypeName; + +/** + * {@code BeamSqlMathUnaryExpression} for 'COT' function. + */ +public class BeamSqlCotExpression extends BeamSqlMathUnaryExpression { + + public BeamSqlCotExpression(List operands) { + super(operands); + } + + @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { + BeamSqlPrimitive result = null; + switch (op.getOutputType()) { + case TINYINT: + case SMALLINT: + case INTEGER: + case BIGINT: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.cot(SqlFunctions.toLong(op.getValue()))); + break; + case FLOAT: + case DOUBLE: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.cot(SqlFunctions.toDouble(op.getValue()))); + break; + case DECIMAL: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.cot(SqlFunctions.toBigDecimal(op.getValue()))); + break; + } + return result; + } +} diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlDegreesExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlDegreesExpression.java new file mode 100644 index 000000000000..6b8351c8416a --- /dev/null +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlDegreesExpression.java @@ -0,0 +1,58 @@ +/* + * 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.beam.dsls.sql.interpreter.operator.math; + +import java.util.List; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; +import org.apache.calcite.runtime.SqlFunctions; +import org.apache.calcite.sql.type.SqlTypeName; + +/** + * {@code BeamSqlMathUnaryExpression} for 'DEGREES' function. + */ +public class BeamSqlDegreesExpression extends BeamSqlMathUnaryExpression { + + public BeamSqlDegreesExpression(List operands) { + super(operands); + } + + @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { + BeamSqlPrimitive result = null; + switch (op.getOutputType()) { + case TINYINT: + case SMALLINT: + case INTEGER: + case BIGINT: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.degrees(SqlFunctions.toLong(op.getValue()))); + break; + case FLOAT: + case DOUBLE: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.degrees(SqlFunctions.toDouble(op.getValue()))); + break; + case DECIMAL: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.degrees(SqlFunctions.toBigDecimal(op.getValue()))); + break; + } + return result; + } +} diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlRadiansExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlRadiansExpression.java new file mode 100644 index 000000000000..df80f202fd1a --- /dev/null +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlRadiansExpression.java @@ -0,0 +1,58 @@ +/* + * 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.beam.dsls.sql.interpreter.operator.math; + +import java.util.List; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; +import org.apache.calcite.runtime.SqlFunctions; +import org.apache.calcite.sql.type.SqlTypeName; + +/** + * {@code BeamSqlMathUnaryExpression} for 'RADIANS' function. + */ +public class BeamSqlRadiansExpression extends BeamSqlMathUnaryExpression { + + public BeamSqlRadiansExpression(List operands) { + super(operands); + } + + @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { + BeamSqlPrimitive result = null; + switch (op.getOutputType()) { + case TINYINT: + case SMALLINT: + case INTEGER: + case BIGINT: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.radians(SqlFunctions.toLong(op.getValue()))); + break; + case FLOAT: + case DOUBLE: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.radians(SqlFunctions.toDouble(op.getValue()))); + break; + case DECIMAL: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.radians(SqlFunctions.toBigDecimal(op.getValue()))); + break; + } + return result; + } +} diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlSignExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlSignExpression.java new file mode 100644 index 000000000000..3ca42e603bc0 --- /dev/null +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlSignExpression.java @@ -0,0 +1,61 @@ +/* + * 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.beam.dsls.sql.interpreter.operator.math; + +import java.util.List; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; +import org.apache.calcite.runtime.SqlFunctions; +import org.apache.calcite.sql.type.SqlTypeName; + +/** + * {@code BeamSqlMathUnaryExpression} for 'SIGN' function. + */ +public class BeamSqlSignExpression extends BeamSqlMathUnaryExpression { + + public BeamSqlSignExpression(List operands) { + super(operands); + } + + @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { + BeamSqlPrimitive result = null; + switch (op.getOutputType()) { + case TINYINT: + case SMALLINT: + case INTEGER: + result = BeamSqlPrimitive + .of(SqlTypeName.INTEGER, SqlFunctions.sign(SqlFunctions.toInt(op.getValue()))); + break; + case BIGINT: + result = BeamSqlPrimitive + .of(SqlTypeName.BIGINT, SqlFunctions.sign(SqlFunctions.toLong(op.getValue()))); + break; + case FLOAT: + case DOUBLE: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.sign(SqlFunctions.toDouble(op.getValue()))); + break; + case DECIMAL: + result = BeamSqlPrimitive + .of(SqlTypeName.DECIMAL, SqlFunctions.sign(SqlFunctions.toBigDecimal(op.getValue()))); + break; + } + return result; + } +} diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlSinExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlSinExpression.java new file mode 100644 index 000000000000..db82591c2ca5 --- /dev/null +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlSinExpression.java @@ -0,0 +1,58 @@ +/* + * 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.beam.dsls.sql.interpreter.operator.math; + +import java.util.List; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; +import org.apache.calcite.runtime.SqlFunctions; +import org.apache.calcite.sql.type.SqlTypeName; + +/** + * {@code BeamSqlMathUnaryExpression} for 'SIN' function. + */ +public class BeamSqlSinExpression extends BeamSqlMathUnaryExpression { + + public BeamSqlSinExpression(List operands) { + super(operands); + } + + @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { + BeamSqlPrimitive result = null; + switch (op.getOutputType()) { + case TINYINT: + case SMALLINT: + case INTEGER: + case BIGINT: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.sin(SqlFunctions.toLong(op.getValue()))); + break; + case FLOAT: + case DOUBLE: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.sin(SqlFunctions.toDouble(op.getValue()))); + break; + case DECIMAL: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.sin(SqlFunctions.toBigDecimal(op.getValue()))); + break; + } + return result; + } +} diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlTanExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlTanExpression.java new file mode 100644 index 000000000000..1e39d20c8099 --- /dev/null +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlTanExpression.java @@ -0,0 +1,58 @@ +/* + * 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.beam.dsls.sql.interpreter.operator.math; + +import java.util.List; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; +import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; +import org.apache.calcite.runtime.SqlFunctions; +import org.apache.calcite.sql.type.SqlTypeName; + +/** + * {@code BeamSqlMathUnaryExpression} for 'TAN' function. + */ +public class BeamSqlTanExpression extends BeamSqlMathUnaryExpression { + + public BeamSqlTanExpression(List operands) { + super(operands); + } + + @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { + BeamSqlPrimitive result = null; + switch (op.getOutputType()) { + case TINYINT: + case SMALLINT: + case INTEGER: + case BIGINT: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.tan(SqlFunctions.toLong(op.getValue()))); + break; + case FLOAT: + case DOUBLE: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.tan(SqlFunctions.toDouble(op.getValue()))); + break; + case DECIMAL: + result = BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.tan(SqlFunctions.toBigDecimal(op.getValue()))); + break; + } + return result; + } +} diff --git a/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java b/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java index 281a7ad0ec78..a0338cbb185a 100644 --- a/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java +++ b/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java @@ -126,4 +126,174 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { new BeamSqlExpExpression(operands).evaluate(record).getValue()); } + @Test public void testForACosExpression() { + List operands = new ArrayList<>(); + + // test for exp function with operand type smallint + operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); + Assert.assertEquals(Double.NaN, + new BeamSqlACosExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type double + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 0.45)); + Assert.assertEquals(1.1040309877476002, + new BeamSqlACosExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type decimal + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(-0.367))); + Assert.assertEquals(1.9465782472653976, + new BeamSqlACosExpression(operands).evaluate(record).getValue()); + } + + @Test public void testForASinExpression() { + List operands = new ArrayList<>(); + + // test for exp function with operand type double + operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 0.45)); + Assert.assertEquals(0.4667653390472964, + new BeamSqlASinExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type decimal + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(-0.367))); + Assert.assertEquals(-0.3757819204705009, + new BeamSqlASinExpression(operands).evaluate(record).getValue()); + } + + @Test public void testForATanExpression() { + List operands = new ArrayList<>(); + + // test for exp function with operand type double + operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 0.45)); + Assert.assertEquals(0.4228539261329407, + new BeamSqlATanExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type decimal + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(-0.367))); + Assert.assertEquals(-0.3517385919208851, + new BeamSqlATanExpression(operands).evaluate(record).getValue()); + } + + @Test public void testForCosExpression() { + List operands = new ArrayList<>(); + + // test for exp function with operand type double + operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 0.45)); + Assert.assertEquals(0.9004471023526769, + new BeamSqlCosExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type decimal + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(-0.367))); + Assert.assertEquals(0.933407994804752, + new BeamSqlCosExpression(operands).evaluate(record).getValue()); + } + + @Test public void testForCotExpression() { + List operands = new ArrayList<>(); + + // test for exp function with operand type double + operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, .45)); + Assert.assertEquals(2.0701573613012125, + new BeamSqlCotExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type decimal + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(-.367))); + Assert.assertEquals(-2.601349560400992, + new BeamSqlCotExpression(operands).evaluate(record).getValue()); + } + + @Test public void testForDegreesExpression() { + List operands = new ArrayList<>(); + + // test for exp function with operand type smallint + operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); + Assert.assertEquals(114.59155902616465, + new BeamSqlDegreesExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type double + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 2.4)); + Assert.assertEquals(137.50987083139756, + new BeamSqlDegreesExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type decimal + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(2.56))); + Assert.assertEquals(146.67719555349075, + new BeamSqlDegreesExpression(operands).evaluate(record).getValue()); + } + + @Test public void testForRadiansExpression() { + List operands = new ArrayList<>(); + + // test for exp function with operand type smallint + operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); + Assert.assertEquals(0.03490658503988659, + new BeamSqlRadiansExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type double + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 2.4)); + Assert.assertEquals(0.041887902047863905, + new BeamSqlRadiansExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type decimal + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(2.56))); + Assert.assertEquals(0.04468042885105484, + new BeamSqlRadiansExpression(operands).evaluate(record).getValue()); + } + + @Test public void testForSinExpression() { + List operands = new ArrayList<>(); + + // test for exp function with operand type smallint + operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); + Assert.assertEquals(0.9092974268256817, + new BeamSqlSinExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type double + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 2.4)); + Assert.assertEquals(0.675463180551151, + new BeamSqlSinExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type decimal + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(2.56))); + Assert.assertEquals(0.5493554364271266, + new BeamSqlSinExpression(operands).evaluate(record).getValue()); + } + + @Test public void testForTanExpression() { + List operands = new ArrayList<>(); + + // test for exp function with operand type smallint + operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); + Assert.assertEquals(-2.185039863261519, + new BeamSqlTanExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type double + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 2.4)); + Assert.assertEquals(-0.9160142896734107, + new BeamSqlTanExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type decimal + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(2.56))); + Assert.assertEquals(-0.6574471216727855, + new BeamSqlTanExpression(operands).evaluate(record).getValue()); + } + + @Test public void testForSignExpression() { + List operands = new ArrayList<>(); + + // test for exp function with operand type smallint + operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); + Assert.assertEquals(1, + new BeamSqlSignExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type double + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 2.4)); + Assert.assertEquals(1.0, + new BeamSqlSignExpression(operands).evaluate(record).getValue()); + // test for exp function with operand type decimal + operands.clear(); + operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(2.56))); + Assert.assertEquals(BigDecimal.ONE, + new BeamSqlSignExpression(operands).evaluate(record).getValue()); + } + } From 53f430229f32637f94ccf3018636465d54f3d7fb Mon Sep 17 00:00:00 2001 From: tarushapptech Date: Wed, 21 Jun 2017 19:49:26 +0530 Subject: [PATCH 3/5] commiting changes for review comments --- .../operator/math/BeamSqlACosExpression.java | 23 +----- .../operator/math/BeamSqlASinExpression.java | 23 +----- .../operator/math/BeamSqlATanExpression.java | 23 +----- .../operator/math/BeamSqlCosExpression.java | 23 +----- .../operator/math/BeamSqlCotExpression.java | 23 +----- .../math/BeamSqlDegreesExpression.java | 23 +----- .../operator/math/BeamSqlExpExpression.java | 23 +----- .../operator/math/BeamSqlLnExpression.java | 22 +---- .../operator/math/BeamSqlLogExpression.java | 23 +----- .../math/BeamSqlRadiansExpression.java | 23 +----- .../operator/math/BeamSqlSinExpression.java | 23 +----- .../operator/math/BeamSqlTanExpression.java | 23 +----- .../math/BeamSqlMathUnaryExpressionTest.java | 81 +++++++++---------- 13 files changed, 74 insertions(+), 282 deletions(-) diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlACosExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlACosExpression.java index 4216642eccbf..8cb891b32ef9 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlACosExpression.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlACosExpression.java @@ -19,6 +19,7 @@ package org.apache.beam.dsls.sql.interpreter.operator.math; import java.util.List; + import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; import org.apache.calcite.runtime.SqlFunctions; @@ -34,25 +35,7 @@ public BeamSqlACosExpression(List operands) { } @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { - BeamSqlPrimitive result = null; - switch (op.getOutputType()) { - case TINYINT: - case SMALLINT: - case INTEGER: - case BIGINT: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.acos(SqlFunctions.toLong(op.getValue()))); - break; - case FLOAT: - case DOUBLE: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.acos(SqlFunctions.toDouble(op.getValue()))); - break; - case DECIMAL: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.acos(SqlFunctions.toBigDecimal(op.getValue()))); - break; - } - return result; + return BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.acos(SqlFunctions.toDouble(op.getValue()))); } } diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlASinExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlASinExpression.java index d0e61f37f10d..19d0cbd3363c 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlASinExpression.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlASinExpression.java @@ -19,6 +19,7 @@ package org.apache.beam.dsls.sql.interpreter.operator.math; import java.util.List; + import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; import org.apache.calcite.runtime.SqlFunctions; @@ -34,25 +35,7 @@ public BeamSqlASinExpression(List operands) { } @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { - BeamSqlPrimitive result = null; - switch (op.getOutputType()) { - case TINYINT: - case SMALLINT: - case INTEGER: - case BIGINT: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.asin(SqlFunctions.toLong(op.getValue()))); - break; - case FLOAT: - case DOUBLE: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.asin(SqlFunctions.toDouble(op.getValue()))); - break; - case DECIMAL: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.asin(SqlFunctions.toBigDecimal(op.getValue()))); - break; - } - return result; + return BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.asin(SqlFunctions.toDouble(op.getValue()))); } } diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlATanExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlATanExpression.java index be0024a055a2..a17954848df6 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlATanExpression.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlATanExpression.java @@ -19,6 +19,7 @@ package org.apache.beam.dsls.sql.interpreter.operator.math; import java.util.List; + import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; import org.apache.calcite.runtime.SqlFunctions; @@ -34,25 +35,7 @@ public BeamSqlATanExpression(List operands) { } @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { - BeamSqlPrimitive result = null; - switch (op.getOutputType()) { - case TINYINT: - case SMALLINT: - case INTEGER: - case BIGINT: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.atan(SqlFunctions.toLong(op.getValue()))); - break; - case FLOAT: - case DOUBLE: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.atan(SqlFunctions.toDouble(op.getValue()))); - break; - case DECIMAL: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.atan(SqlFunctions.toBigDecimal(op.getValue()))); - break; - } - return result; + return BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.atan(SqlFunctions.toDouble(op.getValue()))); } } diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlCosExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlCosExpression.java index d584d72a5f4f..2e1334bf3c63 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlCosExpression.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlCosExpression.java @@ -19,6 +19,7 @@ package org.apache.beam.dsls.sql.interpreter.operator.math; import java.util.List; + import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; import org.apache.calcite.runtime.SqlFunctions; @@ -34,25 +35,7 @@ public BeamSqlCosExpression(List operands) { } @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { - BeamSqlPrimitive result = null; - switch (op.getOutputType()) { - case TINYINT: - case SMALLINT: - case INTEGER: - case BIGINT: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.cos(SqlFunctions.toLong(op.getValue()))); - break; - case FLOAT: - case DOUBLE: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.cos(SqlFunctions.toDouble(op.getValue()))); - break; - case DECIMAL: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.cos(SqlFunctions.toBigDecimal(op.getValue()))); - break; - } - return result; + return BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.cos(SqlFunctions.toDouble(op.getValue()))); } } diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlCotExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlCotExpression.java index 0b970258ac04..8fd83ed5d199 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlCotExpression.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlCotExpression.java @@ -19,6 +19,7 @@ package org.apache.beam.dsls.sql.interpreter.operator.math; import java.util.List; + import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; import org.apache.calcite.runtime.SqlFunctions; @@ -34,25 +35,7 @@ public BeamSqlCotExpression(List operands) { } @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { - BeamSqlPrimitive result = null; - switch (op.getOutputType()) { - case TINYINT: - case SMALLINT: - case INTEGER: - case BIGINT: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.cot(SqlFunctions.toLong(op.getValue()))); - break; - case FLOAT: - case DOUBLE: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.cot(SqlFunctions.toDouble(op.getValue()))); - break; - case DECIMAL: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.cot(SqlFunctions.toBigDecimal(op.getValue()))); - break; - } - return result; + return BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.cot(SqlFunctions.toDouble(op.getValue()))); } } diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlDegreesExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlDegreesExpression.java index 6b8351c8416a..2cbaf3515772 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlDegreesExpression.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlDegreesExpression.java @@ -19,6 +19,7 @@ package org.apache.beam.dsls.sql.interpreter.operator.math; import java.util.List; + import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; import org.apache.calcite.runtime.SqlFunctions; @@ -34,25 +35,7 @@ public BeamSqlDegreesExpression(List operands) { } @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { - BeamSqlPrimitive result = null; - switch (op.getOutputType()) { - case TINYINT: - case SMALLINT: - case INTEGER: - case BIGINT: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.degrees(SqlFunctions.toLong(op.getValue()))); - break; - case FLOAT: - case DOUBLE: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.degrees(SqlFunctions.toDouble(op.getValue()))); - break; - case DECIMAL: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.degrees(SqlFunctions.toBigDecimal(op.getValue()))); - break; - } - return result; + return BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.degrees(SqlFunctions.toDouble(op.getValue()))); } } diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlExpExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlExpExpression.java index 2675e35101d6..d2b349737800 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlExpExpression.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlExpExpression.java @@ -19,6 +19,7 @@ package org.apache.beam.dsls.sql.interpreter.operator.math; import java.util.List; + import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; import org.apache.calcite.runtime.SqlFunctions; @@ -34,25 +35,7 @@ public BeamSqlExpExpression(List operands) { } @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { - BeamSqlPrimitive result = null; - switch (op.getOutputType()) { - case TINYINT: - case SMALLINT: - case INTEGER: - case BIGINT: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.exp(SqlFunctions.toLong(op.getValue()))); - break; - case FLOAT: - case DOUBLE: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.exp(SqlFunctions.toDouble(op.getValue()))); - break; - case DECIMAL: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.exp(SqlFunctions.toBigDecimal(op.getValue()))); - break; - } - return result; + return BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.exp(SqlFunctions.toDouble(op.getValue()))); } } diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlLnExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlLnExpression.java index 57f3db86009b..a30d1ca6d1b7 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlLnExpression.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlLnExpression.java @@ -35,25 +35,7 @@ public BeamSqlLnExpression(List operands) { } @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { - BeamSqlPrimitive result = null; - switch (op.getOutputType()) { - case TINYINT: - case SMALLINT: - case INTEGER: - case BIGINT: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.ln(SqlFunctions.toLong(op.getValue()))); - break; - case FLOAT: - case DOUBLE: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.ln(SqlFunctions.toDouble(op.getValue()))); - break; - case DECIMAL: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.ln(SqlFunctions.toBigDecimal(op.getValue()))); - break; - } - return result; + return BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.ln(SqlFunctions.toDouble(op.getValue()))); } } diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlLogExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlLogExpression.java index ff72a7b86f11..c83f81621bd6 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlLogExpression.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlLogExpression.java @@ -19,6 +19,7 @@ package org.apache.beam.dsls.sql.interpreter.operator.math; import java.util.List; + import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; import org.apache.calcite.runtime.SqlFunctions; @@ -34,25 +35,7 @@ public BeamSqlLogExpression(List operands) { } @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { - BeamSqlPrimitive result = null; - switch (op.getOutputType()) { - case TINYINT: - case SMALLINT: - case INTEGER: - case BIGINT: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.log10(SqlFunctions.toLong(op.getValue()))); - break; - case FLOAT: - case DOUBLE: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.log10(SqlFunctions.toDouble(op.getValue()))); - break; - case DECIMAL: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.log10(SqlFunctions.toBigDecimal(op.getValue()))); - break; - } - return result; + return BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.log10(SqlFunctions.toDouble(op.getValue()))); } } diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlRadiansExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlRadiansExpression.java index df80f202fd1a..1ec80996e584 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlRadiansExpression.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlRadiansExpression.java @@ -19,6 +19,7 @@ package org.apache.beam.dsls.sql.interpreter.operator.math; import java.util.List; + import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; import org.apache.calcite.runtime.SqlFunctions; @@ -34,25 +35,7 @@ public BeamSqlRadiansExpression(List operands) { } @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { - BeamSqlPrimitive result = null; - switch (op.getOutputType()) { - case TINYINT: - case SMALLINT: - case INTEGER: - case BIGINT: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.radians(SqlFunctions.toLong(op.getValue()))); - break; - case FLOAT: - case DOUBLE: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.radians(SqlFunctions.toDouble(op.getValue()))); - break; - case DECIMAL: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.radians(SqlFunctions.toBigDecimal(op.getValue()))); - break; - } - return result; + return BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.radians(SqlFunctions.toDouble(op.getValue()))); } } diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlSinExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlSinExpression.java index db82591c2ca5..a7efd6913a2e 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlSinExpression.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlSinExpression.java @@ -19,6 +19,7 @@ package org.apache.beam.dsls.sql.interpreter.operator.math; import java.util.List; + import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; import org.apache.calcite.runtime.SqlFunctions; @@ -34,25 +35,7 @@ public BeamSqlSinExpression(List operands) { } @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { - BeamSqlPrimitive result = null; - switch (op.getOutputType()) { - case TINYINT: - case SMALLINT: - case INTEGER: - case BIGINT: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.sin(SqlFunctions.toLong(op.getValue()))); - break; - case FLOAT: - case DOUBLE: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.sin(SqlFunctions.toDouble(op.getValue()))); - break; - case DECIMAL: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.sin(SqlFunctions.toBigDecimal(op.getValue()))); - break; - } - return result; + return BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.sin(SqlFunctions.toDouble(op.getValue()))); } } diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlTanExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlTanExpression.java index 1e39d20c8099..4d4340875816 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlTanExpression.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlTanExpression.java @@ -19,6 +19,7 @@ package org.apache.beam.dsls.sql.interpreter.operator.math; import java.util.List; + import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlExpression; import org.apache.beam.dsls.sql.interpreter.operator.BeamSqlPrimitive; import org.apache.calcite.runtime.SqlFunctions; @@ -34,25 +35,7 @@ public BeamSqlTanExpression(List operands) { } @Override public BeamSqlPrimitive calculate(BeamSqlPrimitive op) { - BeamSqlPrimitive result = null; - switch (op.getOutputType()) { - case TINYINT: - case SMALLINT: - case INTEGER: - case BIGINT: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.tan(SqlFunctions.toLong(op.getValue()))); - break; - case FLOAT: - case DOUBLE: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.tan(SqlFunctions.toDouble(op.getValue()))); - break; - case DECIMAL: - result = BeamSqlPrimitive - .of(SqlTypeName.DOUBLE, SqlFunctions.tan(SqlFunctions.toBigDecimal(op.getValue()))); - break; - } - return result; + return BeamSqlPrimitive + .of(SqlTypeName.DOUBLE, SqlFunctions.tan(SqlFunctions.toDouble(op.getValue()))); } } diff --git a/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java b/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java index a0338cbb185a..52bfb10a75a3 100644 --- a/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java +++ b/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java @@ -73,18 +73,17 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { // test for LN function with operand type smallint operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); - Assert.assertEquals(0.6931471805599453, - new BeamSqlLnExpression(operands).evaluate(record).getValue()); + Assert.assertEquals(Math.log(2), new BeamSqlLnExpression(operands).evaluate(record).getValue()); // test for LN function with operand type double operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 2.4)); - Assert.assertEquals(0.8754687373538999, - new BeamSqlLnExpression(operands).evaluate(record).getValue()); + Assert + .assertEquals(Math.log(2.4), new BeamSqlLnExpression(operands).evaluate(record).getValue()); // test for LN function with operand type decimal operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(2.56))); - Assert.assertEquals(0.9400072584914712, + Assert.assertEquals(Math.log(2.56), new BeamSqlLnExpression(operands).evaluate(record).getValue()); } @@ -93,17 +92,17 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { // test for log10 function with operand type smallint operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); - Assert.assertEquals(0.3010299956639812, + Assert.assertEquals(Math.log10(2), new BeamSqlLogExpression(operands).evaluate(record).getValue()); // test for log10 function with operand type double operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 2.4)); - Assert.assertEquals(0.38021124171160603, + Assert.assertEquals(Math.log10(2.4), new BeamSqlLogExpression(operands).evaluate(record).getValue()); // test for log10 function with operand type decimal operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(2.56))); - Assert.assertEquals(0.4082399653118496, + Assert.assertEquals(Math.log10(2.56), new BeamSqlLogExpression(operands).evaluate(record).getValue()); } @@ -112,17 +111,17 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { // test for exp function with operand type smallint operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); - Assert.assertEquals(7.38905609893065, - new BeamSqlExpExpression(operands).evaluate(record).getValue()); + Assert + .assertEquals(Math.exp(2), new BeamSqlExpExpression(operands).evaluate(record).getValue()); // test for exp function with operand type double operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 2.4)); - Assert.assertEquals(11.023176380641601, + Assert.assertEquals(Math.exp(2.4), new BeamSqlExpExpression(operands).evaluate(record).getValue()); // test for exp function with operand type decimal operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(2.56))); - Assert.assertEquals(12.935817315543076, + Assert.assertEquals(Math.exp(2.56), new BeamSqlExpExpression(operands).evaluate(record).getValue()); } @@ -131,17 +130,17 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { // test for exp function with operand type smallint operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); - Assert.assertEquals(Double.NaN, - new BeamSqlACosExpression(operands).evaluate(record).getValue()); + Assert + .assertEquals(Double.NaN, new BeamSqlACosExpression(operands).evaluate(record).getValue()); // test for exp function with operand type double operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 0.45)); - Assert.assertEquals(1.1040309877476002, + Assert.assertEquals(Math.acos(0.45), new BeamSqlACosExpression(operands).evaluate(record).getValue()); // test for exp function with operand type decimal operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(-0.367))); - Assert.assertEquals(1.9465782472653976, + Assert.assertEquals(Math.acos(-0.367), new BeamSqlACosExpression(operands).evaluate(record).getValue()); } @@ -150,12 +149,12 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { // test for exp function with operand type double operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 0.45)); - Assert.assertEquals(0.4667653390472964, + Assert.assertEquals(Math.asin(0.45), new BeamSqlASinExpression(operands).evaluate(record).getValue()); // test for exp function with operand type decimal operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(-0.367))); - Assert.assertEquals(-0.3757819204705009, + Assert.assertEquals(Math.asin(-0.367), new BeamSqlASinExpression(operands).evaluate(record).getValue()); } @@ -164,12 +163,12 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { // test for exp function with operand type double operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 0.45)); - Assert.assertEquals(0.4228539261329407, + Assert.assertEquals(Math.atan(0.45), new BeamSqlATanExpression(operands).evaluate(record).getValue()); // test for exp function with operand type decimal operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(-0.367))); - Assert.assertEquals(-0.3517385919208851, + Assert.assertEquals(Math.atan(-0.367), new BeamSqlATanExpression(operands).evaluate(record).getValue()); } @@ -178,12 +177,12 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { // test for exp function with operand type double operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 0.45)); - Assert.assertEquals(0.9004471023526769, + Assert.assertEquals(Math.cos(0.45), new BeamSqlCosExpression(operands).evaluate(record).getValue()); // test for exp function with operand type decimal operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(-0.367))); - Assert.assertEquals(0.933407994804752, + Assert.assertEquals(Math.cos(-0.367), new BeamSqlCosExpression(operands).evaluate(record).getValue()); } @@ -192,12 +191,12 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { // test for exp function with operand type double operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, .45)); - Assert.assertEquals(2.0701573613012125, + Assert.assertEquals(1.0d / Math.tan(0.45), new BeamSqlCotExpression(operands).evaluate(record).getValue()); // test for exp function with operand type decimal operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(-.367))); - Assert.assertEquals(-2.601349560400992, + Assert.assertEquals(1.0d / Math.tan(-0.367), new BeamSqlCotExpression(operands).evaluate(record).getValue()); } @@ -206,17 +205,17 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { // test for exp function with operand type smallint operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); - Assert.assertEquals(114.59155902616465, + Assert.assertEquals(Math.toDegrees(2), new BeamSqlDegreesExpression(operands).evaluate(record).getValue()); // test for exp function with operand type double operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 2.4)); - Assert.assertEquals(137.50987083139756, + Assert.assertEquals(Math.toDegrees(2.4), new BeamSqlDegreesExpression(operands).evaluate(record).getValue()); // test for exp function with operand type decimal operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(2.56))); - Assert.assertEquals(146.67719555349075, + Assert.assertEquals(Math.toDegrees(2.56), new BeamSqlDegreesExpression(operands).evaluate(record).getValue()); } @@ -225,17 +224,17 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { // test for exp function with operand type smallint operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); - Assert.assertEquals(0.03490658503988659, + Assert.assertEquals(Math.toRadians(2), new BeamSqlRadiansExpression(operands).evaluate(record).getValue()); // test for exp function with operand type double operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 2.4)); - Assert.assertEquals(0.041887902047863905, + Assert.assertEquals(Math.toRadians(2.4), new BeamSqlRadiansExpression(operands).evaluate(record).getValue()); // test for exp function with operand type decimal operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(2.56))); - Assert.assertEquals(0.04468042885105484, + Assert.assertEquals(Math.toRadians(2.56), new BeamSqlRadiansExpression(operands).evaluate(record).getValue()); } @@ -244,17 +243,17 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { // test for exp function with operand type smallint operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); - Assert.assertEquals(0.9092974268256817, - new BeamSqlSinExpression(operands).evaluate(record).getValue()); + Assert + .assertEquals(Math.sin(2), new BeamSqlSinExpression(operands).evaluate(record).getValue()); // test for exp function with operand type double operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 2.4)); - Assert.assertEquals(0.675463180551151, + Assert.assertEquals(Math.sin(2.4), new BeamSqlSinExpression(operands).evaluate(record).getValue()); // test for exp function with operand type decimal operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(2.56))); - Assert.assertEquals(0.5493554364271266, + Assert.assertEquals(Math.sin(2.56), new BeamSqlSinExpression(operands).evaluate(record).getValue()); } @@ -263,17 +262,17 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { // test for exp function with operand type smallint operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); - Assert.assertEquals(-2.185039863261519, - new BeamSqlTanExpression(operands).evaluate(record).getValue()); + Assert + .assertEquals(Math.tan(2), new BeamSqlTanExpression(operands).evaluate(record).getValue()); // test for exp function with operand type double operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 2.4)); - Assert.assertEquals(-0.9160142896734107, + Assert.assertEquals(Math.tan(2.4), new BeamSqlTanExpression(operands).evaluate(record).getValue()); // test for exp function with operand type decimal operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(2.56))); - Assert.assertEquals(-0.6574471216727855, + Assert.assertEquals(Math.tan(2.56), new BeamSqlTanExpression(operands).evaluate(record).getValue()); } @@ -282,13 +281,11 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { // test for exp function with operand type smallint operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); - Assert.assertEquals(1, - new BeamSqlSignExpression(operands).evaluate(record).getValue()); + Assert.assertEquals(1, new BeamSqlSignExpression(operands).evaluate(record).getValue()); // test for exp function with operand type double operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 2.4)); - Assert.assertEquals(1.0, - new BeamSqlSignExpression(operands).evaluate(record).getValue()); + Assert.assertEquals(1.0, new BeamSqlSignExpression(operands).evaluate(record).getValue()); // test for exp function with operand type decimal operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(2.56))); From 1ca946d2d1d19bc00653da51d3d534fb8b1f90f3 Mon Sep 17 00:00:00 2001 From: tarushapptech Date: Thu, 22 Jun 2017 11:52:33 +0530 Subject: [PATCH 4/5] renamed BeamSqlACosExpression to BeamSqlAcosExpression and similar --- .../dsls/sql/interpreter/BeamSqlFnExecutor.java | 12 ++++++------ ...sExpression.java => BeamSqlAcosExpression.java} | 4 ++-- ...nExpression.java => BeamSqlAsinExpression.java} | 4 ++-- ...nExpression.java => BeamSqlAtanExpression.java} | 4 ++-- .../math/BeamSqlMathUnaryExpressionTest.java | 14 +++++++------- 5 files changed, 19 insertions(+), 19 deletions(-) rename dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/{BeamSqlACosExpression.java => BeamSqlAcosExpression.java} (91%) rename dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/{BeamSqlASinExpression.java => BeamSqlAsinExpression.java} (91%) rename dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/{BeamSqlATanExpression.java => BeamSqlAtanExpression.java} (91%) diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/BeamSqlFnExecutor.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/BeamSqlFnExecutor.java index 9498b1afa81b..4678da56ed70 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/BeamSqlFnExecutor.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/BeamSqlFnExecutor.java @@ -53,10 +53,10 @@ import org.apache.beam.dsls.sql.interpreter.operator.logical.BeamSqlAndExpression; import org.apache.beam.dsls.sql.interpreter.operator.logical.BeamSqlNotExpression; import org.apache.beam.dsls.sql.interpreter.operator.logical.BeamSqlOrExpression; -import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlACosExpression; -import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlASinExpression; -import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlATanExpression; import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlAbsExpression; +import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlAcosExpression; +import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlAsinExpression; +import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlAtanExpression; import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlCotExpression; import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlDegreesExpression; import org.apache.beam.dsls.sql.interpreter.operator.math.BeamSqlExpExpression; @@ -252,13 +252,13 @@ static BeamSqlExpression buildExpression(RexNode rexNode) { ret = new BeamSqlExpExpression(subExps); break; case "ACOS": - ret = new BeamSqlACosExpression(subExps); + ret = new BeamSqlAcosExpression(subExps); break; case "ASIN": - ret = new BeamSqlASinExpression(subExps); + ret = new BeamSqlAsinExpression(subExps); break; case "ATAN": - ret = new BeamSqlATanExpression(subExps); + ret = new BeamSqlAtanExpression(subExps); break; case "COT": ret = new BeamSqlCotExpression(subExps); diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlACosExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlAcosExpression.java similarity index 91% rename from dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlACosExpression.java rename to dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlAcosExpression.java index 8cb891b32ef9..a74ed0dab299 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlACosExpression.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlAcosExpression.java @@ -28,9 +28,9 @@ /** * {@code BeamSqlMathUnaryExpression} for 'ACOS' function. */ -public class BeamSqlACosExpression extends BeamSqlMathUnaryExpression { +public class BeamSqlAcosExpression extends BeamSqlMathUnaryExpression { - public BeamSqlACosExpression(List operands) { + public BeamSqlAcosExpression(List operands) { super(operands); } diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlASinExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlAsinExpression.java similarity index 91% rename from dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlASinExpression.java rename to dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlAsinExpression.java index 19d0cbd3363c..c30d6d3f9f31 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlASinExpression.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlAsinExpression.java @@ -28,9 +28,9 @@ /** * {@code BeamSqlMathUnaryExpression} for 'ASIN' function. */ -public class BeamSqlASinExpression extends BeamSqlMathUnaryExpression { +public class BeamSqlAsinExpression extends BeamSqlMathUnaryExpression { - public BeamSqlASinExpression(List operands) { + public BeamSqlAsinExpression(List operands) { super(operands); } diff --git a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlATanExpression.java b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlAtanExpression.java similarity index 91% rename from dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlATanExpression.java rename to dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlAtanExpression.java index a17954848df6..05c1bf625e07 100644 --- a/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlATanExpression.java +++ b/dsls/sql/src/main/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlAtanExpression.java @@ -28,9 +28,9 @@ /** * {@code BeamSqlMathUnaryExpression} for 'ATAN' function. */ -public class BeamSqlATanExpression extends BeamSqlMathUnaryExpression { +public class BeamSqlAtanExpression extends BeamSqlMathUnaryExpression { - public BeamSqlATanExpression(List operands) { + public BeamSqlAtanExpression(List operands) { super(operands); } diff --git a/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java b/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java index 52bfb10a75a3..55ae4599a7c0 100644 --- a/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java +++ b/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java @@ -131,17 +131,17 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { // test for exp function with operand type smallint operands.add(BeamSqlPrimitive.of(SqlTypeName.SMALLINT, Short.valueOf("2"))); Assert - .assertEquals(Double.NaN, new BeamSqlACosExpression(operands).evaluate(record).getValue()); + .assertEquals(Double.NaN, new BeamSqlAcosExpression(operands).evaluate(record).getValue()); // test for exp function with operand type double operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 0.45)); Assert.assertEquals(Math.acos(0.45), - new BeamSqlACosExpression(operands).evaluate(record).getValue()); + new BeamSqlAcosExpression(operands).evaluate(record).getValue()); // test for exp function with operand type decimal operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(-0.367))); Assert.assertEquals(Math.acos(-0.367), - new BeamSqlACosExpression(operands).evaluate(record).getValue()); + new BeamSqlAcosExpression(operands).evaluate(record).getValue()); } @Test public void testForASinExpression() { @@ -150,12 +150,12 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { // test for exp function with operand type double operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 0.45)); Assert.assertEquals(Math.asin(0.45), - new BeamSqlASinExpression(operands).evaluate(record).getValue()); + new BeamSqlAsinExpression(operands).evaluate(record).getValue()); // test for exp function with operand type decimal operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(-0.367))); Assert.assertEquals(Math.asin(-0.367), - new BeamSqlASinExpression(operands).evaluate(record).getValue()); + new BeamSqlAsinExpression(operands).evaluate(record).getValue()); } @Test public void testForATanExpression() { @@ -164,12 +164,12 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { // test for exp function with operand type double operands.add(BeamSqlPrimitive.of(SqlTypeName.DOUBLE, 0.45)); Assert.assertEquals(Math.atan(0.45), - new BeamSqlATanExpression(operands).evaluate(record).getValue()); + new BeamSqlAtanExpression(operands).evaluate(record).getValue()); // test for exp function with operand type decimal operands.clear(); operands.add(BeamSqlPrimitive.of(SqlTypeName.DECIMAL, BigDecimal.valueOf(-0.367))); Assert.assertEquals(Math.atan(-0.367), - new BeamSqlATanExpression(operands).evaluate(record).getValue()); + new BeamSqlAtanExpression(operands).evaluate(record).getValue()); } @Test public void testForCosExpression() { From 9b80af9cca933debc814c4a3f8a58dadd4235a84 Mon Sep 17 00:00:00 2001 From: tarushapptech Date: Thu, 22 Jun 2017 14:50:18 +0530 Subject: [PATCH 5/5] renamed test name from ACos to Acos and similar --- .../operator/math/BeamSqlMathUnaryExpressionTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java b/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java index 55ae4599a7c0..38f5db647d55 100644 --- a/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java +++ b/dsls/sql/src/test/java/org/apache/beam/dsls/sql/interpreter/operator/math/BeamSqlMathUnaryExpressionTest.java @@ -125,7 +125,7 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { new BeamSqlExpExpression(operands).evaluate(record).getValue()); } - @Test public void testForACosExpression() { + @Test public void testForAcosExpression() { List operands = new ArrayList<>(); // test for exp function with operand type smallint @@ -144,7 +144,7 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { new BeamSqlAcosExpression(operands).evaluate(record).getValue()); } - @Test public void testForASinExpression() { + @Test public void testForAsinExpression() { List operands = new ArrayList<>(); // test for exp function with operand type double @@ -158,7 +158,7 @@ public class BeamSqlMathUnaryExpressionTest extends BeamSqlFnExecutorTestBase { new BeamSqlAsinExpression(operands).evaluate(record).getValue()); } - @Test public void testForATanExpression() { + @Test public void testForAtanExpression() { List operands = new ArrayList<>(); // test for exp function with operand type double