Skip to content

Commit a8e6ec6

Browse files
committed
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 <grajoria@redhat.com>
1 parent f371855 commit a8e6ec6

File tree

6 files changed

+115
-0
lines changed

6 files changed

+115
-0
lines changed

test/s3select_test.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "s3select.h"
22
#include "gtest/gtest.h"
33
#include <string>
4+
#include <fstream>
45
#include <iomanip>
56
#include <algorithm>
67
#include "boost/date_time/gregorian/gregorian.hpp"
@@ -2448,3 +2449,65 @@ TEST(TestS3selectFunctions, trim11)
24482449
test_single_column_single_row( "select trim(trailing from trim(leading from \" foobar \")) from stdin ;" ,"foobar,\n");
24492450
}
24502451

2452+
TEST(TestS3selectFunctions, nested_query_single_row_result)
2453+
{
2454+
std::fstream query_file, result_file, input_csv;
2455+
query_file.open("./test/test_queries_single.txt", std::ios::in);
2456+
result_file.open("./test/test_key_single.txt", std::ios::in);
2457+
ASSERT_EQ(query_file.is_open(), true);
2458+
ASSERT_EQ(result_file.is_open(), true);
2459+
2460+
std::string input_query, expected_res;
2461+
int i = 1;
2462+
while(getline(query_file, input_query) && getline(result_file, expected_res))
2463+
{
2464+
std::cout << "Running query: " << i << std::endl;
2465+
auto s3select_res = run_s3select(input_query);
2466+
EXPECT_EQ(s3select_res, expected_res);
2467+
i++;
2468+
}
2469+
2470+
query_file.close();
2471+
result_file.close();
2472+
}
2473+
2474+
TEST(TestS3selectFunctions, nested_multirow_queries)
2475+
{
2476+
std::fstream query_file, result_file, input_csv;
2477+
query_file.open("./test/test_queries_multirow.txt", std::ios::in);
2478+
result_file.open("./test/test_key_multirow.txt", std::ios::in);
2479+
input_csv.open("./test/test_data.csv", std::ios::in);
2480+
ASSERT_EQ(query_file.is_open(), true);
2481+
ASSERT_EQ(result_file.is_open(), true);
2482+
ASSERT_EQ(input_csv.is_open(), true);
2483+
2484+
std::string input, temp;
2485+
while (std::getline(input_csv, temp))
2486+
{
2487+
input += temp;
2488+
input.push_back('\n');
2489+
}
2490+
2491+
std::string input_query, expected_res;
2492+
int i = 1;
2493+
while (getline(query_file, input_query) && getline(result_file, temp))
2494+
{
2495+
expected_res = temp;
2496+
2497+
while (getline(result_file, temp))
2498+
{
2499+
if (temp == "-----***-----")
2500+
break;
2501+
expected_res.push_back('\n');
2502+
expected_res += temp;
2503+
}
2504+
2505+
std::cout << "Running query: " << i << std::endl;
2506+
auto s3select_res = run_s3select(input_query, input);
2507+
EXPECT_EQ(s3select_res, expected_res);
2508+
i++;
2509+
}
2510+
2511+
query_file.close();
2512+
result_file.close();
2513+
}

test/test_data.csv

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
1,42926,7334,5.5,Brandise,Letsou,Brandise.Letsou@yopmail.com,worker,2020-10-26T11:21:30.397Z
2+
2,21169,3648,9.0,Zaria,Weinreb,Zaria.Weinreb@yopmail.com,worker,2009-12-02T01:22:45.8327Z
3+
3,35581,9091,2.1,Bibby,Primalia,Bibby.Primalia@yopmail.com,doctor,2001-02-27T23:18:23.446633Z
4+
4,38388,7345,4.7,Damaris,Arley,Damaris.Arley@yopmail.com,firefighter,1995-08-24T01:40:00Z
5+
5,42802,6464,7.0,Georgina,Georas,Georgina.Georas@yopmail.com,worker,2013-01-30T05:27:59.2Z
6+
6,45582,5863,0.1,Kelly,Hamil,Kelly.Hamil@yopmail.com,police officer,1998-03-31T17:25Z
7+
7,8548,7665,3.6,Claresta,Flita,Claresta.Flita@yopmail.com,doctor,2007-10-10T22:00:30Z
8+
8,22633,528,5.3,Bibby,Virgin,Bibby.Virgin@yopmail.com,developer,2020-06-30T11:07:01.23323Z
9+
9,38439,5645,2.8,Mahalia,Aldric,Mahalia.Aldric@yopmail.com,doctor,2019-04-20T20:21:22.23Z
10+
10,6611,7287,1.0,Pamella,Sibyls,Pamella.Sibyls@yopmail.com,police officer,2000-09-13T14:41Z

test/test_key_multirow.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
t5562009wopg06,
2+
t5562009wopg06,
3+
t5562009wopg06,
4+
t5562009wopg06,
5+
t5562009wopg06,
6+
t5562009wopg06,
7+
t5562009wopg06,
8+
t5562009wopg06,
9+
t5562009wopg06,
10+
t5562009wopg06,
11+
12+
-----***-----
13+
2009-09-17T17:56:06.234567,
14+
2009-09-17T17:56:06.234567,
15+
2009-09-17T17:56:06.234567,
16+
2009-09-17T17:56:06.234567,
17+
2009-09-17T17:56:06.234567,
18+
2009-09-17T17:56:06.234567,
19+
2009-09-17T17:56:06.234567,
20+
2009-09-17T17:56:06.234567,
21+
2009-09-17T17:56:06.234567,
22+
2009-09-17T17:56:06.234567,
23+
24+
-----***-----
25+
4,
26+
-----***-----
27+
2020-10-26T11:21:30.397Z,
28+
2013-01-30T05:27:59.2Z,
29+
2020-06-30T11:07:01.23323Z,
30+
2019-04-20T20:21:22.23Z,
31+
32+
-----***-----

test/test_key_single.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
t5562009wopg06
2+
2009-09-17T17:56:06.234567
3+
1

test/test_queries_multirow.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
select to_string(to_timestamp('2009-09-17T17:56:06.234567Z'), substring(' athmywopgss-nghjkl', 3, 10)) from stdin;
2+
select to_timestamp(upper('2009-09-17t17:56:06.234567z')) from stdin;
3+
select count(*) from s3object where extract( year from to_timestamp(_9)) > 2010;
4+
select _9 from s3object where extract( year from to_timestamp(_9)) > 2010;

test/test_queries_single.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
select to_string(to_timestamp('2009-09-17T17:56:06.234567Z'), substring(' athmywopgss-nghjkl', 3, 10)) from stdin;
2+
select to_timestamp(upper('2009-09-17t17:56:06.234567z')) from stdin;
3+
select count(0) from s3object where extract( year from to_timestamp('2009-09-17T17:56:06Z')) < 2010;

0 commit comments

Comments
 (0)