Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Scalaapi #2673

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Scalaapi #2673

wants to merge 10 commits into from

Conversation

skanjila
Copy link
Contributor

Added the first set of scala files and bazel build file that links in java implementations.

skanjila and others added 5 commits January 20, 2018 15:31
move scripts/docker to scripts/images (#2672)

* build docker images in build-artifacts.sh

* rename scripts/docker to scripts/images for building docker images

added all new scala files from converter
@CLAassistant
Copy link

CLAassistant commented Jan 20, 2018

CLA assistant check
All committers have signed the CLA.

@@ -0,0 +1,52 @@
licenses(["notice"])
Copy link
Member

Choose a reason for hiding this comment

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

General BUILD Comment:
*.scala files are not referenced here. Bazel supports Scala via
https://github.com/bazelbuild/rules_scala
so i think we need to use scala_library to compile scala files by referencing
com/twitter/heron/streamlet/scala/**/*.scala as src.

@@ -0,0 +1,46 @@
//
Copy link
Member

Choose a reason for hiding this comment

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

General Comment:
Currently, All files look living under heron/api/src/scala.

  • Related *.scala files should be under package: heron/api/src/scala/com/twitter/heron/streamlet/scala (except BUILD file)
    e.g: Currently, Java Streamlet API lives under heron/api/src/java/com/twitter/heron/streamlet

* All sources of the computation should register using addSource.
* @param supplier The supplier function that is used to create the streamlet
*/
def newSource[R](supplier: SerializableSupplier[R]): Streamlet[R]
Copy link
Member

Choose a reason for hiding this comment

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

In the light of Scala User perspective and in my opinion, All exposed Scala Traits should be pure scala. This means Scala traits should accept Scala Functions instead of FunctionalInterface here:

def newSource[R](supplier: () => R): Streamlet[R]

instead of

def newSource[R](supplier: SerializableSupplier[R]): Streamlet[R]

@@ -0,0 +1,28 @@
//
Copy link
Member

Choose a reason for hiding this comment

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

General Serializable-FunctionalInterfaces Comment
I think all Serializable Functional Interfaces(SerializableFunction, SerializableConsumer etc...) should be hidden from Scala Users. This means Scala API should just accept pure Scala functions instead of them. In the light of this, i think we do not need to have these Serializable interfaces' s Scala versions. These can be wrapped at Scala StreamletImpl level by transforming incoming Scala Function to related SerializableFunctionalInterface

* Return a new Streamlet by applying mapFn to each element of this Streamlet
* @param mapFn The Map Function that should be applied to each element
*/
def map[T](mapFn: SerializableFunction[R, _ <: T]): Streamlet[T]
Copy link
Member

Choose a reason for hiding this comment

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

In the light of my previous comment, as a sample for map function, i think this should be as follows.
def map[T](mapFn: R => _ <: T): Streamlet[T]
instead of
def map[T](mapFn: SerializableFunction[R, _ <: T]): Streamlet[T]

Same comment for the following functions.

skanjila and others added 5 commits January 21, 2018 09:53
move scripts/docker to scripts/images (#2672)

* build docker images in build-artifacts.sh

* rename scripts/docker to scripts/images for building docker images

* added scala build files and bazel file
move scripts/docker to scripts/images (#2672)

* build docker images in build-artifacts.sh

* rename scripts/docker to scripts/images for building docker images

added all new scala files from converter

added all new scala files from converter again

added all new scala files from converter

added all new scala files from converter again

code reorganization and added some bits to build file to use scala plugin
* user-defined key/value pairs are passed on to the topology runner via
* this class.
*/
@SerialVersionUID(6204498077403076352L)
Copy link
Contributor

Choose a reason for hiding this comment

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

UIDs seem to be the same as Java version. Just to confirm if this what we want or not.

def newBuilder(): Builder = new Builder()

private def translateSemantics(semantics: DeliverySemantics)
: com.twitter.heron.api.Config.TopologyReliabilityMode = semantics match {
Copy link
Contributor

Choose a reason for hiding this comment

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

consider import the package as
import com.twitter.heron.api.{Config => ApiConfig}

then use ApiConfig.TopologyReliabilityMode, etc

instead of full path.

* serialized between components.
*/
@SerialVersionUID(-7120757965590727554L)
class KeyValue[K, V]() extends Serializable {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if we can use case class here? if it is not expected to be extended.

case class KeyValue[K, V](
@BeanProperty val key: K,
@BeanProperty val value V) {
override def toString() = ....
}

val or var depending on the usage.

* using this class
*/
@SerialVersionUID(4193319775040181971L)
class KeyedWindow[T]() extends Serializable {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as KeyValue, maybe case class if possible.

def run(name: String, config: Config, builder: Builder): Unit = {
val bldr: BuilderImpl = builder.asInstanceOf[BuilderImpl]
val topologyBuilder: TopologyBuilder = bldr.build()
try HeronSubmitter.submitTopology(name,
Copy link
Contributor

Choose a reason for hiding this comment

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

suggest to add {}.

try {
...
} catch {
...
}

* @param builder The builder used to keep track of the sources.
*/
def run(name: String, config: Config, builder: Builder): Unit = {
val bldr: BuilderImpl = builder.asInstanceOf[BuilderImpl]
Copy link
Contributor

Choose a reason for hiding this comment

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

is this line necessary?

* inside their streamlets using this container.
*/
@SerialVersionUID(5103471810104775854L)
class Window() extends Serializable {
Copy link
Contributor

Choose a reason for hiding this comment

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

another candidate to be case class.

}

override def toString(): String =
"{ " + String.valueOf(key) + " : " + String.valueOf(value) +
Copy link
Member

Choose a reason for hiding this comment

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

can't we just use "{ " + key + " : " + value + " }"?

}

override def toString(): String =
"{ Key: " + String.valueOf(key) + " Window: " + window.toString +
Copy link
Member

Choose a reason for hiding this comment

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

do we really need String.valueOf or toString? if you just "{ key: " + key + " window: " + window + " }", it is better than explicitly call toString, because it handles null field, while window.toString would throw NPE if window is null.

* Return a new Streamlet by applying mapFn to each element of this Streamlet
* @param mapFn The Map Function that should be applied to each element
*/
def map[T](mapFn: SerializableFunction[R, _ <: T]): Streamlet[T]
Copy link
Member

Choose a reason for hiding this comment

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

SerializableFunction is a java function, not a scala function. which I think you can't really use all those scala syntactic sugar. if we are generating a scala oriented api, it would be better to think about taking scala function, rather than using java functions.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants