org.qcri.rheem.basic.operators.CollectionSource Maven / Gradle / Ivy
package org.qcri.rheem.basic.operators;
import org.apache.commons.lang3.Validate;
import org.qcri.rheem.core.api.Configuration;
import org.qcri.rheem.core.optimizer.cardinality.CardinalityEstimator;
import org.qcri.rheem.core.optimizer.cardinality.DefaultCardinalityEstimator;
import org.qcri.rheem.core.plan.rheemplan.ElementaryOperator;
import org.qcri.rheem.core.plan.rheemplan.UnarySource;
import org.qcri.rheem.core.types.DataSetType;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
/**
* This source takes as input a Java {@link java.util.Collection}.
*/
public class CollectionSource extends UnarySource implements ElementaryOperator {
protected final Collection collection;
public CollectionSource(Collection collection, Class typeClass) {
this(collection, DataSetType.createDefault(typeClass));
}
public CollectionSource(Collection collection, DataSetType type) {
super(type);
this.collection = collection;
}
/**
* Copies an instance (exclusive of broadcasts).
*
* @param that that should be copied
*/
public CollectionSource(CollectionSource that) {
super(that);
this.collection = that.getCollection();
}
public Collection getCollection() {
return this.collection;
}
@Override
public Optional createCardinalityEstimator(
final int outputIndex,
final Configuration configuration) {
Validate.inclusiveBetween(0, this.getNumOutputs() - 1, outputIndex);
return Optional.of(new DefaultCardinalityEstimator(1d, this.getNumInputs(), this.isSupportingBroadcastInputs(),
inputCards -> this.collection.size()));
}
/**
* Creates a new instance without any data quanta.
*/
public static CollectionSource empty(Class typeClass) {
final CollectionSource instance = new CollectionSource<>(Collections.emptyList(), typeClass);
instance.setName("{}");
return instance;
}
/**
* Creates a new instance without any data quanta.
*/
public static CollectionSource singleton(T value, Class typeClass) {
final CollectionSource instance = new CollectionSource<>(Collections.singleton(value), typeClass);
instance.setName("{" + value + "}");
return instance;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy