Formatting, ready for part 2
This commit is contained in:
parent
a9a58d2cbd
commit
4b0f36a85d
@ -9,83 +9,83 @@ import heap.HeapScan;
|
||||
* version takes schema into consideration and generates real tuples.
|
||||
*/
|
||||
public class FileScan extends Iterator {
|
||||
private HeapFile file = null; // needed for restart(), getFile();
|
||||
private HeapScan scan = null;
|
||||
private RID rid = null;
|
||||
private boolean isOpen = false;
|
||||
private HeapFile file = null; // needed for restart(), getFile();
|
||||
private HeapScan scan = null;
|
||||
private RID rid = null;
|
||||
private boolean isOpen = false;
|
||||
|
||||
/**
|
||||
* Constructs a file scan, given the schema and heap file.
|
||||
*/
|
||||
public FileScan(Schema aSchema, HeapFile aFile) {
|
||||
this.schema = aSchema;
|
||||
this.file = aFile;
|
||||
this.scan = file.openScan();
|
||||
this.rid = new RID();
|
||||
isOpen = true;
|
||||
}
|
||||
/**
|
||||
* Constructs a file scan, given the schema and heap file.
|
||||
*/
|
||||
public FileScan(Schema aSchema, HeapFile aFile) {
|
||||
this.schema = aSchema;
|
||||
this.file = aFile;
|
||||
this.scan = file.openScan();
|
||||
this.rid = new RID();
|
||||
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.
|
||||
*/
|
||||
public void explain(int depth) {
|
||||
for(int i = 0; i < depth; i++){
|
||||
System.out.printf(" ");
|
||||
}
|
||||
System.out.printf("FileScan\n");
|
||||
}
|
||||
/**
|
||||
* 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++) {
|
||||
System.out.printf(" ");
|
||||
}
|
||||
System.out.printf("FileScan\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Restarts the iterator, i.e. as if it were just constructed.
|
||||
*/
|
||||
public void restart() {
|
||||
scan.close();
|
||||
scan = file.openScan();
|
||||
//rid = new RID();
|
||||
}
|
||||
/**
|
||||
* Restarts the iterator, i.e. as if it were just constructed.
|
||||
*/
|
||||
public void restart() {
|
||||
scan.close();
|
||||
scan = file.openScan();
|
||||
// rid = new RID();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the iterator is open; false otherwise.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
return isOpen;
|
||||
}
|
||||
/**
|
||||
* Returns true if the iterator is open; false otherwise.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the iterator, releasing any resources (i.e. pinned pages).
|
||||
*/
|
||||
public void close() {
|
||||
scan.close();
|
||||
isOpen = false;
|
||||
}
|
||||
/**
|
||||
* Closes the iterator, releasing any resources (i.e. pinned pages).
|
||||
*/
|
||||
public void close() {
|
||||
scan.close();
|
||||
isOpen = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there are more tuples, false otherwise.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return scan.hasNext();
|
||||
}
|
||||
/**
|
||||
* Returns true if there are more tuples, false otherwise.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return scan.hasNext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next tuple in the iteration.
|
||||
*
|
||||
* @throws IllegalStateException if no more tuples
|
||||
*/
|
||||
public Tuple getNext() {
|
||||
return new Tuple(schema, scan.getNext(rid));
|
||||
}
|
||||
/**
|
||||
* Gets the next tuple in the iteration.
|
||||
*
|
||||
* @throws IllegalStateException if no more tuples
|
||||
*/
|
||||
public Tuple getNext() {
|
||||
return new Tuple(schema, scan.getNext(rid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RID of the last tuple returned.
|
||||
*/
|
||||
public RID getLastRID() {
|
||||
return rid;
|
||||
}
|
||||
/**
|
||||
* Gets the RID of the last tuple returned.
|
||||
*/
|
||||
public RID getLastRID() {
|
||||
return rid;
|
||||
}
|
||||
|
||||
// getter; added so HashJoin doesn't have to copy the file;
|
||||
public HeapFile getFile(){
|
||||
return file;
|
||||
}
|
||||
// getter; added so HashJoin doesn't have to copy the file;
|
||||
public HeapFile getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
} // public class FileScan extends Iterator
|
||||
|
@ -8,53 +8,58 @@ 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.
|
||||
*/
|
||||
public void explain(int depth) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
|
||||
/**
|
||||
* Restarts the iterator, i.e. as if it were just constructed.
|
||||
*/
|
||||
public void restart() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
/**
|
||||
* Restarts the iterator, i.e. as if it were just constructed.
|
||||
*/
|
||||
public void restart() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the iterator is open; false otherwise.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
/**
|
||||
* Returns true if the iterator is open; false otherwise.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the iterator, releasing any resources (i.e. pinned pages).
|
||||
*/
|
||||
public void close() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
/**
|
||||
* Closes the iterator, releasing any resources (i.e. pinned pages).
|
||||
*/
|
||||
public void close() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there are more tuples, false otherwise.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
/**
|
||||
* Returns true if there are more tuples, false otherwise.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next tuple in the iteration.
|
||||
*
|
||||
* @throws IllegalStateException if no more tuples
|
||||
*/
|
||||
public Tuple getNext() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
/**
|
||||
* Gets the next tuple in the iteration.
|
||||
*
|
||||
* @throws IllegalStateException if no more tuples
|
||||
*/
|
||||
public Tuple getNext() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
} // end class HashJoin;
|
||||
|
@ -10,102 +10,101 @@ import index.HashIndex;
|
||||
* Wrapper for bucket scan, an index access method.
|
||||
*/
|
||||
public class IndexScan extends Iterator {
|
||||
private HeapFile file = null;
|
||||
private BucketScan scan = null;
|
||||
private HashIndex index = null;
|
||||
private boolean isOpen = false;
|
||||
private HeapFile file = null;
|
||||
private BucketScan scan = null;
|
||||
private HashIndex index = null;
|
||||
private boolean isOpen = false;
|
||||
|
||||
/**
|
||||
* Constructs an index scan, given the hash index and schema.
|
||||
*/
|
||||
public IndexScan(Schema schema, HashIndex index, HeapFile file) {
|
||||
this.file = file;
|
||||
this.schema = schema;
|
||||
this.index = index;
|
||||
this.scan = this.index.openScan();
|
||||
this.isOpen = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an index scan, given the hash index and schema.
|
||||
*/
|
||||
public IndexScan(Schema schema, HashIndex index, HeapFile file) {
|
||||
this.file = file;
|
||||
this.schema = schema;
|
||||
this.index = index;
|
||||
this.scan = this.index.openScan();
|
||||
this.isOpen = true;
|
||||
}
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
/**
|
||||
* Restarts the iterator, i.e. as if it were just constructed.
|
||||
*/
|
||||
public void restart() {
|
||||
if (this.isOpen()) {
|
||||
scan.close();
|
||||
this.isOpen = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restarts the iterator, i.e. as if it were just constructed.
|
||||
*/
|
||||
public void restart() {
|
||||
if (this.isOpen()) {
|
||||
scan.close();
|
||||
this.isOpen = false;
|
||||
}
|
||||
this.scan = this.index.openScan();
|
||||
this.isOpen = true;
|
||||
}
|
||||
|
||||
this.scan = this.index.openScan();
|
||||
this.isOpen = true;
|
||||
}
|
||||
/**
|
||||
* Returns true if the iterator is open; false otherwise.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
return this.isOpen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the iterator is open; false otherwise.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
return this.isOpen;
|
||||
}
|
||||
/**
|
||||
* Closes the iterator, releasing any resources (i.e. pinned pages).
|
||||
*/
|
||||
public void close() {
|
||||
if (this.isOpen()) {
|
||||
this.scan.close();
|
||||
this.scan = null;
|
||||
this.isOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the iterator, releasing any resources (i.e. pinned pages).
|
||||
*/
|
||||
public void close() {
|
||||
if (this.isOpen()) {
|
||||
this.scan.close();
|
||||
this.scan = null;
|
||||
this.isOpen = false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns true if there are more tuples, false otherwise.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
if (this.isOpen()) {
|
||||
return this.scan.hasNext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there are more tuples, false otherwise.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
if (this.isOpen()) {
|
||||
return this.scan.hasNext();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Gets the next tuple in the iteration.
|
||||
*
|
||||
* @throws IllegalStateException if no more tuples
|
||||
*/
|
||||
public Tuple getNext() {
|
||||
if (this.isOpen()) {
|
||||
RID rid = this.scan.getNext();
|
||||
byte[] data = this.file.selectRecord(rid);
|
||||
Tuple tuple = new Tuple(this.getSchema(), data);
|
||||
return tuple;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next tuple in the iteration.
|
||||
*
|
||||
* @throws IllegalStateException if no more tuples
|
||||
*/
|
||||
public Tuple getNext() {
|
||||
if (this.isOpen()) {
|
||||
RID rid = this.scan.getNext();
|
||||
byte[] data = this.file.selectRecord(rid);
|
||||
Tuple tuple = new Tuple(this.getSchema(), data);
|
||||
return tuple;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Gets the key of the last tuple returned.
|
||||
*/
|
||||
public SearchKey getLastKey() {
|
||||
return this.scan.getLastKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the key of the last tuple returned.
|
||||
*/
|
||||
public SearchKey getLastKey() {
|
||||
return this.scan.getLastKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hash value for the bucket containing the next tuple, or maximum
|
||||
* number of buckets if none.
|
||||
*/
|
||||
public int getNextHash() {
|
||||
return this.scan.getNextHash();
|
||||
}
|
||||
/**
|
||||
* Returns the hash value for the bucket containing the next tuple, or maximum
|
||||
* number of buckets if none.
|
||||
*/
|
||||
public int getNextHash() {
|
||||
return this.scan.getNextHash();
|
||||
}
|
||||
|
||||
} // public class IndexScan extends Iterator
|
||||
|
@ -10,86 +10,86 @@ import index.HashScan;
|
||||
* Wrapper for hash scan, an index access method.
|
||||
*/
|
||||
public class KeyScan extends Iterator {
|
||||
private HeapFile file = null; // needed for restart(), getFile();
|
||||
private HashScan scan = null;
|
||||
private HashIndex index = null;
|
||||
private SearchKey key = null;
|
||||
private boolean isOpen;
|
||||
private HeapFile file = null; // needed for restart(), getFile();
|
||||
private HashScan scan = null;
|
||||
private HashIndex index = null;
|
||||
private SearchKey key = null;
|
||||
private boolean isOpen;
|
||||
|
||||
/**
|
||||
* Constructs an index scan, given the hash index and schema.
|
||||
*/
|
||||
public KeyScan(Schema aSchema, HashIndex aIndex, SearchKey aKey, HeapFile aFile) {
|
||||
this.schema = aSchema;
|
||||
this.index = aIndex;
|
||||
this.key = aKey;
|
||||
this.file = aFile;
|
||||
this.scan = this.index.openScan(this.key);
|
||||
this.isOpen = true;
|
||||
}
|
||||
/**
|
||||
* Constructs an index scan, given the hash index and schema.
|
||||
*/
|
||||
public KeyScan(Schema aSchema, HashIndex aIndex, SearchKey aKey, HeapFile aFile) {
|
||||
this.schema = aSchema;
|
||||
this.index = aIndex;
|
||||
this.key = aKey;
|
||||
this.file = aFile;
|
||||
this.scan = this.index.openScan(this.key);
|
||||
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.
|
||||
*/
|
||||
public void explain(int depth) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
|
||||
/**
|
||||
* Restarts the iterator, i.e. as if it were just constructed.
|
||||
*/
|
||||
public void restart() {
|
||||
this.isOpen = false; // In case of errors maybe?
|
||||
this.close();
|
||||
this.scan = this.index.openScan(this.key);
|
||||
this.isOpen = true;
|
||||
}
|
||||
/**
|
||||
* Restarts the iterator, i.e. as if it were just constructed.
|
||||
*/
|
||||
public void restart() {
|
||||
this.isOpen = false; // In case of errors maybe?
|
||||
this.close();
|
||||
this.scan = this.index.openScan(this.key);
|
||||
this.isOpen = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the iterator is open; false otherwise.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
return this.isOpen;
|
||||
}
|
||||
/**
|
||||
* Returns true if the iterator is open; false otherwise.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
return this.isOpen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the iterator, releasing any resources (i.e. pinned pages).
|
||||
*/
|
||||
public void close() {
|
||||
if (this.isOpen()) {
|
||||
this.scan.close();
|
||||
this.scan = null;
|
||||
this.isOpen = false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Closes the iterator, releasing any resources (i.e. pinned pages).
|
||||
*/
|
||||
public void close() {
|
||||
if (this.isOpen()) {
|
||||
this.scan.close();
|
||||
this.scan = null;
|
||||
this.isOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there are more tuples, false otherwise.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
if (this.isOpen()) {
|
||||
return this.scan.hasNext();
|
||||
}
|
||||
/**
|
||||
* Returns true if there are more tuples, false otherwise.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
if (this.isOpen()) {
|
||||
return this.scan.hasNext();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next tuple in the iteration.
|
||||
*
|
||||
* @throws IllegalStateException if no more tuples
|
||||
*/
|
||||
public Tuple getNext() {
|
||||
if (this.isOpen()) {
|
||||
RID rid = scan.getNext();
|
||||
byte[] data = this.file.selectRecord(rid);
|
||||
Tuple tuple = new Tuple(this.getSchema(), data);
|
||||
/**
|
||||
* Gets the next tuple in the iteration.
|
||||
*
|
||||
* @throws IllegalStateException if no more tuples
|
||||
*/
|
||||
public Tuple getNext() {
|
||||
if (this.isOpen()) {
|
||||
RID rid = scan.getNext();
|
||||
byte[] data = this.file.selectRecord(rid);
|
||||
Tuple tuple = new Tuple(this.getSchema(), data);
|
||||
|
||||
return tuple;
|
||||
}
|
||||
return tuple;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
} // public class KeyScan extends Iterator
|
||||
|
@ -1,62 +1,93 @@
|
||||
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");
|
||||
}
|
||||
/**
|
||||
* Constructs a projection, given the underlying iterator and field numbers.
|
||||
*/
|
||||
public Projection(Iterator aIter, Integer... aFields) {
|
||||
this.iterator = aIter;
|
||||
this.fields = aFields;
|
||||
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
// We need to make a deep copy instead of referencing Iterator's.
|
||||
// this.projectingSchema = this.iterator.getSchema();
|
||||
|
||||
/**
|
||||
* Restarts the iterator, i.e. as if it were just constructed.
|
||||
*/
|
||||
public void restart() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
Schema originalSchema = this.iterator.getSchema();
|
||||
this.projectingSchema = new Schema(fields.length);
|
||||
|
||||
/**
|
||||
* Returns true if the iterator is open; false otherwise.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
this.projectingSchema.initField(i, originalSchema.fieldType(fields[i]),
|
||||
originalSchema.fieldLength(fields[i]), originalSchema.fieldName(fields[i]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the iterator, releasing any resources (i.e. pinned pages).
|
||||
*/
|
||||
public void close() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
this.isOpen = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there are more tuples, false otherwise.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next tuple in the iteration.
|
||||
*
|
||||
* @throws IllegalStateException if no more tuples
|
||||
*/
|
||||
public Tuple getNext() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
/**
|
||||
* Restarts the iterator, i.e. as if it were just constructed.
|
||||
*/
|
||||
public void restart() {
|
||||
this.isOpen = false;
|
||||
this.iterator.restart();
|
||||
this.isOpen = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the iterator is open; false otherwise.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
return this.isOpen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the iterator, releasing any resources (i.e. pinned pages).
|
||||
*/
|
||||
public void close() {
|
||||
this.iterator.close();
|
||||
this.isOpen = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there are more tuples, false otherwise.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return this.iterator.hasNext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next tuple in the iteration.
|
||||
*
|
||||
* @throws IllegalStateException if no more tuples
|
||||
*/
|
||||
public Tuple getNext() {
|
||||
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,57 +6,108 @@ 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");
|
||||
}
|
||||
/**
|
||||
* Constructs a selection, given the underlying iterator and predicates.
|
||||
*/
|
||||
public Selection(Iterator aIter, Predicate... aPreds) {
|
||||
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.
|
||||
*/
|
||||
public void explain(int depth) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
|
||||
/**
|
||||
* Restarts the iterator, i.e. as if it were just constructed.
|
||||
*/
|
||||
public void restart() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
/**
|
||||
* Restarts the iterator, i.e. as if it were just constructed.
|
||||
*/
|
||||
public void restart() {
|
||||
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");
|
||||
}
|
||||
/**
|
||||
* Returns true if the iterator is open; false otherwise.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
return this.isOpen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the iterator, releasing any resources (i.e. pinned pages).
|
||||
*/
|
||||
public void close() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
/**
|
||||
* Closes the iterator, releasing any resources (i.e. pinned pages).
|
||||
*/
|
||||
public void close() {
|
||||
this.iterator.close();
|
||||
this.isOpen = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there are more tuples, false otherwise.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
/**
|
||||
* Returns true if there are more tuples, false otherwise.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
if (this.currentTuple != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next tuple in the iteration.
|
||||
*
|
||||
* @throws IllegalStateException if no more tuples
|
||||
*/
|
||||
public Tuple getNext() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next tuple in the iteration.
|
||||
*
|
||||
* @throws IllegalStateException if no more tuples
|
||||
*/
|
||||
public Tuple getNext() {
|
||||
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
|
||||
|
@ -6,123 +6,121 @@ package relop;
|
||||
*/
|
||||
public class SimpleJoin extends Iterator {
|
||||
|
||||
private Iterator outer;
|
||||
private Iterator inner;
|
||||
private Predicate[] preds;
|
||||
private Iterator outer;
|
||||
private Iterator inner;
|
||||
private Predicate[] preds;
|
||||
|
||||
private boolean startJoin = true;
|
||||
Tuple leftTuple;
|
||||
private boolean startJoin = true;
|
||||
Tuple leftTuple;
|
||||
|
||||
// boolean variable to indicate whether the pre-fetched tuple is consumed or not
|
||||
private boolean nextTupleIsConsumed;
|
||||
// boolean variable to indicate whether the pre-fetched tuple is consumed or not
|
||||
private boolean nextTupleIsConsumed;
|
||||
|
||||
// pre-fetched tuple
|
||||
private Tuple nextTuple;
|
||||
// pre-fetched tuple
|
||||
private Tuple nextTuple;
|
||||
|
||||
/**
|
||||
* Constructs a join, given the left and right iterators and join predicates
|
||||
* (relative to the combined schema).
|
||||
*/
|
||||
public SimpleJoin(Iterator left, Iterator right, Predicate... preds) {
|
||||
/**
|
||||
* Constructs a join, given the left and right iterators and join predicates
|
||||
* (relative to the combined schema).
|
||||
*/
|
||||
public SimpleJoin(Iterator left, Iterator right, Predicate... preds) {
|
||||
|
||||
this.outer = left;
|
||||
this.inner = right;
|
||||
this.preds = preds;
|
||||
this.schema = Schema.join(left.schema, right.schema);
|
||||
this.outer = left;
|
||||
this.inner = right;
|
||||
this.preds = preds;
|
||||
this.schema = Schema.join(left.schema, right.schema);
|
||||
|
||||
nextTupleIsConsumed = true;
|
||||
}
|
||||
nextTupleIsConsumed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Restarts the iterator, i.e. as if it were just constructed.
|
||||
*/
|
||||
public void restart() {
|
||||
/**
|
||||
* Restarts the iterator, i.e. as if it were just constructed.
|
||||
*/
|
||||
public void restart() {
|
||||
|
||||
outer.restart();
|
||||
nextTupleIsConsumed = true;
|
||||
}
|
||||
outer.restart();
|
||||
nextTupleIsConsumed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the iterator is open; false otherwise.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
/**
|
||||
* Returns true if the iterator is open; false otherwise.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
|
||||
if (outer.isOpen())
|
||||
return true;
|
||||
if (outer.isOpen())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the iterator, releasing any resources (i.e. pinned pages).
|
||||
*/
|
||||
public void close() {
|
||||
/**
|
||||
* Closes the iterator, releasing any resources (i.e. pinned pages).
|
||||
*/
|
||||
public void close() {
|
||||
|
||||
outer.close();
|
||||
inner.close();
|
||||
}
|
||||
outer.close();
|
||||
inner.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there are more tuples, false otherwise.
|
||||
*
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
/**
|
||||
* Returns true if there are more tuples, false otherwise.
|
||||
*
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
|
||||
if (!nextTupleIsConsumed)
|
||||
return true;
|
||||
if (!nextTupleIsConsumed)
|
||||
return true;
|
||||
|
||||
if (!outer.hasNext())
|
||||
//if(!inner.hasNext() && !outer.hasNext()) // Piazza post 116
|
||||
return false;
|
||||
if (!outer.hasNext())
|
||||
// if(!inner.hasNext() && !outer.hasNext()) // Piazza post 116
|
||||
return false;
|
||||
|
||||
Tuple rightTuple;
|
||||
Tuple rightTuple;
|
||||
|
||||
if (startJoin) {
|
||||
leftTuple = outer.getNext();
|
||||
startJoin = false;
|
||||
}
|
||||
if (startJoin) {
|
||||
leftTuple = outer.getNext();
|
||||
startJoin = false;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
while (true) {
|
||||
|
||||
while (inner.hasNext()) {
|
||||
while (inner.hasNext()) {
|
||||
|
||||
rightTuple = inner.getNext();
|
||||
rightTuple = inner.getNext();
|
||||
|
||||
// try to match
|
||||
nextTuple = Tuple.join(leftTuple, rightTuple, this.schema);
|
||||
for (int i = 0; i < preds.length; i++)
|
||||
if (preds[i].evaluate(nextTuple)) {
|
||||
nextTupleIsConsumed = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// try to match
|
||||
nextTuple = Tuple.join(leftTuple, rightTuple, this.schema);
|
||||
for (int i = 0; i < preds.length; i++)
|
||||
if (preds[i].evaluate(nextTuple)) {
|
||||
nextTupleIsConsumed = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (outer.hasNext()) {
|
||||
leftTuple = outer.getNext();
|
||||
inner.restart();
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (outer.hasNext()) {
|
||||
leftTuple = outer.getNext();
|
||||
inner.restart();
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next tuple in the iteration.
|
||||
*
|
||||
* @throws IllegalStateException if no more tuples
|
||||
*/
|
||||
public Tuple getNext() {
|
||||
/**
|
||||
* Gets the next tuple in the iteration.
|
||||
* @throws IllegalStateException if no more tuples
|
||||
*/
|
||||
public Tuple getNext() {
|
||||
|
||||
nextTupleIsConsumed = true;
|
||||
return nextTuple;
|
||||
}
|
||||
nextTupleIsConsumed = true;
|
||||
return nextTuple;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user