[GitHub] flink pull request: FLINK-3254: Adding functionality to support th...

2016-02-03 Thread fhueske
Github user fhueske commented on the pull request:

https://github.com/apache/flink/pull/1568#issuecomment-179464772
  
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request: FLINK-3254: Adding functionality to support th...

2016-02-03 Thread asfgit
Github user asfgit closed the pull request at:

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


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request: FLINK-3254: Adding functionality to support th...

2016-02-01 Thread fhueske
Github user fhueske commented on the pull request:

https://github.com/apache/flink/pull/1568#issuecomment-178060233
  
Good to merge. Thanks!


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request: FLINK-3254: Adding functionality to support th...

2016-02-01 Thread kl0u
GitHub user kl0u opened a pull request:

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

FLINK-3254: Adding functionality to support the CombineFunction contract.

Solves ISSUE-3254: now a function that implements the GroupReduceFunction 
and the CombineFunction interfaces will be executed with a combiner. Before, 
this was the case only if the function was implementing the GroupReduceFunction 
and the GroupCombineFunction interfaces.

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

$ git pull https://github.com/kl0u/flink combiner_fix

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

https://github.com/apache/flink/pull/1568.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 #1568


commit 49aabd959472a49f9803023bbec360fec824db75
Author: Kostas Kloudas 
Date:   2016-02-01T08:46:00Z

FLINK-3254: Adding functionality to support the CombineFunction contract.




---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request: FLINK-3254: Adding functionality to support th...

2016-02-01 Thread fhueske
Github user fhueske commented on a diff in the pull request:

https://github.com/apache/flink/pull/1568#discussion_r51425852
  
--- Diff: 
flink-core/src/main/java/org/apache/flink/api/common/functions/util/CombineToGroupCombineWrapper.java
 ---
@@ -0,0 +1,49 @@
+/*
+ * 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.common.functions.util;
+
+import com.google.common.base.Preconditions;
+import org.apache.flink.api.common.functions.CombineFunction;
+import org.apache.flink.api.common.functions.GroupCombineFunction;
+import org.apache.flink.api.common.functions.GroupReduceFunction;
+import org.apache.flink.util.Collector;
+
+/**
+ * A wrapper the wraps a function that implements both {@link 
CombineFunction} and {@link GroupReduceFunction} interfaces
+ * and makes it look like a function that implements {@link 
GroupCombineFunction} and {@link GroupReduceFunction} to the runtime.
+ */
+public class CombineToGroupCombineWrapper & GroupReduceFunction>
+   implements GroupCombineFunction, GroupReduceFunction {
+
+   private final F wrappedFunction;
+
+   public CombineToGroupCombineWrapper(F wrappedFunction) {
+   this.wrappedFunction = 
Preconditions.checkNotNull(wrappedFunction);
+   }
+
+   @Override
+   public void combine(Iterable values, Collector out) throws 
Exception {
--- End diff --

Should be `Collector`. A combine function (if applied in the context of 
a reduce function) must preserve the input type.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request: FLINK-3254: Adding functionality to support th...

2016-02-01 Thread fhueske
Github user fhueske commented on a diff in the pull request:

https://github.com/apache/flink/pull/1568#discussion_r51426746
  
--- Diff: 
flink-java/src/main/java/org/apache/flink/api/java/operators/GroupReduceOperator.java
 ---
@@ -119,6 +123,8 @@ private void checkCombinability() {
combineTypes != null && combineTypes.length == 
2) {
 
if (reduceTypes[0].equals(combineTypes[0]) && 
reduceTypes[0].equals(combineTypes[1])) {
+   LOG.info("Combine() and Reduce() 
methods have compatible input and output types. " +
--- End diff --

This is expected behavior. I would remove this log statement. 


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request: FLINK-3254: Adding functionality to support th...

2016-02-01 Thread fhueske
Github user fhueske commented on a diff in the pull request:

https://github.com/apache/flink/pull/1568#discussion_r51425707
  
--- Diff: 
flink-core/src/main/java/org/apache/flink/api/common/functions/util/CombineToGroupCombineWrapper.java
 ---
@@ -0,0 +1,49 @@
+/*
+ * 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.common.functions.util;
+
+import com.google.common.base.Preconditions;
+import org.apache.flink.api.common.functions.CombineFunction;
+import org.apache.flink.api.common.functions.GroupCombineFunction;
+import org.apache.flink.api.common.functions.GroupReduceFunction;
+import org.apache.flink.util.Collector;
+
+/**
+ * A wrapper the wraps a function that implements both {@link 
CombineFunction} and {@link GroupReduceFunction} interfaces
+ * and makes it look like a function that implements {@link 
GroupCombineFunction} and {@link GroupReduceFunction} to the runtime.
+ */
+public class CombineToGroupCombineWrapper & GroupReduceFunction>
--- End diff --

The generic parameters of the `CombineFunction` and `GroupCombineFunction` 
should be ``


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request: FLINK-3254: Adding functionality to support th...

2016-02-01 Thread fhueske
Github user fhueske commented on a diff in the pull request:

https://github.com/apache/flink/pull/1568#discussion_r51427090
  
--- Diff: 
flink-java/src/main/java/org/apache/flink/api/java/operators/GroupReduceOperator.java
 ---
@@ -156,8 +162,8 @@ public boolean isCombinable() {

public GroupReduceOperator setCombinable(boolean combinable) {
// sanity check that the function is a subclass of the combine 
interface
-   if (combinable && !(function instanceof GroupCombineFunction)) {
-   throw new IllegalArgumentException("The function does 
not implement the combine interface.");
+   if (combinable && !(function instanceof GroupCombineFunction || 
function instanceof CombineFunction)) {
--- End diff --

If we change the `checkCombinability` method to return a boolean instead of 
setting `this.combinable` directly, we can also use it here.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request: FLINK-3254: Adding functionality to support th...

2016-02-01 Thread kl0u
Github user kl0u commented on a diff in the pull request:

https://github.com/apache/flink/pull/1568#discussion_r51427689
  
--- Diff: 
flink-java/src/main/java/org/apache/flink/api/java/operators/GroupReduceOperator.java
 ---
@@ -156,8 +162,8 @@ public boolean isCombinable() {

public GroupReduceOperator setCombinable(boolean combinable) {
// sanity check that the function is a subclass of the combine 
interface
-   if (combinable && !(function instanceof GroupCombineFunction)) {
-   throw new IllegalArgumentException("The function does 
not implement the combine interface.");
+   if (combinable && !(function instanceof GroupCombineFunction || 
function instanceof CombineFunction)) {
--- End diff --

Hi @fhueske, could you explain this a bit more?



---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request: FLINK-3254: Adding functionality to support th...

2016-02-01 Thread fhueske
Github user fhueske commented on a diff in the pull request:

https://github.com/apache/flink/pull/1568#discussion_r51428276
  
--- Diff: 
flink-tests/src/test/java/org/apache/flink/test/javaApiOperators/ReduceWithCombinerITCase.java
 ---
@@ -0,0 +1,377 @@
+/*
+ * 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.test.javaApiOperators;
+
+import org.apache.flink.api.common.functions.CombineFunction;
+import org.apache.flink.api.common.functions.GroupCombineFunction;
+import org.apache.flink.api.common.functions.GroupReduceFunction;
+import org.apache.flink.api.java.DataSet;
+import org.apache.flink.api.java.ExecutionEnvironment;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.api.java.operators.UnsortedGrouping;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.test.util.MultipleProgramsTestBase;
+import org.apache.flink.util.Collector;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+@SuppressWarnings("serial")
+@RunWith(Parameterized.class)
+public class ReduceWithCombinerITCase extends MultipleProgramsTestBase {
+
+   public ReduceWithCombinerITCase(TestExecutionMode mode) {
+   super(TestExecutionMode.CLUSTER);
+   }
+
+   @Test
+   public void testReduceOnNonKeyedDataset() throws Exception {
+
+   final ExecutionEnvironment env = 
ExecutionEnvironment.getExecutionEnvironment();
+   env.setParallelism(4);
+
+   // creates the input data and distributes them evenly among the 
available downstream tasks
+   DataSet> input = 
createNonKeyedInput(env);
+
+   List> actual = input.reduceGroup(new 
NonKeyedCombReducer()).collect();
+   List> expected = 
Collections.singletonList(new Tuple2<>(10, true));
+
+   compareResultCollections(expected, actual, new 
Comparator>() {
--- End diff --

Can you use `compareResultAsText` or `compareResultAsTuples` to make the 
tests more concise?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request: FLINK-3254: Adding functionality to support th...

2016-02-01 Thread fhueske
Github user fhueske commented on a diff in the pull request:

https://github.com/apache/flink/pull/1568#discussion_r51427409
  
--- Diff: 
flink-core/src/main/java/org/apache/flink/api/common/functions/util/CombineToGroupCombineWrapper.java
 ---
@@ -0,0 +1,49 @@
+/*
+ * 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.common.functions.util;
--- End diff --

Wrappers such as this function are located in the `flink-java` module in 
the `org.apache.flink.api.java.operators.translation` package.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request: FLINK-3254: Adding functionality to support th...

2016-02-01 Thread fhueske
Github user fhueske commented on a diff in the pull request:

https://github.com/apache/flink/pull/1568#discussion_r51427575
  
--- Diff: 
flink-java/src/main/java/org/apache/flink/api/java/operators/GroupReduceOperator.java
 ---
@@ -193,7 +199,11 @@ public SingleInputSemanticProperties 
getSemanticProperties() {
protected GroupReduceOperatorBase 
translateToDataFlow(Operator input) {
 
String name = getName() != null ? getName() : "GroupReduce at " 
+ defaultName;
-   
+
+   this.function = (function instanceof CombineFunction) ?
+   new CombineToGroupCombineWrapper((CombineFunction) 
function) :
--- End diff --

This does also add a bit of overhead to the `reduce` method because it is 
wrapped. However, this should be OK since it is called just once per 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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] flink pull request: FLINK-3254: Adding functionality to support th...

2016-02-01 Thread fhueske
Github user fhueske commented on the pull request:

https://github.com/apache/flink/pull/1568#issuecomment-178011362
  
Thanks for the PR. I had a few minor comments. Looks good 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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---