Shekharrajak commented on code in PR #19266: URL: https://github.com/apache/druid/pull/19266#discussion_r3254176806
########## extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergNativeRecordReader.java: ########## @@ -0,0 +1,335 @@ +/* + * 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.iceberg.input; + +import org.apache.druid.data.input.InputRow; +import org.apache.druid.data.input.InputRowListPlusRawValues; +import org.apache.druid.data.input.InputRowSchema; +import org.apache.druid.data.input.InputSourceFactory; +import org.apache.druid.data.input.InputSourceReader; +import org.apache.druid.data.input.InputStats; +import org.apache.druid.data.input.impl.MapInputRowParser; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.java.util.common.parsers.CloseableIterator; +import org.apache.hadoop.conf.Configuration; +import org.apache.iceberg.Schema; +import org.apache.iceberg.SchemaParser; +import org.apache.iceberg.data.Record; +import org.apache.iceberg.data.parquet.GenericParquetReaders; +import org.apache.iceberg.hadoop.HadoopInputFile; +import org.apache.iceberg.io.CloseableIterable; +import org.apache.iceberg.io.DeleteSchemaUtil; +import org.apache.iceberg.io.InputFile; +import org.apache.iceberg.parquet.Parquet; +import org.apache.iceberg.types.Types; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; + +/** + * An {@link InputSourceReader} that reads an Iceberg data file and applies + * associated positional and equality delete files before converting records + * to Druid {@link InputRow} objects. + * + * Delete application follows the Iceberg v2 spec: + * <ol> + * <li>Positional deletes: read (file_path, pos) pairs, filter by current data file, + * build a Set of deleted positions</li> + * <li>Equality deletes: read key tuples from equality delete files, build Sets + * of deleted key values per equality field set</li> + * <li>Stream data file: for each record, skip if position-deleted or equality-deleted</li> + * </ol> + * + * All reads use Iceberg's Parquet reader with {@link GenericParquetReaders} for + * schema-aware reading. Files are accessed via Hadoop {@link Configuration}. + */ +public class IcebergNativeRecordReader implements InputSourceReader +{ + private static final Logger log = new Logger(IcebergNativeRecordReader.class); + + private final String dataFilePath; + private final List<DeleteFileInfo> deleteFiles; + private final String tableSchemaJson; + private final InputSourceFactory warehouseSource; + private final InputRowSchema inputRowSchema; + private final Configuration hadoopConf; + + public IcebergNativeRecordReader( + final String dataFilePath, + final List<DeleteFileInfo> deleteFiles, + final String tableSchemaJson, + final InputSourceFactory warehouseSource, + final InputRowSchema inputRowSchema + ) + { + this.dataFilePath = dataFilePath; + this.deleteFiles = deleteFiles; + this.tableSchemaJson = tableSchemaJson; + this.warehouseSource = warehouseSource; + this.inputRowSchema = inputRowSchema; + this.hadoopConf = new Configuration(); + } + + @Override + public CloseableIterator<InputRow> read(final InputStats inputStats) throws IOException + { + final Schema tableSchema = SchemaParser.fromJson(tableSchemaJson); + + // Step 1: Collect positional deletes + final Set<Long> deletedPositions = collectPositionalDeletes(); + + // Step 2: Collect equality deletes + final List<EqualityDeleteSet> equalityDeleteSets = collectEqualityDeletes(tableSchema); + + // Step 3: Stream data file with delete application + final InputFile dataInputFile = HadoopInputFile.fromLocation(dataFilePath, hadoopConf); Review Comment: Thanks for checking - updated : https://github.com/apache/druid/pull/19266/changes/23ef4dbe6c910b238c0379943b58f7fe2d954d51#diff-1b9776e43fa17c32a610eee043a6fd6cbf32b29ae4026d24ea798ac9a6f638bcR299 -- 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]
