JeffBolle commented on code in PR #10995: URL: https://github.com/apache/pinot/pull/10995#discussion_r1258765974
########## pinot-plugins/pinot-stream-ingestion/pinot-pulsar/src/main/java/org/apache/pinot/plugin/stream/pulsar/PulsarMetadataExtractor.java: ########## @@ -0,0 +1,124 @@ +/** + * 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.pinot.plugin.stream.pulsar; + +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.pinot.spi.data.readers.GenericRow; +import org.apache.pinot.spi.stream.RowMetadata; +import org.apache.pulsar.client.api.Message; + + +public interface PulsarMetadataExtractor { + static PulsarMetadataExtractor build(boolean populateMetadata, boolean setRecordTimeFromEventTime) { + return message -> { + long eventTime = message.getEventTime(); + long publishTime = message.getPublishTime(); + long recordTimestamp = setRecordTimeFromEventTime ? eventTime : publishTime; + + Map<String, String> metadataMap = populateMetadataMap(populateMetadata, message); + + if (!populateMetadata) { + return new PulsarStreamMessageMetadata(recordTimestamp, null, metadataMap); + } + GenericRow headerGenericRow = buildGenericRow(message); + return new PulsarStreamMessageMetadata(recordTimestamp, headerGenericRow, metadataMap); + }; + } + + RowMetadata extract(Message<?> record); + + static GenericRow buildGenericRow(Message<?> message) { + if (MapUtils.isEmpty(message.getProperties())) { + return null; + } + GenericRow genericRow = new GenericRow(); + for (Map.Entry<String, String> entry : message.getProperties().entrySet()) { + genericRow.putValue(entry.getKey(), entry.getValue()); + } + return genericRow; + } + + static Map<String, String> populateMetadataMap(boolean populateAllFields, Message<?> message) { Review Comment: I implemented a config option with a list of fields and pushed it on a branch to give a view into what it looks like: https://github.com/Q6Cyber/pinot/compare/pulsar-headers...metadata_field_config -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
