| 2343 | } |
| 2344 | |
| 2345 | void TestDeltaDict() { |
| 2346 | auto type = dictionary(int8(), utf8()); |
| 2347 | auto batch1 = MakeBatch(ArrayFromJSON(type, R"(["foo", "foo", "bar", null])")); |
| 2348 | // Potential delta |
| 2349 | auto batch2 = MakeBatch(ArrayFromJSON(type, R"(["foo", "bar", "quux", "foo"])")); |
| 2350 | // Potential delta |
| 2351 | auto batch3 = |
| 2352 | MakeBatch(ArrayFromJSON(type, R"(["foo", "bar", "quux", "zzz", "foo"])")); |
| 2353 | auto batch4 = MakeBatch(ArrayFromJSON(type, R"(["bar", null, "quux", "foo"])")); |
| 2354 | RecordBatchVector batches{batch1, batch2, batch3, batch4}; |
| 2355 | RecordBatchVector only_deltas{batch1, batch2, batch3}; |
| 2356 | |
| 2357 | // Emit replacements |
| 2358 | if (WriterHelper::kIsFileFormat) { |
| 2359 | CheckWritingFails(batches, 1); |
| 2360 | } else { |
| 2361 | CheckRoundtrip(batches); |
| 2362 | EXPECT_EQ(read_stats_.num_messages, 9); // including schema message |
| 2363 | EXPECT_EQ(read_stats_.num_record_batches, 4); |
| 2364 | EXPECT_EQ(read_stats_.num_dictionary_batches, 4); |
| 2365 | EXPECT_EQ(read_stats_.num_replaced_dictionaries, 3); |
| 2366 | EXPECT_EQ(read_stats_.num_dictionary_deltas, 0); |
| 2367 | } |
| 2368 | |
| 2369 | // Emit deltas |
| 2370 | write_options_.emit_dictionary_deltas = true; |
| 2371 | if (WriterHelper::kIsFileFormat) { |
| 2372 | // batch4 is incompatible with the previous batches and would emit |
| 2373 | // a replacement |
| 2374 | CheckWritingFails(batches, 3); |
| 2375 | } else { |
| 2376 | CheckRoundtrip(batches); |
| 2377 | EXPECT_EQ(read_stats_.num_messages, 9); // including schema message |
| 2378 | EXPECT_EQ(read_stats_.num_record_batches, 4); |
| 2379 | EXPECT_EQ(read_stats_.num_dictionary_batches, 4); |
| 2380 | EXPECT_EQ(read_stats_.num_replaced_dictionaries, 1); |
| 2381 | EXPECT_EQ(read_stats_.num_dictionary_deltas, 2); |
| 2382 | } |
| 2383 | |
| 2384 | CheckRoundtrip(only_deltas, |
| 2385 | /*expect_expanded_dictionary=*/WriterHelper::kIsFileFormat); |
| 2386 | EXPECT_EQ(read_stats_.num_messages, 7); // including schema message |
| 2387 | EXPECT_EQ(read_stats_.num_record_batches, 3); |
| 2388 | EXPECT_EQ(read_stats_.num_dictionary_batches, 3); |
| 2389 | EXPECT_EQ(read_stats_.num_replaced_dictionaries, 0); |
| 2390 | EXPECT_EQ(read_stats_.num_dictionary_deltas, 2); |
| 2391 | |
| 2392 | // IPC file format: WriteTable should unify dicts |
| 2393 | RecordBatchVector actual; |
| 2394 | write_options_.unify_dictionaries = true; |
| 2395 | ASSERT_OK(RoundTripTable(batches, &actual)); |
| 2396 | if (WriterHelper::kIsFileFormat) { |
| 2397 | EXPECT_EQ(read_stats_.num_messages, 6); // including schema message |
| 2398 | EXPECT_EQ(read_stats_.num_record_batches, 4); |
| 2399 | EXPECT_EQ(read_stats_.num_dictionary_batches, 1); |
| 2400 | EXPECT_EQ(read_stats_.num_replaced_dictionaries, 0); |
| 2401 | EXPECT_EQ(read_stats_.num_dictionary_deltas, 0); |
| 2402 | CheckBatchesLogical(batches, actual); |
no test coverage detected