Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 649cf60

Browse files
committed
added namespace sql test
1 parent 1599922 commit 649cf60

File tree

3 files changed

+84
-50
lines changed

3 files changed

+84
-50
lines changed

src/common/internal_types.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ std::string QueryTypeToString(QueryType query_type) {
585585
return "EXECUTE";
586586
case QueryType::QUERY_SELECT:
587587
return "SELECT";
588-
case QueryType::QUERY_EXPLAIN:
588+
case QueryType::QUERY_EXPLAIN:
589589
return "EXPLAIN";
590590
case QueryType::QUERY_OTHER:
591591
default:
@@ -633,20 +633,18 @@ QueryType StatementTypeToQueryType(StatementType stmt_type,
633633
const parser::SQLStatement *sql_stmt) {
634634
LOG_TRACE("%s", StatementTypeToString(stmt_type).c_str());
635635
static std::unordered_map<StatementType, QueryType, EnumHash<StatementType>>
636-
type_map{
637-
{StatementType::EXECUTE, QueryType::QUERY_EXECUTE},
638-
{StatementType::PREPARE, QueryType::QUERY_PREPARE},
639-
{StatementType::INSERT, QueryType::QUERY_INSERT},
640-
{StatementType::UPDATE, QueryType::QUERY_UPDATE},
641-
{StatementType::DELETE, QueryType::QUERY_DELETE},
642-
{StatementType::COPY, QueryType::QUERY_COPY},
643-
{StatementType::ANALYZE, QueryType::QUERY_ANALYZE},
644-
{StatementType::ALTER, QueryType::QUERY_ALTER},
645-
{StatementType::DROP, QueryType::QUERY_DROP},
646-
{StatementType::SELECT, QueryType::QUERY_SELECT},
647-
{StatementType::VARIABLE_SET, QueryType::QUERY_SET},
648-
{StatementType::EXPLAIN, QueryType::QUERY_EXPLAIN}
649-
};
636+
type_map{{StatementType::EXECUTE, QueryType::QUERY_EXECUTE},
637+
{StatementType::PREPARE, QueryType::QUERY_PREPARE},
638+
{StatementType::INSERT, QueryType::QUERY_INSERT},
639+
{StatementType::UPDATE, QueryType::QUERY_UPDATE},
640+
{StatementType::DELETE, QueryType::QUERY_DELETE},
641+
{StatementType::COPY, QueryType::QUERY_COPY},
642+
{StatementType::ANALYZE, QueryType::QUERY_ANALYZE},
643+
{StatementType::ALTER, QueryType::QUERY_ALTER},
644+
{StatementType::DROP, QueryType::QUERY_DROP},
645+
{StatementType::SELECT, QueryType::QUERY_SELECT},
646+
{StatementType::VARIABLE_SET, QueryType::QUERY_SET},
647+
{StatementType::EXPLAIN, QueryType::QUERY_EXPLAIN}};
650648
QueryType query_type = QueryType::QUERY_OTHER;
651649
std::unordered_map<StatementType, QueryType,
652650
EnumHash<StatementType>>::iterator it =
@@ -2004,6 +2002,9 @@ std::string ResultTypeToString(ResultType type) {
20042002
case ResultType::QUEUING: {
20052003
return ("QUEUING");
20062004
}
2005+
case ResultType::TO_ABORT: {
2006+
return ("TO_ABORT");
2007+
}
20072008
default: {
20082009
throw ConversionException(
20092010
StringUtil::Format("No string conversion for ResultType value '%d'",

test/catalog/catalog_test.cpp

Lines changed: 64 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "concurrency/transaction_manager_factory.h"
2424
#include "storage/storage_manager.h"
2525
#include "type/ephemeral_pool.h"
26+
#include "sql/testing_sql_util.h"
2627

2728
namespace peloton {
2829
namespace test {
@@ -116,40 +117,6 @@ TEST_F(CatalogTests, CreatingTable) {
116117
->GetColumnObject(1)
117118
->GetColumnName());
118119
txn_manager.CommitTransaction(txn);
119-
// EXPECT_EQ(5, time_stamp);
120-
121-
// We remove these tests so people can add new catalogs without breaking this
122-
// test...
123-
// 3 + 4
124-
// EXPECT_EQ(catalog::Catalog::GetInstance()
125-
// ->GetDatabaseWithName("pg_catalog")
126-
// ->GetTableWithName("pg_table")
127-
// ->GetTupleCount(),
128-
// 11);
129-
// // 6 + pg_database(2) + pg_table(3) + pg_attribute(7) + pg_index(6)
130-
// EXPECT_EQ(catalog::Catalog::GetInstance()
131-
// ->GetDatabaseWithName("pg_catalog")
132-
// ->GetTableWithName("pg_attribute")
133-
// ->GetTupleCount(),
134-
// 57);
135-
// // pg_catalog + emp_db
136-
// EXPECT_EQ(catalog::Catalog::GetInstance()
137-
// ->GetDatabaseWithName("pg_catalog")
138-
// ->GetTableWithName("pg_database")
139-
// ->GetTupleCount(),
140-
// 2);
141-
// // 3 + pg_index(3) + pg_attribute(3) + pg_table(3) + pg_database(2)
142-
// EXPECT_EQ(catalog::Catalog::GetInstance()
143-
// ->GetDatabaseWithName("pg_catalog")
144-
// ->GetTableWithName("pg_index")
145-
// ->GetTupleCount(),
146-
// 18);
147-
// EXPECT_EQ(catalog::Catalog::GetInstance()
148-
// ->GetDatabaseWithName("pg_catalog")
149-
// ->GetTableWithName("pg_table")
150-
// ->GetSchema()
151-
// ->GetLength(),
152-
// 72);
153120
}
154121

155122
TEST_F(CatalogTests, TableObject) {
@@ -200,6 +167,69 @@ TEST_F(CatalogTests, TableObject) {
200167
txn_manager.CommitTransaction(txn);
201168
}
202169

170+
TEST_F(CatalogTests, TestingNamespace) {
171+
EXPECT_EQ(ResultType::SUCCESS, TestingSQLUtil::ExecuteSQLQuery("begin;"));
172+
// create namespaces emp_ns0 and emp_ns1
173+
EXPECT_EQ(ResultType::SUCCESS, TestingSQLUtil::ExecuteSQLQuery(
174+
"create database default_database;"));
175+
EXPECT_EQ(ResultType::SUCCESS,
176+
TestingSQLUtil::ExecuteSQLQuery("create schema emp_ns0;"));
177+
EXPECT_EQ(ResultType::SUCCESS,
178+
TestingSQLUtil::ExecuteSQLQuery("create schema emp_ns1;"));
179+
180+
// create emp_table0 and emp_table1 in namespaces
181+
EXPECT_EQ(ResultType::SUCCESS,
182+
TestingSQLUtil::ExecuteSQLQuery(
183+
"create table emp_ns0.emp_table0 (a int, b varchar);"));
184+
EXPECT_EQ(ResultType::SUCCESS,
185+
TestingSQLUtil::ExecuteSQLQuery(
186+
"create table emp_ns0.emp_table1 (a int, b varchar);"));
187+
EXPECT_EQ(ResultType::SUCCESS,
188+
TestingSQLUtil::ExecuteSQLQuery(
189+
"create table emp_ns1.emp_table0 (a int, b varchar);"));
190+
EXPECT_EQ(ResultType::FAILURE,
191+
TestingSQLUtil::ExecuteSQLQuery(
192+
"create table emp_ns1.emp_table0 (a int, b varchar);"));
193+
194+
// insert values into emp_table0
195+
EXPECT_EQ(ResultType::SUCCESS,
196+
TestingSQLUtil::ExecuteSQLQuery(
197+
"insert into emp_ns0.emp_table0 values (1, 'abc');"));
198+
EXPECT_EQ(ResultType::SUCCESS,
199+
TestingSQLUtil::ExecuteSQLQuery(
200+
"insert into emp_ns0.emp_table0 values (2, 'abc');"));
201+
EXPECT_EQ(ResultType::SUCCESS,
202+
TestingSQLUtil::ExecuteSQLQuery(
203+
"insert into emp_ns1.emp_table0 values (1, 'abc');"));
204+
205+
// select values from emp_table0 and emp_table1
206+
TestingSQLUtil::ExecuteSQLQueryAndCheckResult(
207+
"select * from emp_ns0.emp_table1;", {});
208+
TestingSQLUtil::ExecuteSQLQueryAndCheckResult(
209+
"select * from emp_ns0.emp_table0;", {"1|abc", "2|abc"});
210+
TestingSQLUtil::ExecuteSQLQueryAndCheckResult(
211+
"select * from emp_ns1.emp_table0;", {"1|abc"});
212+
EXPECT_EQ(ResultType::SUCCESS, TestingSQLUtil::ExecuteSQLQuery("commit;"));
213+
EXPECT_EQ(ResultType::SUCCESS, TestingSQLUtil::ExecuteSQLQuery("begin;"));
214+
EXPECT_EQ(ResultType::FAILURE, TestingSQLUtil::ExecuteSQLQuery(
215+
"select * from emp_ns1.emp_table1;"));
216+
EXPECT_EQ(ResultType::ABORTED, TestingSQLUtil::ExecuteSQLQuery("commit;"));
217+
218+
// drop namespace emp_ns0 and emp_ns1
219+
EXPECT_EQ(ResultType::SUCCESS, TestingSQLUtil::ExecuteSQLQuery("begin;"));
220+
EXPECT_EQ(ResultType::SUCCESS,
221+
TestingSQLUtil::ExecuteSQLQuery("drop schema emp_ns0;"));
222+
TestingSQLUtil::ExecuteSQLQueryAndCheckResult(
223+
"select * from emp_ns1.emp_table0;", {"1|abc"});
224+
EXPECT_EQ(ResultType::SUCCESS, TestingSQLUtil::ExecuteSQLQuery("commit;"));
225+
EXPECT_EQ(ResultType::SUCCESS, TestingSQLUtil::ExecuteSQLQuery("begin;"));
226+
EXPECT_EQ(ResultType::FAILURE,
227+
TestingSQLUtil::ExecuteSQLQuery("drop schema emp_ns0;"));
228+
EXPECT_EQ(ResultType::FAILURE, TestingSQLUtil::ExecuteSQLQuery(
229+
"select * from emp_ns0.emp_table1;"));
230+
EXPECT_EQ(ResultType::ABORTED, TestingSQLUtil::ExecuteSQLQuery("commit;"));
231+
}
232+
203233
TEST_F(CatalogTests, DroppingTable) {
204234
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
205235
auto txn = txn_manager.BeginTransaction();

test/sql/testing_sql_util.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ ResultType TestingSQLUtil::ExecuteSQLQueryWithOptimizer(
115115
bind_node_visitor.BindNameToNode(parsed_stmt->GetStatement(0));
116116

117117
auto plan = optimizer->BuildPelotonPlanTree(parsed_stmt, txn);
118+
txn_manager.CommitTransaction(txn);
118119
tuple_descriptor =
119120
traffic_cop_.GenerateTupleDescriptor(parsed_stmt->GetStatement(0));
120121
auto result_format = std::vector<int>(tuple_descriptor.size(), 0);
@@ -248,7 +249,9 @@ void TestingSQLUtil::ExecuteSQLQueryAndCheckResult(
248249
// Execute query
249250
TestingSQLUtil::ExecuteSQLQuery(std::move(query), result, tuple_descriptor,
250251
rows_changed, error_message);
251-
unsigned int rows = result.size() / tuple_descriptor.size();
252+
unsigned int rows = tuple_descriptor.size() == 0
253+
? result.size()
254+
: result.size() / tuple_descriptor.size();
252255

253256
// Build actual result as set of rows for comparison
254257
std::vector<std::string> actual_result(rows);

0 commit comments

Comments
 (0)