-
Notifications
You must be signed in to change notification settings - Fork 594
Scalaapi #2673
base: master
Are you sure you want to change the base?
Scalaapi #2673
Conversation
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
@@ -0,0 +1,52 @@ | |||
licenses(["notice"]) |
There was a problem hiding this comment.
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
.
heron/api/src/scala/Builder.scala
Outdated
@@ -0,0 +1,46 @@ | |||
// |
There was a problem hiding this comment.
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
(exceptBUILD
file)
e.g: Currently, Java Streamlet API lives underheron/api/src/java/com/twitter/heron/streamlet
heron/api/src/scala/Builder.scala
Outdated
* 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] |
There was a problem hiding this comment.
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 @@ | |||
// |
There was a problem hiding this comment.
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
heron/api/src/scala/Streamlet.scala
Outdated
* 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] |
There was a problem hiding this comment.
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.
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) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) + |
There was a problem hiding this comment.
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 + |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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.
Added the first set of scala files and bazel build file that links in java implementations.