Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-6658][cep] Use scala Collections in scala CEP API #3963

Closed
wants to merge 4 commits into from

Conversation

dawidwys
Copy link
Contributor

Thanks for contributing to Apache Flink. Before you open your pull request, please take the following check list into consideration.
If your changes take all of the items into account, feel free to open your pull request. For more information and/or questions please refer to the How To Contribute guide.
In addition to going through the list, please provide a meaningful description of your changes.

  • General

    • The pull request references the related JIRA issue ("[FLINK-XXX] Jira title text")
    • The pull request addresses only one issue
    • Each commit in the PR has a meaningful commit message (including the JIRA id)
  • Documentation

    • Documentation has been added for new functionality
    • Old documentation affected by the pull request has been updated
    • JavaDoc for public methods has been added
  • Tests & Build

    • Functionality added by the pull request is covered by tests
    • mvn clean verify has been executed successfully locally or a Travis build has passed

@dawidwys dawidwys changed the title [FLINK-6658] Use scala Collections in scala CEP API [FLINK-6658][cep] Use scala Collections in scala CEP API May 22, 2017
}

private[flink] def mapToScala[T](map: JMap[String, JList[T]]): Map[String, Iterable[T]] = {
map.asScala.mapValues(_.asScala.toIterable).toMap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not getting rid of the last .toMap and return a collection.Map? This will avoid an iteration over the elements of the JMap which is important given that this method will be invoked at every incoming element. From the rest, I think we are ok as the asScalas are just wrappers and the .mapValues are lazily evaluated.

pattern: JMap[String, JList[T]],
timeoutTimestamp: Long, out: Collector[L])
: Unit = {
cleanTimeoutFun(mapToScala(pattern), timeoutTimestamp, out)
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the following two methods added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the scala way of applying flatFunction. We also provide both of those alternatives for e.g. DataStream#flatMap.

Copy link
Contributor

@kl0u kl0u May 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to the 2 methods that follow :) . The ones that for example use the foreach (lines 332 and 366).

Copy link
Contributor Author

@dawidwys dawidwys May 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I am also referring to those methods. :) In fact I should write all three of those alternatives.

The version that results with a TraversableOnce is important for composable style of programming in scala. Scala supports constructs like transform1 andThen transform2 which can be applied only in the case with a meaningful return value (not in case of Unit).

* @param name The name of the pattern.
*/
def apply(name: String): Iterable[T]
}
Copy link
Contributor

@kl0u kl0u May 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why having different method names between Java and Scala? In Java this method is called getEventsForPattern(). I would suggest that same methods should have the same name and also, specifically for this, writing context(stateName) does not really seem nice. If you agree I can change it and then merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right I was also not really decided on that one. Of course you can change it.

@kl0u
Copy link
Contributor

kl0u commented May 26, 2017

@dawidwys merged this. Could you close the PR and the related JIRA?

@dawidwys dawidwys closed this May 27, 2017
@dawidwys dawidwys deleted the cep-scala-api branch May 27, 2017 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants