Skip to content

Commit

Permalink
Tests for nested queries
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
grajoria committed Mar 10, 2021
1 parent f371855 commit 27aa3cd
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 0 deletions.
63 changes: 63 additions & 0 deletions test/s3select_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "s3select.h"
#include "gtest/gtest.h"
#include <string>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include "boost/date_time/gregorian/gregorian.hpp"
Expand Down Expand Up @@ -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();
}
10 changes: 10 additions & 0 deletions test/test_data.csv
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions test/test_key_multirow.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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,
-----***-----
3 changes: 3 additions & 0 deletions test/test_key_single.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
t5562009wopg06
2009-09-17T17:56:06.234567
1
3 changes: 3 additions & 0 deletions test/test_queries_multirow.txt
Original file line number Diff line number Diff line change
@@ -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(*) from s3object where extract( year from to_timestamp(_9)) > 2010;
3 changes: 3 additions & 0 deletions test/test_queries_single.txt
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 27aa3cd

Please sign in to comment.