Skip to content

Commit

Permalink
Release Lab 2
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffxy committed Sep 26, 2022
1 parent 848263e commit cc5abdd
Show file tree
Hide file tree
Showing 48 changed files with 6,357 additions and 0 deletions.
650 changes: 650 additions & 0 deletions lab2.md

Large diffs are not rendered by default.

Binary file added lib/zql.jar
Binary file not shown.
746 changes: 746 additions & 0 deletions src/java/simpledb/Parser.java

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/java/simpledb/ParsingException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package simpledb;

public class ParsingException extends Exception {
public ParsingException(String string) {
super(string);
}

public ParsingException(Exception e) {
super(e);
}

/**
*
*/
private static final long serialVersionUID = 1L;
}
139 changes: 139 additions & 0 deletions src/java/simpledb/execution/Aggregate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package simpledb.execution;

import simpledb.common.DbException;
import simpledb.common.Type;
import simpledb.execution.Aggregator.Op;
import simpledb.storage.Tuple;
import simpledb.storage.TupleDesc;
import simpledb.transaction.TransactionAbortedException;

import java.util.NoSuchElementException;

/**
* The Aggregation operator that computes an aggregate (e.g., sum, avg, max,
* min). Note that we only support aggregates over a single column, grouped by a
* single column.
*/
public class Aggregate extends Operator {

private static final long serialVersionUID = 1L;

/**
* Constructor.
* <p>
* Implementation hint: depending on the type of afield, you will want to
* construct an {@link IntegerAggregator} or {@link StringAggregator} to help
* you with your implementation of readNext().
*
* @param child The OpIterator that is feeding us tuples.
* @param afield The column over which we are computing an aggregate.
* @param gfield The column over which we are grouping the result, or -1 if
* there is no grouping
* @param aop The aggregation operator to use
*/
public Aggregate(OpIterator child, int afield, int gfield, Aggregator.Op aop) {
// TODO: some code goes here
}

/**
* @return If this aggregate is accompanied by a groupby, return the groupby
* field index in the <b>INPUT</b> tuples. If not, return
* {@link Aggregator#NO_GROUPING}
*/
public int groupField() {
// TODO: some code goes here
return -1;
}

/**
* @return If this aggregate is accompanied by a group by, return the name
* of the groupby field in the <b>OUTPUT</b> tuples. If not, return
* null;
*/
public String groupFieldName() {
// TODO: some code goes here
return null;
}

/**
* @return the aggregate field
*/
public int aggregateField() {
// TODO: some code goes here
return -1;
}

/**
* @return return the name of the aggregate field in the <b>OUTPUT</b>
* tuples
*/
public String aggregateFieldName() {
// TODO: some code goes here
return null;
}

/**
* @return return the aggregate operator
*/
public Aggregator.Op aggregateOp() {
// TODO: some code goes here
return null;
}

public static String nameOfAggregatorOp(Aggregator.Op aop) {
return aop.toString();
}

public void open() throws NoSuchElementException, DbException,
TransactionAbortedException {
// TODO: some code goes here
}

/**
* Returns the next tuple. If there is a group by field, then the first
* field is the field by which we are grouping, and the second field is the
* result of computing the aggregate. If there is no group by field, then
* the result tuple should contain one field representing the result of the
* aggregate. Should return null if there are no more tuples.
*/
protected Tuple fetchNext() throws TransactionAbortedException, DbException {
// TODO: some code goes here
return null;
}

public void rewind() throws DbException, TransactionAbortedException {
// TODO: some code goes here
}

/**
* Returns the TupleDesc of this Aggregate. If there is no group by field,
* this will have one field - the aggregate column. If there is a group by
* field, the first field will be the group by field, and the second will be
* the aggregate value column.
* <p>
* The name of an aggregate column should be informative. For example:
* "aggName(aop) (child_td.getFieldName(afield))" where aop and afield are
* given in the constructor, and child_td is the TupleDesc of the child
* iterator.
*/
public TupleDesc getTupleDesc() {
// TODO: some code goes here
return null;
}

public void close() {
// TODO: some code goes here
}

@Override
public OpIterator[] getChildren() {
// TODO: some code goes here
return null;
}

@Override
public void setChildren(OpIterator[] children) {
// TODO: some code goes here
}

}
88 changes: 88 additions & 0 deletions src/java/simpledb/execution/Aggregator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package simpledb.execution;

import simpledb.storage.Tuple;
import simpledb.storage.TupleIterator;

import java.io.Serializable;

/**
* The common interface for any class that can compute an aggregate over a
* list of Tuples.
*/
public interface Aggregator extends Serializable {
int NO_GROUPING = -1;

/**
* SUM_COUNT and SC_AVG will
* only be used in lab7, you are not required
* to implement them until then.
*/
enum Op implements Serializable {
MIN, MAX, SUM, AVG, COUNT,
/**
* SUM_COUNT: compute sum and count simultaneously, will be
* needed to compute distributed avg in lab7.
*/
SUM_COUNT,
/**
* SC_AVG: compute the avg of a set of SUM_COUNT tuples,
* will be used to compute distributed avg in lab7.
*/
SC_AVG;

/**
* Interface to access operations by a string containing an integer
* index for command-line convenience.
*
* @param s a string containing a valid integer Op index
*/
public static Op getOp(String s) {
return getOp(Integer.parseInt(s));
}

/**
* Interface to access operations by integer value for command-line
* convenience.
*
* @param i a valid integer Op index
*/
public static Op getOp(int i) {
return values()[i];
}

public String toString() {
if (this == MIN)
return "min";
if (this == MAX)
return "max";
if (this == SUM)
return "sum";
if (this == SUM_COUNT)
return "sum_count";
if (this == AVG)
return "avg";
if (this == COUNT)
return "count";
if (this == SC_AVG)
return "sc_avg";
throw new IllegalStateException("impossible to reach here");
}
}

/**
* Merge a new tuple into the aggregate for a distinct group value;
* creates a new group aggregate result if the group value has not yet
* been encountered.
*
* @param tup the Tuple containing an aggregate field and a group-by field
*/
void mergeTupleIntoGroup(Tuple tup);

/**
* Create a OpIterator over group aggregate results.
*
* @see TupleIterator for a possible helper
*/
OpIterator iterator();

}
76 changes: 76 additions & 0 deletions src/java/simpledb/execution/Delete.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package simpledb.execution;

import simpledb.common.Database;
import simpledb.common.DbException;
import simpledb.common.Type;
import simpledb.storage.BufferPool;
import simpledb.storage.IntField;
import simpledb.storage.Tuple;
import simpledb.storage.TupleDesc;
import simpledb.transaction.TransactionAbortedException;
import simpledb.transaction.TransactionId;

import java.io.IOException;

/**
* The delete operator. Delete reads tuples from its child operator and removes
* them from the table they belong to.
*/
public class Delete extends Operator {

private static final long serialVersionUID = 1L;

/**
* Constructor specifying the transaction that this delete belongs to as
* well as the child to read from.
*
* @param t The transaction this delete runs in
* @param child The child operator from which to read tuples for deletion
*/
public Delete(TransactionId t, OpIterator child) {
// TODO: some code goes here
}

public TupleDesc getTupleDesc() {
// TODO: some code goes here
return null;
}

public void open() throws DbException, TransactionAbortedException {
// TODO: some code goes here
}

public void close() {
// TODO: some code goes here
}

public void rewind() throws DbException, TransactionAbortedException {
// TODO: some code goes here
}

/**
* Deletes tuples as they are read from the child operator. Deletes are
* processed via the buffer pool (which can be accessed via the
* Database.getBufferPool() method.
*
* @return A 1-field tuple containing the number of deleted records.
* @see Database#getBufferPool
* @see BufferPool#deleteTuple
*/
protected Tuple fetchNext() throws TransactionAbortedException, DbException {
// TODO: some code goes here
return null;
}

@Override
public OpIterator[] getChildren() {
// TODO: some code goes here
return null;
}

@Override
public void setChildren(OpIterator[] children) {
// TODO: some code goes here
}

}
Loading

0 comments on commit cc5abdd

Please sign in to comment.