eolivelli commented on code in PR #16041: URL: https://github.com/apache/pulsar/pull/16041#discussion_r896487789
########## pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionCommon.java: ########## @@ -120,8 +121,20 @@ public static Class<?>[] getFunctionTypes(Class userClass, boolean isWindowConfi } else { if (Function.class.isAssignableFrom(userClass)) { typeArgs = TypeResolver.resolveRawArguments(Function.class, userClass); + if (typeArgs[1].equals(Record.class)) { Review Comment: we need some unit test coverage for these branches ########## pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/utils/FunctionRecord.java: ########## @@ -0,0 +1,109 @@ +/** + * 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.api.utils; + +import java.util.Map; +import java.util.Optional; +import lombok.Builder; +import org.apache.pulsar.client.api.Schema; +import org.apache.pulsar.functions.api.Context; +import org.apache.pulsar.functions.api.Record; + +@Builder(builderMethodName = "") +public class FunctionRecord<T> implements Record<T> { + + private final T value; + private final String topicName; + private final String destinationTopic; + private final Map<String, String> properties; + private final String key; + private final Schema<T> schema; + private final Long eventTime; + private final String partitionId; + private final Integer partitionIndex; + private final Long recordSequence; + + public static <T> FunctionRecord.FunctionRecordBuilder<T> from(Context context) { + Record<?> currentRecord = context.getCurrentRecord(); + FunctionRecordBuilder<T> builder = new FunctionRecordBuilder<T>() + .destinationTopic(context.getOutputTopic()) + .properties(currentRecord.getProperties()); + currentRecord.getTopicName().ifPresent(builder::topicName); + currentRecord.getKey().ifPresent(builder::key); + currentRecord.getEventTime().ifPresent(builder::eventTime); + currentRecord.getPartitionId().ifPresent(builder::partitionId); + currentRecord.getPartitionIndex().ifPresent(builder::partitionIndex); + currentRecord.getRecordSequence().ifPresent(builder::recordSequence); + + // TODO: add message Review Comment: if you want to do this, please create a ticket and link it, otherwise please remove this "TODO" TODOs are usually some kind of code smell, especially in a big open source project like Pulsar. we could explain why the "message" is not available here ########## tests/integration/src/test/java/org/apache/pulsar/tests/integration/functions/java/PulsarFunctionsJavaTest.java: ########## @@ -166,7 +166,7 @@ public void testSlidingCountWindowTest() throws Exception { @Test(groups = {"java_function", "function"}) public void testMergeFunctionTest() throws Exception { testMergeFunction(); - } + } Review Comment: nit: remove space ########## pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/utils/FunctionRecord.java: ########## @@ -0,0 +1,109 @@ +/** + * 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.api.utils; + +import java.util.Map; +import java.util.Optional; +import lombok.Builder; +import org.apache.pulsar.client.api.Schema; +import org.apache.pulsar.functions.api.Context; +import org.apache.pulsar.functions.api.Record; + +@Builder(builderMethodName = "") +public class FunctionRecord<T> implements Record<T> { + + private final T value; + private final String topicName; + private final String destinationTopic; + private final Map<String, String> properties; + private final String key; + private final Schema<T> schema; + private final Long eventTime; + private final String partitionId; + private final Integer partitionIndex; + private final Long recordSequence; + + public static <T> FunctionRecord.FunctionRecordBuilder<T> from(Context context) { Review Comment: we need unit test coverage for this method (ensure that every field is properly handled) ########## pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/Context.java: ########## @@ -161,4 +162,11 @@ public interface Context extends BaseContext { * @throws PulsarClientException */ <X> ConsumerBuilder<X> newConsumerBuilder(Schema<X> schema) throws PulsarClientException; + + /** + * Create a FunctionRecordBuilder. Review Comment: please explain a little bit how this is supposed to be used. -- 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-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org