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

[15721]Sequence Final PR #1367

Closed
wants to merge 92 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
30d48ac
finish part of parser; need to add handler function in create_executo…
HenryZhou0333 Mar 22, 2018
086b493
finish part of parser; need to add handler function in create_executo…
HenryZhou0333 Mar 22, 2018
59b85f6
Merge branch 'master' of https://github.com/HenryZhou0333/peloton
HenryZhou0333 Mar 22, 2018
282afb3
Merge remote-tracking branch 'upstream/master'
HenryZhou0333 Mar 27, 2018
28b702e
add postgresql parser test for sequences
HenryZhou0333 Mar 28, 2018
ddb3dd7
remove AS in sequencce
HenryZhou0333 Mar 28, 2018
26230e3
add exception for redefined parser
HenryZhou0333 Mar 28, 2018
b273056
finish compiling create sequence
HenryZhou0333 Mar 31, 2018
d90a649
Merge remote-tracking branch 'upstream/master'
HenryZhou0333 Mar 31, 2018
c1a4e1d
having issue with GetSequence()
HenryZhou0333 Apr 2, 2018
f8ec42a
add new GetSequence impl; fix BasicTest in sequence
HenryZhou0333 Apr 8, 2018
0d3521c
add tests for sequence
HenryZhou0333 Apr 10, 2018
8fe7d6c
fix merge conflict
HenryZhou0333 Apr 10, 2018
87680be
one step before submitting pr
HenryZhou0333 Apr 12, 2018
7d7955c
change way of update pg_sequence table in nextval
HenryZhou0333 Apr 12, 2018
503c89f
style fix
Apr 12, 2018
7762354
rename sequence test
HenryZhou0333 Apr 12, 2018
b340c86
Merge remote-tracking branch 'upstream/master'
HenryZhou0333 Apr 12, 2018
6897566
remove unnecessary file
HenryZhou0333 Apr 12, 2018
b8c7317
adding nextval & currval functions; comment out lock and nextval not …
danae-s Apr 14, 2018
d665c94
update pg_sequence after calling nextval; have seg fault in txn;
HenryZhou0333 Apr 16, 2018
e71a21c
temporary add code from other team
HenryZhou0333 Apr 23, 2018
ca8f8fe
fix conflict with master
HenryZhou0333 May 4, 2018
85af574
again fix conflicts
HenryZhou0333 May 4, 2018
2649a7d
Implemented basic func for temp
May 4, 2018
7997a9a
move sequence catalog into system catalogs
HenryZhou0333 May 4, 2018
dadb91f
Make files compiled
May 4, 2018
15913b6
fix bug in setting session namespace
May 4, 2018
0e97cb9
added drop temp schema
May 4, 2018
35d6a5a
fix issues in comments; add sanity check for sequence arguments
HenryZhou0333 May 4, 2018
42a360d
Fix typo DEFUALT_SCHEMA_NAME in all test code
lym953 May 4, 2018
cfc0158
Add session namespace as an argument in some function calls in test code
lym953 May 4, 2018
0ec87c6
Fix bug in GetTableObject()
lym953 May 4, 2018
c3a0cd5
Add java test cases for temp tables
lym953 Apr 10, 2018
eb85cd5
Add test for parsing CREATE statements for temp tables
lym953 Apr 11, 2018
6b12584
move sequence functions from string files to new files
HenryZhou0333 May 5, 2018
bd4210e
implement nextval&currval for multi-session, minor bugs
danae-s May 5, 2018
80ad516
partially implemented drop seq
bdengNE May 5, 2018
e6811f9
merge
danae-s May 5, 2018
9106ba8
Merge branch 'pr2' of https://github.com/HenryZhou0333/peloton into pr2
danae-s May 5, 2018
28045be
fix bug with nextval & currval. now support multi-session
danae-s May 5, 2018
3d93dc6
fix bug with nextval & currval. now support multi-session
danae-s May 5, 2018
fc4a385
fixing some comments
HenryZhou0333 May 5, 2018
527bfc5
add an exception case for currval
danae-s May 5, 2018
836ffc0
drop seq with errors
bdengNE May 5, 2018
5c760c6
drop seq with a bug about txn visibility
bdengNE May 6, 2018
8ca350b
Merge remote-tracking branch 'temptable/temp_table' into currval
HenryZhou0333 May 9, 2018
87dd1c5
add currval session binding
HenryZhou0333 May 9, 2018
5a62fc7
Implemented basic func for temp
May 4, 2018
74ce47f
Make files compiled
May 4, 2018
205e2d3
fix bug in setting session namespace
May 4, 2018
d0d3a5e
added drop temp schema
May 4, 2018
968f8f1
Fix typo DEFUALT_SCHEMA_NAME in all test code
lym953 May 4, 2018
c371663
Add session namespace as an argument in some function calls in test code
lym953 May 4, 2018
09f0587
Fix bug in GetTableObject()
lym953 May 4, 2018
6519434
Add java test cases for temp tables
lym953 Apr 10, 2018
da349d5
Add test for parsing CREATE statements for temp tables
lym953 Apr 11, 2018
37704dd
Fix bugs
lym953 May 11, 2018
2559c54
fix existing test; add invalid argument test;
HenryZhou0333 May 11, 2018
2ff113d
Format code
May 12, 2018
0993d7e
Add comments
May 12, 2018
91990ef
Fix funciton specifications
May 12, 2018
03b45a2
Add temp table C++ test
lym953 May 12, 2018
a37333e
added foriegnk key constraints for the same schema
May 13, 2018
501e390
solve conflict with remote
May 13, 2018
7989406
Add ForeignKeyTest for temp table
lym953 May 13, 2018
49cd4a4
Add a small test to TableVisibilityTest
lym953 May 13, 2018
747e89a
finished foreign key feature
May 13, 2018
fde290f
added oid_table for txn. TODO: on commit support for create table
May 13, 2018
97c5930
Added parser option for on commit upon creating table
May 13, 2018
03f0729
Fix compilation error
lym953 May 13, 2018
f318be8
Fix a bug in ForeignKeyTest
lym953 May 13, 2018
a073cf0
Simplify test code using EXPECT_THROW
lym953 May 13, 2018
7389bf1
Fix bugs in PsqlTempTableTests
lym953 May 13, 2018
b31e2ee
added on commit drop option
May 13, 2018
e632496
Merge branch 'temp_table' of https://github.com/lym953/peloton into t…
May 13, 2018
535ee0d
Enclose each test in PsqlTempTableTests with a try-catch block
lym953 May 13, 2018
f3b0b33
Add OnCommitOptionsTest for temp table
lym953 May 13, 2018
b482c2e
add drop seq tests and format the codesbased on review
bdengNE May 14, 2018
9ba0eea
Comment out test code for ON COMMIT DELETE ROWS because it is not sup…
lym953 May 14, 2018
60e222d
Add tests.
danae-s May 14, 2018
b4dfb68
fix sequence_functions_test
HenryZhou0333 May 14, 2018
9c4e2f3
Fix tests.
danae-s May 14, 2018
df186bb
Remove TempTableTest.java
lym953 May 14, 2018
7e49b44
fix bugs in foreign key constraint
May 14, 2018
bbc1193
Merge branch 'temp_table' of https://github.com/lym953/peloton into t…
May 14, 2018
c35ab86
Build with release, remove unused variables.
danae-s May 14, 2018
f282909
Conflicts resolved
danae-s May 14, 2018
0e61e12
Fix tests. catalog table 8->9
danae-s May 14, 2018
acac8fc
fix test in valgrind
HenryZhou0333 May 14, 2018
65318ca
fix comment in pr2
HenryZhou0333 May 14, 2018
d85e1c7
fix test
HenryZhou0333 May 14, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions script/testing/junit/SequenceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
//===----------------------------------------------------------------------===//
//
// Peloton
//
// SequenceTest.java
//
// Identification: script/testing/junit/SequenceTest.java
//
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

import java.sql.*;
import org.junit.*;
import org.postgresql.util.PSQLException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static junit.framework.TestCase.fail;

public class SequenceTest extends PLTestBase {
private Connection conn1;
private Connection conn2;

private static final String SQL_DROP_SEQ =
"DROP SEQUENCE seq;";

private static final String SQL_CREATE_SEQ =
"CREATE SEQUENCE seq;";

private static final String SQL_NEXTVAL =
"SELECT NEXTVAL('seq')";

private static final String SQL_CURRVAL =
"SELECT CURRVAL('seq')";

/**
* Test sequence functions for single-statment transactions
*/
@Test
public void test_SingleStmtTxn() throws SQLException {
conn1 = makeDefaultConnection();
conn1.setAutoCommit(true);
Statement stmt1 = conn1.createStatement();

conn2 = makeDefaultConnection();
conn2.setAutoCommit(true);
Statement stmt2 = conn2.createStatement();

// Create a sequence
stmt1.execute(SQL_CREATE_SEQ);

// Check the sequence is visible by others
try {
stmt2.execute(SQL_CREATE_SEQ);
fail();
} catch (PSQLException e) { }

// Check currval cannot be called before nextval
try {
stmt1.execute(SQL_CURRVAL);
fail();
} catch (PSQLException e) { }

// Check functionality with conn1
stmt1.execute(SQL_NEXTVAL);
ResultSet res1 = stmt1.executeQuery(SQL_CURRVAL);
res1.next();
assertEquals(1, res1.getInt(1));
assertNoMoreRows(res1);

// Update should be visible to conn2
stmt2.execute(SQL_NEXTVAL);
ResultSet res2 = stmt2.executeQuery(SQL_CURRVAL);
res2.next();
assertEquals(2, res2.getInt(1));
assertNoMoreRows(res2);

// Currval should be session consistent
res1 = stmt1.executeQuery(SQL_CURRVAL);
res1.next();
assertEquals(1, res1.getInt(1));
assertNoMoreRows(res1);

// Clean up
stmt1.close();
conn1.close();
stmt2.close();
conn2.close();
}

/**
* Test sequence functions for multi-statment transactions
*/
@Test
public void test_MultiStmtTxn() throws SQLException {
conn1 = makeDefaultConnection();
conn1.setAutoCommit(false);
Statement stmt1 = conn1.createStatement();

conn2 = makeDefaultConnection();
conn2.setAutoCommit(false);
Statement stmt2 = conn2.createStatement();

// Check functionality with conn1
stmt1.execute(SQL_NEXTVAL);
ResultSet res1 = stmt1.executeQuery(SQL_CURRVAL);
res1.next();
assertEquals(3, res1.getInt(1));
assertNoMoreRows(res1);

// Update should be visible to conn2
stmt2.execute(SQL_NEXTVAL);
ResultSet res2 = stmt2.executeQuery(SQL_CURRVAL);
res2.next();
assertEquals(4, res2.getInt(1));
assertNoMoreRows(res2);

// Rollback transactions
conn1.rollback();
conn2.rollback();

// Check sequence incremental will not rollback
conn1.setAutoCommit(true);
stmt1.execute(SQL_NEXTVAL);
res1 = stmt1.executeQuery(SQL_CURRVAL);
res1.next();
assertEquals(5, res1.getInt(1));
assertNoMoreRows(res1);

// Clean up
stmt1.close();
conn1.close();
stmt2.close();
conn2.close();
}

/**
* Test dropping sequence
*/
@Test
public void test_Drop_Seq() throws SQLException {
conn1 = makeDefaultConnection();
conn1.setAutoCommit(true);
Statement stmt1 = conn1.createStatement();

conn2 = makeDefaultConnection();
conn2.setAutoCommit(true);
Statement stmt2 = conn2.createStatement();

// Drop the sequence
stmt1.execute(SQL_DROP_SEQ);

// Check the sequence is invisible to all conns
try {
stmt1.execute(SQL_CURRVAL);
fail();
} catch (PSQLException e) { }
try {
stmt2.execute(SQL_CURRVAL);
fail();
} catch (PSQLException e) { }

// Check the same sequence can be created w/o exception
stmt2.execute(SQL_CREATE_SEQ);

// Clean up
stmt1.close();
conn1.close();
stmt2.close();
conn2.close();
}
}
179 changes: 179 additions & 0 deletions script/testing/junit/TempTableTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
//===----------------------------------------------------------------------===//
//
// Peloton
//
// TempTableTest.java
//
// Identification: script/testing/junit/TempTableTest.java
//
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

import java.sql.*;
import org.junit.*;
import org.postgresql.util.PSQLException;

import static junit.framework.TestCase.fail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class TempTableTest extends PLTestBase {

private static final String SQL_DROP_TABLE =
"DROP TABLE IF EXISTS tbl;";

// Create a permanent table called "tbl"
private static final String SQL_CREATE_PERM_TABLE =
"CREATE TABLE tbl (id integer, year integer);";
// Create temp table using "TEMP" keyword
private static final String SQL_CREATE_TEMP_TABLE =
"CREATE TEMP TABLE tbl (id integer, year integer);";
// Create temp table using "TEMPORARY" keyword
private static final String SQL_CREATE_TEMPORARY_TABLE =
"CREATE TEMPORARY TABLE tbl (id integer, year integer);";

private static final String SQL_INSERT =
"INSERT INTO tbl VALUES (10, 1995);";

private static final String SQL_SELECT = "SELECT * FROM tbl;";

/**
* Check the temp table created by one session is visible to itself,
* but not visible to other sessions
*/
@Test
public void test_Visibility() throws SQLException {
Connection conn1 = makeDefaultConnection();
conn1.setAutoCommit(true);
Statement stmt1 = conn1.createStatement();

Connection conn2 = makeDefaultConnection();
conn2.setAutoCommit(true);
Statement stmt2 = conn2.createStatement();

// Part 1: Create temp table using "TEMP" keyword
stmt1.execute(SQL_DROP_TABLE);
// Create a temp table called "tbl"
stmt1.execute(SQL_CREATE_TEMP_TABLE);
// Insert a tuple into the temp table
stmt1.execute(SQL_INSERT);

// Check the temp table is visible to the session created it
ResultSet res1 = stmt1.executeQuery(SQL_SELECT);
res1.next();
checkRow(res1,
new String [] {"id", "year"},
new int [] {10, 1995});
assertNoMoreRows(res1);

// Check the temp table is invisible to another session started
// before the temp table was created
// Expect an exception: "Table tbl is not found"
try {
stmt2.execute(SQL_SELECT);
fail();
} catch (PSQLException e) { }

// Check the temp table is invisible to another session started
// after the temp table was created
// Expect an exception: "Table tbl is not found"
conn2 = makeDefaultConnection();
conn2.setAutoCommit(true);
stmt2 = conn2.createStatement();
try {
stmt2.execute(SQL_SELECT);
fail();
} catch (PSQLException e) { }
stmt2.close();
conn2.close();

// Check the temp table is invisible to another session started
// after the session which created it has closed
// Expect an exception: "Table tbl is not found"
stmt1.close();
conn1.close();
conn2 = makeDefaultConnection();
conn2.setAutoCommit(true);
stmt2 = conn2.createStatement();
try {
stmt2.execute(SQL_SELECT);
fail();
} catch (PSQLException e) { }
stmt2.close();
conn2.close();

// Part 2: Create temp table using "TEMPORARY" keyword
conn1 = makeDefaultConnection();
conn1.setAutoCommit(true);
stmt1 = conn1.createStatement();
stmt1.execute(SQL_DROP_TABLE);
stmt1.execute(SQL_CREATE_TEMPORARY_TABLE);

// Check the temp table is visible to the session created it
ResultSet res2 = stmt1.executeQuery(SQL_SELECT);
res2.next();
assertNoMoreRows(res2);

// Check the temp table is invisible to another session started
// before the table was created
// Expect an exception: "Table tbl is not found"
try {
stmt2.execute(SQL_SELECT);
fail();
} catch (PSQLException e) { }

stmt1.close();
conn1.close();
stmt2.close();
conn2.close();
}

/**
* Check that during the lifetime of a temp table, the permanent table
* with the same name is invisible
*/
@Test
public void test_Temp_Table_Hides_Perm_Table() throws SQLException {
Connection conn = makeDefaultConnection();
conn.setAutoCommit(true);
Statement stmt = conn.createStatement();

stmt.execute(SQL_DROP_TABLE);
// Create a permanent table called "tbl"
stmt.execute(SQL_CREATE_PERM_TABLE);
// Create a temp table called "tbl"
stmt.execute(SQL_CREATE_TEMP_TABLE);
// Insert a tuple into the temp table
stmt.execute(SQL_INSERT);

// Check the "tbl" visible now is the temp table, not the permanent table
ResultSet res1 = stmt.executeQuery(SQL_SELECT);
res1.next();
checkRow(res1,
new String [] {"id", "year"},
new int [] {10, 1995});
assertNoMoreRows(res1);

// Drop the temp table
stmt.execute(SQL_DROP_TABLE);

// Check the "tbl" visible now is the permanent table
ResultSet res2 = stmt.executeQuery(SQL_SELECT);
res2.next();
assertNoMoreRows(res2);

// Drop the permanent table
stmt.execute(SQL_DROP_TABLE);

// No table named "tbl" should exist now
// Expect an exception: "Table tbl is not found"
try {
stmt.execute(SQL_SELECT);
fail();
} catch (PSQLException e) { }

stmt.close();
conn.close();
}
}
14 changes: 9 additions & 5 deletions src/binder/bind_node_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ namespace peloton {
namespace binder {

BindNodeVisitor::BindNodeVisitor(concurrency::TransactionContext *txn,
std::string default_database_name)
: txn_(txn), default_database_name_(default_database_name) {
std::string default_database_name,
std::string session_namespace)
: txn_(txn), default_database_name_(default_database_name),
session_namespace_(session_namespace) {
catalog_ = catalog::Catalog::GetInstance();
context_ = nullptr;
}
Expand Down Expand Up @@ -117,7 +119,7 @@ void BindNodeVisitor::Visit(parser::TableRef *node) {
}
// Single table
else {
context_->AddRegularTable(node, default_database_name_, txn_);
context_->AddRegularTable(node, default_database_name_, session_namespace_, txn_);
}
}

Expand Down Expand Up @@ -156,7 +158,8 @@ void BindNodeVisitor::Visit(parser::DeleteStatement *node) {
context_ = std::make_shared<BinderContext>(nullptr);
node->TryBindDatabaseName(default_database_name_);
context_->AddRegularTable(node->GetDatabaseName(), node->GetSchemaName(),
node->GetTableName(), node->GetTableName(), txn_);
node->GetTableName(), node->GetTableName(),
session_namespace_, txn_);

if (node->expr != nullptr) {
node->expr->Accept(this);
Expand All @@ -175,7 +178,8 @@ void BindNodeVisitor::Visit(parser::InsertStatement *node) {
node->TryBindDatabaseName(default_database_name_);
context_ = std::make_shared<BinderContext>(nullptr);
context_->AddRegularTable(node->GetDatabaseName(), node->GetSchemaName(),
node->GetTableName(), node->GetTableName(), txn_);
node->GetTableName(), node->GetTableName(),
session_namespace_, txn_);
if (node->select != nullptr) {
node->select->Accept(this);
}
Expand Down
Loading