You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@storm.apache.org by HeartSaVioR <gi...@git.apache.org> on 2016/08/31 04:22:06 UTC

[GitHub] storm pull request #1663: STORM-2072 Add map, flatMap with different outputs...

GitHub user HeartSaVioR opened a pull request:

    https://github.com/apache/storm/pull/1663

    STORM-2072 Add map, flatMap with different outputs (T->V) in Trident

    * Introduce overloading methods of map and flatMap
      * Now users can specify new output fields which replace origin fields
    * Introduce OperationMapFunction and OperationFlatMapFunction
      * which also extends Operation
      * Trident will automatically determine this and handle properly
    
    Also updated example code and docs page.
    
    This change is needed for optimizing Storm SQL on Trident mode to have minimized steps.
    I'll work on optimization on top of this and submit that as well. 

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

    $ git pull https://github.com/HeartSaVioR/storm STORM-2072

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

    https://github.com/apache/storm/pull/1663.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 #1663
    
----
commit 07c5cef073c4dc58770c8ccf19cb7a0b8d6ca333
Author: Jungtaek Lim <ka...@gmail.com>
Date:   2016-08-31T04:16:46Z

    STORM-2072 Add map, flatMap with different outputs (T->V) in Trident
    
    * Introduce overloading methods of map and flatMap
      * Now users can specify new output fields which replace origin fields
    * Introduce OperationMapFunction and OperationFlatMapFunction
      * which also extends Operation
      * Trident will automatically determine this and handle properly

----


---
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] storm pull request #1663: STORM-2072 Add map, flatMap with different outputs...

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

    https://github.com/apache/storm/pull/1663#discussion_r81951366
  
    --- Diff: storm-core/src/jvm/org/apache/storm/trident/operation/OperationAwareMapFunction.java ---
    @@ -0,0 +1,24 @@
    +/**
    + * 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.storm.trident.operation;
    +
    +/**
    + * A one-one transformation function which is aware of Operation (lifecycle of the Trident component)
    + */
    +public interface OperationAwareMapFunction extends MapFunction, Operation {
    --- End diff --
    
    Cant we directly modify the MapFunction to implement Operation ? You could add default methods for prepare and cleanup and keep the interface Functional.


---
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] storm pull request #1663: STORM-2072 Add map, flatMap with different outputs...

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

    https://github.com/apache/storm/pull/1663#discussion_r81990483
  
    --- Diff: storm-core/src/jvm/org/apache/storm/trident/Stream.java ---
    @@ -421,6 +421,25 @@ public Stream map(MapFunction function) {
         }
     
         /**
    +     * Returns a stream consisting of the result of applying the given mapping function to the values of this stream.
    +     * This method replaces old output fields with new output fields, achieving T -> V conversion.
    +     *
    +     * @param function a mapping function to be applied to each value in this stream.
    +     * @param outputFields new output fields
    +     * @return the new stream
    +     */
    +    public Stream map(MapFunction function, Fields outputFields) {
    +        projectionValidation(getOutputFields());
    --- End diff --
    
    `projectionValidation()` checks that input fields are all existing in current output fields. Not for output fields.
    
    Btw, `projectionValidation(getOutputFields())` is no effect, hence can be removed.


---
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] storm pull request #1663: STORM-2072 Add map, flatMap with different outputs...

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

    https://github.com/apache/storm/pull/1663#discussion_r81951698
  
    --- Diff: docs/Trident-API-Overview.md ---
    @@ -139,6 +139,21 @@ Of course these operations can be chained, so a stream of uppercase words can be
     ```java
     mystream.flatMap(new Split()).map(new UpperCase())
     ```
    +
    --- End diff --
    
    May be add a note above for the older implementation to call out that outputFields is same as inputFields.


---
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] storm issue #1663: STORM-2072 Add map, flatMap with different outputs (T->V)...

Posted by HeartSaVioR <gi...@git.apache.org>.
Github user HeartSaVioR commented on the issue:

    https://github.com/apache/storm/pull/1663
  
    @arunmahadevan I have commented or addressed all of comments. Please have a look again. 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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] storm pull request #1663: STORM-2072 Add map, flatMap with different outputs...

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

    https://github.com/apache/storm/pull/1663#discussion_r81991303
  
    --- Diff: storm-core/src/jvm/org/apache/storm/trident/operation/OperationAwareFlatMapFunction.java ---
    @@ -0,0 +1,24 @@
    +/**
    + * 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.storm.trident.operation;
    +
    +/**
    + * A one to many transformation function which is aware of Operation (lifecycle of the Trident component)
    + */
    +public interface OperationAwareFlatMapFunction extends FlatMapFunction, Operation {
    --- End diff --
    
    I couldn't do this because we need to ensure it runs with Java 7 if we want to backport this to 1.x branch.


---
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] storm pull request #1663: STORM-2072 Add map, flatMap with different outputs...

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

    https://github.com/apache/storm/pull/1663#discussion_r81950872
  
    --- Diff: storm-core/src/jvm/org/apache/storm/trident/Stream.java ---
    @@ -421,6 +421,25 @@ public Stream map(MapFunction function) {
         }
     
         /**
    +     * Returns a stream consisting of the result of applying the given mapping function to the values of this stream.
    +     * This method replaces old output fields with new output fields, achieving T -> V conversion.
    +     *
    +     * @param function a mapping function to be applied to each value in this stream.
    +     * @param outputFields new output fields
    +     * @return the new stream
    +     */
    +    public Stream map(MapFunction function, Fields outputFields) {
    +        projectionValidation(getOutputFields());
    --- End diff --
    
    Shouldnt this be outputFields?


---
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] storm issue #1663: STORM-2072 Add map, flatMap with different outputs (T->V)...

Posted by harshach <gi...@git.apache.org>.
Github user harshach commented on the issue:

    https://github.com/apache/storm/pull/1663
  
    +1. @arunmahadevan you might want to take a look again.


---
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] storm pull request #1663: STORM-2072 Add map, flatMap with different outputs...

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

    https://github.com/apache/storm/pull/1663#discussion_r81992974
  
    --- Diff: docs/Trident-API-Overview.md ---
    @@ -139,6 +139,21 @@ Of course these operations can be chained, so a stream of uppercase words can be
     ```java
     mystream.flatMap(new Split()).map(new UpperCase())
     ```
    +
    --- End diff --
    
    Thanks for the suggestion. Addressed.


---
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] storm pull request #1663: STORM-2072 Add map, flatMap with different outputs...

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

    https://github.com/apache/storm/pull/1663


---
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] storm pull request #1663: STORM-2072 Add map, flatMap with different outputs...

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

    https://github.com/apache/storm/pull/1663#discussion_r81950911
  
    --- Diff: storm-core/src/jvm/org/apache/storm/trident/Stream.java ---
    @@ -440,6 +459,27 @@ public Stream flatMap(FlatMapFunction function) {
         }
     
         /**
    +     * Returns a stream consisting of the results of replacing each value of this stream with the contents
    +     * produced by applying the provided mapping function to each value. This has the effect of applying
    +     * a one-to-many transformation to the values of the stream, and then flattening the resulting elements into a new stream.
    +     * This method replaces old output fields with new output fields, achieving T -> V conversion.
    +     *
    +     * @param function a mapping function to be applied to each value in this stream which produces new values.
    +     * @param outputFields new output fields
    +     * @return the new stream
    +     */
    +    public Stream flatMap(FlatMapFunction function, Fields outputFields) {
    +        projectionValidation(getOutputFields());
    --- End diff --
    
    Shouldnt this be outputFields?


---
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] storm pull request #1663: STORM-2072 Add map, flatMap with different outputs...

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

    https://github.com/apache/storm/pull/1663#discussion_r81951336
  
    --- Diff: storm-core/src/jvm/org/apache/storm/trident/operation/OperationAwareFlatMapFunction.java ---
    @@ -0,0 +1,24 @@
    +/**
    + * 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.storm.trident.operation;
    +
    +/**
    + * A one to many transformation function which is aware of Operation (lifecycle of the Trident component)
    + */
    +public interface OperationAwareFlatMapFunction extends FlatMapFunction, Operation {
    --- End diff --
    
    Cant we directly modify the FlatMapFunction to implement Operation ? You could add default methods for prepare and cleanup and keep the interface Functional.


---
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] storm issue #1663: STORM-2072 Add map, flatMap with different outputs (T->V)...

Posted by arunmahadevan <gi...@git.apache.org>.
Github user arunmahadevan commented on the issue:

    https://github.com/apache/storm/pull/1663
  
    +1


---
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.
---