diff --git a/simpledb/lib/zql.jar b/simpledb/lib/zql.jar index ac02332..7e7b256 100644 Binary files a/simpledb/lib/zql.jar and b/simpledb/lib/zql.jar differ diff --git a/simpledb/src/java/simpledb/ExperimentRunner.java b/simpledb/src/java/simpledb/ExperimentRunner.java index 9a258f6..526add3 100644 --- a/simpledb/src/java/simpledb/ExperimentRunner.java +++ b/simpledb/src/java/simpledb/ExperimentRunner.java @@ -1,9 +1,9 @@ package simpledb; -import org.gibello.zql.ParseException; -import org.gibello.zql.ZQuery; -import org.gibello.zql.ZStatement; -import org.gibello.zql.ZqlParser; +import Zql.ParseException; +import Zql.ZQuery; +import Zql.ZStatement; +import Zql.ZqlParser; import java.io.ByteArrayInputStream; import java.io.FileWriter; diff --git a/simpledb/src/java/simpledb/Parser.java b/simpledb/src/java/simpledb/Parser.java index d44e935..075a029 100644 --- a/simpledb/src/java/simpledb/Parser.java +++ b/simpledb/src/java/simpledb/Parser.java @@ -1,6 +1,6 @@ package simpledb; -import org.gibello.zql.*; +import Zql.*; import java.io.*; import java.lang.reflect.InvocationTargetException; import java.util.*; @@ -127,6 +127,9 @@ void processExpression(TransactionId tid, ZExpression wx, LogicalPlan lp) } catch (IOException e) { throw new simpledb.ParsingException("Invalid subquery " + ops.elementAt(1)); + } catch (Zql.ParseException e) { + throw new simpledb.ParsingException("Invalid subquery " + + ops.elementAt(1)); } } else { tab2field = ((ZConstant) ops.elementAt(1)).getValue(); @@ -153,7 +156,9 @@ void processExpression(TransactionId tid, ZExpression wx, LogicalPlan lp) } - public LogicalPlan parseQueryLogicalPlan(TransactionId tid, ZQuery q) throws IOException, simpledb.ParsingException { + public LogicalPlan parseQueryLogicalPlan(TransactionId tid, ZQuery q) + throws IOException, Zql.ParseException, simpledb.ParsingException { + @SuppressWarnings("unchecked") Vector from = q.getFrom(); LogicalPlan lp = planFactory.apply(null); lp.setQuery(q.toString()); @@ -224,6 +229,7 @@ public LogicalPlan parseQueryLogicalPlan(TransactionId tid, ZQuery q) throws IOE // walk the select list, pick out aggregates, and check for query // validity + @SuppressWarnings("unchecked") Vector selectList = q.getSelect(); String aggField = null; String aggFun = null; @@ -269,6 +275,7 @@ public LogicalPlan parseQueryLogicalPlan(TransactionId tid, ZQuery q) throws IOE // sort the data if (q.getOrderBy() != null) { + @SuppressWarnings("unchecked") Vector obys = q.getOrderBy(); if (obys.size() > 1) { throw new simpledb.ParsingException( @@ -289,7 +296,7 @@ public LogicalPlan parseQueryLogicalPlan(TransactionId tid, ZQuery q) throws IOE public Query handleQueryStatement(ZQuery s, TransactionId tId) throws TransactionAbortedException, DbException, IOException, - simpledb.ParsingException, ParseException { + simpledb.ParsingException, Zql.ParseException { Query query = new Query(tId); LogicalPlan lp = parseQueryLogicalPlan(tId, s); @@ -336,7 +343,7 @@ public Query handleQueryStatement(ZQuery s, TransactionId tId) public Query handleQueryStatementSilent(ZQuery s, TransactionId tId) throws TransactionAbortedException, DbException, IOException, - simpledb.ParsingException, ParseException { + simpledb.ParsingException, Zql.ParseException { Query query = new Query(tId); LogicalPlan lp = parseQueryLogicalPlan(tId, s); DbIterator physicalPlan = lp.physicalPlan(tId, @@ -348,7 +355,7 @@ public Query handleQueryStatementSilent(ZQuery s, TransactionId tId) public Query handleInsertStatement(ZInsert s, TransactionId tId) throws TransactionAbortedException, DbException, IOException, - simpledb.ParsingException, ParseException { + simpledb.ParsingException, Zql.ParseException { int tableId; try { tableId = Database.getCatalog().getTableId(s.getTable()); // will @@ -422,7 +429,7 @@ public Query handleInsertStatement(ZInsert s, TransactionId tId) public Query handleDeleteStatement(ZDelete s, TransactionId tid) throws TransactionAbortedException, DbException, IOException, - simpledb.ParsingException, ParseException { + simpledb.ParsingException, Zql.ParseException { int id; try { id = Database.getCatalog().getTableId(s.getTable()); // will fall @@ -453,6 +460,38 @@ public Query handleDeleteStatement(ZDelete s, TransactionId tid) } + public void handleTransactStatement(ZTransactStmt s) + throws TransactionAbortedException, DbException, IOException, + simpledb.ParsingException, Zql.ParseException { + if (s.getStmtType().equals("COMMIT")) { + if (curtrans == null) + throw new simpledb.ParsingException( + "No transaction is currently running"); + curtrans.commit(); + curtrans = null; + inUserTrans = false; + } else if (s.getStmtType().equals("ROLLBACK")) { + if (curtrans == null) + throw new simpledb.ParsingException( + "No transaction is currently running"); + curtrans.abort(); + curtrans = null; + inUserTrans = false; + System.err.println("Transaction " + curtrans.getId().getId() + + " aborted."); + + } else if (s.getStmtType().equals("SET TRANSACTION")) { + if (curtrans != null) + throw new simpledb.ParsingException( + "Can't start new transactions until current transaction has been committed or rolledback."); + curtrans = new Transaction(); + curtrans.start(); + inUserTrans = true; + } else { + throw new simpledb.ParsingException("Unsupported operation"); + } + } + public LogicalPlan generateLogicalPlan(TransactionId tid, String s) throws simpledb.ParsingException { ByteArrayInputStream bis = new ByteArrayInputStream(s.getBytes()); @@ -463,7 +502,7 @@ public LogicalPlan generateLogicalPlan(TransactionId tid, String s) LogicalPlan lp = parseQueryLogicalPlan(tid, (ZQuery) stmt); return lp; } - } catch (org.gibello.zql.ParseException e) { + } catch (Zql.ParseException e) { throw new simpledb.ParsingException( "Invalid SQL expression: \n \t " + e); } catch (IOException e) { @@ -496,9 +535,9 @@ public void processNextStatement(InputStream is, ATupleFormatter formatter) { ZStatement s = p.readStatement(); Query query = null; - if (s instanceof ZTransactStmt) { - throw new simpledb.ParsingException("Transaction statements are not supported."); - } else { + if (s instanceof ZTransactStmt) + handleTransactStatement((ZTransactStmt) s); + else { if (!this.inUserTrans) { curtrans = new Transaction(); curtrans.start(); @@ -540,10 +579,10 @@ else if (s instanceof ZQuery) this.inUserTrans = false; if (a instanceof simpledb.ParsingException - || a instanceof ParseException) + || a instanceof Zql.ParseException) throw new ParsingException((Exception) a); - if (a instanceof TokenMgrError) - throw (TokenMgrError) a; + if (a instanceof Zql.TokenMgrError) + throw (Zql.TokenMgrError) a; throw new DbException(a.getMessage()); } finally { if (!inUserTrans) @@ -551,6 +590,8 @@ else if (s instanceof ZQuery) } } + } catch (TransactionAbortedException e) { + e.printStackTrace(); } catch (DbException e) { e.printStackTrace(); } catch (IOException e) { @@ -558,9 +599,9 @@ else if (s instanceof ZQuery) } catch (simpledb.ParsingException e) { System.err .println("Invalid SQL expression: \n \t" + e.getMessage()); - } catch (ParseException e) { + } catch (Zql.ParseException e) { System.err.println("Invalid SQL expression: \n \t " + e); - } catch (TokenMgrError e) { + } catch (Zql.TokenMgrError e) { System.err.println("Invalid SQL expression: \n \t " + e); } } diff --git a/simpledb/src/java/simpledb/SimpleDb.java b/simpledb/src/java/simpledb/SimpleDb.java index 7f03e53..2cf680b 100644 --- a/simpledb/src/java/simpledb/SimpleDb.java +++ b/simpledb/src/java/simpledb/SimpleDb.java @@ -1,8 +1,8 @@ package simpledb; -import org.gibello.zql.ZQuery; -import org.gibello.zql.ZStatement; -import org.gibello.zql.ZqlParser; +import Zql.ZQuery; +import Zql.ZStatement; +import Zql.ZqlParser; import java.io.*; import java.nio.file.Files; @@ -76,7 +76,7 @@ private static int draw(String[] args) throws IOException, TransactionAbortedExc Query plan = pp.handleQueryStatement((ZQuery)s, new TransactionId()); String fileName = outputPrefix + "_" + i + ".dot"; QueryPlanDotter.print(plan.getPhysicalPlan(), fileName); - } catch (org.gibello.zql.ParseException | ParsingException e) { + } catch (Zql.ParseException | ParsingException e) { e.printStackTrace(); } } diff --git a/simpledb/test/acstest/CleanTest.java b/simpledb/test/acstest/CleanTest.java index a4b38ff..c34d1b6 100644 --- a/simpledb/test/acstest/CleanTest.java +++ b/simpledb/test/acstest/CleanTest.java @@ -8,10 +8,10 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -import org.gibello.zql.ParseException; -import org.gibello.zql.ZQuery; -import org.gibello.zql.ZStatement; -import org.gibello.zql.ZqlParser; +import Zql.ParseException; +import Zql.ZQuery; +import Zql.ZStatement; +import Zql.ZqlParser; import simpledb.*; @Ignore diff --git a/simpledb/test/acstest/DirtyTest.java b/simpledb/test/acstest/DirtyTest.java index 3be7f06..cba4fe3 100644 --- a/simpledb/test/acstest/DirtyTest.java +++ b/simpledb/test/acstest/DirtyTest.java @@ -13,10 +13,10 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -import org.gibello.zql.ParseException; -import org.gibello.zql.ZQuery; -import org.gibello.zql.ZStatement; -import org.gibello.zql.ZqlParser; +import Zql.ParseException; +import Zql.ZQuery; +import Zql.ZStatement; +import Zql.ZqlParser; import simpledb.*; @Ignore diff --git a/simpledb/test/acstest/RunQueries.java b/simpledb/test/acstest/RunQueries.java index 7216b2c..8a8a136 100644 --- a/simpledb/test/acstest/RunQueries.java +++ b/simpledb/test/acstest/RunQueries.java @@ -11,10 +11,10 @@ import org.junit.Assert; -import org.gibello.zql.ParseException; -import org.gibello.zql.ZQuery; -import org.gibello.zql.ZStatement; -import org.gibello.zql.ZqlParser; +import Zql.ParseException; +import Zql.ZQuery; +import Zql.ZStatement; +import Zql.ZqlParser; import simpledb.BadErrorException; import simpledb.Database; import simpledb.DbException;