diff --git a/include/s3select.h b/include/s3select.h index fa7f640d..74e9e38b 100644 --- a/include/s3select.h +++ b/include/s3select.h @@ -2267,7 +2267,10 @@ class base_s3object size_t m_error_count; bool m_is_limit_on; unsigned long m_limit; + //number of rows processed by the query unsigned long m_processed_rows; + //number of rows returned by the query + unsigned long m_returned_rows; size_t m_returned_bytes_size; std::function m_fp_ext_debug_mesg=nullptr;//dispache debug message into external system std::vector m_projection_keys{}; @@ -2395,6 +2398,7 @@ class base_s3object } m_processed_rows = 0; + m_returned_rows = 0; } void set_continue_mesg_interval(std::chrono::seconds interval) @@ -2472,6 +2476,9 @@ class base_s3object std::string output_delimiter(1,m_csv_defintion.output_column_delimiter); std::string output_row_delimiter(1,m_csv_defintion.output_row_delimiter); + //each call to this function is a new row + m_returned_rows++; + if(m_csv_defintion.output_json_format && projections_resuls.values.size()) { json_result_format(projections_resuls, result, output_delimiter); result.append(output_row_delimiter); @@ -2551,7 +2558,7 @@ class base_s3object { multi_values projections_resuls; - if (m_is_limit_on && m_processed_rows == m_limit) + if (m_is_limit_on && m_returned_rows == m_limit) { return m_sql_processing_status = Status::LIMIT_REACHED; } @@ -2605,7 +2612,7 @@ class base_s3object } } - if(m_is_limit_on && m_processed_rows == m_limit) + if(m_is_limit_on && m_returned_rows == m_limit) { for (auto& i : m_projections) { @@ -2645,14 +2652,14 @@ class base_s3object } } - while (multiple_row_processing() && m_where_clause && !(where_clause_result = m_where_clause->eval().is_true()) && !(m_is_limit_on && m_processed_rows == m_limit)); + while (multiple_row_processing() && m_where_clause && !(where_clause_result = m_where_clause->eval().is_true()) && !(m_is_limit_on && m_returned_rows == m_limit)); // in the of JSON it needs to evaluate the where-clause(for the first time) if(!multiple_row_processing() && m_where_clause){ where_clause_result = m_where_clause->eval().is_true(); } - if(m_where_clause && ! where_clause_result && m_is_limit_on && m_processed_rows == m_limit) + if(m_where_clause && ! where_clause_result && m_is_limit_on && m_returned_rows == m_limit) { return m_sql_processing_status = Status::LIMIT_REACHED; } @@ -2672,11 +2679,11 @@ class base_s3object { projections_resuls.push_value( &(i->eval()) ); } - result_values_to_string(projections_resuls,result); - if(m_sql_processing_status == Status::SQL_ERROR) - { + result_values_to_string(projections_resuls,result); + if(m_sql_processing_status == Status::SQL_ERROR) + { return m_sql_processing_status; - } + } } } diff --git a/test/s3select_test.cpp b/test/s3select_test.cpp index 86f24dcb..307a8da0 100644 --- a/test/s3select_test.cpp +++ b/test/s3select_test.cpp @@ -2648,44 +2648,44 @@ TEST(TestS3selectFunctions, limit) s3select_res = run_s3select(input_query, input_csv); EXPECT_EQ(s3select_res, expected_res); - input_query = "select _1 from stdin where _2 > _3 limit 8;"; + input_query = "select _1 from stdin where _2 > _3 limit 1;"; expected_res = "7\n"; std::cout << "Running query: 3 (non-aggregate_query, where + limit clause)" << std::endl; s3select_res = run_s3select(input_query, input_csv); EXPECT_EQ(s3select_res, expected_res); - input_query = "select _1 from stdin where _2 > _3 limit 7;"; + input_query = "select _1 from stdin where _2 > _3 limit 1;"; expected_res = "7\n"; std::cout << "Running query: 4 (non-aggregate_query, where + limit clause)" << std::endl; s3select_res = run_s3select(input_query, input_csv); EXPECT_EQ(s3select_res, expected_res); - input_query = "select _1 from stdin where _2 > _3 limit 6;"; - expected_res = ""; + input_query = "select _1 from stdin where _2 < _3 limit 3;"; + expected_res = "1\n2\n3\n"; std::cout << "Running query: 5 (non-aggregate_query, where + limit clause)" << std::endl; s3select_res = run_s3select(input_query, input_csv); EXPECT_EQ(s3select_res, expected_res); - input_query = "select count(0) from stdin limit 9;"; - expected_res = "9"; + input_query = "select count(0) from stdin limit 9;";//limit X has no affect because it is aggregate query + expected_res = "20"; std::cout << "Running query: 6 (aggregate query, limit clause only)" << std::endl; s3select_res = run_s3select(input_query, input_csv); EXPECT_EQ(s3select_res, expected_res); input_query = "select count(0) from stdin where _2 > _3 limit 8;"; - expected_res = "1"; + expected_res = "2"; std::cout << "Running query: 7 (aggregate_query, where + limit clause)" << std::endl; s3select_res = run_s3select(input_query, input_csv); EXPECT_EQ(s3select_res, expected_res); input_query = "select count(0) from stdin where _2 > _3 limit 7;"; - expected_res = "1"; + expected_res = "2"; std::cout << "Running query: 8 (aggregate_query, where + limit clause)" << std::endl; s3select_res = run_s3select(input_query, input_csv); EXPECT_EQ(s3select_res, expected_res); input_query = "select count(0) from stdin where _2 > _3 limit 6;"; - expected_res = "0"; + expected_res = "2"; std::cout << "Running query: 9 (aggregate_query, where + limit clause)" << std::endl; s3select_res = run_s3select(input_query, input_csv); EXPECT_EQ(s3select_res, expected_res); @@ -2693,13 +2693,13 @@ TEST(TestS3selectFunctions, limit) generate_csv_multirow(input_csv, 10000); input_query = "select count(0) from stdin limit 90000;"; - expected_res = "90000"; + expected_res = "100000"; std::cout << "Running query: 10 (aggregate_query, limit clause only, with Large input)" << std::endl; s3select_res = run_s3select(input_query, input_csv); EXPECT_EQ(s3select_res, expected_res); input_query = "select count(0) from stdin where _2 > _3 limit 90000;"; - expected_res = "9000"; + expected_res = "10000"; std::cout << "Running query: 11 (aggregate_query, where + limit clause, with Large input)" << std::endl; s3select_res = run_s3select(input_query, input_csv); EXPECT_EQ(s3select_res, expected_res); @@ -2757,13 +2757,13 @@ TEST(TestS3selectFunctions, limit) EXPECT_EQ(s3select_res, expected_res); input_query_json = "select _1.addr from s3object[*].phoneNumbers where _1.type like \"%1%\" limit 12;"; - expected_res = "11\n100\n101\n102\n"; + expected_res = "11\n100\n101\n102\n103\n104\n105\n"; std::cout << "Running query: 14 (json, non-aggregate query, where + limit clause)" << std::endl; run_json_query(input_query_json, json_input, s3select_res); EXPECT_EQ(s3select_res, expected_res); input_query_json = "select count(0) from s3object[*].phoneNumbers limit 9;"; - expected_res = "9"; + expected_res = "15"; std::cout << "Running query: 15 (json, aggregate query, limit clause only, limit reached)" << std::endl; run_json_query(input_query_json, json_input, s3select_res); EXPECT_EQ(s3select_res, expected_res); @@ -2775,7 +2775,7 @@ TEST(TestS3selectFunctions, limit) EXPECT_EQ(s3select_res, expected_res); input_query_json = "select count(0) from s3object[*].phoneNumbers where _1.type like \"%1_\" limit 10;"; - expected_res = "1"; + expected_res = "6"; std::cout << "Running query: 17 (json, aggregate query, where + limit clause)" << std::endl; run_json_query(input_query_json, json_input, s3select_res); EXPECT_EQ(s3select_res, expected_res);