FrankChen021 commented on code in PR #19379: URL: https://github.com/apache/druid/pull/19379#discussion_r3147672255
########## processing/src/main/java/org/apache/druid/segment/transform/ScanTransform.java: ########## @@ -0,0 +1,268 @@ +/* + * 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.druid.segment.transform; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.druid.data.input.InputRow; +import org.apache.druid.data.input.MapBasedInputRow; +import org.apache.druid.java.util.common.Intervals; +import org.apache.druid.java.util.common.guava.Sequences; +import org.apache.druid.query.filter.DimFilter; +import org.apache.druid.segment.BaseObjectColumnValueSelector; +import org.apache.druid.segment.ColumnSelectorFactory; +import org.apache.druid.segment.Cursor; +import org.apache.druid.segment.CursorBuildSpec; +import org.apache.druid.segment.CursorFactory; +import org.apache.druid.segment.CursorHolder; +import org.apache.druid.segment.RowAdapters; +import org.apache.druid.segment.RowBasedSegment; +import org.apache.druid.segment.UnnestCursorFactory; +import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.ColumnHolder; +import org.apache.druid.segment.column.ColumnType; +import org.apache.druid.segment.column.RowSignature; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +/** + * A multi-row transform that unnests array columns during ingestion using the cursor-based unnest machinery. + * Each input row is wrapped in a single-row segment, the unnest cursor iterates over array elements, + * and each element becomes a separate output row. + * + * If the unnest column is missing or the array is empty, the input row passes through with the + * unnest output column set to null. + */ +public class ScanTransform implements Transform +{ + private final String name; + private final VirtualColumn unnestColumn; + @Nullable + private final DimFilter unnestFilter; + + @JsonCreator + public ScanTransform( + @JsonProperty("name") final String name, + @JsonProperty("unnestColumn") final VirtualColumn unnestColumn, + @JsonProperty("unnestFilter") @Nullable final DimFilter unnestFilter + ) + { + this.name = name; Review Comment: [P2] Validate scan transform output name ScanTransform stores `name` separately from `unnestColumn.getOutputName()`, but the transform framework treats `Transform.getName()` as the generated field name for collision checks and input-column pruning. If a spec sets `name: "tag"` but the virtual column outputs `"elt"`, Druid accepts it, writes `elt`, and silently leaves references to `tag` unresolved while also missing collisions on `elt`. Reject mismatches or derive the transform name from the virtual column output. -- 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]
