[ 
https://issues.apache.org/jira/browse/BEAM-4599?focusedWorklogId=122018&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-122018
 ]

ASF GitHub Bot logged work on BEAM-4599:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 11/Jul/18 18:57
            Start Date: 11/Jul/18 18:57
    Worklog Time Spent: 10m 
      Work Description: XuMingmin closed pull request #5921: [BEAM-4599] [SQL] 
add testArithmeticOperator
URL: https://github.com/apache/beam/pull/5921
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamSqlDslSqlStdOperatorsTest.java
 
b/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamSqlDslSqlStdOperatorsTest.java
index 4a5ef026b2a..a2b558be3c5 100644
--- 
a/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamSqlDslSqlStdOperatorsTest.java
+++ 
b/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamSqlDslSqlStdOperatorsTest.java
@@ -32,6 +32,8 @@
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.Arrays;
 import java.util.Comparator;
 import java.util.HashSet;
@@ -53,6 +55,13 @@
  * org.apache.calcite.sql.fun.SqlStdOperatorTable}.
  */
 public class BeamSqlDslSqlStdOperatorsTest extends 
BeamSqlBuiltinFunctionsIntegrationTestBase {
+  private static final BigDecimal ZERO = BigDecimal.valueOf(0.0);
+  private static final BigDecimal ONE = BigDecimal.valueOf(1.0);
+  private static final BigDecimal ONE2 = 
BigDecimal.valueOf(1.0).multiply(BigDecimal.valueOf(1.0));
+  private static final BigDecimal ONE10 =
+      BigDecimal.ONE.divide(BigDecimal.ONE, 10, RoundingMode.HALF_EVEN);
+  private static final BigDecimal TWO = BigDecimal.valueOf(2.0);
+  private static final BigDecimal TWO0 = BigDecimal.ONE.add(BigDecimal.ONE);
 
   @Rule public ExpectedException thrown = ExpectedException.none();
 
@@ -258,6 +267,97 @@ public void testLogicOperators() {
     checker.buildRunAndCheck();
   }
 
+  @Test
+  @SqlOperatorTest(name = "+", kind = "PLUS")
+  @SqlOperatorTest(name = "-", kind = "MINUS")
+  @SqlOperatorTest(name = "*", kind = "TIMES")
+  @SqlOperatorTest(name = "/", kind = "DIVIDE")
+  @SqlOperatorTest(name = "MOD", kind = "MOD")
+  public void testArithmeticOperator() {
+    ExpressionChecker checker =
+        new ExpressionChecker()
+            .addExpr("1 + 1", 2)
+            .addExpr("1.0 + 1", TWO)
+            .addExpr("1 + 1.0", TWO)
+            .addExpr("1.0 + 1.0", TWO)
+            .addExpr("c_tinyint + c_tinyint", (byte) 2)
+            .addExpr("c_smallint + c_smallint", (short) 2)
+            .addExpr("c_bigint + c_bigint", 2L)
+            .addExpr("c_decimal + c_decimal", TWO0)
+            .addExpr("c_tinyint + c_decimal", TWO0)
+            .addExpr("c_float + c_decimal", 2.0)
+            .addExpr("c_double + c_decimal", 2.0)
+            .addExpr("c_float + c_float", 2.0f)
+            .addExpr("c_double + c_float", 2.0)
+            .addExpr("c_double + c_double", 2.0)
+            .addExpr("c_float + c_bigint", 2.0f)
+            .addExpr("c_double + c_bigint", 2.0)
+            .addExpr("1 - 1", 0)
+            .addExpr("1.0 - 1", ZERO)
+            .addExpr("1 - 0.0", ONE)
+            .addExpr("1.0 - 1.0", ZERO)
+            .addExpr("c_tinyint - c_tinyint", (byte) 0)
+            .addExpr("c_smallint - c_smallint", (short) 0)
+            .addExpr("c_bigint - c_bigint", 0L)
+            .addExpr("c_decimal - c_decimal", BigDecimal.ZERO)
+            .addExpr("c_tinyint - c_decimal", BigDecimal.ZERO)
+            .addExpr("c_float - c_decimal", 0.0)
+            .addExpr("c_double - c_decimal", 0.0)
+            .addExpr("c_float - c_float", 0.0f)
+            .addExpr("c_double - c_float", 0.0)
+            .addExpr("c_double - c_double", 0.0)
+            .addExpr("c_float - c_bigint", 0.0f)
+            .addExpr("c_double - c_bigint", 0.0)
+            .addExpr("1 * 1", 1)
+            .addExpr("1.0 * 1", ONE)
+            .addExpr("1 * 1.0", ONE)
+            .addExpr("1.0 * 1.0", ONE2)
+            .addExpr("c_tinyint * c_tinyint", (byte) 1)
+            .addExpr("c_smallint * c_smallint", (short) 1)
+            .addExpr("c_bigint * c_bigint", 1L)
+            .addExpr("c_decimal * c_decimal", BigDecimal.ONE)
+            .addExpr("c_tinyint * c_decimal", BigDecimal.ONE)
+            .addExpr("c_float * c_decimal", 1.0)
+            .addExpr("c_double * c_decimal", 1.0)
+            .addExpr("c_float * c_float", 1.0f)
+            .addExpr("c_double * c_float", 1.0)
+            .addExpr("c_double * c_double", 1.0)
+            .addExpr("c_float * c_bigint", 1.0f)
+            .addExpr("c_double * c_bigint", 1.0)
+            .addExpr("1 / 1", 1)
+            .addExpr("1.0 / 1", ONE10)
+            .addExpr("1 / 1.0", ONE10)
+            .addExpr("1.0 / 1.0", ONE10)
+            .addExpr("c_tinyint / c_tinyint", (byte) 1)
+            .addExpr("c_smallint / c_smallint", (short) 1)
+            .addExpr("c_bigint / c_bigint", 1L)
+            .addExpr("c_decimal / c_decimal", ONE10)
+            .addExpr("c_tinyint / c_decimal", ONE10)
+            .addExpr("c_float / c_decimal", 1.0)
+            .addExpr("c_double / c_decimal", 1.0)
+            .addExpr("c_float / c_float", 1.0f)
+            .addExpr("c_double / c_float", 1.0)
+            .addExpr("c_double / c_double", 1.0)
+            .addExpr("c_float / c_bigint", 1.0f)
+            .addExpr("c_double / c_bigint", 1.0)
+            .addExpr("mod(1, 1)", 0)
+            .addExpr("mod(1.0, 1)", 0)
+            .addExpr("mod(1, 1.0)", ZERO)
+            .addExpr("mod(1.0, 1.0)", ZERO)
+            .addExpr("mod(c_tinyint, c_tinyint)", (byte) 0)
+            .addExpr("mod(c_smallint, c_smallint)", (short) 0)
+            .addExpr("mod(c_bigint, c_bigint)", 0L)
+            .addExpr("mod(c_decimal, c_decimal)", ZERO)
+            .addExpr("mod(c_tinyint, c_decimal)", ZERO)
+            // Test overflow
+            .addExpr("c_tinyint_max + c_tinyint_max", (byte) -2)
+            .addExpr("c_smallint_max + c_smallint_max", (short) -2)
+            .addExpr("c_integer_max + c_integer_max", -2)
+            .addExpr("c_bigint_max + c_bigint_max", -2L);
+
+    checker.buildRunAndCheck();
+  }
+
   @Test
   @SqlOperatorTest(name = "<", kind = "LESS_THAN")
   @SqlOperatorTest(name = ">", kind = "GREATER_THAN")
diff --git 
a/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/integrationtest/BeamSqlArithmeticOperatorsIntegrationTest.java
 
b/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/integrationtest/BeamSqlArithmeticOperatorsIntegrationTest.java
deleted file mode 100644
index 62a49dfe492..00000000000
--- 
a/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/integrationtest/BeamSqlArithmeticOperatorsIntegrationTest.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * 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.sdk.extensions.sql.integrationtest;
-
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import org.junit.Test;
-
-/** Integration test for arithmetic operators. */
-public class BeamSqlArithmeticOperatorsIntegrationTest
-    extends BeamSqlBuiltinFunctionsIntegrationTestBase {
-
-  private static final BigDecimal ZERO = BigDecimal.valueOf(0.0);
-  private static final BigDecimal ONE = BigDecimal.valueOf(1.0);
-  private static final BigDecimal ONE2 = 
BigDecimal.valueOf(1.0).multiply(BigDecimal.valueOf(1.0));
-  private static final BigDecimal ONE10 =
-      BigDecimal.ONE.divide(BigDecimal.ONE, 10, RoundingMode.HALF_EVEN);
-  private static final BigDecimal TWO = BigDecimal.valueOf(2.0);
-  private static final BigDecimal TWO0 = BigDecimal.ONE.add(BigDecimal.ONE);
-
-  @Test
-  public void testPlus() throws Exception {
-    ExpressionChecker checker =
-        new ExpressionChecker()
-            .addExpr("1 + 1", 2)
-            .addExpr("1.0 + 1", TWO)
-            .addExpr("1 + 1.0", TWO)
-            .addExpr("1.0 + 1.0", TWO)
-            .addExpr("c_tinyint + c_tinyint", (byte) 2)
-            .addExpr("c_smallint + c_smallint", (short) 2)
-            .addExpr("c_bigint + c_bigint", 2L)
-            .addExpr("c_decimal + c_decimal", TWO0)
-            .addExpr("c_tinyint + c_decimal", TWO0)
-            .addExpr("c_float + c_decimal", 2.0)
-            .addExpr("c_double + c_decimal", 2.0)
-            .addExpr("c_float + c_float", 2.0f)
-            .addExpr("c_double + c_float", 2.0)
-            .addExpr("c_double + c_double", 2.0)
-            .addExpr("c_float + c_bigint", 2.0f)
-            .addExpr("c_double + c_bigint", 2.0);
-
-    checker.buildRunAndCheck();
-  }
-
-  @Test
-  public void testPlus_overflow() throws Exception {
-    ExpressionChecker checker =
-        new ExpressionChecker()
-            .addExpr("c_tinyint_max + c_tinyint_max", (byte) -2)
-            .addExpr("c_smallint_max + c_smallint_max", (short) -2)
-            .addExpr("c_integer_max + c_integer_max", -2)
-            .addExpr("c_bigint_max + c_bigint_max", -2L);
-
-    checker.buildRunAndCheck();
-  }
-
-  @Test
-  public void testMinus() throws Exception {
-    ExpressionChecker checker =
-        new ExpressionChecker()
-            .addExpr("1 - 1", 0)
-            .addExpr("1.0 - 1", ZERO)
-            .addExpr("1 - 0.0", ONE)
-            .addExpr("1.0 - 1.0", ZERO)
-            .addExpr("c_tinyint - c_tinyint", (byte) 0)
-            .addExpr("c_smallint - c_smallint", (short) 0)
-            .addExpr("c_bigint - c_bigint", 0L)
-            .addExpr("c_decimal - c_decimal", BigDecimal.ZERO)
-            .addExpr("c_tinyint - c_decimal", BigDecimal.ZERO)
-            .addExpr("c_float - c_decimal", 0.0)
-            .addExpr("c_double - c_decimal", 0.0)
-            .addExpr("c_float - c_float", 0.0f)
-            .addExpr("c_double - c_float", 0.0)
-            .addExpr("c_double - c_double", 0.0)
-            .addExpr("c_float - c_bigint", 0.0f)
-            .addExpr("c_double - c_bigint", 0.0);
-
-    checker.buildRunAndCheck();
-  }
-
-  @Test
-  public void testMultiply() throws Exception {
-    ExpressionChecker checker =
-        new ExpressionChecker()
-            .addExpr("1 * 1", 1)
-            .addExpr("1.0 * 1", ONE)
-            .addExpr("1 * 1.0", ONE)
-            .addExpr("1.0 * 1.0", ONE2)
-            .addExpr("c_tinyint * c_tinyint", (byte) 1)
-            .addExpr("c_smallint * c_smallint", (short) 1)
-            .addExpr("c_bigint * c_bigint", 1L)
-            .addExpr("c_decimal * c_decimal", BigDecimal.ONE)
-            .addExpr("c_tinyint * c_decimal", BigDecimal.ONE)
-            .addExpr("c_float * c_decimal", 1.0)
-            .addExpr("c_double * c_decimal", 1.0)
-            .addExpr("c_float * c_float", 1.0f)
-            .addExpr("c_double * c_float", 1.0)
-            .addExpr("c_double * c_double", 1.0)
-            .addExpr("c_float * c_bigint", 1.0f)
-            .addExpr("c_double * c_bigint", 1.0);
-
-    checker.buildRunAndCheck();
-  }
-
-  @Test
-  public void testDivide() throws Exception {
-    ExpressionChecker checker =
-        new ExpressionChecker()
-            .addExpr("1 / 1", 1)
-            .addExpr("1.0 / 1", ONE10)
-            .addExpr("1 / 1.0", ONE10)
-            .addExpr("1.0 / 1.0", ONE10)
-            .addExpr("c_tinyint / c_tinyint", (byte) 1)
-            .addExpr("c_smallint / c_smallint", (short) 1)
-            .addExpr("c_bigint / c_bigint", 1L)
-            .addExpr("c_decimal / c_decimal", ONE10)
-            .addExpr("c_tinyint / c_decimal", ONE10)
-            .addExpr("c_float / c_decimal", 1.0)
-            .addExpr("c_double / c_decimal", 1.0)
-            .addExpr("c_float / c_float", 1.0f)
-            .addExpr("c_double / c_float", 1.0)
-            .addExpr("c_double / c_double", 1.0)
-            .addExpr("c_float / c_bigint", 1.0f)
-            .addExpr("c_double / c_bigint", 1.0);
-
-    checker.buildRunAndCheck();
-  }
-
-  @Test
-  public void testMod() throws Exception {
-    ExpressionChecker checker =
-        new ExpressionChecker()
-            .addExpr("mod(1, 1)", 0)
-            .addExpr("mod(1.0, 1)", 0)
-            .addExpr("mod(1, 1.0)", ZERO)
-            .addExpr("mod(1.0, 1.0)", ZERO)
-            .addExpr("mod(c_tinyint, c_tinyint)", (byte) 0)
-            .addExpr("mod(c_smallint, c_smallint)", (short) 0)
-            .addExpr("mod(c_bigint, c_bigint)", 0L)
-            .addExpr("mod(c_decimal, c_decimal)", ZERO)
-            .addExpr("mod(c_tinyint, c_decimal)", ZERO);
-
-    checker.buildRunAndCheck();
-  }
-}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 122018)
    Time Spent: 2h 20m  (was: 2h 10m)

> Test arithmetic operators at the DSL level
> ------------------------------------------
>
>                 Key: BEAM-4599
>                 URL: https://issues.apache.org/jira/browse/BEAM-4599
>             Project: Beam
>          Issue Type: Sub-task
>          Components: dsl-sql
>            Reporter: Kenneth Knowles
>            Assignee: Rui Wang
>            Priority: Major
>          Time Spent: 2h 20m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to