ajothomas commented on a change in pull request #1560:
URL: https://github.com/apache/samza/pull/1560#discussion_r787188642



##########
File path: 
samza-core/src/main/java/org/apache/samza/operators/impl/SendToTableOperatorImpl.java
##########
@@ -54,7 +56,12 @@ protected void handleInit(Context context) {
   @Override
   protected CompletionStage<Collection<KV<K, V>>> handleMessageAsync(KV<K, V> 
message, MessageCollector collector,
       TaskCoordinator coordinator) {
-    return table.putAsync(message.getKey(), message.getValue(), 
sendToTableOpSpec.getArgs())
+    if (message.getValue() instanceof UpdateMessage) {
+      throw new SamzaException("Incorrect use of .sendTo operator with 
UpdateMessage value type. "
+          + "Please use the following method on MessageStream- 
sendTo(Table<KV<K, UpdateMessage<U, V>>> table,"
+          + "UpdateOptions updateOptions).");

Review comment:
       I would have definitely preferred to do it during construction over 
doing it `handleAsync`. Type erasure in java complicates creating an instance 
of a generic type parameter as type V is not known until runtime. I think it's 
possible to do it using some code like below if we had the `Class<V>` as 
parameter. 
   ```
   public static class Container<E> {
       private Class<E> clazz;
   
       public Container(Class<E> clazz) {
           this.clazz = clazz;
       }
   
       public E createContents() throws Exception {
           return clazz.newInstance();
       }
   }
   ```
   Please let me know if know of any nitfy reflection hacks to get around this.




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

To unsubscribe, e-mail: [email protected]

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


Reply via email to