chenboat commented on code in PR #11210: URL: https://github.com/apache/pinot/pull/11210#discussion_r1287755010
########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/recordtransformer/JsonLogTransformer.java: ########## @@ -0,0 +1,534 @@ +/** + * 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.segment.local.recordtransformer; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.google.common.base.Preconditions; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.apache.pinot.spi.config.table.TableConfig; +import org.apache.pinot.spi.config.table.ingestion.JsonLogTransformerConfig; +import org.apache.pinot.spi.data.FieldSpec; +import org.apache.pinot.spi.data.FieldSpec.DataType; +import org.apache.pinot.spi.data.Schema; +import org.apache.pinot.spi.data.readers.GenericRow; +import org.apache.pinot.spi.stream.StreamDataDecoderImpl; +import org.apache.pinot.spi.utils.JsonUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * This transformer transforms a record representing a JSON log event such that it can be stored in a table. JSON log + * events typically have a user-defined schema, so it is impractical to store each field in its own table column. At the + * same time, most (if not all) fields are important to the user, so we should not drop any field unnecessarily. Thus, + * this transformer primarily takes record-fields that don't exist in the schema and stores them in a type of catchall + * field. + * <p> + * For example, consider this log event: + * <pre> + * { + * "timestamp": 1687786535928, + * "hostname": "host1", + * "level": "INFO", + * "message": "Started processing job1", + * "tags": { + * "platform": "data", + * "service": "serializer", + * "params": { + * "queueLength": 5, + * "timeout": 299, + * "userData_noIndex": { + * "nth": 99 + * } + * } + * } + * } + * </pre> + * And let's say the table's schema contains these fields: + * <ul> + * <li>timestamp</li> + * <li>hostname</li> + * <li>level</li> + * <li>message</li> + * <li>tags.platform</li> + * <li>tags.service</li> + * <li>indexableExtras</li> + * <li>unindexableExtras</li> + * </ul> + * <p> + * Without this transformer, the entire "tags" field would be dropped when storing the record in the table. However, + * with this transformer, the record would be transformed into the following: + * <pre> + * { + * "timestamp": 1687786535928, + * "hostname": "host1", + * "level": "INFO", + * "message": "Started processing job1", + * "tags.platform": "data", + * "tags.service": "serializer", + * "indexableExtras": { + * "tags": { + * "params": { + * "queueLength": 5, + * "timeout": 299 + * } + * } + * }, + * "unindexableExtras": { + * "tags": { + * "userData_noIndex": { + * "nth": 99 + * } + * } + * } + * } + * </pre> + * Notice that the transformer: + * <ul> + * <li>Flattens nested fields which exist in the schema, like "tags.platform"</li> Review Comment: What I meant is fields like "platform" occur multiple times under "tags". -- 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...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org