rohityadav1993 commented on code in PR #16727: URL: https://github.com/apache/pinot/pull/16727#discussion_r2366361527
########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/readers/PinotSegmentColumnReaderImpl.java: ########## @@ -0,0 +1,146 @@ +/** + * 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.segment.readers; + +import java.io.IOException; +import javax.annotation.Nullable; +import org.apache.pinot.common.utils.PinotDataType; +import org.apache.pinot.segment.local.recordtransformer.DataTypeTransformer; +import org.apache.pinot.segment.spi.IndexSegment; +import org.apache.pinot.spi.data.FieldSpec; +import org.apache.pinot.spi.data.readers.ColumnReader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Implementation of ColumnReader for Pinot segments. + * + * <p>This class wraps the existing PinotSegmentColumnReader and provides the ColumnReader interface + * for columnar segment building. It handles: + * <ul> + * <li>Reading column values from Pinot segments</li> + * <li>Data type conversions when target schema differs from source</li> + * <li>Null value detection</li> + * <li>Resource cleanup</li> + * </ul> + */ +public class PinotSegmentColumnReaderImpl implements ColumnReader { + private static final Logger LOGGER = LoggerFactory.getLogger(PinotSegmentColumnReaderImpl.class); + + private final PinotSegmentColumnReader _segmentColumnReader; + private final String _columnName; + private final int _numDocs; + private final boolean _needsConversion; + private final FieldSpec _targetFieldSpec; + + private int _currentIndex; + private Object _currentValue; + private boolean _currentIsNull; + + /** + * Create a PinotSegmentColumnReaderImpl for an existing column in the segment. + * + * @param indexSegment Source segment to read from + * @param columnName Name of the column + * @param targetFieldSpec Target field specification (may differ from source for data type conversion) + */ + public PinotSegmentColumnReaderImpl(IndexSegment indexSegment, String columnName, FieldSpec targetFieldSpec) { + _segmentColumnReader = new PinotSegmentColumnReader(indexSegment, columnName); + _columnName = columnName; + _numDocs = indexSegment.getSegmentMetadata().getTotalDocs(); + _targetFieldSpec = targetFieldSpec; + _currentIndex = 0; + + // Check if data type conversion is needed + FieldSpec sourceFieldSpec = indexSegment.getSegmentMetadata().getSchema().getFieldSpecFor(columnName); + _needsConversion = sourceFieldSpec != null Review Comment: This was a conscious decision to not support `RecordTransformer`. Supporting `RecordTransformer` and getting columnar benefits would be a complex logic. See current implementation of transformPipeline of records: https://github.com/apache/pinot/blob/7f60f1316030059b538d299c91e056b29735c609/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/SegmentIndexCreationDriverImpl.java#L293 For external sources, it may even be more convenient to remodel data externally (e.g. spark job) -- 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]
