Create a test file with dictionary-encoded string columns for testing dictionary-based predicate pushdown
| 552 | // Create a test file with dictionary-encoded string columns for testing |
| 553 | // dictionary-based predicate pushdown |
| 554 | void createDictionaryTestFile(MemoryOutputStream& memStream) { |
| 555 | MemoryPool* pool = getDefaultPool(); |
| 556 | auto type = std::unique_ptr<Type>( |
| 557 | Type::buildTypeFromString("struct<id:bigint,category:string,status:string>")); |
| 558 | WriterOptions options; |
| 559 | options |
| 560 | .setStripeSize(512) // Small stripe size to create multiple stripes |
| 561 | .setCompressionBlockSize(1024) |
| 562 | .setMemoryBlockSize(64) |
| 563 | .setCompression(CompressionKind_ZLIB) |
| 564 | .setMemoryPool(pool) |
| 565 | .setDictionaryKeySizeThreshold(1.0) |
| 566 | .setRowIndexStride(1000); |
| 567 | |
| 568 | auto writer = createWriter(*type, &memStream, options); |
| 569 | auto batch = writer->createRowBatch(1000); |
| 570 | auto& structBatch = dynamic_cast<StructVectorBatch&>(*batch); |
| 571 | auto& idBatch = dynamic_cast<LongVectorBatch&>(*structBatch.fields[0]); |
| 572 | auto& categoryBatch = dynamic_cast<StringVectorBatch&>(*structBatch.fields[1]); |
| 573 | auto& statusBatch = dynamic_cast<StringVectorBatch&>(*structBatch.fields[2]); |
| 574 | |
| 575 | const char* categories[] = {"A", "B", "C", "X", "Y"}; |
| 576 | const char* statuses[] = {"active", "inactive", "pending"}; |
| 577 | |
| 578 | char categoryBuffer[10000]; |
| 579 | char statusBuffer[20000]; |
| 580 | uint64_t categoryOffset = 0; |
| 581 | uint64_t statusOffset = 0; |
| 582 | |
| 583 | for (uint64_t i = 0; i < 10000; ++i) { |
| 584 | idBatch.data[i % 1000] = static_cast<int64_t>(i); |
| 585 | |
| 586 | const char* category = categories[i % 5]; |
| 587 | size_t catLen = strlen(category); |
| 588 | memcpy(categoryBuffer + categoryOffset, category, catLen); |
| 589 | categoryBatch.data[i % 1000] = categoryBuffer + categoryOffset; |
| 590 | categoryBatch.length[i % 1000] = static_cast<int64_t>(catLen); |
| 591 | categoryOffset += catLen; |
| 592 | |
| 593 | const char* status = statuses[i % 3]; |
| 594 | size_t statusLen = strlen(status); |
| 595 | memcpy(statusBuffer + statusOffset, status, statusLen); |
| 596 | statusBatch.data[i % 1000] = statusBuffer + statusOffset; |
| 597 | statusBatch.length[i % 1000] = static_cast<int64_t>(statusLen); |
| 598 | statusOffset += statusLen; |
| 599 | |
| 600 | if ((i + 1) % 1000 == 0) { |
| 601 | structBatch.numElements = 1000; |
| 602 | idBatch.numElements = 1000; |
| 603 | categoryBatch.numElements = 1000; |
| 604 | statusBatch.numElements = 1000; |
| 605 | writer->add(*batch); |
| 606 | categoryOffset = 0; |
| 607 | statusOffset = 0; |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | writer->close(); |
no test coverage detected