You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/08/01 09:00:05 UTC

[jira] [Work logged] (BEAM-5050) [SQL] NULLs are aggregated incorrectly

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

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

                Author: ASF GitHub Bot
            Created on: 01/Aug/18 09:00
            Start Date: 01/Aug/18 09:00
    Worklog Time Spent: 10m 
      Work Description: kanterov commented on a change in pull request #6108: [BEAM-5050] [SQL] Fix aggregation of nulls
URL: https://github.com/apache/beam/pull/6108#discussion_r206803788
 
 

 ##########
 File path: sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamSqlDslAggregationNullableTest.java
 ##########
 @@ -0,0 +1,156 @@
+/*
+ * 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;
+
+import static org.apache.beam.sdk.extensions.sql.utils.RowAsserts.matchesScalar;
+
+import java.util.List;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.testing.PAssert;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.transforms.Create;
+import org.apache.beam.sdk.values.PBegin;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.Row;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+
+/** Integration tests for aggregation nullable columns. */
+public class BeamSqlDslAggregationNullableTest {
+
+  @Rule public TestPipeline pipeline = TestPipeline.create();
+
+  private PCollection<Row> boundedInput;
+
+  @Before
+  public void setUp() {
+    Schema schema =
+        Schema.builder()
+            .addNullableField("f_int1", Schema.FieldType.INT32)
+            .addNullableField("f_int2", Schema.FieldType.INT32)
+            .addInt32Field("f_int3")
+            .build();
+
+    List<Row> rows =
+        TestUtils.RowsBuilder.of(schema)
+            .addRows(1, 5, 1)
+            .addRows(null, 1, 1)
+            .addRows(2, 1, 1)
+            .addRows(null, 1, 1)
+            .addRows(null, null, 1)
+            .addRows(null, null, 1)
+            .addRows(3, 2, 1)
+            .getRows();
+
+    boundedInput = PBegin.in(pipeline).apply(Create.of(rows).withCoder(schema.getRowCoder()));
+  }
+
+  @Test
+  public void testCount() {
+    String sql = "SELECT COUNT(f_int1) FROM PCOLLECTION GROUP BY f_int3";
+
+    PAssert.that(boundedInput.apply(SqlTransform.query(sql))).satisfies(matchesScalar(3L));
+
+    pipeline.run();
+  }
+
+  @Test
+  public void testCountStar() {
+    String sql = "SELECT COUNT(*) FROM PCOLLECTION GROUP BY f_int3";
+
+    PAssert.that(boundedInput.apply(SqlTransform.query(sql))).satisfies(matchesScalar(7L));
+
+    pipeline.run();
+  }
+
+  @Test
+  public void testCountThroughSum() {
+    String sql =
+        "SELECT SUM(CASE f_int1 IS NOT NULL WHEN TRUE THEN 1 ELSE 0 END) "
+            + "FROM PCOLLECTION GROUP BY f_int3";
+
+    PAssert.that(boundedInput.apply(SqlTransform.query(sql))).satisfies(matchesScalar(3));
+
+    pipeline.run();
+  }
+
+  @Test
+  public void testCountNulls() {
+    String sql =
+        "SELECT SUM(CASE f_int1 IS NULL WHEN TRUE THEN 1 ELSE 0 END) "
+            + "FROM PCOLLECTION GROUP BY f_int3";
+
+    PAssert.that(boundedInput.apply(SqlTransform.query(sql))).satisfies(matchesScalar(4));
+
+    pipeline.run();
+  }
+
+  @Test
+  public void testSum() {
+    String sql = "SELECT SUM(f_int1) FROM PCOLLECTION GROUP BY f_int3";
+
+    PAssert.that(boundedInput.apply(SqlTransform.query(sql))).satisfies(matchesScalar(6));
+
+    pipeline.run();
+  }
+
+  @Test
+  public void testAvg() {
+    String sql = "SELECT AVG(f_int1) FROM PCOLLECTION GROUP BY f_int3";
+
+    PAssert.that(boundedInput.apply(SqlTransform.query(sql))).satisfies(matchesScalar(2));
+
+    pipeline.run();
+  }
+
+  @Ignore
+  // FIXME java.lang.IllegalArgumentException: Field EXPR$0 is not nullable
 
 Review comment:
   Created a ticket: https://issues.apache.org/jira/browse/BEAM-5056

----------------------------------------------------------------
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:
users@infra.apache.org


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

            Worklog Id:     (was: 129625)
            Time Spent: 10m
    Remaining Estimate: 0h

> [SQL] NULLs are aggregated incorrectly
> --------------------------------------
>
>                 Key: BEAM-5050
>                 URL: https://issues.apache.org/jira/browse/BEAM-5050
>             Project: Beam
>          Issue Type: Bug
>          Components: dsl-sql
>            Reporter: Anton Kedin
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> For example, COUNT(field) should not count records with NULL field. We also should handle and test on other aggregation functions (like AVG, SUM, MIN, MAX, VAR_POP, VAR_SAMP, etc.)



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