@@ -69,7 +69,8 @@ class LuceneGlobalIndexTest : public ::testing::Test,
6969 const std::shared_ptr<arrow::DataType>& data_type,
7070 const std::map<std::string, std::string>& options,
7171 const std::shared_ptr<arrow::Array>& array,
72- const Range& expected_range) const {
72+ const Range& expected_range,
73+ const std::string& tmp_dir) const {
7374 auto global_index = std::make_shared<LuceneGlobalIndex>(options);
7475 auto path_factory = std::make_shared<FakeIndexPathFactory>(index_root);
7576 auto file_writer = std::make_shared<GlobalIndexFileManager>(fs_, path_factory);
@@ -84,12 +85,25 @@ class LuceneGlobalIndexTest : public ::testing::Test,
8485 std::iota (row_ids.begin (), row_ids.end (), 0 );
8586 PAIMON_RETURN_NOT_OK (global_writer->AddBatch (&c_array, std::move (row_ids)));
8687 PAIMON_ASSIGN_OR_RAISE (auto result_metas, global_writer->Finish ());
88+
89+ // check tmp dir
90+ std::vector<std::unique_ptr<BasicFileStatus>> file_status_list;
91+ EXPECT_OK (fs_->ListDir (tmp_dir, &file_status_list));
92+ EXPECT_EQ (file_status_list.size (), 1 );
93+
8794 // check meta
8895 EXPECT_EQ (result_metas.size (), 1 );
8996 auto file_name = PathUtil::GetName (result_metas[0 ].file_path );
9097 EXPECT_TRUE (StringUtils::StartsWith (file_name, " lucene-fts-global-index-" ));
9198 EXPECT_TRUE (StringUtils::EndsWith (file_name, " .index" ));
9299 EXPECT_TRUE (result_metas[0 ].metadata );
100+
101+ // after reset writer, rm tmp files
102+ global_writer.reset ();
103+ file_status_list.clear ();
104+ EXPECT_OK (fs_->ListDir (tmp_dir, &file_status_list));
105+ EXPECT_TRUE (file_status_list.empty ());
106+
93107 return result_metas[0 ];
94108 }
95109
@@ -128,14 +142,16 @@ class LuceneGlobalIndexTest : public ::testing::Test,
128142
129143TEST_P (LuceneGlobalIndexTest, TestSimple) {
130144 int32_t read_buffer_size = GetParam ();
131-
132145 auto test_root_dir = paimon::test::UniqueTestDirectory::Create ();
133146 ASSERT_TRUE (test_root_dir);
147+ auto tmp_dir = paimon::test::UniqueTestDirectory::Create ();
148+ ASSERT_TRUE (tmp_dir);
134149 std::string test_root = test_root_dir->Str ();
135150
136151 std::map<std::string, std::string> options = {
137152 {" lucene-fts.write.omit-term-freq-and-position" , " false" },
138- {" lucene-fts.read.buffer-size" , std::to_string (read_buffer_size)}};
153+ {" lucene-fts.read.buffer-size" , std::to_string (read_buffer_size)},
154+ {" lucene-fts.write.tmp.directory" , tmp_dir->Str ()}};
139155 std::shared_ptr<arrow::Array> array = arrow::ipc::internal::json::ArrayFromJSON (data_type_,
140156 R"( [
141157 ["This is an test document."],
@@ -146,11 +162,13 @@ TEST_P(LuceneGlobalIndexTest, TestSimple) {
146162 .ValueOrDie ();
147163
148164 // write index
149- ASSERT_OK_AND_ASSIGN (auto meta,
150- WriteGlobalIndex (test_root, data_type_, options, array, Range (0 , 3 )));
165+ ASSERT_OK_AND_ASSIGN (auto meta, WriteGlobalIndex (test_root, data_type_, options, array,
166+ Range (0 , 3 ), tmp_dir-> Str ( )));
151167 if (read_buffer_size == 10 ) {
152- ASSERT_EQ (std::string (meta.metadata ->data (), meta.metadata ->size ()),
153- R"( {"read.buffer-size":"10","write.omit-term-freq-and-position":"false"})" );
168+ ASSERT_EQ (
169+ std::string (meta.metadata ->data (), meta.metadata ->size ()),
170+ R"( {"read.buffer-size":"10","write.omit-term-freq-and-position":"false","write.tmp.directory":")" +
171+ tmp_dir->Str () + R"( "})" );
154172 }
155173
156174 // create reader
@@ -293,13 +311,15 @@ TEST_P(LuceneGlobalIndexTest, TestSimpleChinese) {
293311
294312 auto test_root_dir = paimon::test::UniqueTestDirectory::Create ();
295313 ASSERT_TRUE (test_root_dir);
314+ auto tmp_dir = paimon::test::UniqueTestDirectory::Create ();
315+ ASSERT_TRUE (tmp_dir);
296316 std::string test_root = test_root_dir->Str ();
297317
298318 std::map<std::string, std::string> options = {
299319 {" lucene-fts.write.omit-term-freq-and-position" , " false" },
300320 {" lucene-fts.read.buffer-size" , std::to_string (read_buffer_size)},
301321 {" lucene-fts.jieba.tokenize-mode" , " query" },
302- };
322+ { " lucene-fts.write.tmp.directory " , tmp_dir-> Str ()} };
303323
304324 std::shared_ptr<arrow::Array> array = arrow::ipc::internal::json::ArrayFromJSON (data_type_,
305325 R"( [
@@ -312,12 +332,13 @@ TEST_P(LuceneGlobalIndexTest, TestSimpleChinese) {
312332 .ValueOrDie ();
313333
314334 // write index
315- ASSERT_OK_AND_ASSIGN (auto meta,
316- WriteGlobalIndex (test_root, data_type_, options, array, Range (0 , 4 )));
335+ ASSERT_OK_AND_ASSIGN (auto meta, WriteGlobalIndex (test_root, data_type_, options, array,
336+ Range (0 , 4 ), tmp_dir-> Str ( )));
317337 if (read_buffer_size == 10 ) {
318338 ASSERT_EQ (
319339 std::string (meta.metadata ->data (), meta.metadata ->size ()),
320- R"( {"jieba.tokenize-mode":"query","read.buffer-size":"10","write.omit-term-freq-and-position":"false"})" );
340+ R"( {"jieba.tokenize-mode":"query","read.buffer-size":"10","write.omit-term-freq-and-position":"false","write.tmp.directory":")" +
341+ tmp_dir->Str () + R"( "})" );
321342 }
322343
323344 // create reader
@@ -406,6 +427,23 @@ TEST_P(LuceneGlobalIndexTest, TestSimpleChinese) {
406427 }
407428}
408429
430+ TEST_F (LuceneGlobalIndexTest, TestInvalidWithoutTmpDir) {
431+ auto test_root_dir = paimon::test::UniqueTestDirectory::Create ();
432+ ASSERT_TRUE (test_root_dir);
433+ std::string test_root = test_root_dir->Str ();
434+
435+ std::map<std::string, std::string> options = {
436+ {" lucene-fts.write.omit-term-freq-and-position" , " false" }};
437+ std::shared_ptr<arrow::Array> array = arrow::ipc::internal::json::ArrayFromJSON (data_type_,
438+ R"( [
439+ ["This is an test document."]
440+ ])" )
441+ .ValueOrDie ();
442+
443+ // write index
444+ ASSERT_NOK_WITH_MSG (WriteGlobalIndex (test_root, data_type_, options, array, Range (0 , 0 ), " " ),
445+ " key write.tmp.directory does not exist in map" );
446+ }
409447INSTANTIATE_TEST_SUITE_P (ReadBufferSize, LuceneGlobalIndexTest,
410448 ::testing::ValuesIn (std::vector<int32_t >({10 , 100 , 1024 })));
411449
0 commit comments