Skip to content

Commit

Permalink
Extended and reworked optimizer tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
sewen committed Apr 9, 2013
1 parent f0ff109 commit 15feaff
Show file tree
Hide file tree
Showing 20 changed files with 640 additions and 423 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

package eu.stratosphere.pact.common.contract;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -46,9 +46,6 @@
* unknown.</li>
* <li>The average number of bytes per record. <code>-1.0</code> by default, indicating that this value is unknown.</li>
* </ul>
*
* @author Matthias Ringwald
* @author Fabian Hueske ([email protected])
*/
public class CompilerHints {

Expand All @@ -60,15 +57,62 @@ public class CompilerHints {

private Map<FieldSet, Float> avgNumRecordsPerDistinctFields = new HashMap<FieldSet, Float>();

private Set<FieldSet> uniqueFields = null;
private Set<FieldSet> uniqueFields;

// --------------------------------------------------------------------------------------------
// Basic Record Statistics
// --------------------------------------------------------------------------------------------

/**
* Gets the average number of bytes per record (key/value pair) for the
* contract containing these hints.
*
* @return The average number of bytes per record, or -1.0, if unknown.
*/
public float getAvgBytesPerRecord() {
return avgBytesPerRecord;
}

/**
* Sets the average number of bytes per record (key/value pair) for the
* contract containing these hints.
*
* @param avgBytes
* The average number of bytes per record.
*/
public void setAvgBytesPerRecord(float avgBytes) {
if(avgBytes < 0) {
throw new IllegalArgumentException("Average Bytes per Record must be >= 0!");
}
this.avgBytesPerRecord = avgBytes;
}

/**
* Default constructor. Creates a new <tt>CompilerHints</tt> object
* with the default values for the encapsulated fields.
* Gets the average number of emitted records per stub call.
*
* @return The average number of emitted records per stub call.
*/
public CompilerHints() {
public float getAvgRecordsEmittedPerStubCall() {
return avgRecordsEmittedPerStubCall;
}

/**
* Sets the average number of emitted records per stub call.
*
* @param avgRecordsEmittedPerStubCall
* The average number of emitted records per stub call to set.
*/
public void setAvgRecordsEmittedPerStubCall(float avgRecordsEmittedPerStubCall) {
if(avgRecordsEmittedPerStubCall < 0) {
throw new IllegalArgumentException("Average Number of Emitted Records per Stub Call must be >= 0!");
}
this.avgRecordsEmittedPerStubCall = avgRecordsEmittedPerStubCall;
}

// --------------------------------------------------------------------------------------------
// Column (Group) Statistics
// --------------------------------------------------------------------------------------------

/**
* Gets the count of distinct values for the given set of fields.
*
Expand Down Expand Up @@ -139,78 +183,77 @@ public void setAvgNumRecordsPerDistinctFields(FieldSet fieldSet, float avgNumRec
}
this.avgNumRecordsPerDistinctFields.put(fieldSet, avgNumRecords);
}

// --------------------------------------------------------------------------------------------
// Uniqueness
// --------------------------------------------------------------------------------------------

/**
* Gets the average number of bytes per record (key/value pair) for the
* contract containing these hints.
* Gets the FieldSets that are unique
*
* @return The average number of bytes per record, or -1.0, if unknown.
* @return List of FieldSet that are unique
*/
public float getAvgBytesPerRecord() {
return avgBytesPerRecord;
public Set<FieldSet> getUniqueFields() {
return this.uniqueFields;
}

/**
* Sets the average number of bytes per record (key/value pair) for the
* contract containing these hints.
* Adds a FieldSet to be unique
*
* @param avgBytes
* The average number of bytes per record.
* @param uniqueFieldSet The unique FieldSet
*/
public void setAvgBytesPerRecord(float avgBytes) {
if(avgBytes < 0) {
throw new IllegalArgumentException("Average Bytes per Record must be >= 0!");
public void addUniqueField(FieldSet uniqueFieldSet) {
if (this.uniqueFields == null) {
this.uniqueFields = new HashSet<FieldSet>();
}
this.avgBytesPerRecord = avgBytes;
}

/**
* Gets the average number of emitted records per stub call.
*
* @return The average number of emitted records per stub call.
*/
public float getAvgRecordsEmittedPerStubCall() {
return avgRecordsEmittedPerStubCall;
this.uniqueFields.add(uniqueFieldSet);
}

/**
* Sets the average number of emitted records per stub call.
* Adds a field as having only unique values.
*
* @param avgRecordsEmittedPerStubCall
* The average number of emitted records per stub call to set.
* @param field The field with unique values.
*/
public void setAvgRecordsEmittedPerStubCall(float avgRecordsEmittedPerStubCall) {
if(avgRecordsEmittedPerStubCall < 0) {
throw new IllegalArgumentException("Average Number of Emitted Records per Stub Call must be >= 0!");
public void addUniqueField(int field) {
if (this.uniqueFields == null) {
this.uniqueFields = new HashSet<FieldSet>();
}
this.avgRecordsEmittedPerStubCall = avgRecordsEmittedPerStubCall;
this.uniqueFields.add(new FieldSet(field));
}


/**
* Gets the FieldSets that are unique
* Adds multiple FieldSets to be unique
*
* @return List of FieldSet that are unique
* @param uniqueFieldSets A set of unique FieldSet
*/
public Set<FieldSet> getUniqueFields() {
return this.uniqueFields;
public void addUniqueFields(Set<FieldSet> uniqueFieldSets) {
if (this.uniqueFields == null) {
this.uniqueFields = new HashSet<FieldSet>();
}
this.uniqueFields.addAll(uniqueFieldSets);
}

/**
* Sets a FieldSet to be unique
*
* @param uniqueFieldSet The unique FieldSet
*/
public void setUniqueField(FieldSet uniqueFieldSet) {
this.uniqueFields = Collections.singleton(uniqueFieldSet);
public void clearUniqueFields() {
this.uniqueFields = null;
}

/**
* Sets multiple FieldSets to be unique
*
* @param uniqueFieldSets A set of unique FieldSet
*/
public void setUniqueField(Set<FieldSet> uniqueFieldSets) {
this.uniqueFields = uniqueFieldSets;
// --------------------------------------------------------------------------------------------
// Miscellaneous
// --------------------------------------------------------------------------------------------

protected void copyFrom(CompilerHints source) {
this.avgRecordsEmittedPerStubCall = source.avgRecordsEmittedPerStubCall;
this.avgBytesPerRecord = source.avgBytesPerRecord;
this.distinctCounts.putAll(source.distinctCounts);
this.avgNumRecordsPerDistinctFields.putAll(source.avgNumRecordsPerDistinctFields);

if (source.uniqueFields != null && source.uniqueFields.size() > 0) {
if (this.uniqueFields == null) {
this.uniqueFields = new HashSet<FieldSet>();
} else {
this.uniqueFields.clear();
}
this.uniqueFields.addAll(source.uniqueFields);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public void accept(Visitor<Contract> visitor)
{
boolean descend = visitor.preVisit(this);
if (descend) {
for(Contract c : this.input) {
for (Contract c : this.input) {
c.accept(visitor);
}
visitor.postVisit(this);
Expand Down

This file was deleted.

Loading

0 comments on commit 15feaff

Please sign in to comment.