@@ -2116,6 +2116,109 @@ TEST_P(WriteAndReadInteTest, TestMapStorageLayoutSharedShreddingToDefault) {
21162116 ASSERT_TRUE (success);
21172117}
21182118
2119+ TEST_P (WriteAndReadInteTest, TestAppendMapStorageLayoutSharedShreddingToDefaultCompaction) {
2120+ auto [file_format, file_system] = GetParam ();
2121+ if (file_format != " parquet" && file_format != " orc" ) {
2122+ return ;
2123+ }
2124+
2125+ arrow::FieldVector fields = {
2126+ arrow::field (" id" , arrow::int32 ()),
2127+ arrow::field (" tags" , arrow::map (arrow::utf8 (), arrow::int64 ())),
2128+ };
2129+ std::map<std::string, std::string> options_v0 = {
2130+ {Options::MANIFEST_FORMAT , " avro" },
2131+ {Options::FILE_FORMAT , file_format},
2132+ {Options::TARGET_FILE_SIZE , " 1024" },
2133+ {Options::BUCKET , " 1" },
2134+ {Options::BUCKET_KEY , " id" },
2135+ {Options::FILE_SYSTEM , file_system},
2136+ {" fields.tags.map.storage-layout" , " shared-shredding" },
2137+ {" fields.tags.map.shared-shredding.max-columns" , " 1" },
2138+ };
2139+ if (file_system == " jindo" ) {
2140+ options_v0 = AddOptionsForJindo (options_v0);
2141+ }
2142+ ASSERT_OK_AND_ASSIGN (auto helper,
2143+ TestHelper::Create (test_dir_, arrow::schema (fields),
2144+ /* partition_keys=*/ {}, /* primary_keys=*/ {}, options_v0,
2145+ /* is_streaming_mode=*/ true ));
2146+ std::string table_path = PathUtil::JoinPath (test_dir_, " foo.db/bar" );
2147+ int64_t commit_identifier = 0 ;
2148+
2149+ ASSERT_OK_AND_ASSIGN (auto batch_v0_file1,
2150+ TestHelper::MakeRecordBatch (arrow::struct_ (fields),
2151+ R"( [
2152+ [1, [["a", 10], ["b", 11]]],
2153+ [2, [["c", 20]]]
2154+ ])" ,
2155+ /* partition_map=*/ {}, /* bucket=*/ 0 , {}));
2156+ ASSERT_OK (helper->WriteAndCommit (std::move (batch_v0_file1), commit_identifier++,
2157+ /* expected_commit_messages=*/ std::nullopt ));
2158+
2159+ ASSERT_OK_AND_ASSIGN (auto batch_v0_file2,
2160+ TestHelper::MakeRecordBatch (arrow::struct_ (fields),
2161+ R"( [
2162+ [3, [["d", 30], ["e", 31]]]
2163+ ])" ,
2164+ /* partition_map=*/ {}, /* bucket=*/ 0 , {}));
2165+ ASSERT_OK (helper->WriteAndCommit (std::move (batch_v0_file2), commit_identifier++,
2166+ /* expected_commit_messages=*/ std::nullopt ));
2167+
2168+ std::map<std::string, std::string> options_v1 = options_v0;
2169+ options_v1[" fields.tags.map.storage-layout" ] = " default" ;
2170+ options_v1.erase (" fields.tags.map.shared-shredding.max-columns" );
2171+ ASSERT_OK (WriteNextSchema ({DataField (0 , fields[0 ]), DataField (1 , fields[1 ])},
2172+ /* highest_field_id=*/ 1 , options_v1));
2173+
2174+ helper.reset ();
2175+ ASSERT_OK_AND_ASSIGN (helper, TestHelper::Create (table_path, options_v1,
2176+ /* is_streaming_mode=*/ true ));
2177+ ASSERT_OK_AND_ASSIGN (auto batch_v1_file3,
2178+ TestHelper::MakeRecordBatch (arrow::struct_ (fields),
2179+ R"( [
2180+ [4, [["a", 40], ["f", 41]]],
2181+ [5, null]
2182+ ])" ,
2183+ /* partition_map=*/ {}, /* bucket=*/ 0 , {}));
2184+ ASSERT_OK (helper->WriteAndCommit (std::move (batch_v1_file3), commit_identifier++,
2185+ /* expected_commit_messages=*/ std::nullopt ));
2186+
2187+ WriteContextBuilder write_context_builder (table_path, " commit_user" );
2188+ ASSERT_OK_AND_ASSIGN (
2189+ auto write_context,
2190+ write_context_builder.SetOptions (options_v1).WithStreamingMode (true ).Finish ());
2191+ ASSERT_OK_AND_ASSIGN (auto file_store_write, FileStoreWrite::Create (std::move (write_context)));
2192+ ASSERT_OK (file_store_write->Compact (/* partition=*/ {}, /* bucket=*/ 0 ,
2193+ /* full_compaction=*/ true ));
2194+ ASSERT_OK_AND_ASSIGN (auto compact_messages, file_store_write->PrepareCommit (
2195+ /* wait_compaction=*/ true , commit_identifier));
2196+ ASSERT_FALSE (compact_messages.empty ());
2197+
2198+ CommitContextBuilder commit_context_builder (table_path, " commit_user" );
2199+ ASSERT_OK_AND_ASSIGN (auto commit_context,
2200+ commit_context_builder.SetOptions (options_v1).Finish ());
2201+ ASSERT_OK_AND_ASSIGN (auto file_store_commit,
2202+ FileStoreCommit::Create (std::move (commit_context)));
2203+ ASSERT_OK (file_store_commit->Commit (compact_messages, commit_identifier));
2204+
2205+ arrow::FieldVector expected_fields = fields;
2206+ expected_fields.insert (expected_fields.begin (), arrow::field (" _VALUE_KIND" , arrow::int8 ()));
2207+ ASSERT_OK_AND_ASSIGN (auto splits,
2208+ helper->NewScan (StartupMode::LatestFull (), /* snapshot_id=*/ std::nullopt ));
2209+ ASSERT_EQ (1 , splits.size ());
2210+ ASSERT_OK_AND_ASSIGN (bool success,
2211+ helper->ReadAndCheckResult (arrow::struct_ (expected_fields), splits,
2212+ R"( [
2213+ [0, 1, [["a", 10], ["b", 11]]],
2214+ [0, 2, [["c", 20]]],
2215+ [0, 3, [["d", 30], ["e", 31]]],
2216+ [0, 4, [["a", 40], ["f", 41]]],
2217+ [0, 5, null]
2218+ ])" ));
2219+ ASSERT_TRUE (success);
2220+ }
2221+
21192222// Nested map values through both selected physical columns and overflow.
21202223TEST_P (WriteAndReadInteTest, TestSharedShreddingWithStructValue) {
21212224 auto [file_format, file_system] = GetParam ();
0 commit comments