Skip to content

Commit 8d69bb0

Browse files
committed
wip
1 parent 94aa30a commit 8d69bb0

File tree

4 files changed

+25
-28
lines changed

4 files changed

+25
-28
lines changed

integration_tests/arrow_file_to_stream.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,49 @@
11
#include <cstdlib>
22
#include <filesystem>
3+
#include <fstream>
34
#include <iostream>
45
#include <vector>
56

67
#include "integration_tools.hpp"
78

89
/**
9-
* @brief Reads a JSON file containing record batches and outputs the serialized Arrow IPC stream to stdout.
10+
* @brief Reads a JSON file containing record batches and outputs the serialized Arrow IPC stream to a file.
1011
*
11-
* This program takes a JSON file path as a command-line argument, parses the record batches
12-
* from the JSON data, serializes them into Arrow IPC stream format, and writes the binary
13-
* stream to stdout. The output can be redirected to a file or piped to another program.
12+
* This program takes a JSON file path and an output file path as command-line arguments,
13+
* parses the record batches from the JSON data, serializes them into Arrow IPC stream format,
14+
* and writes the binary stream to the specified output file.
1415
*
15-
* Usage: arrow_file_to_stream <json_file_path>
16+
* Usage: arrow_file_to_stream <json_file_path> <output_arrow_file>
1617
*
1718
* @param argc Number of command-line arguments
1819
* @param argv Array of command-line arguments
1920
* @return EXIT_SUCCESS on success, EXIT_FAILURE on error
2021
*/
2122
int main(int argc, char* argv[])
2223
{
23-
// Check command-line arguments
24-
if (argc != 2)
24+
if (argc != 3)
2525
{
26-
std::cerr << "Usage: " << argv[0] << " <json_file_path>\n";
27-
std::cerr << "Reads a JSON file and outputs the serialized Arrow IPC stream to stdout.\n";
26+
std::cerr << "Usage: " << argv[0] << " <json_file_path> <output_arrow_file>\n";
27+
std::cerr << "Reads a JSON file and outputs the serialized Arrow IPC stream to a file.\n";
2828
return EXIT_FAILURE;
2929
}
3030

3131
const std::filesystem::path json_path(argv[1]);
32+
const std::filesystem::path output_path(argv[2]);
3233

3334
try
3435
{
35-
// Convert JSON file to stream using the library
36-
std::vector<uint8_t> stream_data = integration_tools::json_file_to_stream(json_path);
37-
38-
// Write the binary stream to stdout
39-
std::cout.write(reinterpret_cast<const char*>(stream_data.data()), stream_data.size());
40-
std::cout.flush();
36+
const std::vector<uint8_t> stream_data = integration_tools::json_file_to_stream(json_path);
37+
38+
std::ofstream output_file(output_path, std::ios::binary);
39+
if (!output_file)
40+
{
41+
std::cerr << "Error: Could not open output file: " << output_path << "\n";
42+
return EXIT_FAILURE;
43+
}
44+
45+
output_file.write(reinterpret_cast<const char*>(stream_data.data()), static_cast<std::streamsize>(stream_data.size()));
46+
output_file.close();
4147

4248
return EXIT_SUCCESS;
4349
}

integration_tests/arrow_json_to_file.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
*/
2222
int main(int argc, char* argv[])
2323
{
24-
// Check command-line arguments
2524
if (argc != 3)
2625
{
2726
std::cerr << "Usage: " << argv[0] << " <json_file_path> <output_file_path>\n";
@@ -34,18 +33,15 @@ int main(int argc, char* argv[])
3433

3534
try
3635
{
37-
// Convert JSON file to stream using the library
38-
std::vector<uint8_t> stream_data = integration_tools::json_file_to_arrow_file(json_path);
39-
40-
// Write the binary stream to the output file
36+
const std::vector<uint8_t> file_data = integration_tools::json_file_to_arrow_file(json_path);
4137
std::ofstream output_file(output_path, std::ios::out | std::ios::binary);
4238
if (!output_file.is_open())
4339
{
4440
std::cerr << "Error: Could not open output file: " << output_path << "\n";
4541
return EXIT_FAILURE;
4642
}
4743

48-
output_file.write(reinterpret_cast<const char*>(stream_data.data()), stream_data.size());
44+
output_file.write(reinterpret_cast<const char*>(file_data.data()), file_data.size());
4945
output_file.close();
5046

5147
if (!output_file.good())

integration_tests/arrow_stream_to_file.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,18 @@ int main(int argc, char* argv[])
6262
return EXIT_FAILURE;
6363
}
6464

65-
// Convert stream to file format using the library
66-
const std::vector<uint8_t> output_stream_data = integration_tools::stream_to_file(
65+
const std::vector<uint8_t> output_file_data = integration_tools::stream_to_file(
6766
std::span<const uint8_t>(input_stream_data)
6867
);
6968

70-
// Write the stream to the output file
7169
std::ofstream output_file(output_path, std::ios::out | std::ios::binary);
7270
if (!output_file.is_open())
7371
{
7472
std::cerr << "Error: Could not open output file: " << output_path << "\n";
7573
return EXIT_FAILURE;
7674
}
7775

78-
output_file.write(reinterpret_cast<const char*>(output_stream_data.data()), output_stream_data.size());
76+
output_file.write(reinterpret_cast<const char*>(output_file_data.data()), output_file_data.size());
7977
output_file.close();
8078

8179
if (!output_file.good())

integration_tests/arrow_validate.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*/
2323
int main(int argc, char* argv[])
2424
{
25-
// Check command-line arguments
2625
if (argc != 3)
2726
{
2827
std::cerr << "Usage: " << argv[0] << " <json_file_path> <stream_file_path>\n";
@@ -35,7 +34,6 @@ int main(int argc, char* argv[])
3534

3635
try
3736
{
38-
// Check if the stream file exists
3937
if (!std::filesystem::exists(arrow_file_path))
4038
{
4139
std::cerr << "Error: Arrow file not found: " << arrow_file_path << "\n";
@@ -45,7 +43,6 @@ int main(int argc, char* argv[])
4543
std::cout << "Loading JSON file: " << json_path << "\n";
4644
std::cout << "Loading Arrow file: " << arrow_file_path << "\n";
4745

48-
// Read the stream file
4946
std::ifstream arrow_file(arrow_file_path, std::ios::in | std::ios::binary);
5047
if (!arrow_file.is_open())
5148
{

0 commit comments

Comments
 (0)