@@ -569,6 +569,74 @@ TEST_F(CSVFileWriterTest, TestWriteArrayWithNull) {
569569 ASSERT_EQ (content, expect);
570570}
571571
572+ TEST_F (CSVFileWriterTest, TestWriteHiveArray) {
573+ // type_descs: ARRAY<INT>
574+ std::vector<TypeDescriptor> type_descs;
575+ auto type_int = TypeDescriptor::from_logical_type (TYPE_INT );
576+ auto type_int_array = TypeDescriptor::from_logical_type (TYPE_ARRAY );
577+ type_int_array.children .push_back (type_int);
578+ type_descs.push_back (type_int_array);
579+
580+ auto column_names = _make_type_names (type_descs);
581+ auto maybe_output_file = _fs.new_writable_file (_file_path);
582+ EXPECT_OK (maybe_output_file.status ());
583+ auto output_file = std::move (maybe_output_file.value ());
584+ auto output_stream = std::make_unique<csv::OutputStreamFile>(std::move (output_file), 1024 );
585+ auto column_evaluators = ColumnSlotIdEvaluator::from_types (type_descs);
586+ auto writer_options = std::make_shared<formats::CSVWriterOptions>();
587+ writer_options->is_hive = true ;
588+ writer_options->collection_delim = ' \002 ' ;
589+ auto writer =
590+ std::make_unique<formats::CSVFileWriter>(_file_path, std::move (output_stream), column_names, type_descs,
591+ std::move (column_evaluators), writer_options, []() {});
592+ ASSERT_OK (writer->init ());
593+
594+ auto chunk = std::make_shared<Chunk>();
595+ {
596+ // Create ARRAY<INT> column with data: [1,2,3], [4,5], [], [6]
597+ auto elements_data = Int32Column::create ();
598+ auto offsets = UInt32Column::create ();
599+ auto null_column = UInt8Column::create ();
600+
601+ // row 0: [1,2,3]
602+ elements_data->append (1 );
603+ elements_data->append (2 );
604+ elements_data->append (3 );
605+ offsets->append (0 );
606+
607+ // row 1: [4,5]
608+ elements_data->append (4 );
609+ elements_data->append (5 );
610+ offsets->append (3 );
611+
612+ // row 2: [] (empty array)
613+ offsets->append (5 );
614+
615+ // row 3: [6]
616+ elements_data->append (6 );
617+ offsets->append (5 );
618+ offsets->append (6 );
619+
620+ auto array_column =
621+ ArrayColumn::create (NullableColumn::create (elements_data, UInt8Column::create (6 , 0 )), offsets);
622+ null_column->append_numbers (std::vector<uint8_t >{0 , 0 , 0 , 0 }.data (), 4 );
623+ auto nullable_column = NullableColumn::create (std::move (array_column), std::move (null_column));
624+ chunk->append_column (std::move (nullable_column), chunk->num_columns ());
625+ }
626+
627+ // write chunk
628+ ASSERT_OK (writer->write (chunk.get ()));
629+ auto result = writer->commit ();
630+ ASSERT_OK (result.io_status );
631+ ASSERT_EQ (result.file_statistics .record_count , 4 );
632+
633+ // verify correctness
634+ std::string content;
635+ ASSERT_OK (_fs.read_file (_file_path, &content));
636+ std::string expect = " 1\002 2\002 3\n 4\002 5\n\n 6\n " ;
637+ ASSERT_EQ (content, expect);
638+ }
639+
572640TEST_F (CSVFileWriterTest, TestWriteMap) {
573641 // type_descs
574642 std::vector<TypeDescriptor> type_descs;
0 commit comments