From a8e6ec65fc3f24b8b9716e37861afc95016a5a4c Mon Sep 17 00:00:00 2001 From: Girjesh Rajoria Date: Wed, 10 Mar 2021 03:23:07 -0500 Subject: [PATCH] Tests for nested queries Added tests to run nested complex queries which are combinations of various functions. nested_query_single_row_result tests nested queries which single row output. nested_multirow_queries tests nested queries for multiple rows. Signed-off-by: Girjesh Rajoria --- test/s3select_test.cpp | 63 ++++++++++++++++++++++++++++++++++ test/test_data.csv | 10 ++++++ test/test_key_multirow.txt | 32 +++++++++++++++++ test/test_key_single.txt | 3 ++ test/test_queries_multirow.txt | 4 +++ test/test_queries_single.txt | 3 ++ 6 files changed, 115 insertions(+) create mode 100644 test/test_data.csv create mode 100644 test/test_key_multirow.txt create mode 100644 test/test_key_single.txt create mode 100644 test/test_queries_multirow.txt create mode 100644 test/test_queries_single.txt diff --git a/test/s3select_test.cpp b/test/s3select_test.cpp index 5159f0d9..52f9b189 100644 --- a/test/s3select_test.cpp +++ b/test/s3select_test.cpp @@ -1,6 +1,7 @@ #include "s3select.h" #include "gtest/gtest.h" #include +#include #include #include #include "boost/date_time/gregorian/gregorian.hpp" @@ -2448,3 +2449,65 @@ TEST(TestS3selectFunctions, trim11) test_single_column_single_row( "select trim(trailing from trim(leading from \" foobar \")) from stdin ;" ,"foobar,\n"); } +TEST(TestS3selectFunctions, nested_query_single_row_result) +{ + std::fstream query_file, result_file, input_csv; + query_file.open("./test/test_queries_single.txt", std::ios::in); + result_file.open("./test/test_key_single.txt", std::ios::in); + ASSERT_EQ(query_file.is_open(), true); + ASSERT_EQ(result_file.is_open(), true); + + std::string input_query, expected_res; + int i = 1; + while(getline(query_file, input_query) && getline(result_file, expected_res)) + { + std::cout << "Running query: " << i << std::endl; + auto s3select_res = run_s3select(input_query); + EXPECT_EQ(s3select_res, expected_res); + i++; + } + + query_file.close(); + result_file.close(); +} + +TEST(TestS3selectFunctions, nested_multirow_queries) +{ + std::fstream query_file, result_file, input_csv; + query_file.open("./test/test_queries_multirow.txt", std::ios::in); + result_file.open("./test/test_key_multirow.txt", std::ios::in); + input_csv.open("./test/test_data.csv", std::ios::in); + ASSERT_EQ(query_file.is_open(), true); + ASSERT_EQ(result_file.is_open(), true); + ASSERT_EQ(input_csv.is_open(), true); + + std::string input, temp; + while (std::getline(input_csv, temp)) + { + input += temp; + input.push_back('\n'); + } + + std::string input_query, expected_res; + int i = 1; + while (getline(query_file, input_query) && getline(result_file, temp)) + { + expected_res = temp; + + while (getline(result_file, temp)) + { + if (temp == "-----***-----") + break; + expected_res.push_back('\n'); + expected_res += temp; + } + + std::cout << "Running query: " << i << std::endl; + auto s3select_res = run_s3select(input_query, input); + EXPECT_EQ(s3select_res, expected_res); + i++; + } + + query_file.close(); + result_file.close(); +} diff --git a/test/test_data.csv b/test/test_data.csv new file mode 100644 index 00000000..94036213 --- /dev/null +++ b/test/test_data.csv @@ -0,0 +1,10 @@ +1,42926,7334,5.5,Brandise,Letsou,Brandise.Letsou@yopmail.com,worker,2020-10-26T11:21:30.397Z +2,21169,3648,9.0,Zaria,Weinreb,Zaria.Weinreb@yopmail.com,worker,2009-12-02T01:22:45.8327Z +3,35581,9091,2.1,Bibby,Primalia,Bibby.Primalia@yopmail.com,doctor,2001-02-27T23:18:23.446633Z +4,38388,7345,4.7,Damaris,Arley,Damaris.Arley@yopmail.com,firefighter,1995-08-24T01:40:00Z +5,42802,6464,7.0,Georgina,Georas,Georgina.Georas@yopmail.com,worker,2013-01-30T05:27:59.2Z +6,45582,5863,0.1,Kelly,Hamil,Kelly.Hamil@yopmail.com,police officer,1998-03-31T17:25Z +7,8548,7665,3.6,Claresta,Flita,Claresta.Flita@yopmail.com,doctor,2007-10-10T22:00:30Z +8,22633,528,5.3,Bibby,Virgin,Bibby.Virgin@yopmail.com,developer,2020-06-30T11:07:01.23323Z +9,38439,5645,2.8,Mahalia,Aldric,Mahalia.Aldric@yopmail.com,doctor,2019-04-20T20:21:22.23Z +10,6611,7287,1.0,Pamella,Sibyls,Pamella.Sibyls@yopmail.com,police officer,2000-09-13T14:41Z diff --git a/test/test_key_multirow.txt b/test/test_key_multirow.txt new file mode 100644 index 00000000..18743a8c --- /dev/null +++ b/test/test_key_multirow.txt @@ -0,0 +1,32 @@ +t5562009wopg06, +t5562009wopg06, +t5562009wopg06, +t5562009wopg06, +t5562009wopg06, +t5562009wopg06, +t5562009wopg06, +t5562009wopg06, +t5562009wopg06, +t5562009wopg06, + +-----***----- +2009-09-17T17:56:06.234567, +2009-09-17T17:56:06.234567, +2009-09-17T17:56:06.234567, +2009-09-17T17:56:06.234567, +2009-09-17T17:56:06.234567, +2009-09-17T17:56:06.234567, +2009-09-17T17:56:06.234567, +2009-09-17T17:56:06.234567, +2009-09-17T17:56:06.234567, +2009-09-17T17:56:06.234567, + +-----***----- +4, +-----***----- +2020-10-26T11:21:30.397Z, +2013-01-30T05:27:59.2Z, +2020-06-30T11:07:01.23323Z, +2019-04-20T20:21:22.23Z, + +-----***----- diff --git a/test/test_key_single.txt b/test/test_key_single.txt new file mode 100644 index 00000000..a81148c4 --- /dev/null +++ b/test/test_key_single.txt @@ -0,0 +1,3 @@ +t5562009wopg06 +2009-09-17T17:56:06.234567 +1 diff --git a/test/test_queries_multirow.txt b/test/test_queries_multirow.txt new file mode 100644 index 00000000..b8e747b6 --- /dev/null +++ b/test/test_queries_multirow.txt @@ -0,0 +1,4 @@ +select to_string(to_timestamp('2009-09-17T17:56:06.234567Z'), substring(' athmywopgss-nghjkl', 3, 10)) from stdin; +select to_timestamp(upper('2009-09-17t17:56:06.234567z')) from stdin; +select count(*) from s3object where extract( year from to_timestamp(_9)) > 2010; +select _9 from s3object where extract( year from to_timestamp(_9)) > 2010; diff --git a/test/test_queries_single.txt b/test/test_queries_single.txt new file mode 100644 index 00000000..77a30d37 --- /dev/null +++ b/test/test_queries_single.txt @@ -0,0 +1,3 @@ +select to_string(to_timestamp('2009-09-17T17:56:06.234567Z'), substring(' athmywopgss-nghjkl', 3, 10)) from stdin; +select to_timestamp(upper('2009-09-17t17:56:06.234567z')) from stdin; +select count(0) from s3object where extract( year from to_timestamp('2009-09-17T17:56:06Z')) < 2010;