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

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

                Author: ASF GitHub Bot
            Created on: 10/Aug/18 20:06
            Start Date: 10/Aug/18 20:06
    Worklog Time Spent: 10m 
      Work Description: akedin closed pull request #6174: [BEAM-5106][SQL]test 
conditional operators and functions at DSL level
URL: https://github.com/apache/beam/pull/6174
 
 
   

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 201059e92b4..f969f734af0 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
@@ -43,6 +43,7 @@
 import java.util.stream.Collectors;
 import 
org.apache.beam.sdk.extensions.sql.integrationtest.BeamSqlBuiltinFunctionsIntegrationTestBase;
 import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.schemas.Schema.FieldType;
 import org.apache.calcite.runtime.SqlFunctions;
 import org.apache.calcite.sql.SqlKind;
 import org.apache.calcite.sql.SqlOperator;
@@ -1170,4 +1171,32 @@ public void testTimestampMinusInterval() throws 
Exception {
                 parseDate("1983-01-19 01:01:58"));
     checker.buildRunAndCheck();
   }
+
+  @Test
+  @SqlOperatorTest(name = "CASE", kind = "CASE")
+  @SqlOperatorTest(name = "NULLIF", kind = "NULLIF")
+  @SqlOperatorTest(name = "COALESCE", kind = "COALESCE")
+  public void testConditionalOperatorsAndFunctions() {
+    ExpressionChecker checker =
+        new ExpressionChecker()
+            .addExpr("CASE 1 WHEN 1 THEN 'hello' ELSE 'world' END", "hello")
+            .addExpr(
+                "CASE 2 " + "WHEN 1 THEN 'hello' " + "WHEN 3 THEN 'bond' " + 
"ELSE 'world' END",
+                "world")
+            .addExpr(
+                "CASE 3 " + "WHEN 1 THEN 'hello' " + "WHEN 3 THEN 'bond' " + 
"ELSE 'world' END",
+                "bond")
+            .addExpr("CASE " + "WHEN 1 = 1 THEN 'hello' " + "ELSE 'world' 
END", "hello")
+            .addExpr("CASE " + "WHEN 1 > 1 THEN 'hello' " + "ELSE 'world' 
END", "world")
+            .addExpr("NULLIF(5, 4) ", 5)
+            .addExpr("NULLIF(4, 5) ", 4)
+            .addExpr("NULLIF(5, 5)", null, FieldType.INT32)
+            .addExpr("COALESCE(1, 5) ", 1)
+            .addExpr("COALESCE(NULL, 5) ", 5)
+            .addExpr("COALESCE(NULL, 4, 5) ", 4)
+            .addExpr("COALESCE(NULL, NULL, 5) ", 5)
+            .addExpr("COALESCE(5, NULL) ", 5);
+
+    checker.buildRunAndCheck();
+  }
 }
diff --git 
a/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/integrationtest/BeamSqlBuiltinFunctionsIntegrationTestBase.java
 
b/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/integrationtest/BeamSqlBuiltinFunctionsIntegrationTestBase.java
index 4380b0b7241..8ba5374ec8b 100644
--- 
a/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/integrationtest/BeamSqlBuiltinFunctionsIntegrationTestBase.java
+++ 
b/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/integrationtest/BeamSqlBuiltinFunctionsIntegrationTestBase.java
@@ -30,6 +30,7 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import javax.annotation.Nullable;
 import org.apache.beam.sdk.Pipeline;
 import org.apache.beam.sdk.extensions.sql.SqlTransform;
 import org.apache.beam.sdk.extensions.sql.TestUtils;
@@ -128,6 +129,7 @@ private static ExpressionTestCase of(
 
     abstract String sqlExpr();
 
+    @Nullable
     abstract Object expectedResult();
 
     abstract FieldType resultFieldType();
@@ -176,7 +178,13 @@ public void buildRunAndCheck() {
         String expression = testCase.sqlExpr();
         Object expectedValue = testCase.expectedResult();
         String sql = String.format("SELECT %s FROM PCOLLECTION", expression);
-        Schema schema = Schema.builder().addField(expression, 
testCase.resultFieldType()).build();
+        Schema schema;
+        if (expectedValue == null) {
+          schema =
+              Schema.builder().addNullableField(expression, 
testCase.resultFieldType()).build();
+        } else {
+          schema = Schema.builder().addField(expression, 
testCase.resultFieldType()).build();
+        }
 
         PCollection<Row> output =
             inputCollection.apply(testCase.toString(), 
SqlTransform.query(sql));
diff --git 
a/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/integrationtest/BeamSqlConditionalFunctionsIntegrationTest.java
 
b/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/integrationtest/BeamSqlConditionalFunctionsIntegrationTest.java
deleted file mode 100644
index 47ddd2d1493..00000000000
--- 
a/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/integrationtest/BeamSqlConditionalFunctionsIntegrationTest.java
+++ /dev/null
@@ -1,41 +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 org.junit.Test;
-
-/** Integration test for conditional functions. */
-public class BeamSqlConditionalFunctionsIntegrationTest
-    extends BeamSqlBuiltinFunctionsIntegrationTestBase {
-  @Test
-  public void testConditionalFunctions() throws Exception {
-    ExpressionChecker checker =
-        new ExpressionChecker()
-            .addExpr("CASE 1 WHEN 1 THEN 'hello' ELSE 'world' END", "hello")
-            .addExpr(
-                "CASE 2 " + "WHEN 1 THEN 'hello' " + "WHEN 3 THEN 'bond' " + 
"ELSE 'world' END",
-                "world")
-            .addExpr("CASE " + "WHEN 1 = 1 THEN 'hello' " + "ELSE 'world' 
END", "hello")
-            .addExpr("CASE " + "WHEN 1 > 1 THEN 'hello' " + "ELSE 'world' 
END", "world")
-            .addExpr("NULLIF(5, 4) ", 5)
-            .addExpr("COALESCE(1, 5) ", 1)
-            .addExpr("COALESCE(NULL, 5) ", 5);
-
-    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: 133798)
    Time Spent: 4h 10m  (was: 4h)

> Test conditional functions at DSL level
> ---------------------------------------
>
>                 Key: BEAM-5106
>                 URL: https://issues.apache.org/jira/browse/BEAM-5106
>             Project: Beam
>          Issue Type: Sub-task
>          Components: dsl-sql
>            Reporter: Rui Wang
>            Assignee: Rui Wang
>            Priority: Major
>          Time Spent: 4h 10m
>  Remaining Estimate: 0h
>




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

Reply via email to