@@ -240,4 +240,44 @@ uint64_t IcebergSplitReader::next(uint64_t size, VectorPtr& output) {
240240 return rowsScanned;
241241}
242242
243+ std::vector<TypePtr> IcebergSplitReader::adaptColumns (
244+ const RowTypePtr& fileType,
245+ const std::shared_ptr<const velox::RowType>& tableSchema) const {
246+ // Keep track of schema types for columns in file, used by ColumnSelector.
247+ std::vector<TypePtr> columnTypes = fileType->children ();
248+ auto & childrenSpecs = scanSpec_->children ();
249+ // Iceberg table stores all column's data in data file.
250+ for (size_t i = 0 ; i < childrenSpecs.size (); ++i) {
251+ auto * childSpec = childrenSpecs[i].get ();
252+ const std::string& fieldName = childSpec->fieldName ();
253+ auto fileTypeIdx = fileType->getChildIdxIfExists (fieldName);
254+ auto outputTypeIdx = readerOutputType_->getChildIdxIfExists (fieldName);
255+ if (outputTypeIdx.has_value () && fileTypeIdx.has_value ()) {
256+ childSpec->setConstantValue (nullptr );
257+ auto & outputType = readerOutputType_->childAt (*outputTypeIdx);
258+ columnTypes[*fileTypeIdx] = outputType;
259+ } else if (!fileTypeIdx.has_value ()) {
260+ // Handle columns missing from the data file in two scenarios:
261+ // 1. Schema evolution: Column was added after the data file was written
262+ // and doesn't exist in older data files.
263+ // 2. Partition columns: In Hive-written data files, partition column
264+ // values are stored in partition metadata rather than in the data
265+ // file itself, following Hive's partitioning convention.
266+ if (auto it = hiveSplit_->partitionKeys .find (fieldName);
267+ it != hiveSplit_->partitionKeys .end ()) {
268+ setPartitionValue (childSpec, fieldName, it->second );
269+ } else {
270+ childSpec->setConstantValue (BaseVector::createNullConstant (
271+ tableSchema->findChild (fieldName),
272+ 1 ,
273+ connectorQueryCtx_->memoryPool ()));
274+ }
275+ }
276+ }
277+
278+ scanSpec_->resetCachedValues (false );
279+
280+ return columnTypes;
281+ }
282+
243283} // namespace facebook::velox::connector::hive::iceberg
0 commit comments