You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by twalthr <gi...@git.apache.org> on 2016/03/02 13:39:37 UTC

[GitHub] flink pull request: [FLINK-3564] [table] Implement distinct() for ...

GitHub user twalthr opened a pull request:

    https://github.com/apache/flink/pull/1754

    [FLINK-3564] [table] Implement distinct() for Table API

    Implements some syntactic sugar. Another step towards a SQL-like API.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/twalthr/flink distinctTableApi

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/flink/pull/1754.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1754
    
----
commit 5986e9e284bf64dbc5a382c829b8a5843929b028
Author: twalthr <tw...@apache.org>
Date:   2016-03-02T12:19:38Z

    [FLINK-3564] [table] Implement distinct() for Table API

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3564] [table] Implement distinct() for ...

Posted by twalthr <gi...@git.apache.org>.
Github user twalthr commented on the pull request:

    https://github.com/apache/flink/pull/1754#issuecomment-192228765
  
    I changed it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3564] [table] Implement distinct() for ...

Posted by vasia <gi...@git.apache.org>.
Github user vasia commented on the pull request:

    https://github.com/apache/flink/pull/1754#issuecomment-193258420
  
    Merging this.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3564] [table] Implement distinct() for ...

Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1754#discussion_r54814006
  
    --- Diff: flink-libraries/flink-table/src/test/java/org/apache/flink/api/java/table/test/DistinctITCase.java ---
    @@ -0,0 +1,92 @@
    +/*
    + * 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.flink.api.java.table.test;
    +
    +import java.util.List;
    +import org.apache.flink.api.java.DataSet;
    +import org.apache.flink.api.java.ExecutionEnvironment;
    +import org.apache.flink.api.java.table.TableEnvironment;
    +import org.apache.flink.api.java.tuple.Tuple3;
    +import org.apache.flink.api.java.tuple.Tuple5;
    +import org.apache.flink.api.table.Row;
    +import org.apache.flink.api.table.Table;
    +import org.apache.flink.test.javaApiOperators.util.CollectionDataSets;
    +import org.apache.flink.test.util.MultipleProgramsTestBase;
    +import org.junit.Test;
    +import org.junit.runner.RunWith;
    +import org.junit.runners.Parameterized;
    +
    +@RunWith(Parameterized.class)
    +public class DistinctITCase extends MultipleProgramsTestBase {
    +
    +	public DistinctITCase(TestExecutionMode mode){
    +		super(mode);
    +	}
    +
    +	@Test
    +	public void testAllDistinct() throws Exception {
    +		ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    +		TableEnvironment tableEnv = new TableEnvironment();
    +
    +		DataSet<Tuple3<Integer, Long, String>> input = CollectionDataSets.getSmall3TupleDataSet(env);
    +
    +		Table table = tableEnv.fromDataSet(input, "a, b, c");
    +
    +		Table distinct = table.distinct();
    +
    +		DataSet<Row> ds = tableEnv.toDataSet(distinct, Row.class);
    +		List<Row> results = ds.collect();
    +		String expected = "1,1,Hi\n" + "2,2,Hello\n" + "3,2,Hello world\n";
    +		compareResultAsText(results, expected);
    +	}
    +
    +	@Test
    +	public void testDistinct() throws Exception {
    +		ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    +		TableEnvironment tableEnv = new TableEnvironment();
    +
    +		DataSet<Tuple3<Integer, Long, String>> input = CollectionDataSets.getSmall3TupleDataSet(env);
    +
    +		Table table = tableEnv.fromDataSet(input, "a, b, c");
    +
    +		Table distinct = table.select("b").distinct();
    +
    +		DataSet<Row> ds = tableEnv.toDataSet(distinct, Row.class);
    +		List<Row> results = ds.collect();
    +		String expected = "1\n" + "2\n";
    +		compareResultAsText(results, expected);
    +	}
    +
    +	@Test
    +	public void testDistinctAfterAggregate() throws Exception {
    +		ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    +		TableEnvironment tableEnv = new TableEnvironment();
    +
    +		DataSet<Tuple5<Integer, Long, Integer, String, Long>> input = CollectionDataSets.get5TupleDataSet(env);
    +
    +		Table table = tableEnv.fromDataSet(input, "a, b, c, d, e");
    +
    +		Table distinct = table.groupBy("a").select("e").distinct();
    --- End diff --
    
    Isn't the result of `groupBy('a).select('e)` non-deterministic? Many database systems do not even allow this.
    
    Btw, I looked at the implementation of `GroupedTable.select()` and it looks incorrect. It does not group but just add a selection. Either we should reject the select or select the value an arbitrary row of the group.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3564] [table] Implement distinct() for ...

Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on the pull request:

    https://github.com/apache/flink/pull/1754#issuecomment-192196679
  
    I had a comment about the documentation. 
    Good to merge otherwise.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3564] [table] Implement distinct() for ...

Posted by twalthr <gi...@git.apache.org>.
Github user twalthr commented on the pull request:

    https://github.com/apache/flink/pull/1754#issuecomment-191699364
  
    @fhueske I corrected the tests and rebased. I will create an issue for the wrong aggregation usage.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3564] [table] Implement distinct() for ...

Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1754#discussion_r54808793
  
    --- Diff: flink-libraries/flink-table/src/test/java/org/apache/flink/api/java/table/test/DistinctITCase.java ---
    @@ -0,0 +1,92 @@
    +/*
    + * 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.flink.api.java.table.test;
    +
    +import java.util.List;
    +import org.apache.flink.api.java.DataSet;
    +import org.apache.flink.api.java.ExecutionEnvironment;
    +import org.apache.flink.api.java.table.TableEnvironment;
    +import org.apache.flink.api.java.tuple.Tuple3;
    +import org.apache.flink.api.java.tuple.Tuple5;
    +import org.apache.flink.api.table.Row;
    +import org.apache.flink.api.table.Table;
    +import org.apache.flink.test.javaApiOperators.util.CollectionDataSets;
    +import org.apache.flink.test.util.MultipleProgramsTestBase;
    +import org.junit.Test;
    +import org.junit.runner.RunWith;
    +import org.junit.runners.Parameterized;
    +
    +@RunWith(Parameterized.class)
    +public class DistinctITCase extends MultipleProgramsTestBase {
    +
    +	public DistinctITCase(TestExecutionMode mode){
    +		super(mode);
    +	}
    +
    +	@Test
    +	public void testAllDistinct() throws Exception {
    +		ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    +		TableEnvironment tableEnv = new TableEnvironment();
    +
    +		DataSet<Tuple3<Integer, Long, String>> input = CollectionDataSets.getSmall3TupleDataSet(env);
    +
    +		Table table = tableEnv.fromDataSet(input, "a, b, c");
    +
    +		Table distinct = table.distinct();
    +
    +		DataSet<Row> ds = tableEnv.toDataSet(distinct, Row.class);
    +		List<Row> results = ds.collect();
    +		String expected = "1,1,Hi\n" + "2,2,Hello\n" + "3,2,Hello world\n";
    +		compareResultAsText(results, expected);
    +	}
    +
    +	@Test
    +	public void testDistinct() throws Exception {
    +		ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    +		TableEnvironment tableEnv = new TableEnvironment();
    +
    +		DataSet<Tuple3<Integer, Long, String>> input = CollectionDataSets.getSmall3TupleDataSet(env);
    --- End diff --
    
    Why not use `get3TupleDataSet()` which has more duplicates? 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3564] [table] Implement distinct() for ...

Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1754#discussion_r55005974
  
    --- Diff: docs/apis/batch/libs/table.md ---
    @@ -340,6 +351,18 @@ val result = left.union(right);
     {% endhighlight %}
           </td>
         </tr>
    +
    +    <tr>
    +      <td><strong>Distinct</strong></td>
    +      <td>
    +        <p>Similar to a SQL DISTINCT clause. Removes duplicate values and returns only distinct (different) values.</p>
    --- End diff --
    
    same as above.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3564] [table] Implement distinct() for ...

Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1754#discussion_r55005958
  
    --- Diff: docs/apis/batch/libs/table.md ---
    @@ -238,6 +238,17 @@ Table result = left.union(right);
           </td>
         </tr>
     
    +    <tr>
    +      <td><strong>Distinct</strong></td>
    +      <td>
    +        <p>Similar to a SQL DISTINCT clause. Removes duplicate values and returns only distinct (different) values.</p>
    --- End diff --
    
    We should make clear that rows with distinct value combinations are returned.
    How about: "Returns rows with distinct value combinations."


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3564] [table] Implement distinct() for ...

Posted by fhueske <gi...@git.apache.org>.
Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1754#discussion_r54808671
  
    --- Diff: flink-libraries/flink-table/src/test/java/org/apache/flink/api/java/table/test/DistinctITCase.java ---
    @@ -0,0 +1,92 @@
    +/*
    + * 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.flink.api.java.table.test;
    +
    +import java.util.List;
    +import org.apache.flink.api.java.DataSet;
    +import org.apache.flink.api.java.ExecutionEnvironment;
    +import org.apache.flink.api.java.table.TableEnvironment;
    +import org.apache.flink.api.java.tuple.Tuple3;
    +import org.apache.flink.api.java.tuple.Tuple5;
    +import org.apache.flink.api.table.Row;
    +import org.apache.flink.api.table.Table;
    +import org.apache.flink.test.javaApiOperators.util.CollectionDataSets;
    +import org.apache.flink.test.util.MultipleProgramsTestBase;
    +import org.junit.Test;
    +import org.junit.runner.RunWith;
    +import org.junit.runners.Parameterized;
    +
    +@RunWith(Parameterized.class)
    +public class DistinctITCase extends MultipleProgramsTestBase {
    +
    +	public DistinctITCase(TestExecutionMode mode){
    +		super(mode);
    +	}
    +
    +	@Test
    +	public void testAllDistinct() throws Exception {
    --- End diff --
    
    This test does not check if `distinct` is working. The tuples of `CollectionDataSets.getSmall3TupleDataSet()` are already distinct.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3564] [table] Implement distinct() for ...

Posted by twalthr <gi...@git.apache.org>.
Github user twalthr closed the pull request at:

    https://github.com/apache/flink/pull/1754


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3564] [table] Implement distinct() for ...

Posted by vasia <gi...@git.apache.org>.
Github user vasia commented on the pull request:

    https://github.com/apache/flink/pull/1754#issuecomment-193324252
  
    You can close this @twalthr!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---