You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "remyhaemmerle-da (via GitHub)" <gi...@apache.org> on 2024/10/09 15:30:19 UTC

[I] zipWithIndex is broken for org.apache.pekko.stream.scaladsl.GraphDSL.Implicits.PortOps [pekko]

remyhaemmerle-da opened a new issue, #1525:
URL: https://github.com/apache/pekko/issues/1525

   On the one hand,  [org.apache.pekko.stream.scaladsl.GraphDSL.Implicits.PortOps](https://github.com/apache/pekko/blob/95e8355c4c6f2041587e4d64590764e008d1f2b2/stream/src/main/scala/org/apache/pekko/stream/scaladsl/Graph.scala#L1839) inherits from [org.apache.pekko.stream.scaladsl.Flow](https://github.com/apache/pekko/blob/95e8355c4c6f2041587e4d64590764e008d1f2b2/stream/src/main/scala/org/apache/pekko/stream/scaladsl/Flow.scala#L61). 
   
   As of https://github.com/apache/pekko/pull/591 the implementation of [Flow#zipWithIndex](https://github.com/apache/pekko/blob/95e8355c4c6f2041587e4d64590764e008d1f2b2/stream/src/main/scala/org/apache/pekko/stream/scaladsl/Flow.scala#L3307) call [Flow#withAttributes](https://github.com/apache/pekko/blob/95e8355c4c6f2041587e4d64590764e008d1f2b2/stream/src/main/scala/org/apache/pekko/stream/scaladsl/Flow.scala#L3310)
   ```
    def zipWithIndex: Repr[(Out, Long)] =
       statefulMap(() => 0L)((index, out) =>
           (index + 1L, (out, index)), _ => None)
         .withAttributes(DefaultAttributes.zipWithIndex)
   ```
   However `PortOpsImpl` the implementation of `PortOps` does not support [`withAttributes`](https://github.com/apache/pekko/blob/95e8355c4c6f2041587e4d64590764e008d1f2b2/stream/src/main/scala/org/apache/pekko/stream/scaladsl/Graph.scala#L1848)
   ```
     override def withAttributes(attr: Attributes): Repr[Out] = throw settingAttrNotSupported
   ```
    
   Here is a small snipet that works with pekko 1.0.2 but crashes with 1.1.1
   
   ```
   import org.apache.pekko
   import pekko.actor.ActorSystem
   import pekko.stream._
   import pekko.stream.scaladsl._
   
   object Example extends App {
     import GraphDSL.Implicits._
   
     implicit val system = ActorSystem("GraphAndShapeExampleSystem")
     implicit val materializer = ActorMaterializer()
   
     val pickMaxOfThree = GraphDSL.create() { implicit b =>
       import GraphDSL.Implicits._
   
       val zip1 = b.add(ZipWith[Int, Int, Int](math.max _))
       val zip2 = b.add(ZipWith[Int, Int, Int](math.max _))
       zip1.out ~> zip2.in0
   
       UniformFanInShape(zip2.out, zip1.in0, zip1.in1, zip2.in1)
     }
   
     val resultSink = Sink.foreach(println)
   
     val g = RunnableGraph.fromGraph(GraphDSL.createGraph(resultSink) { implicit b => sink =>
       import GraphDSL.Implicits._
   
       // importing the partial graph will return its shape (inlets & outlets)
       val pm3 = b.add(pickMaxOfThree)
   
       Source.single(1) ~> pm3.in(0)
       Source.single(2) ~> pm3.in(1)
       Source.single(3) ~> pm3.in(2)
       pm3.out.zipWithIndex ~> sink.in
       ClosedShape
     })
   
     g.run()
   }
   ```
   
   
   <!--
   Please report issues regarding specific projects in their respective issue trackers, e.g.:
    - Pekko HTTP: https://github.com/apache/pekko-http/issues
    - Pekko Connectors: https://github.com/apache/pekko-connectors/issues 
    - Pekko Persistence Cassandra Plugin: https://github.com/apache/pekko-persistence-cassandra/issues
    - ...
   
   Please explain your issue precisely, and if possible provide a reproducer snippet (this helps resolve issues much quicker).
   
   Thanks for contributing!
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [I] zipWithIndex is broken for org.apache.pekko.stream.scaladsl.GraphDSL.Implicits.PortOps [pekko]

Posted by "remyhaemmerle-da (via GitHub)" <gi...@apache.org>.
remyhaemmerle-da commented on issue #1525:
URL: https://github.com/apache/pekko/issues/1525#issuecomment-2402814148

   Here is the stack trace.
   
   ```
   [error] java.lang.UnsupportedOperationException: Cannot set attributes on chained ops from a junction output port
   [error]         at org.apache.pekko.stream.scaladsl.GraphDSL$Implicits$PortOpsImpl.withAttributes(Graph.scala:1854)
   [error]         at org.apache.pekko.stream.scaladsl.GraphDSL$Implicits$PortOpsImpl.withAttributes(Graph.scala:1845)
   [error]         at org.apache.pekko.stream.scaladsl.FlowOps.zipWithIndex(Flow.scala:3310)
   [error]         at org.apache.pekko.stream.scaladsl.FlowOps.zipWithIndex$(Flow.scala:3307)
   [error]         at org.apache.pekko.stream.scaladsl.GraphDSL$Implicits$PortOpsImpl.zipWithIndex(Graph.scala:1845)
   [error]         at Example$.$anonfun$g$2(Example.scala:33)
   [error]         at org.apache.pekko.stream.scaladsl.GraphApply.createGraph(GraphApply.scala:53)
   [error]         at org.apache.pekko.stream.scaladsl.GraphApply.createGraph$(GraphApply.scala:50)
   [error]         at org.apache.pekko.stream.scaladsl.GraphDSL$.createGraph(Graph.scala:1589)
   [error]         at Example$.delayedEndpoint$Example$1(Example.scala:24)
   [error]         at Example$delayedInit$body.apply(Example.scala:6)
   [error]         at scala.Function0.apply$mcV$sp(Function0.scala:42)
   [error]         at scala.Function0.apply$mcV$sp$(Function0.scala:42)
   [error]         at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
   [error]         at scala.App.$anonfun$main$1(App.scala:98)
   [error]         at scala.App.$anonfun$main$1$adapted(App.scala:98)
   [error]         at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:619)
   [error]         at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:617)
   [error]         at scala.collection.AbstractIterable.foreach(Iterable.scala:935)
   [error]         at scala.App.main(App.scala:98)
   [error]         at scala.App.main$(App.scala:96)
   [error]         at Example$.main(Example.scala:6)
   [error]         at Example.main(Example.scala)
   [error]         at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
   [error]         at java.base/java.lang.reflect.Method.invoke(Method.java:580)
   [error] stack trace is suppressed; run last Compile / run for the full output
   [error] (Compile / run) java.lang.UnsupportedOperationException: Cannot set attributes on chained ops from a junction output port
   [error] Total time: 7 s, completed Oct 9, 2024, 6:41:49 PM
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [I] zipWithIndex is broken for org.apache.pekko.stream.scaladsl.GraphDSL.Implicits.PortOps [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on issue #1525:
URL: https://github.com/apache/pekko/issues/1525#issuecomment-2465858966

   #1526 was merged


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [I] zipWithIndex is broken for org.apache.pekko.stream.scaladsl.GraphDSL.Implicits.PortOps [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning closed issue #1525: zipWithIndex is broken for org.apache.pekko.stream.scaladsl.GraphDSL.Implicits.PortOps
URL: https://github.com/apache/pekko/issues/1525


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [I] zipWithIndex is broken for org.apache.pekko.stream.scaladsl.GraphDSL.Implicits.PortOps [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on issue #1525:
URL: https://github.com/apache/pekko/issues/1525#issuecomment-2404715320

   I plan to revert #591. It didn't lead to any major perf gain and it breaks this use case.
   
   We can always revisit.
   
   #591 was one of a few changes of this style made for v1.1.0 and I think we're going to have to check all those changes for similar issues.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [I] zipWithIndex is broken for org.apache.pekko.stream.scaladsl.GraphDSL.Implicits.PortOps [pekko]

Posted by "mdedetrich (via GitHub)" <gi...@apache.org>.
mdedetrich commented on issue #1525:
URL: https://github.com/apache/pekko/issues/1525#issuecomment-2402721369

   Assigning to @He-Pin since the change was done by him


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [I] zipWithIndex is broken for org.apache.pekko.stream.scaladsl.GraphDSL.Implicits.PortOps [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on issue #1525:
URL: https://github.com/apache/pekko/issues/1525#issuecomment-2408530652

   I still favour starting by reverting #591 but I think we could consider later following up and seeing if we can make PortOps support attributes instead of throwing UnsupportedOperationException.
   
   https://github.com/apache/pekko/blob/95e8355c4c6f2041587e4d64590764e008d1f2b2/stream/src/main/scala/org/apache/pekko/stream/scaladsl/Graph.scala#L1854
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [I] zipWithIndex is broken for org.apache.pekko.stream.scaladsl.GraphDSL.Implicits.PortOps [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on issue #1525:
URL: https://github.com/apache/pekko/issues/1525#issuecomment-2402788421

   @remyhaemmerle-da Can you include the compile error or stack trace? It saves the volunteers a lot of time not to have to go and reproduce the issue.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org