| 304 | } |
| 305 | |
| 306 | Status FileMetadataUtils::AdjustFieldIdForMigratedPartitionedTables(int *fieldID) const { |
| 307 | DCHECK(file_desc_ != nullptr); |
| 308 | DCHECK(scan_node_->hdfs_table()->IsIcebergTable()); |
| 309 | DCHECK(fieldID != nullptr); |
| 310 | |
| 311 | using namespace org::apache::impala::fb; |
| 312 | |
| 313 | auto transforms = IcebergPartitionTransforms(); |
| 314 | if (transforms == nullptr || transforms->size() == 0) return Status::OK(); |
| 315 | |
| 316 | vector<int> sourceIDs; |
| 317 | sourceIDs.reserve(transforms->size()); |
| 318 | for (auto transform : *transforms) { |
| 319 | if (transform->transform_type() != |
| 320 | FbIcebergTransformType::FbIcebergTransformType_IDENTITY) { |
| 321 | return Status(Substitute("$0 has invalid partition transform: $1", |
| 322 | file_desc_->filename, transform->transform_type())); |
| 323 | } |
| 324 | sourceIDs.push_back(transform->source_id()); |
| 325 | } |
| 326 | |
| 327 | DCHECK_EQ(sourceIDs.size(), transforms->size()); |
| 328 | sort(sourceIDs.begin(), sourceIDs.end()); |
| 329 | |
| 330 | string errorMsg = Substitute( |
| 331 | "Migrated file $0 has unexpected schema or partitioning.", file_desc_->filename); |
| 332 | |
| 333 | // Field IDs must be consecutive. |
| 334 | for (int i = 0; i < sourceIDs.size() - 1; ++i) { |
| 335 | if (sourceIDs[i+1] - sourceIDs[i] != 1) { |
| 336 | return Status(errorMsg); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | int fileFieldID = *fieldID; |
| 341 | |
| 342 | if (sourceIDs.front() == fileFieldID) { |
| 343 | // Partition columns are not stored in the data file (as expected). |
| 344 | // In this case we need to adjust fieldID (as it was calculated based on |
| 345 | // the file schema only). |
| 346 | *fieldID += sourceIDs.size(); |
| 347 | } else if (sourceIDs.back() == fileFieldID - 1) { |
| 348 | // Partition columns are stored in the data file, no need to adjust fieldID. |
| 349 | } else { |
| 350 | // Some partitions are stored, some aren't let's raise an error for this mess. |
| 351 | return Status(errorMsg); |
| 352 | } |
| 353 | |
| 354 | return Status::OK(); |
| 355 | } |
| 356 | |
| 357 | bool FileMetadataUtils::NeedDataInFile(const SlotDescriptor* slot_desc) { |
| 358 | if (IsValuePartitionCol(slot_desc)) return false; |
no test coverage detected