Formatting, ready for part 2
This commit is contained in:
parent
a9a58d2cbd
commit
4b0f36a85d
@ -26,11 +26,11 @@ public class FileScan extends Iterator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives a one-line explanation of the iterator, repeats the call on any
|
||||
* child iterators, and increases the indent depth along the way.
|
||||
* Gives a one-line explanation of the iterator, repeats the call on any child
|
||||
* iterators, and increases the indent depth along the way.
|
||||
*/
|
||||
public void explain(int depth) {
|
||||
for(int i = 0; i < depth; i++){
|
||||
for (int i = 0; i < depth; i++) {
|
||||
System.out.printf(" ");
|
||||
}
|
||||
System.out.printf("FileScan\n");
|
||||
@ -42,7 +42,7 @@ public class FileScan extends Iterator {
|
||||
public void restart() {
|
||||
scan.close();
|
||||
scan = file.openScan();
|
||||
//rid = new RID();
|
||||
// rid = new RID();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,7 +84,7 @@ public class FileScan extends Iterator {
|
||||
}
|
||||
|
||||
// getter; added so HashJoin doesn't have to copy the file;
|
||||
public HeapFile getFile(){
|
||||
public HeapFile getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
|
@ -8,14 +8,19 @@ import global.AttrOperator;
|
||||
import global.AttrType;
|
||||
|
||||
public class HashJoin extends Iterator {
|
||||
private Iterator outer;
|
||||
private Iterator inner;
|
||||
private Predicate[] preds;
|
||||
|
||||
public HashJoin(Iterator aIter1, Iterator aIter2, int aJoinCol1, int aJoinCol2){
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
public HashJoin(Iterator aIter1, Iterator aIter2, int aJoinCol1, int aJoinCol2) {
|
||||
aIter1.getSchema().getLength();
|
||||
this.outer = aIter1;
|
||||
this.inner = aIter2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives a one-line explanation of the iterator, repeats the call on any
|
||||
* child iterators, and increases the indent depth along the way.
|
||||
* Gives a one-line explanation of the iterator, repeats the call on any child
|
||||
* iterators, and increases the indent depth along the way.
|
||||
*/
|
||||
public void explain(int depth) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
|
@ -15,7 +15,6 @@ public class IndexScan extends Iterator {
|
||||
private HashIndex index = null;
|
||||
private boolean isOpen = false;
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* child iterators, and increases the indent depth along the way.
|
||||
* Gives a one-line explaination of the iterator, repeats the call on any child
|
||||
* iterators, and increases the indent depth along the way.
|
||||
*/
|
||||
public void explain(int depth) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
|
@ -29,8 +29,8 @@ public class KeyScan extends Iterator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives a one-line explanation of the iterator, repeats the call on any
|
||||
* child iterators, and increases the indent depth along the way.
|
||||
* Gives a one-line explanation of the iterator, repeats the call on any child
|
||||
* iterators, and increases the indent depth along the way.
|
||||
*/
|
||||
public void explain(int depth) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
|
@ -1,22 +1,39 @@
|
||||
package relop;
|
||||
|
||||
|
||||
/**
|
||||
* The projection operator extracts columns from a relation; unlike in
|
||||
* relational algebra, this operator does NOT eliminate duplicate tuples.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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
|
||||
* child iterators, and increases the indent depth along the way.
|
||||
* Gives a one-line explanation of the iterator, repeats the call on any child
|
||||
* iterators, and increases the indent depth along the way.
|
||||
*/
|
||||
public void explain(int depth) {
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
return this.isOpen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the iterator, releasing any resources (i.e. pinned pages).
|
||||
*/
|
||||
public void close() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
this.iterator.close();
|
||||
this.isOpen = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there are more tuples, false otherwise.
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
|
@ -6,17 +6,25 @@ package relop;
|
||||
* connected by OR operators.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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
|
||||
* child iterators, and increases the indent depth along the way.
|
||||
* Gives a one-line explanation of the iterator, repeats the call on any child
|
||||
* iterators, and increases the indent depth along the way.
|
||||
*/
|
||||
public void explain(int depth) {
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
return this.isOpen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the iterator, releasing any resources (i.e. pinned pages).
|
||||
*/
|
||||
public void close() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
this.iterator.close();
|
||||
this.isOpen = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there are more tuples, false otherwise.
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
|
@ -34,8 +34,8 @@ public class SimpleJoin extends Iterator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives a one-line explanation of the iterator, repeats the call on any
|
||||
* child iterators, and increases the indent depth along the way.
|
||||
* Gives a one-line explanation of the iterator, repeats the call on any child
|
||||
* iterators, and increases the indent depth along the way.
|
||||
*/
|
||||
public void explain(int depth) {
|
||||
|
||||
@ -81,7 +81,7 @@ public class SimpleJoin extends Iterator {
|
||||
return true;
|
||||
|
||||
if (!outer.hasNext())
|
||||
//if(!inner.hasNext() && !outer.hasNext()) // Piazza post 116
|
||||
// if(!inner.hasNext() && !outer.hasNext()) // Piazza post 116
|
||||
return false;
|
||||
|
||||
Tuple rightTuple;
|
||||
@ -109,15 +109,13 @@ public class SimpleJoin extends Iterator {
|
||||
if (outer.hasNext()) {
|
||||
leftTuple = outer.getNext();
|
||||
inner.restart();
|
||||
}
|
||||
else
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next tuple in the iteration.
|
||||
*
|
||||
* @throws IllegalStateException if no more tuples
|
||||
*/
|
||||
public Tuple getNext() {
|
||||
|
Loading…
Reference in New Issue
Block a user