@@ -40,13 +40,12 @@ namespace paimon::lucene {
4040LuceneGlobalIndexWriter::LuceneWriteContext::LuceneWriteContext (
4141 const std::string& _tmp_index_path, const Lucene::FSDirectoryPtr& _lucene_dir,
4242 const Lucene::IndexWriterPtr& _index_writer, const Lucene::DocumentPtr& _doc,
43- const Lucene::FieldPtr& _field, const Lucene::FieldPtr& _row_id_field )
43+ const Lucene::FieldPtr& _field)
4444 : tmp_index_path(_tmp_index_path),
4545 lucene_dir (_lucene_dir),
4646 index_writer(_index_writer),
4747 doc(_doc),
48- field(_field),
49- row_id_field(_row_id_field) {}
48+ field(_field) {}
5049
5150Result<std::shared_ptr<LuceneGlobalIndexWriter>> LuceneGlobalIndexWriter::Create (
5251 const std::string& field_name, const std::shared_ptr<arrow::DataType>& arrow_type,
@@ -89,17 +88,11 @@ Result<std::shared_ptr<LuceneGlobalIndexWriter>> LuceneGlobalIndexWriter::Create
8988 auto field = Lucene::newLucene<Lucene::Field>(LuceneUtils::StringToWstring (field_name),
9089 kEmptyWstring , Lucene::Field::STORE_NO ,
9190 Lucene::Field::INDEX_ANALYZED_NO_NORMS );
92- auto row_id_field = Lucene::newLucene<Lucene::Field>(
93- kRowIdFieldWstring , kEmptyWstring , Lucene::Field::STORE_YES ,
94- Lucene::Field::INDEX_NOT_ANALYZED_NO_NORMS );
9591 field->setOmitTermFreqAndPositions (omit_term_freq_and_positions);
96- row_id_field->setOmitTermFreqAndPositions (true );
9792 doc->add (field);
98- doc->add (row_id_field);
9993 return std::shared_ptr<LuceneGlobalIndexWriter>(new LuceneGlobalIndexWriter (
100- field_name, arrow_type,
101- LuceneWriteContext (tmp_path, lucene_dir, writer, doc, field, row_id_field), file_writer,
102- options, pool));
94+ field_name, arrow_type, LuceneWriteContext (tmp_path, lucene_dir, writer, doc, field),
95+ file_writer, options, pool));
10396 } catch (const std::exception& e) {
10497 return Status::Invalid (
10598 fmt::format (" create lucene global index writer failed, with {} error." , e.what ()));
@@ -153,8 +146,7 @@ Status LuceneGlobalIndexWriter::AddBatch(::ArrowArray* arrow_array) {
153146 auto view = string_array->Value (i);
154147 write_context_.field ->setValue (LuceneUtils::StringToWstring (view));
155148 }
156- write_context_.row_id_field ->setValue (
157- LuceneUtils::StringToWstring (std::to_string (row_id_++)));
149+ row_id_++;
158150 write_context_.index_writer ->addDocument (write_context_.doc );
159151 }
160152 } catch (const std::exception& e) {
@@ -170,6 +162,11 @@ Status LuceneGlobalIndexWriter::AddBatch(::ArrowArray* arrow_array) {
170162Result<std::string> LuceneGlobalIndexWriter::FlushIndexToFinal () {
171163 try {
172164 // flush index to tmp dir
165+ if (write_context_.index_writer ->numDocs () != row_id_) {
166+ return Status::Invalid (
167+ fmt::format (" lucene writer row count {} mismatch paimon inner row count {}" ,
168+ write_context_.index_writer ->numDocs (), row_id_));
169+ }
173170 write_context_.index_writer ->optimize ();
174171 write_context_.index_writer ->close ();
175172
0 commit comments