-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue #45394: Handle single-line JSON without line ending
- Loading branch information
1 parent
0556905
commit 6cd73d5
Showing
5 changed files
with
175 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Add test source files | ||
set(TEST_SOURCES | ||
test_file_json.cc | ||
) | ||
|
||
# Create test executable | ||
add_executable(ArrowJsonTests ${TEST_SOURCES}) | ||
|
||
# Link Google Test and your project libraries | ||
target_link_libraries(ArrowJsonTests gtest gtest_main arrow_dataset arrow_io) | ||
|
||
# Add tests | ||
add_test(NAME ArrowJsonTests COMMAND ArrowJsonTests) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include <gtest/gtest.h> | ||
#include "arrow/dataset/file_json.h" | ||
#include "arrow/io/memory.h" | ||
#include "arrow/status.h" | ||
#include "arrow/testing/gtest_util.h" | ||
|
||
using namespace arrow; | ||
using namespace arrow::dataset; | ||
|
||
class JsonFragmentScannerTest : public ::testing::Test { | ||
protected: | ||
void SetUp() override { | ||
// Set up necessary objects and state for the tests | ||
} | ||
|
||
void TearDown() override { | ||
// Clean up after tests | ||
} | ||
}; | ||
|
||
TEST_F(JsonFragmentScannerTest, InvalidBlockSize) { | ||
FragmentScanRequest scan_request; | ||
JsonFragmentScanOptions format_options; | ||
JsonInspectedFragment inspected; | ||
Executor* cpu_executor = nullptr; | ||
|
||
format_options.read_options.block_size = -1; // Invalid block size | ||
|
||
auto result = JsonFragmentScanner::Make(scan_request, format_options, inspected, cpu_executor); | ||
ASSERT_FALSE(result.ok()); | ||
ASSERT_EQ(result.status().code(), StatusCode::Invalid); | ||
ASSERT_EQ(result.status().message(), "Block size must be positive"); | ||
} | ||
|
||
TEST_F(JsonFragmentScannerTest, ValidBlockSize) { | ||
FragmentScanRequest scan_request; | ||
JsonFragmentScanOptions format_options; | ||
JsonInspectedFragment inspected; | ||
Executor* cpu_executor = nullptr; | ||
|
||
format_options.read_options.block_size = 1024; // Valid block size | ||
inspected.num_bytes = 2048; | ||
|
||
auto result = JsonFragmentScanner::Make(scan_request, format_options, inspected, cpu_executor); | ||
ASSERT_TRUE(result.ok()); | ||
} | ||
|
||
TEST_F(JsonFragmentScannerTest, SingleLineJson) { | ||
FragmentScanRequest scan_request; | ||
JsonFragmentScanOptions format_options; | ||
JsonInspectedFragment inspected; | ||
Executor* cpu_executor = nullptr; | ||
|
||
format_options.read_options.block_size = 1024; | ||
inspected.num_bytes = 1024; | ||
|
||
// Create a single-line JSON input stream | ||
std::string json_content = R"({"key": "value"})"; | ||
inspected.stream = std::make_shared<arrow::io::BufferReader>(json_content); | ||
|
||
auto result = JsonFragmentScanner::Make(scan_request, format_options, inspected, cpu_executor); | ||
ASSERT_TRUE(result.ok()); | ||
} | ||
|
||
TEST_F(JsonFragmentScannerTest, MultiLineJson) { | ||
FragmentScanRequest scan_request; | ||
JsonFragmentScanOptions format_options; | ||
JsonInspectedFragment inspected; | ||
Executor* cpu_executor = nullptr; | ||
|
||
format_options.read_options.block_size = 1024; | ||
inspected.num_bytes = 2048; | ||
|
||
// Create a multi-line JSON input stream | ||
std::string json_content = R"({"key1": "value1"} | ||
{"key2": "value2"})"; | ||
inspected.stream = std::make_shared<arrow::io::BufferReader>(json_content); | ||
|
||
auto result = JsonFragmentScanner::Make(scan_request, format_options, inspected, cpu_executor); | ||
ASSERT_TRUE(result.ok()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"field": 1} |