diff --git a/presto-native-execution/presto_cpp/main/connectors/IcebergPrestoToVeloxConnector.cpp b/presto-native-execution/presto_cpp/main/connectors/IcebergPrestoToVeloxConnector.cpp index fc8852ef72a09..07a9a6cbd28b0 100644 --- a/presto-native-execution/presto_cpp/main/connectors/IcebergPrestoToVeloxConnector.cpp +++ b/presto-native-execution/presto_cpp/main/connectors/IcebergPrestoToVeloxConnector.cpp @@ -108,6 +108,48 @@ std::unique_ptr toIcebergTableHandle( columnHandles); } +velox::connector::hive::iceberg::IcebergPartitionSpec::Field +toVeloxIcebergPartitionField( + const protocol::iceberg::IcebergPartitionField& field, + const TypeParser& typeParser, + const protocol::iceberg::PrestoIcebergSchema& schema) { + std::string type; + for (const auto& column : schema.columns) { + if (column.name == field.name) { + type = column.prestoType; + break; + } + } + + VELOX_USER_CHECK( + !type.empty(), + "Partition column not found in table schema: {}", + field.name); + + return velox::connector::hive::iceberg::IcebergPartitionSpec::Field{ + field.name, + stringToType(type, typeParser), + static_cast( + field.transform), + field.parameter ? *field.parameter : std::optional()}; +} + +std::unique_ptr +toVeloxIcebergPartitionSpec( + const protocol::iceberg::PrestoIcebergPartitionSpec& spec, + const TypeParser& typeParser) { + std::vector + fields; + fields.reserve(spec.fields.size()); + for (const auto& field : spec.fields) { + fields.emplace_back( + toVeloxIcebergPartitionField(field, typeParser, spec.schema)); + } + return std::make_unique< + velox::connector::hive::iceberg::IcebergPartitionSpec>( + spec.specId, fields); +} + } // namespace std::unique_ptr @@ -293,6 +335,8 @@ IcebergPrestoToVeloxConnector::toVeloxInsertTableHandle( fmt::format("{}/data", icebergOutputTableHandle->outputPath), velox::connector::hive::LocationHandle::TableType::kNew), toVeloxFileFormat(icebergOutputTableHandle->fileFormat), + toVeloxIcebergPartitionSpec( + icebergOutputTableHandle->partitionSpec, typeParser), std::optional( toFileCompressionKind(icebergOutputTableHandle->compressionCodec))); } @@ -321,6 +365,8 @@ IcebergPrestoToVeloxConnector::toVeloxInsertTableHandle( fmt::format("{}/data", icebergInsertTableHandle->outputPath), velox::connector::hive::LocationHandle::TableType::kExisting), toVeloxFileFormat(icebergInsertTableHandle->fileFormat), + toVeloxIcebergPartitionSpec( + icebergInsertTableHandle->partitionSpec, typeParser), std::optional( toFileCompressionKind(icebergInsertTableHandle->compressionCodec))); } diff --git a/presto-native-execution/velox b/presto-native-execution/velox index 946eb039b7d3a..d2a6822fdb185 160000 --- a/presto-native-execution/velox +++ b/presto-native-execution/velox @@ -1 +1 @@ -Subproject commit 946eb039b7d3a367cd1b995be3275cfe0da6825b +Subproject commit d2a6822fdb1858066484002b93a502d07bfcf32e