@@ -96,8 +96,13 @@ Result<std::vector<DataField>> GetExtraFields(const TableSchema& table_schema,
9696 extra_fields.reserve (extra_field_names.size ());
9797 std::set<std::string> dedup_field_names;
9898 for (const auto & extra_field_name : extra_field_names) {
99- if (extra_field_name == field_name || !dedup_field_names.insert (extra_field_name).second ) {
100- continue ;
99+ if (extra_field_name == field_name) {
100+ return Status::Invalid (fmt::format (
101+ " global index extra field {} must not be the indexed field" , extra_field_name));
102+ }
103+ if (!dedup_field_names.insert (extra_field_name).second ) {
104+ return Status::Invalid (fmt::format (" global index extra field {} must not be duplicated" ,
105+ extra_field_name));
101106 }
102107 PAIMON_ASSIGN_OR_RAISE (DataField extra_field, table_schema.GetField (extra_field_name));
103108 extra_fields.push_back (extra_field);
@@ -174,11 +179,6 @@ Result<std::vector<GlobalIndexIOMeta>> BuildIndex(
174179 return Status::Invalid (
175180 " array read from batch reader is not a struct array in GlobalIndexWriteTask" );
176181 }
177- auto indexed_array = struct_array->GetFieldByName (field_name);
178- if (!indexed_array) {
179- return Status::Invalid (fmt::format (
180- " read array does not contain {} field in GlobalIndexWriteTask" , field_name));
181- }
182182 auto row_id_array = struct_array->GetFieldByName (SpecialFields::RowId ().Name ());
183183 auto typed_row_id_array = std::dynamic_pointer_cast<arrow::Int64Array>(row_id_array);
184184 if (!typed_row_id_array) {
@@ -222,7 +222,8 @@ Result<std::vector<GlobalIndexIOMeta>> BuildIndex(
222222Result<std::shared_ptr<CommitMessage>> ToCommitMessage (
223223 const std::string& index_type, int32_t field_id, const Range& range,
224224 const std::vector<GlobalIndexIOMeta>& global_index_io_metas, const BinaryRow& partition,
225- int32_t bucket, const std::shared_ptr<GlobalIndexFileManager>& file_manager) {
225+ int32_t bucket, const std::shared_ptr<GlobalIndexFileManager>& file_manager,
226+ const std::optional<std::vector<int32_t >>& extra_field_ids) {
226227 std::vector<std::shared_ptr<IndexFileMeta>> index_file_metas;
227228 index_file_metas.reserve (global_index_io_metas.size ());
228229 bool is_external_path = file_manager->IsExternalPath ();
@@ -235,8 +236,7 @@ Result<std::shared_ptr<CommitMessage>> ToCommitMessage(
235236 index_file_metas.push_back (std::make_shared<IndexFileMeta>(
236237 index_type, PathUtil::GetName (io_meta.file_path ), io_meta.file_size , range.Count (),
237238 /* dv_ranges=*/ std::nullopt , external_path,
238- GlobalIndexMeta (range.from , range.to , field_id, io_meta.extra_field_ids ,
239- io_meta.metadata )));
239+ GlobalIndexMeta (range.from , range.to , field_id, extra_field_ids, io_meta.metadata )));
240240 }
241241 DataIncrement data_increment (std::move (index_file_metas));
242242 return std::make_shared<CommitMessageImpl>(partition, bucket,
@@ -313,13 +313,11 @@ Result<std::shared_ptr<CommitMessage>> GlobalIndexWriteTask::WriteIndex(
313313 PAIMON_ASSIGN_OR_RAISE (std::vector<GlobalIndexIOMeta> global_index_io_metas,
314314 BuildIndex (field_name, range, writer_field_names, batch_reader.get (),
315315 global_index_writer.get ()));
316- for (auto & io_meta : global_index_io_metas) {
317- io_meta.extra_field_ids = extra_field_ids;
318- }
319316
320317 // generate commit message
321318 return ToCommitMessage (index_type, field.Id (), range, global_index_io_metas,
322- data_split->Partition (), data_split->Bucket (), index_file_manager);
319+ data_split->Partition (), data_split->Bucket (), index_file_manager,
320+ extra_field_ids);
323321}
324322
325323} // namespace paimon
0 commit comments