Skip to content

Commit 21ca096

Browse files
committed
fix tests
1 parent 93c68e3 commit 21ca096

3 files changed

Lines changed: 46 additions & 10 deletions

File tree

src/paimon/common/data/shredding/map_shared_shredding_utils_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ TEST(MapSharedShreddingUtilsTest, LogicalToPhysicalSchemaBasic) {
9191

9292
// Build expected schema for comparison
9393
auto expected_struct = arrow::struct_({
94-
arrow::field("__field_mapping", arrow::list(arrow::int32()), true),
94+
arrow::field("__field_mapping", arrow::list(arrow::int32()), false),
9595
arrow::field("__col_0", arrow::utf8(), true),
9696
arrow::field("__col_1", arrow::utf8(), true),
9797
arrow::field("__col_2", arrow::utf8(), true),
@@ -118,7 +118,7 @@ TEST(MapSharedShreddingUtilsTest, LogicalToPhysicalSchemaNestedValue) {
118118
schema, field_to_num_columns));
119119

120120
auto expected_struct = arrow::struct_({
121-
arrow::field("__field_mapping", arrow::list(arrow::int32()), true),
121+
arrow::field("__field_mapping", arrow::list(arrow::int32()), false),
122122
arrow::field("__col_0", nested_value, true),
123123
arrow::field("__col_1", nested_value, true),
124124
arrow::field("__overflow", arrow::map(arrow::int32(), nested_value), true),

src/paimon/core/operation/append_only_file_store_write.cpp

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@
1616

1717
#include "paimon/core/operation/append_only_file_store_write.h"
1818

19+
#include <functional>
1920
#include <vector>
2021

22+
#include "arrow/c/bridge.h"
23+
#include "arrow/c/helpers.h"
2124
#include "paimon/common/data/binary_row.h"
25+
#include "paimon/common/data/shredding/map_shared_shredding_batch_converter.h"
26+
#include "paimon/common/data/shredding/map_shared_shredding_utils.h"
27+
#include "paimon/common/data/shredding/map_shredding_defs.h"
2228
#include "paimon/common/table/special_fields.h"
2329
#include "paimon/common/utils/arrow/arrow_utils.h"
2430
#include "paimon/core/append/append_only_writer.h"
@@ -111,10 +117,14 @@ Result<std::vector<std::shared_ptr<DataFileMeta>>> AppendOnlyFileStoreWrite::Com
111117

112118
PAIMON_ASSIGN_OR_RAISE(std::unique_ptr<BatchReader> reader,
113119
CreateFilesReader(partition, bucket, dv_factory, to_compact));
120+
PAIMON_ASSIGN_OR_RAISE(
121+
std::shared_ptr<MapSharedShreddingContext> shredding_context,
122+
MapSharedShreddingUtils::CreateShreddingContext(write_schema_, options_));
114123
auto rewriter =
115124
std::make_unique<RollingFileWriter<::ArrowArray*, std::shared_ptr<DataFileMeta>>>(
116125
options_.GetTargetFileSize(/*has_primary_key=*/false),
117-
GetDataFileWriterCreator(partition, bucket, write_schema_, write_cols_, to_compact));
126+
GetDataFileWriterCreator(partition, bucket, write_schema_, write_cols_, to_compact,
127+
shredding_context));
118128

119129
ScopeGuard reader_guard([&]() {
120130
if (reader) {
@@ -210,34 +220,58 @@ AppendOnlyFileStoreWrite::SingleFileWriterCreator
210220
AppendOnlyFileStoreWrite::GetDataFileWriterCreator(
211221
const BinaryRow& partition, int32_t bucket, const std::shared_ptr<arrow::Schema>& schema,
212222
const std::optional<std::vector<std::string>>& write_cols,
213-
const std::vector<std::shared_ptr<DataFileMeta>>& to_compact) const {
223+
const std::vector<std::shared_ptr<DataFileMeta>>& to_compact,
224+
const std::shared_ptr<MapSharedShreddingContext>& shredding_context) const {
214225
return
215-
[this, partition, bucket, schema, write_cols, to_compact]()
226+
[this, partition, bucket, schema, write_cols, to_compact, shredding_context]()
216227
-> Result<
217228
std::unique_ptr<SingleFileWriter<::ArrowArray*, std::shared_ptr<DataFileMeta>>>> {
229+
PAIMON_ASSIGN_OR_RAISE(MapSharedShreddingBatchConverter::ConverterBundle bundle,
230+
MapSharedShreddingBatchConverter::CreateConverter(
231+
schema, shredding_context, pool_));
232+
std::shared_ptr<arrow::Schema> file_schema =
233+
bundle.physical_schema ? bundle.physical_schema : schema;
234+
218235
::ArrowSchema arrow_schema;
219236
ScopeGuard guard([&arrow_schema]() { ArrowSchemaRelease(&arrow_schema); });
220-
PAIMON_RETURN_NOT_OK_FROM_ARROW(arrow::ExportSchema(*schema, &arrow_schema));
237+
PAIMON_RETURN_NOT_OK_FROM_ARROW(arrow::ExportSchema(*file_schema, &arrow_schema));
221238
auto format = options_.GetFileFormat();
222239
PAIMON_ASSIGN_OR_RAISE(
223240
std::shared_ptr<WriterBuilder> writer_builder,
224241
format->CreateWriterBuilder(&arrow_schema, options_.GetWriteBatchSize()));
225242
writer_builder->WithMemoryPool(pool_);
226243

227-
PAIMON_RETURN_NOT_OK_FROM_ARROW(arrow::ExportSchema(*schema, &arrow_schema));
244+
PAIMON_RETURN_NOT_OK_FROM_ARROW(arrow::ExportSchema(*file_schema, &arrow_schema));
228245
PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<FormatStatsExtractor> stats_extractor,
229246
format->CreateStatsExtractor(&arrow_schema));
230247
PAIMON_ASSIGN_OR_RAISE(
231248
std::shared_ptr<DataFilePathFactory> data_file_path_factory,
232249
file_store_path_factory_->CreateDataFilePathFactory(partition, bucket));
250+
251+
std::function<Status(ArrowArray*, ArrowArray*)> batch_converter;
252+
if (bundle.converter) {
253+
auto converter = bundle.converter;
254+
batch_converter = [converter](ArrowArray* input, ArrowArray* output) -> Status {
255+
PAIMON_ASSIGN_OR_RAISE(std::unique_ptr<ArrowArray> physical,
256+
converter->Convert(input));
257+
ArrowArrayMove(physical.get(), output);
258+
return Status::OK();
259+
};
260+
}
261+
233262
auto writer = std::make_unique<DataFileWriter>(
234-
options_.GetFileCompression(), std::function<Status(ArrowArray*, ArrowArray*)>(),
235-
table_schema_->Id(),
263+
options_.GetFileCompression(), batch_converter, table_schema_->Id(),
236264
std::make_shared<LongCounter>(to_compact[0]->min_sequence_number),
237265
FileSource::Compact(), stats_extractor, data_file_path_factory->IsExternalPath(),
238266
write_cols, pool_);
239267
PAIMON_RETURN_NOT_OK(writer->Init(options_.GetFileSystem(),
240268
data_file_path_factory->NewPath(), writer_builder));
269+
270+
if (bundle.converter) {
271+
writer->SetMetadataFinalizer(MapSharedShreddingUtils::BuildMetadataFinalizer(
272+
bundle.converter, MapSharedShreddingDefine::kDefaultDictCompression,
273+
shredding_context, file_schema));
274+
}
241275
return writer;
242276
};
243277
}

src/paimon/core/operation/append_only_file_store_write.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class BinaryRow;
5858
class CoreOptions;
5959
class Executor;
6060
class Logger;
61+
class MapSharedShreddingContext;
6162
class MemoryPool;
6263
class SchemaManager;
6364
class TableSchema;
@@ -108,7 +109,8 @@ class AppendOnlyFileStoreWrite : public AbstractFileStoreWrite {
108109
SingleFileWriterCreator GetDataFileWriterCreator(
109110
const BinaryRow& partition, int32_t bucket, const std::shared_ptr<arrow::Schema>& schema,
110111
const std::optional<std::vector<std::string>>& write_cols,
111-
const std::vector<std::shared_ptr<DataFileMeta>>& to_compact) const;
112+
const std::vector<std::shared_ptr<DataFileMeta>>& to_compact,
113+
const std::shared_ptr<MapSharedShreddingContext>& shredding_context) const;
112114

113115
Result<std::unique_ptr<BatchReader>> CreateFilesReader(
114116
const BinaryRow& partition, int32_t bucket, DeletionVector::Factory dv_factory,

0 commit comments

Comments
 (0)