exceptionfactory commented on code in PR #9738: URL: https://github.com/apache/nifi/pull/9738#discussion_r1976460269
########## nifi-extension-bundles/nifi-aws-bundle/nifi-aws-processors/src/main/java/org/apache/nifi/processors/aws/kinesis/stream/record/converter/RecordConverterWrapper.java: ########## @@ -0,0 +1,75 @@ +/* + * 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.nifi.processors.aws.kinesis.stream.record.converter; + +import org.apache.nifi.serialization.SimpleRecordSchema; +import org.apache.nifi.serialization.record.MapRecord; +import org.apache.nifi.serialization.record.Record; +import org.apache.nifi.serialization.record.RecordField; +import org.apache.nifi.serialization.record.RecordFieldType; +import org.apache.nifi.serialization.record.RecordSchema; +import org.apache.nifi.util.Tuple; +import software.amazon.kinesis.retrieval.KinesisClientRecord; + +import java.time.Instant; +import java.util.*; + +public class RecordConverterWrapper implements RecordConverter { + + private static final String VALUE = "value"; + private static final String METADATA = "metadata"; + + private static final String STREAM = "aws.kinesis.stream"; + private static final String SHARD_ID = "aws.kinesis.shard.id"; + private static final String SEQUENCE_NUMBER = "aws.kinesis.sequence.number"; + private static final String PARTITION_KEY = "aws.kinesis.partition.key"; + private static final String APPROX_ARRIVAL_TIMESTAMP = "aws.kinesis.approximate.arrival.timestamp"; + + private static final RecordField FIELD_STREAM = new RecordField(STREAM, RecordFieldType.STRING.getDataType()); + private static final RecordField FIELD_SHARD_ID = new RecordField(SHARD_ID, RecordFieldType.STRING.getDataType()); + private static final RecordField FIELD_SEQUENCE_NUMBER = new RecordField(SEQUENCE_NUMBER, RecordFieldType.STRING.getDataType()); + private static final RecordField FIELD_PARTITION_KEY = new RecordField(PARTITION_KEY, RecordFieldType.STRING.getDataType()); + private static final RecordField FIELD_APPROX_ARRIVAL_TIMESTAMP = new RecordField(APPROX_ARRIVAL_TIMESTAMP, RecordFieldType.TIMESTAMP.getDataType()); + private static final RecordSchema SCHEMA_METADATA = new SimpleRecordSchema(Arrays.asList( + FIELD_STREAM, FIELD_SHARD_ID, FIELD_SEQUENCE_NUMBER, FIELD_PARTITION_KEY, FIELD_APPROX_ARRIVAL_TIMESTAMP)); + + public static final RecordField FIELD_METADATA = new RecordField(METADATA, RecordFieldType.RECORD.getRecordDataType(SCHEMA_METADATA)); + + + @Override + public Record convert(final Record record, final KinesisClientRecord kinesisRecord, final String streamName, final String shardId) { + final Tuple<String, Object> metadata = toWrapperRecordMetadata(kinesisRecord, streamName, shardId); Review Comment: I recommend refactoring this method to combine it with `toWrapperRecordMetadata` so that the creation of the `Tuple` object can be avoided. For a simple conversion method, which will be executed thousands of times, there is some value in minimizing unnecessary object creation where possible. ########## nifi-extension-bundles/nifi-aws-bundle/nifi-aws-processors/src/main/java/org/apache/nifi/processors/aws/kinesis/stream/record/converter/RecordConverterWrapper.java: ########## @@ -0,0 +1,75 @@ +/* + * 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.nifi.processors.aws.kinesis.stream.record.converter; + +import org.apache.nifi.serialization.SimpleRecordSchema; +import org.apache.nifi.serialization.record.MapRecord; +import org.apache.nifi.serialization.record.Record; +import org.apache.nifi.serialization.record.RecordField; +import org.apache.nifi.serialization.record.RecordFieldType; +import org.apache.nifi.serialization.record.RecordSchema; +import org.apache.nifi.util.Tuple; +import software.amazon.kinesis.retrieval.KinesisClientRecord; + +import java.time.Instant; +import java.util.*; Review Comment: Wildcard imports should be avoided. It can happen automatically in some cases with IntelliJ default formatting, so that may be something to check. -- 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]
