You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by sa...@apache.org on 2018/07/12 21:26:54 UTC

[incubator-pulsar] branch master updated: Minor bug-fixes to examples (#2145)

This is an automated email from the ASF dual-hosted git repository.

sanjeevrk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 2f38b89  Minor bug-fixes to examples (#2145)
2f38b89 is described below

commit 2f38b8965521a3169601430b4ad922f16e62e678
Author: Sanjeev Kulkarni <sa...@gmail.com>
AuthorDate: Thu Jul 12 14:26:52 2018 -0700

    Minor bug-fixes to examples (#2145)
    
    * Minor bug-fixes to examples
    
    * method overloading in python is via default arguments
    
    * Bring implementation up to date with interface
---
 pulsar-client-cpp/python/pulsar/functions/context.py             | 9 ++-------
 pulsar-functions/instance/src/main/python/contextimpl.py         | 5 +----
 pulsar-functions/python-examples/config_based_append_function.py | 4 ++--
 pulsar-functions/python-examples/publish_function.py             | 2 +-
 4 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/pulsar-client-cpp/python/pulsar/functions/context.py b/pulsar-client-cpp/python/pulsar/functions/context.py
index 0257b69..ed1164a 100644
--- a/pulsar-client-cpp/python/pulsar/functions/context.py
+++ b/pulsar-client-cpp/python/pulsar/functions/context.py
@@ -104,16 +104,11 @@ class Context(object):
     pass
 
   @abstractmethod
-  def publish(self, topic_name, message, serde_class_name):
+  def publish(self, topic_name, message, serde_class_name="serde.IdentitySerDe"):
     """Publishes message to topic_name by first serializing the message using serde_class_name serde"""
     pass
 
   @abstractmethod
-  def publish(self, topic_name, message):
-    """Publishes message to topic_name by first serializing the message using IdentitySerDe"""
-    pass
-
-  @abstractmethod
   def get_output_topic(self):
     """Returns the output topic of function"""
     pass
@@ -126,4 +121,4 @@ class Context(object):
   @abstractmethod
   def ack(self, msgid, topic):
     """ack this message id"""
-    pass
\ No newline at end of file
+    pass
diff --git a/pulsar-functions/instance/src/main/python/contextimpl.py b/pulsar-functions/instance/src/main/python/contextimpl.py
index 35a5443..9f4a34f 100644
--- a/pulsar-functions/instance/src/main/python/contextimpl.py
+++ b/pulsar-functions/instance/src/main/python/contextimpl.py
@@ -117,10 +117,7 @@ class ContextImpl(pulsar.Context):
   def get_output_serde_class_name(self):
     return self.instance_config.function_details.outputSerdeClassName
 
-  def publish(self, topic_name, message):
-    return self.publish(topic_name, message, "serde.IdentitySerDe")
-
-  def publish(self, topic_name, message, serde_class_name):
+  def publish(self, topic_name, message, serde_class_name="serde.IdentitySerDe"):
     # Just make sure that user supplied values are properly typed
     topic_name = str(topic_name)
     serde_class_name = str(serde_class_name)
diff --git a/pulsar-functions/python-examples/config_based_append_function.py b/pulsar-functions/python-examples/config_based_append_function.py
index 3459736..5608cbd 100755
--- a/pulsar-functions/python-examples/config_based_append_function.py
+++ b/pulsar-functions/python-examples/config_based_append_function.py
@@ -29,6 +29,6 @@ class ConfigBasedAppendFunction(Function):
   def process(self, input, context):
     key = "config-key"
     append_value = "!"
-    if key in context.get_user_config_map:
-      append_value = context.get_user_config_value(append_value)
+    if key in context.get_user_config_map():
+      append_value = context.get_user_config_value(key)
     return input + append_value
diff --git a/pulsar-functions/python-examples/publish_function.py b/pulsar-functions/python-examples/publish_function.py
index c0c3c91..e06a61c 100755
--- a/pulsar-functions/python-examples/publish_function.py
+++ b/pulsar-functions/python-examples/publish_function.py
@@ -29,7 +29,7 @@ class PublishFunction(Function):
 
   def process(self, input, context):
     publish_topic = "publishtopic"
-    if "publish-topic" in context.get_user_config_map:
+    if "publish-topic" in context.get_user_config_map():
       publish_topic = context.get_user_config_value("publish-topic")
     context.publish(publish_topic, input + '!')
     return