diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 4cb204c5..0a7e6c75 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,7 +1,7 @@ add_executable(s3select_example s3select_example.cpp) target_include_directories(s3select_example PUBLIC ../include ../rapidjson/include) add_executable(s3select_scaleup s3select_scaleup.cpp) -target_include_directories(s3select_scaleup PUBLIC ../include) +target_include_directories(s3select_scaleup PUBLIC ../include ../rapidjson/include) find_package(Arrow QUIET) diff --git a/example/s3select_example.cpp b/example/s3select_example.cpp index 3733eaa0..1e0c4811 100644 --- a/example/s3select_example.cpp +++ b/example/s3select_example.cpp @@ -458,6 +458,7 @@ int run_on_localFile(char* input_query) s3select_result result; s3selectEngine::csv_object::csv_defintions csv; csv.use_header_info = false; + bool do_aggregate = false; //csv.column_delimiter='|'; //csv.row_delimiter='\t'; diff --git a/include/s3select.h b/include/s3select.h index fc1c3231..0015c2e2 100644 --- a/include/s3select.h +++ b/include/s3select.h @@ -2723,7 +2723,7 @@ class json_object : public base_s3object JsonParserHandler JsonHandler; size_t m_processed_bytes; bool m_end_of_stream; - std::string s3select_result; + s3select_result m_result; size_t m_row_count; bool star_operation_ind; std::string m_error_description; @@ -2792,23 +2792,23 @@ class json_object : public base_s3object //execute statement on row //create response (TODO callback) - size_t result_len = s3select_result.size(); + size_t result_len = m_result.size(); int status=0; try{ - status = getMatchRow(s3select_result); + status = getMatchRow(m_result); } catch(s3selectEngine::base_s3select_exception& e) { - sql_error_handling(e,s3select_result); + sql_error_handling(e,m_result.str()); status = -1; } m_sa->clear_data(); - if(star_operation_ind && (s3select_result.size() != result_len)) + if(star_operation_ind && (m_result.size() != result_len)) {//as explained above the star-operation is displayed differently std::string end_of_row; end_of_row = "#=== " + std::to_string(m_row_count++) + " ===#\n"; - s3select_result.append(end_of_row); + m_result.append(end_of_row); } return status; } @@ -2833,10 +2833,10 @@ class json_object : public base_s3object //the error-handling takes care of the error flow. m_error_description = e.what(); m_error_count++; - s3select_result.append(std::to_string(m_error_count)); - s3select_result += " : "; - s3select_result.append(m_error_description); - s3select_result += m_csv_defintion.output_row_delimiter; + m_result.append(std::to_string(m_error_count)); + m_result.append(std::string(" : ")); + m_result.append(m_error_description); + m_result.append(&m_csv_defintion.output_row_delimiter,1); } public: @@ -2845,21 +2845,21 @@ class json_object : public base_s3object { int status=0; m_processed_bytes += stream_length; - s3select_result.clear(); + m_result.clear(); if(!stream_length || !json_stream)//TODO m_processed_bytes(?) {//last processing cycle JsonHandler.process_json_buffer(0, 0, true);//TODO end-of-stream = end-of-row m_end_of_stream = true; sql_execution_on_row_cb(); - result = s3select_result; + result = m_result.str(); return 0; } try{ //the handler is processing any buffer size and return results per each buffer status = JsonHandler.process_json_buffer((char*)json_stream, stream_length); - result = s3select_result;//TODO remove this result copy + result = m_result.str();//TODO remove this result copy } catch(std::exception &e) { @@ -2878,6 +2878,8 @@ class json_object : public base_s3object ~json_object() = default; +}; + class merge_results : public base_s3object {//purpose: upon processing several stream on a single aggregate query, this object should merge results. diff --git a/include/s3select_oper.h b/include/s3select_oper.h index 62b4c1b0..53a4d8ce 100644 --- a/include/s3select_oper.h +++ b/include/s3select_oper.h @@ -1335,6 +1335,8 @@ class base_statement m_projection_alias(nullptr), m_eval_stack_depth(0), m_skip_non_aggregate_op(false), execution_phase(multiple_executions_en::NA){} + multiple_executions_en execution_phase; + virtual value& eval() { //purpose: on aggregation flow to run only the correct subtree(aggregation subtree) diff --git a/test/s3select_test.cpp b/test/s3select_test.cpp index b4f93204..801cc2be 100644 --- a/test/s3select_test.cpp +++ b/test/s3select_test.cpp @@ -825,8 +825,7 @@ void test_single_column_single_row(const char* input_query,const char* expected_ #ifdef _ARROW_EXIST parquet_csv_report_error(parquet_result.str(),csv_result.str()); #endif - json_csv_report_error(json_result, s3select_result); - ASSERT_EQ(s3select_result, std::string(expected_result)); + json_csv_report_error(json_result, csv_result.str()); ASSERT_EQ(csv_result.str(), std::string(expected_result)); } @@ -2664,7 +2663,8 @@ void generate_csv_quote_and_escape(std::string& out, char quote = '"', char escp TEST(TestS3selectFunctions, csv_quote_string_and_escape_char) { - std::string input, s3select_result_1, s3select_result_2, s3select_result_3; + std::string input; + s3select_result s3select_result_1, s3select_result_2, s3select_result_3; csv_object::csv_defintions csv; generate_csv_quote_and_escape(input); s3select s3select_syntax1, s3select_syntax2, s3select_syntax3; @@ -2683,7 +2683,7 @@ TEST(TestS3selectFunctions, csv_quote_string_and_escape_char) s3selectEngine::csv_object s3_csv_object_second(&s3select_syntax2, csv); s3_csv_object_second.run_s3select_on_object(s3select_result_2, input.c_str(), input.size(), false, false, true); - EXPECT_EQ(s3select_result_1, s3select_result_2); + EXPECT_EQ(s3select_result_1.str(), s3select_result_2.str()); csv.escape_char = '\0'; csv.quot_char = '\0'; @@ -2695,13 +2695,13 @@ TEST(TestS3selectFunctions, csv_quote_string_and_escape_char) s3selectEngine::csv_object s3_csv_object_third(&s3select_syntax3, csv); s3_csv_object_third.run_s3select_on_object(s3select_result_3, input.c_str(), input.size(), false, false, true); - EXPECT_EQ(s3select_result_3, input); + EXPECT_EQ(s3select_result_3.str(), input); } TEST(TestS3selectFunctions, csv_comment_line_and_trim_char) { std::string input; - std::string s3select_result_1, s3select_result_2; + s3select_result s3select_result_1, s3select_result_2; generate_csv_quote_and_escape(input); s3select s3select_syntax; @@ -2725,7 +2725,7 @@ TEST(TestS3selectFunctions, csv_comment_line_and_trim_char) s3selectEngine::csv_object s3_csv_object_second(&s3select_syntax, csv); s3_csv_object_second.run_s3select_on_object(s3select_result_2, input.c_str(), input.size(), false, false, true); - EXPECT_EQ(s3select_result_1, s3select_result_2); + EXPECT_EQ(s3select_result_1.str(), s3select_result_2.str()); } TEST(TestS3selectFunctions, presto_syntax_alignments) diff --git a/test/s3select_test.h b/test/s3select_test.h index e5b8f94d..be0ad2f6 100644 --- a/test/s3select_test.h +++ b/test/s3select_test.h @@ -691,7 +691,7 @@ std::string run_s3select(std::string expression,std::string input, const char* j } run_json_query(json_query, js, json_result); - json_csv_report_error(json_result, s3select_result); + json_csv_report_error(json_result, csv_result.str()); return csv_result.str(); }