add explicit test to TPC-H query properties

This commit is contained in:
Pedro 2017-03-08 16:55:29 +01:00
parent a0e55035fd
commit 9a5a352a0b
2 changed files with 56 additions and 4 deletions

View File

@ -10,6 +10,13 @@
using namespace hsql; using namespace hsql;
std::string readFileContents(std::string file_path) {
std::ifstream t(file_path.c_str());
std::string text((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
return text;
}
TEST(TPCHQueryGrammarTests) { TEST(TPCHQueryGrammarTests) {
std::vector<std::string> files = { std::vector<std::string> files = {
"test/queries/tpc-h-01.sql", "test/queries/tpc-h-01.sql",
@ -28,9 +35,7 @@ TEST(TPCHQueryGrammarTests) {
int testsFailed = 0; int testsFailed = 0;
for (const std::string& file_path : files) { for (const std::string& file_path : files) {
std::ifstream t(file_path.c_str()); std::string query = readFileContents(file_path);
std::string query((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
SQLParserResult* result = SQLParser::parseSQLString(query.c_str()); SQLParserResult* result = SQLParser::parseSQLString(query.c_str());
if (!result->isValid()) { if (!result->isValid()) {
@ -44,3 +49,50 @@ TEST(TPCHQueryGrammarTests) {
} }
ASSERT_EQ(testsFailed, 0); ASSERT_EQ(testsFailed, 0);
} }
TEST(TPCHQueryDetailTest) {
std::string query = readFileContents("test/queries/tpc-h-16-22.sql");
SQLParserResult* result = SQLParser::parseSQLString(query.c_str());
ASSERT(result->isValid());
ASSERT_EQ(result->size(), 7);
const SQLStatement* stmt20 = result->getStatement(4);
ASSERT_EQ(stmt20->type(), kStmtSelect);
const SelectStatement* select20 = (const SelectStatement*) stmt20;
ASSERT_EQ(select20->selectList->size(), 2);
ASSERT_STREQ(select20->selectList->at(0)->getName(), "S_NAME");
ASSERT_STREQ(select20->selectList->at(1)->getName(), "S_ADDRESS");
// Test WHERE Clause.
Expr* where = select20->whereClause;
ASSERT_NOTNULL(where);
ASSERT(where->isType(kExprOperator));
ASSERT_EQ(where->opType, Expr::AND);
Expr* andExpr2 = where->expr;
ASSERT_NOTNULL(andExpr2);
ASSERT(andExpr2->isType(kExprOperator));
ASSERT_EQ(andExpr2->opType, Expr::AND);
// Test IN expression.
Expr* inExpr = andExpr2->expr;
ASSERT_NOTNULL(inExpr);
ASSERT(inExpr->isType(kExprOperator));
ASSERT_EQ(inExpr->opType, Expr::IN);
ASSERT_STREQ(inExpr->expr->getName(), "S_SUPPKEY");
ASSERT_NOTNULL(inExpr->select);
ASSERT_EQ(inExpr->select->selectList->size(), 1);
ASSERT(inExpr->select->selectList->at(0)->isType(kExprColumnRef));
ASSERT_STREQ(inExpr->select->selectList->at(0)->getName(), "PS_SUPPKEY");
// Test ORDER BY clause.
ASSERT_NOTNULL(select20->order);
ASSERT_EQ(select20->order->size(), 1);
ASSERT(select20->order->at(0)->expr->isType(kExprColumnRef));
ASSERT_STREQ(select20->order->at(0)->expr->getName(), "S_NAME");
delete result;
}