Formatting, ready for part 2

This commit is contained in:
Max O'Cull 2019-03-29 00:37:22 -04:00
parent a9a58d2cbd
commit 4b0f36a85d
8 changed files with 587 additions and 503 deletions

View File

@ -26,8 +26,8 @@ public class FileScan extends Iterator {
} }
/** /**
* Gives a one-line explanation of the iterator, repeats the call on any * Gives a one-line explanation of the iterator, repeats the call on any child
* child iterators, and increases the indent depth along the way. * iterators, and increases the indent depth along the way.
*/ */
public void explain(int depth) { public void explain(int depth) {
for (int i = 0; i < depth; i++) { for (int i = 0; i < depth; i++) {

View File

@ -8,14 +8,19 @@ import global.AttrOperator;
import global.AttrType; import global.AttrType;
public class HashJoin extends Iterator { public class HashJoin extends Iterator {
private Iterator outer;
private Iterator inner;
private Predicate[] preds;
public HashJoin(Iterator aIter1, Iterator aIter2, int aJoinCol1, int aJoinCol2) { public HashJoin(Iterator aIter1, Iterator aIter2, int aJoinCol1, int aJoinCol2) {
throw new UnsupportedOperationException("Not implemented"); aIter1.getSchema().getLength();
this.outer = aIter1;
this.inner = aIter2;
} }
/** /**
* Gives a one-line explanation of the iterator, repeats the call on any * Gives a one-line explanation of the iterator, repeats the call on any child
* child iterators, and increases the indent depth along the way. * iterators, and increases the indent depth along the way.
*/ */
public void explain(int depth) { public void explain(int depth) {
throw new UnsupportedOperationException("Not implemented"); throw new UnsupportedOperationException("Not implemented");

View File

@ -15,7 +15,6 @@ public class IndexScan extends Iterator {
private HashIndex index = null; private HashIndex index = null;
private boolean isOpen = false; private boolean isOpen = false;
/** /**
* Constructs an index scan, given the hash index and schema. * Constructs an index scan, given the hash index and schema.
*/ */
@ -28,8 +27,8 @@ public class IndexScan extends Iterator {
} }
/** /**
* Gives a one-line explaination of the iterator, repeats the call on any * Gives a one-line explaination of the iterator, repeats the call on any child
* child iterators, and increases the indent depth along the way. * iterators, and increases the indent depth along the way.
*/ */
public void explain(int depth) { public void explain(int depth) {
throw new UnsupportedOperationException("Not implemented"); throw new UnsupportedOperationException("Not implemented");

View File

@ -29,8 +29,8 @@ public class KeyScan extends Iterator {
} }
/** /**
* Gives a one-line explanation of the iterator, repeats the call on any * Gives a one-line explanation of the iterator, repeats the call on any child
* child iterators, and increases the indent depth along the way. * iterators, and increases the indent depth along the way.
*/ */
public void explain(int depth) { public void explain(int depth) {
throw new UnsupportedOperationException("Not implemented"); throw new UnsupportedOperationException("Not implemented");

View File

@ -1,22 +1,39 @@
package relop; package relop;
/** /**
* The projection operator extracts columns from a relation; unlike in * The projection operator extracts columns from a relation; unlike in
* relational algebra, this operator does NOT eliminate duplicate tuples. * relational algebra, this operator does NOT eliminate duplicate tuples.
*/ */
public class Projection extends Iterator { public class Projection extends Iterator {
private Iterator iterator;
private Integer[] fields;
private Schema projectingSchema;
private boolean isOpen;
/** /**
* Constructs a projection, given the underlying iterator and field numbers. * Constructs a projection, given the underlying iterator and field numbers.
*/ */
public Projection(Iterator aIter, Integer... aFields) { public Projection(Iterator aIter, Integer... aFields) {
throw new UnsupportedOperationException("Not implemented"); this.iterator = aIter;
this.fields = aFields;
// We need to make a deep copy instead of referencing Iterator's.
// this.projectingSchema = this.iterator.getSchema();
Schema originalSchema = this.iterator.getSchema();
this.projectingSchema = new Schema(fields.length);
for (int i = 0; i < fields.length; i++) {
this.projectingSchema.initField(i, originalSchema.fieldType(fields[i]),
originalSchema.fieldLength(fields[i]), originalSchema.fieldName(fields[i]));
}
this.isOpen = true;
} }
/** /**
* Gives a one-line explanation of the iterator, repeats the call on any * Gives a one-line explanation of the iterator, repeats the call on any child
* child iterators, and increases the indent depth along the way. * iterators, and increases the indent depth along the way.
*/ */
public void explain(int depth) { public void explain(int depth) {
throw new UnsupportedOperationException("Not implemented"); throw new UnsupportedOperationException("Not implemented");
@ -26,28 +43,31 @@ public class Projection extends Iterator {
* Restarts the iterator, i.e. as if it were just constructed. * Restarts the iterator, i.e. as if it were just constructed.
*/ */
public void restart() { public void restart() {
throw new UnsupportedOperationException("Not implemented"); this.isOpen = false;
this.iterator.restart();
this.isOpen = true;
} }
/** /**
* Returns true if the iterator is open; false otherwise. * Returns true if the iterator is open; false otherwise.
*/ */
public boolean isOpen() { public boolean isOpen() {
throw new UnsupportedOperationException("Not implemented"); return this.isOpen;
} }
/** /**
* Closes the iterator, releasing any resources (i.e. pinned pages). * Closes the iterator, releasing any resources (i.e. pinned pages).
*/ */
public void close() { public void close() {
throw new UnsupportedOperationException("Not implemented"); this.iterator.close();
this.isOpen = false;
} }
/** /**
* Returns true if there are more tuples, false otherwise. * Returns true if there are more tuples, false otherwise.
*/ */
public boolean hasNext() { public boolean hasNext() {
throw new UnsupportedOperationException("Not implemented"); return this.iterator.hasNext();
} }
/** /**
@ -56,7 +76,18 @@ public class Projection extends Iterator {
* @throws IllegalStateException if no more tuples * @throws IllegalStateException if no more tuples
*/ */
public Tuple getNext() { public Tuple getNext() {
throw new UnsupportedOperationException("Not implemented"); if (this.iterator.hasNext()) {
Tuple original = this.iterator.getNext();
Tuple projecting = new Tuple(this.projectingSchema);
for (int i = 0; i < this.fields.length; i++) {
projecting.setField(i, original.getField(this.fields[i]));
}
return projecting;
}
return new Tuple(new Schema(1));
} }
} // public class Projection extends Iterator } // public class Projection extends Iterator

View File

@ -6,17 +6,25 @@ package relop;
* connected by OR operators. * connected by OR operators.
*/ */
public class Selection extends Iterator { public class Selection extends Iterator {
private Iterator iterator;
private Predicate[] predicates;
private Tuple currentTuple;
private boolean isOpen;
/** /**
* Constructs a selection, given the underlying iterator and predicates. * Constructs a selection, given the underlying iterator and predicates.
*/ */
public Selection(Iterator aIter, Predicate... aPreds) { public Selection(Iterator aIter, Predicate... aPreds) {
throw new UnsupportedOperationException("Not implemented"); this.iterator = aIter;
this.predicates = aPreds;
this.schema = this.iterator.schema;
this.isOpen = true;
this.currentTuple = null;
} }
/** /**
* Gives a one-line explanation of the iterator, repeats the call on any * Gives a one-line explanation of the iterator, repeats the call on any child
* child iterators, and increases the indent depth along the way. * iterators, and increases the indent depth along the way.
*/ */
public void explain(int depth) { public void explain(int depth) {
throw new UnsupportedOperationException("Not implemented"); throw new UnsupportedOperationException("Not implemented");
@ -26,28 +34,50 @@ public class Selection extends Iterator {
* Restarts the iterator, i.e. as if it were just constructed. * Restarts the iterator, i.e. as if it were just constructed.
*/ */
public void restart() { public void restart() {
throw new UnsupportedOperationException("Not implemented"); this.isOpen = false;
this.iterator.restart();
this.isOpen = true;
} }
/** /**
* Returns true if the iterator is open; false otherwise. * Returns true if the iterator is open; false otherwise.
*/ */
public boolean isOpen() { public boolean isOpen() {
throw new UnsupportedOperationException("Not implemented"); return this.isOpen;
} }
/** /**
* Closes the iterator, releasing any resources (i.e. pinned pages). * Closes the iterator, releasing any resources (i.e. pinned pages).
*/ */
public void close() { public void close() {
throw new UnsupportedOperationException("Not implemented"); this.iterator.close();
this.isOpen = false;
} }
/** /**
* Returns true if there are more tuples, false otherwise. * Returns true if there are more tuples, false otherwise.
*/ */
public boolean hasNext() { public boolean hasNext() {
throw new UnsupportedOperationException("Not implemented"); if (this.currentTuple != null) {
return true;
}
while (this.iterator.hasNext()) {
if (this.predicates.length == 0) {
return true;
}
this.currentTuple = iterator.getNext();
for (int i = 0; i < this.predicates.length; i++) {
if (this.predicates[i].evaluate(this.currentTuple)) {
return true;
}
}
}
this.currentTuple = null;
return false;
} }
/** /**
@ -56,7 +86,28 @@ public class Selection extends Iterator {
* @throws IllegalStateException if no more tuples * @throws IllegalStateException if no more tuples
*/ */
public Tuple getNext() { public Tuple getNext() {
throw new UnsupportedOperationException("Not implemented"); if (this.currentTuple != null) {
Tuple tuple = this.currentTuple;
this.currentTuple = null;
return tuple;
}
while (this.iterator.hasNext()) {
Tuple tuple = this.iterator.getNext();
if (this.predicates.length == 0) {
return tuple;
}
this.currentTuple = iterator.getNext();
for (int i = 0; i < this.predicates.length; i++) {
if (this.predicates[i].evaluate(this.currentTuple)) {
return tuple;
}
}
}
return null;
} }
} // public class Selection extends Iterator } // public class Selection extends Iterator

View File

@ -34,8 +34,8 @@ public class SimpleJoin extends Iterator {
} }
/** /**
* Gives a one-line explanation of the iterator, repeats the call on any * Gives a one-line explanation of the iterator, repeats the call on any child
* child iterators, and increases the indent depth along the way. * iterators, and increases the indent depth along the way.
*/ */
public void explain(int depth) { public void explain(int depth) {
@ -109,15 +109,13 @@ public class SimpleJoin extends Iterator {
if (outer.hasNext()) { if (outer.hasNext()) {
leftTuple = outer.getNext(); leftTuple = outer.getNext();
inner.restart(); inner.restart();
} } else
else
return false; return false;
} }
} }
/** /**
* Gets the next tuple in the iteration. * Gets the next tuple in the iteration.
*
* @throws IllegalStateException if no more tuples * @throws IllegalStateException if no more tuples
*/ */
public Tuple getNext() { public Tuple getNext() {