You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/07/27 08:45:35 UTC

[GitHub] [pulsar] cbornet opened a new pull request, #16816: Add doc on Record as Function output type

cbornet opened a new pull request, #16816:
URL: https://github.com/apache/pulsar/pull/16816

   ### Documentation
   
   Check the box below or label this PR directly.
   
   Need to update docs? 
   
   - [ ] `doc-required` 
   (Your PR needs to update docs and you will update later)
     
   - [ ] `doc-not-needed` 
   (Please explain why)
     
   - [x] `doc` 
   (Your PR contains doc changes)
   
   - [ ] `doc-complete`
   (Docs have been already added)


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] eolivelli commented on a diff in pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
eolivelli commented on code in PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#discussion_r933801453


##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,39 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+The return type of the `Function` can be wrapped in a Pulsar `Record` generic which gives more control on the output message (topic, schema, properties, ...)
+You can use the `Context::newOutputRecordBuilder` method to build this `Record` output.
+
+```java
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.pulsar.functions.api.Context;
+import org.apache.pulsar.functions.api.Function;
+import org.apache.pulsar.functions.api.Record;
+
+public class RecordFunction implements Function<String, Record<String>> {
+
+    @Override
+    public Record<String> process(String input, Context context) throws Exception {
+        String publishTopic = (String) context.getUserConfigValueOrDefault("publish-topic", "publishtopic");

Review Comment:
   This example is not good, with this example the function won't write to this topic (that is a  custom parameter)  but to the topic configured as output topic for the function.
   
   We should rework the example
   Otherwise it seems that the function can change the destination



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] cbornet commented on pull request #16816: Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
cbornet commented on PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#issuecomment-1196438256

   cc @momo-jun 


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] cbornet commented on a diff in pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
cbornet commented on code in PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#discussion_r933881595


##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,39 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+The return type of the `Function` can be wrapped in a Pulsar `Record` generic which gives more control on the output message (topic, schema, properties, ...)
+You can use the `Context::newOutputRecordBuilder` method to build this `Record` output.
+
+```java
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.pulsar.functions.api.Context;
+import org.apache.pulsar.functions.api.Function;
+import org.apache.pulsar.functions.api.Record;
+
+public class RecordFunction implements Function<String, Record<String>> {
+
+    @Override
+    public Record<String> process(String input, Context context) throws Exception {
+        String publishTopic = (String) context.getUserConfigValueOrDefault("publish-topic", "publishtopic");

Review Comment:
   The function *will* write to publishTopic. That's the interest of returning a Record 🙂



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] eolivelli commented on a diff in pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
eolivelli commented on code in PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#discussion_r933801453


##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,39 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+The return type of the `Function` can be wrapped in a Pulsar `Record` generic which gives more control on the output message (topic, schema, properties, ...)
+You can use the `Context::newOutputRecordBuilder` method to build this `Record` output.
+
+```java
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.pulsar.functions.api.Context;
+import org.apache.pulsar.functions.api.Function;
+import org.apache.pulsar.functions.api.Record;
+
+public class RecordFunction implements Function<String, Record<String>> {
+
+    @Override
+    public Record<String> process(String input, Context context) throws Exception {
+        String publishTopic = (String) context.getUserConfigValueOrDefault("publish-topic", "publishtopic");

Review Comment:
   This example is not good, with this example the function won't write to this topic (that is a  custom parameter)  but to the topic configured as output topic for the function.
   
   We should rework the example



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] cbornet commented on a diff in pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
cbornet commented on code in PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#discussion_r931806728


##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,13 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+:::note
+
+The return type of the `Function` can be wrapped in a Pulsar `Record` generic which gives more control on the output message (topic, schema, properties, ...)
+You can use the `Context::newOutputRecordBuilder` method to build this `Record` output.

Review Comment:
   I can do the page in the Develop section. But currently it's only available in Java.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] momo-jun commented on a diff in pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
momo-jun commented on code in PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#discussion_r931713881


##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,13 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+:::note
+
+The return type of the `Function` can be wrapped in a Pulsar `Record` generic which gives more control on the output message (topic, schema, properties, ...)
+You can use the `Context::newOutputRecordBuilder` method to build this `Record` output.

Review Comment:
   Yes, if you have a specific use case to write a function for because the current tutorial page is use-case-based.
   Or you can create a new topic under the "Develop" section to introduce the new method/context.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] cbornet commented on a diff in pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
cbornet commented on code in PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#discussion_r931187807


##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,13 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+:::note
+
+The return type of the `Function` can be wrapped in a Pulsar `Record` generic which gives more control on the output message (topic, schema, properties, ...)
+You can use the `Context::newOutputRecordBuilder` method to build this `Record` output.

Review Comment:
   Yes, sure. Is `functions-develop-tutorial` the page where it could be added ?



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] cbornet commented on a diff in pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
cbornet commented on code in PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#discussion_r933780318


##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,39 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+The return type of the `Function` can be wrapped in a Pulsar `Record` generic which gives more control on the output message (topic, schema, properties, ...)

Review Comment:
   I generally agree with the proposed changes except for inverting `generic` and `Record`. Generic here is for a Java generic (noun), it's not an adjective.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] momo-jun commented on a diff in pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
momo-jun commented on code in PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#discussion_r933327519


##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,39 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+The return type of the `Function` can be wrapped in a Pulsar `Record` generic which gives more control on the output message (topic, schema, properties, ...)

Review Comment:
   ```suggestion
   The return type of the function can be wrapped in a generic `Record` which gives you more control over the output messages, such as topics, schemas, properties, and so on.
   ```



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] momo-jun commented on a diff in pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
momo-jun commented on code in PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#discussion_r930955198


##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,13 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+:::note
+
+The return type of the `Function` can be wrapped in a Pulsar `Record` generic which gives more control on the output message (topic, schema, properties, ...)
+You can use the `Context::newOutputRecordBuilder` method to build this `Record` output.

Review Comment:
   Does it make sense to provide at least an example to show users how to use this method and what they can get?



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] cbornet commented on a diff in pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
cbornet commented on code in PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#discussion_r932300553


##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,13 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+:::note
+
+The return type of the `Function` can be wrapped in a Pulsar `Record` generic which gives more control on the output message (topic, schema, properties, ...)
+You can use the `Context::newOutputRecordBuilder` method to build this `Record` output.

Review Comment:
   It's really related to the Java API so I've put the example in the Java tab of this page.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] momo-jun commented on a diff in pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
momo-jun commented on code in PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#discussion_r933327519


##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,39 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+The return type of the `Function` can be wrapped in a Pulsar `Record` generic which gives more control on the output message (topic, schema, properties, ...)

Review Comment:
   ```suggestion
   The return type of the function can be wrapped in a generic `Record` which gives you more control over the output message, such as topic, schema, properties, and so on.
   ```



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] eolivelli commented on a diff in pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
eolivelli commented on code in PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#discussion_r949882483


##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,39 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+The return type of the function can be wrapped in a `Record` generic which gives you more control over the output messages, such as topics, schemas, properties, and so on.
+Use the `Context::newOutputRecordBuilder` method to build this `Record` output.
+
+```java
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.pulsar.functions.api.Context;
+import org.apache.pulsar.functions.api.Function;
+import org.apache.pulsar.functions.api.Record;
+
+public class RecordFunction implements Function<String, Record<String>> {
+
+    @Override
+    public Record<String> process(String input, Context context) throws Exception {
+        String publishTopic = (String) context.getUserConfigValueOrDefault("publish-topic", "publishtopic");
+        String output = String.format("%s!", input);
+
+        Map<String, String> properties = new HashMap<>(context.getCurrentRecord().getProperties());
+        context.getCurrentRecord().getTopicName().ifPresent(topic -> properties.put("input_topic", topic));
+
+        return context.<String>newOutputRecordBuilder()

Review Comment:
   please update this



##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,39 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+The return type of the `Function` can be wrapped in a Pulsar `Record` generic which gives more control on the output message (topic, schema, properties, ...)
+You can use the `Context::newOutputRecordBuilder` method to build this `Record` output.
+
+```java
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.pulsar.functions.api.Context;
+import org.apache.pulsar.functions.api.Function;
+import org.apache.pulsar.functions.api.Record;
+
+public class RecordFunction implements Function<String, Record<String>> {
+
+    @Override
+    public Record<String> process(String input, Context context) throws Exception {
+        String publishTopic = (String) context.getUserConfigValueOrDefault("publish-topic", "publishtopic");

Review Comment:
   In my opinion changing the destination (routing) is a secondary case, and it is not the core value of this feature.
   
   
   I suggest to add a second paragraph about "routing", 
   we should focus the first paragraph about the ability of setting a Schema, that is the main feature that was not available 
   
   



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] momo-jun commented on a diff in pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
momo-jun commented on code in PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#discussion_r933327519


##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,39 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+The return type of the `Function` can be wrapped in a Pulsar `Record` generic which gives more control on the output message (topic, schema, properties, ...)

Review Comment:
   ```suggestion
   The return type of the function can be wrapped in a `Record` generic which gives you more control over the output messages, such as topics, schemas, properties, and so on.
   ```



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] momo-jun commented on a diff in pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
momo-jun commented on code in PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#discussion_r934157243


##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,39 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+The return type of the `Function` can be wrapped in a Pulsar `Record` generic which gives more control on the output message (topic, schema, properties, ...)

Review Comment:
   Got your point. I've updated my suggestion.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] cbornet commented on a diff in pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
cbornet commented on code in PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#discussion_r936750055


##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,39 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+The return type of the `Function` can be wrapped in a Pulsar `Record` generic which gives more control on the output message (topic, schema, properties, ...)
+You can use the `Context::newOutputRecordBuilder` method to build this `Record` output.

Review Comment:
   I changed `You can use` to just `Use`.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] cbornet commented on a diff in pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
cbornet commented on code in PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#discussion_r949932680


##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,39 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+The return type of the `Function` can be wrapped in a Pulsar `Record` generic which gives more control on the output message (topic, schema, properties, ...)
+You can use the `Context::newOutputRecordBuilder` method to build this `Record` output.
+
+```java
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.pulsar.functions.api.Context;
+import org.apache.pulsar.functions.api.Function;
+import org.apache.pulsar.functions.api.Record;
+
+public class RecordFunction implements Function<String, Record<String>> {
+
+    @Override
+    public Record<String> process(String input, Context context) throws Exception {
+        String publishTopic = (String) context.getUserConfigValueOrDefault("publish-topic", "publishtopic");

Review Comment:
   I removed the destinationTopic part.



##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,39 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+The return type of the function can be wrapped in a `Record` generic which gives you more control over the output messages, such as topics, schemas, properties, and so on.
+Use the `Context::newOutputRecordBuilder` method to build this `Record` output.
+
+```java
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.pulsar.functions.api.Context;
+import org.apache.pulsar.functions.api.Function;
+import org.apache.pulsar.functions.api.Record;
+
+public class RecordFunction implements Function<String, Record<String>> {
+
+    @Override
+    public Record<String> process(String input, Context context) throws Exception {
+        String publishTopic = (String) context.getUserConfigValueOrDefault("publish-topic", "publishtopic");
+        String output = String.format("%s!", input);
+
+        Map<String, String> properties = new HashMap<>(context.getCurrentRecord().getProperties());
+        context.getCurrentRecord().getTopicName().ifPresent(topic -> properties.put("input_topic", topic));
+
+        return context.<String>newOutputRecordBuilder()

Review Comment:
   done



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] momo-jun commented on pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
momo-jun commented on PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#issuecomment-1196635841

   @cbornet thanks for adding the docs for #16041. I left a comment and I think adding more context would be helpful.


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] Anonymitaet merged pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
Anonymitaet merged PR #16816:
URL: https://github.com/apache/pulsar/pull/16816


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] momo-jun commented on pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
momo-jun commented on PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#issuecomment-1222057626

   Ping @Anonymitaet for review and labeling.


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] eolivelli commented on a diff in pull request #16816: [improve][doc] Add doc on Record as Function output type

Posted by GitBox <gi...@apache.org>.
eolivelli commented on code in PR #16816:
URL: https://github.com/apache/pulsar/pull/16816#discussion_r933801289


##########
site2/docs/functions-develop-api.md:
##########
@@ -102,6 +102,39 @@ public class ExclamationFunction implements Function<String, String> {
 
 For more details, see [code example](https://github.com/apache/pulsar/blob/master/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/ExclamationFunction.java).
 
+The return type of the `Function` can be wrapped in a Pulsar `Record` generic which gives more control on the output message (topic, schema, properties, ...)
+You can use the `Context::newOutputRecordBuilder` method to build this `Record` output.

Review Comment:
   I would say you 'must' and not you 'can'. (Even if we don't enforce that in the code)
   This is stronger and we really don't want users to build their own implementations of Record.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org