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/06/06 10:58:46 UTC

[GitHub] [pulsar] cbornet commented on a diff in pull request #15903: [feature][functions]Create a built-in Function implementing the most common basic transformations

cbornet commented on code in PR #15903:
URL: https://github.com/apache/pulsar/pull/15903#discussion_r890040559


##########
pulsar-functions/transforms/src/main/java/org/apache/pulsar/functions/transforms/TransformContext.java:
##########
@@ -0,0 +1,131 @@
+/**
+ * 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.pulsar.functions.transforms;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Map;
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.avro.generic.GenericDatumWriter;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.io.BinaryEncoder;
+import org.apache.avro.io.EncoderFactory;
+import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.client.api.TypedMessageBuilder;
+import org.apache.pulsar.client.api.schema.GenericObject;
+import org.apache.pulsar.client.api.schema.KeyValueSchema;
+import org.apache.pulsar.common.schema.KeyValue;
+import org.apache.pulsar.common.schema.KeyValueEncodingType;
+import org.apache.pulsar.common.schema.SchemaType;
+import org.apache.pulsar.functions.api.Context;
+import org.apache.pulsar.functions.api.Record;
+
+@Slf4j
+@Data
+public class TransformContext {
+    private Context context;
+    private Schema<?> keySchema;
+    private Object keyObject;
+    private boolean keyModified;
+    private Schema<?> valueSchema;
+    private Object valueObject;
+    private boolean valueModified;
+    private KeyValueEncodingType keyValueEncodingType;
+    private String key;
+    private Map<String, String> properties;
+    private String outputTopic;
+
+    public TransformContext(Context context, Object value) {
+        Record<?> currentRecord = context.getCurrentRecord();
+        this.context = context;
+        this.outputTopic = context.getOutputTopic();
+        Schema<?> schema = currentRecord.getSchema();
+        //TODO: should we make a copy ?

Review Comment:
   That's the thing. We want to give the possibility of steps to modify the properties. Wrapping in an unmodifiable map is a good idea as the step would have to make the copy itself.



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