You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by StephanEwen <gi...@git.apache.org> on 2017/02/24 14:07:39 UTC

[GitHub] flink pull request #3303: [FLINK-5133][core] Support to set resource for ope...

Github user StephanEwen commented on a diff in the pull request:

    https://github.com/apache/flink/pull/3303#discussion_r102946206
  
    --- Diff: flink-streaming-scala/src/main/scala/org/apache/flink/streaming/api/scala/DataStream.scala ---
    @@ -144,6 +145,43 @@ class DataStream[T](stream: JavaStream[T]) {
         this
       }
     
    +
    +  /**
    +   * Returns the minimum resource of this operation.
    +   */
    +  def getMinResource: ResourceSpec = stream.getMinResource()
    +
    +  /**
    +   * Returns the maximum resource of this operation.
    +   */
    +  def getMaxResource: ResourceSpec = stream.getMaxResource()
    +
    +  /**
    +   * Sets the minimum and maximum resources of this operation.
    +   */
    +  def setResource(minResource: ResourceSpec, maxResource: ResourceSpec): DataStream[T] = {
    +    stream match {
    +      case ds: SingleOutputStreamOperator[T] => ds.setResource(minResource, maxResource)
    +      case _ =>
    +        throw new UnsupportedOperationException(
    +          "Operator " + stream + " cannot set the resource.")
    +    }
    +    this
    +  }
    +
    +  /**
    +   * Sets the resource of this operation.
    +   */
    +  def setResource(resource: ResourceSpec): DataStream[T] = {
    --- End diff --
    
    The more Scala-like way of writing this would be
    ```scala
    def resource_=(resource: ResourceSpec): Unit = {
        ...
    }
    ```
    That way you can write Scala code like this (and it will translate to the setter call):
    ```scala
    val stream: DataStream[MyType] = ...
    stream.resource = new Resource(a, b, c, d)
    ```
    (We have missed that in most places in Flink so far, but it may make sense to start picking up the proper Scala style for new changed)


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