vvcephei commented on a change in pull request #8955:
URL: https://github.com/apache/kafka/pull/8955#discussion_r479356312



##########
File path: 
streams/streams-scala/src/main/scala/org/apache/kafka/streams/scala/serialization/Serdes.scala
##########
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2018 Lightbend Inc. <https://www.lightbend.com>
+ * Copyright (C) 2017-2018 Alexis Seigneurin.
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.streams.scala.serialization
+
+import java.nio.ByteBuffer
+import java.util
+import java.util.UUID
+
+import org.apache.kafka.common.serialization.{Deserializer, Serde, Serializer, 
Serdes => JSerdes}
+import org.apache.kafka.streams.kstream.WindowedSerdes
+
+object Serdes extends LowPrioritySerdes {
+  implicit def stringSerde: Serde[String] = JSerdes.String()
+  implicit def longSerde: Serde[Long] = 
JSerdes.Long().asInstanceOf[Serde[Long]]
+  implicit def javaLongSerde: Serde[java.lang.Long] = JSerdes.Long()
+  implicit def byteArraySerde: Serde[Array[Byte]] = JSerdes.ByteArray()
+  implicit def bytesSerde: Serde[org.apache.kafka.common.utils.Bytes] = 
JSerdes.Bytes()
+  implicit def byteBufferSerde: Serde[ByteBuffer] = JSerdes.ByteBuffer()
+  implicit def shortSerde: Serde[Short] = 
JSerdes.Short().asInstanceOf[Serde[Short]]
+  implicit def javaShortSerde: Serde[java.lang.Short] = JSerdes.Short()
+  implicit def floatSerde: Serde[Float] = 
JSerdes.Float().asInstanceOf[Serde[Float]]
+  implicit def javaFloatSerde: Serde[java.lang.Float] = JSerdes.Float()
+  implicit def doubleSerde: Serde[Double] = 
JSerdes.Double().asInstanceOf[Serde[Double]]
+  implicit def javaDoubleSerde: Serde[java.lang.Double] = JSerdes.Double()
+  implicit def intSerde: Serde[Int] = 
JSerdes.Integer().asInstanceOf[Serde[Int]]
+  implicit def javaIntegerSerde: Serde[java.lang.Integer] = JSerdes.Integer()
+  implicit def uuidSerde: Serde[UUID] = JSerdes.UUID()
+
+  implicit def timeWindowedSerde[T](implicit tSerde: Serde[T]): 
WindowedSerdes.TimeWindowedSerde[T] =
+    new WindowedSerdes.TimeWindowedSerde[T](tSerde)

Review comment:
       Thanks @LMnet ,
   
   I agree with you about option 2, it seems unlikely to actually work 
automatically and very likely to result in confusing implicit resolution 
conflict compiler errors.
   
   (1) and (3) are both fine with me. (3) seems mildly unnecessary, since it 
would just pass through directly to the constructor of the TimeWindowedSerde. 
Just to be clear, though, I would _not_ recommend :
   
   ```scala
   def timeWindowedSerde[T](tSerde: Serde[T], properties: Properties): 
WindowedSerdes.TimeWindowedSerde[T]
   ```
   
   Rather, I'd suggest:
   ```scala
   def timeWindowedSerde[T](tSerde: Serde[T], windowSize: Long): 
WindowedSerdes.TimeWindowedSerde[T] = new 
WindowedSerdes.TimeWindowedSerde[T](tSerde, windowSize)
   ```
   
   I.e., if you're explicitly constructing the serde anyway, you might as well 
explicitly specify its parameters. The config properties are really for the 
case when the serde is reflectively constructed by the Consumer.
   
   By the way, I agree about the idea of configuring serdes to be confusing. 
It's really to support more complex serdes that store their schemas externally 
AND that are constructed reflectively by Streams. For example, instead of 
passing the serdes into the DSL at all (which is what these implicits automate 
for Scala users), you might just set `default.value.serde` to a "json serde" or 
an "avro serde" or a "schema registry serde". These things need access to the 
runtime config, and the mechanism to give it to them is to reflectively 
construct them via the zero-arg constructor and then invoke `configure()` with 
the runtime configs. On the other hand, the serdes in _this_ file, like 
UUIDSerde or LongSerde, don't need any configuration; they already fully 
specify their schemas with no additional input. The TimeWindowedSerde does need 
some additional input (the inner type and the window size). When it's 
constructed reflectively, this information has to be passed to the serde via 
configs,
  but when it's constructed by user code, we can (and should) just pass all the 
information to the constructor.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to