Skip to content

Commit

Permalink
Revert "feat: upgrade zql version"
Browse files Browse the repository at this point in the history
This reverts commit 2543c4f.
  • Loading branch information
Jack Feser committed Nov 2, 2017
1 parent 2543c4f commit bc9bbd0
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 35 deletions.
Binary file modified simpledb/lib/zql.jar
Binary file not shown.
8 changes: 4 additions & 4 deletions 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;
Expand Down
71 changes: 56 additions & 15 deletions 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.*;
Expand Down Expand Up @@ -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();
Expand All @@ -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<ZFromItem> from = q.getFrom();
LogicalPlan lp = planFactory.apply(null);
lp.setQuery(q.toString());
Expand Down Expand Up @@ -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<ZSelectItem> selectList = q.getSelect();
String aggField = null;
String aggFun = null;
Expand Down Expand Up @@ -269,6 +275,7 @@ public LogicalPlan parseQueryLogicalPlan(TransactionId tid, ZQuery q) throws IOE
// sort the data

if (q.getOrderBy() != null) {
@SuppressWarnings("unchecked")
Vector<ZOrderBy> obys = q.getOrderBy();
if (obys.size() > 1) {
throw new simpledb.ParsingException(
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -540,27 +579,29 @@ 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)
curtrans = null;
}
}

} catch (TransactionAbortedException e) {
e.printStackTrace();
} catch (DbException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} 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);
}
}
Expand Down
8 changes: 4 additions & 4 deletions 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;
Expand Down Expand Up @@ -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();
}
}
Expand Down
8 changes: 4 additions & 4 deletions simpledb/test/acstest/CleanTest.java
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions simpledb/test/acstest/DirtyTest.java
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions simpledb/test/acstest/RunQueries.java
Expand Up @@ -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;
Expand Down

0 comments on commit bc9bbd0

Please sign in to comment.