Skip to content

Commit

Permalink
wrong initialization of the JSON parser engine caused wrong access (a…
Browse files Browse the repository at this point in the history
…ctually, a miss-match)

different combinations of from-clause and projection-key-path had caused a miss-match

Signed-off-by: Gal Salomon <[email protected]>
  • Loading branch information
galsalomon66 committed Jul 3, 2024
1 parent 5700676 commit 4243bae
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 4 deletions.
7 changes: 3 additions & 4 deletions include/s3select.h
Original file line number Diff line number Diff line change
Expand Up @@ -3225,10 +3225,6 @@ class json_object : public base_s3object
f_push_key_value_into_scratch_area_per_star_operation = [this](s3selectEngine::scratch_area::json_key_value_t& key_value)
{return push_key_value_into_scratch_area_per_star_operation(key_value);};

//setting the container for all json-variables, to be extracted by the json reader
JsonHandler.set_statement_json_variables(query->get_json_variables_access());


//calling to getMatchRow. processing a single row per each call.
JsonHandler.set_s3select_processing_callback(f_sql);
//upon excat match between input-json-key-path and sql-statement-variable-path the callback pushes to scratch area
Expand Down Expand Up @@ -3270,6 +3266,9 @@ class json_object : public base_s3object
}

m_sa->set_parquet_type();//TODO json type

//setting the container for all json-variables, to be extracted by the json reader
JsonHandler.set_statement_json_variables(query->get_json_variables_access());
}

json_object(s3select* query):base_s3object(query),m_processed_bytes(0),m_end_of_stream(false),m_row_count(0),star_operation_ind(false),m_init_json_processor_ind(false)
Expand Down
99 changes: 99 additions & 0 deletions test/s3select_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3482,6 +3482,105 @@ input_json_data = R"(

}

TEST(TestS3selectFunctions, json_access_array_with_differential_from_clause)
{
//purpose: to test the json-parser matcher(combination of the from-clause and projection variables) whether it
//access correctly to different key-values in a nested JSON input.
//the tests, run queries with different combinations of from-clause, and key-path.


std::string input_json_data = R"(
{
"root": {
"hello": "world",
"t": "true",
"f": "false",
"n": "null",
"i": 123,
"pi": 3.1416,
"nested_obj": {
"hello2": "world",
"t2": true,
"nested2": {
"c1": "c1_value",
"array_nested2": [
10,
20,
30,
40
],
"c2": "c2_valuec2_value"
},
"nested3": {
"hello3": "world",
"t2": true,
"nested4": {
"c1": "c1_value",
"array_nested3": [
100,
200,
300,
400
]
}
}
},
"array_1": [
1,
2,
3,
4
]
}
}
)";

std::string expected_result=R"(100,400,null
)";
std::string input_query = "select _1.array_nested3[0],_1.array_nested3[3],_1.array_nested3[5] from s3object[*].root.nested_obj.nested3.nested4;";
std::string result;

run_json_query(input_query.c_str(), input_json_data, result);
ASSERT_EQ(result,expected_result);

expected_result=R"(100,400,null
)";
input_query = "select _1.nested3.nested4.array_nested3[0], _1.nested3.nested4.array_nested3[3], _1.nested3.nested4.array_nested3[5] from s3object[*].root.nested_obj;";
run_json_query(input_query.c_str(), input_json_data, result);
ASSERT_EQ(result,expected_result);

expected_result=R"(10,40,null
)";
input_query = "select _1.array_nested2[0],_1.array_nested2[3],_1.array_nested2[4] from s3object[*].root.nested_obj.nested2;";
run_json_query(input_query.c_str(), input_json_data, result);
ASSERT_EQ(result,expected_result);

expected_result=R"(10,40,null
)";
input_query = "select _1.nested_obj.nested2.array_nested2[0],_1.nested_obj.nested2.array_nested2[3],_1.nested_obj.nested2.array_nested2[4] from s3object[*].root;";
run_json_query(input_query.c_str(), input_json_data, result);
ASSERT_EQ(result,expected_result);

expected_result=R"(10,40,null
)";
input_query = "select _1.root.nested_obj.nested2.array_nested2[0],_1.root.nested_obj.nested2.array_nested2[3],_1.root.nested_obj.nested2.array_nested2[4] from s3object[*];";
run_json_query(input_query.c_str(), input_json_data, result);
ASSERT_EQ(result,expected_result);

expected_result=R"(c1_value
)";
input_query = "select _1.root.nested_obj.nested2.c1 from s3object[*];";
run_json_query(input_query.c_str(), input_json_data, result);
ASSERT_EQ(result,expected_result);

expected_result=R"(c1_value
)";
input_query = "select _1.c1 from s3object[*].root.nested_obj.nested2;";
run_json_query(input_query.c_str(), input_json_data, result);
ASSERT_EQ(result,expected_result);

}

TEST(TestS3selectFunctions, json_queries_format)
{
std::string result;
Expand Down

0 comments on commit 4243bae

Please sign in to comment.