org.apache.flink.api.common.operators.CompilerHints Java Examples

The following examples show how to use org.apache.flink.api.common.operators.CompilerHints. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OptimizerNode.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Causes this node to compute its output estimates (such as number of rows, size in bytes)
 * based on the inputs and the compiler hints. The compiler hints are instantiated with conservative
 * default values which are used if no other values are provided. Nodes may access the statistics to
 * determine relevant information.
 * 
 * @param statistics
 *        The statistics object which may be accessed to get statistical information.
 *        The parameter may be null, if no statistics are available.
 */
public void computeOutputEstimates(DataStatistics statistics) {
	// sanity checking
	for (DagConnection c : getIncomingConnections()) {
		if (c.getSource() == null) {
			throw new CompilerException("Bug: Estimate computation called before inputs have been set.");
		}
	}
	
	// let every operator do its computation
	computeOperatorSpecificDefaultEstimates(statistics);
	
	if (this.estimatedOutputSize < 0) {
		this.estimatedOutputSize = -1;
	}
	if (this.estimatedNumRecords < 0) {
		this.estimatedNumRecords = -1;
	}
	
	// overwrite default estimates with hints, if given
	if (getOperator() == null || getOperator().getCompilerHints() == null) {
		return ;
	}
	
	CompilerHints hints = getOperator().getCompilerHints();
	if (hints.getOutputSize() >= 0) {
		this.estimatedOutputSize = hints.getOutputSize();
	}
	
	if (hints.getOutputCardinality() >= 0) {
		this.estimatedNumRecords = hints.getOutputCardinality();
	}
	
	if (hints.getFilterFactor() >= 0.0f) {
		if (this.estimatedNumRecords >= 0) {
			this.estimatedNumRecords = (long) (this.estimatedNumRecords * hints.getFilterFactor());
			
			if (this.estimatedOutputSize >= 0) {
				this.estimatedOutputSize = (long) (this.estimatedOutputSize * hints.getFilterFactor());
			}
		}
		else if (this instanceof SingleInputNode) {
			OptimizerNode pred = ((SingleInputNode) this).getPredecessorNode();
			if (pred != null && pred.getEstimatedNumRecords() >= 0) {
				this.estimatedNumRecords = (long) (pred.getEstimatedNumRecords() * hints.getFilterFactor());
			}
		}
	}
	
	// use the width to infer the cardinality (given size) and vice versa
	if (hints.getAvgOutputRecordSize() >= 1) {
		// the estimated number of rows based on size
		if (this.estimatedNumRecords == -1 && this.estimatedOutputSize >= 0) {
			this.estimatedNumRecords = (long) (this.estimatedOutputSize / hints.getAvgOutputRecordSize());
		}
		else if (this.estimatedOutputSize == -1 && this.estimatedNumRecords >= 0) {
			this.estimatedOutputSize = (long) (this.estimatedNumRecords * hints.getAvgOutputRecordSize());
		}
	}
}
 
Example #2
Source File: OptimizerNode.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Causes this node to compute its output estimates (such as number of rows, size in bytes)
 * based on the inputs and the compiler hints. The compiler hints are instantiated with conservative
 * default values which are used if no other values are provided. Nodes may access the statistics to
 * determine relevant information.
 * 
 * @param statistics
 *        The statistics object which may be accessed to get statistical information.
 *        The parameter may be null, if no statistics are available.
 */
public void computeOutputEstimates(DataStatistics statistics) {
	// sanity checking
	for (DagConnection c : getIncomingConnections()) {
		if (c.getSource() == null) {
			throw new CompilerException("Bug: Estimate computation called before inputs have been set.");
		}
	}
	
	// let every operator do its computation
	computeOperatorSpecificDefaultEstimates(statistics);
	
	if (this.estimatedOutputSize < 0) {
		this.estimatedOutputSize = -1;
	}
	if (this.estimatedNumRecords < 0) {
		this.estimatedNumRecords = -1;
	}
	
	// overwrite default estimates with hints, if given
	if (getOperator() == null || getOperator().getCompilerHints() == null) {
		return ;
	}
	
	CompilerHints hints = getOperator().getCompilerHints();
	if (hints.getOutputSize() >= 0) {
		this.estimatedOutputSize = hints.getOutputSize();
	}
	
	if (hints.getOutputCardinality() >= 0) {
		this.estimatedNumRecords = hints.getOutputCardinality();
	}
	
	if (hints.getFilterFactor() >= 0.0f) {
		if (this.estimatedNumRecords >= 0) {
			this.estimatedNumRecords = (long) (this.estimatedNumRecords * hints.getFilterFactor());
			
			if (this.estimatedOutputSize >= 0) {
				this.estimatedOutputSize = (long) (this.estimatedOutputSize * hints.getFilterFactor());
			}
		}
		else if (this instanceof SingleInputNode) {
			OptimizerNode pred = ((SingleInputNode) this).getPredecessorNode();
			if (pred != null && pred.getEstimatedNumRecords() >= 0) {
				this.estimatedNumRecords = (long) (pred.getEstimatedNumRecords() * hints.getFilterFactor());
			}
		}
	}
	
	// use the width to infer the cardinality (given size) and vice versa
	if (hints.getAvgOutputRecordSize() >= 1) {
		// the estimated number of rows based on size
		if (this.estimatedNumRecords == -1 && this.estimatedOutputSize >= 0) {
			this.estimatedNumRecords = (long) (this.estimatedOutputSize / hints.getAvgOutputRecordSize());
		}
		else if (this.estimatedOutputSize == -1 && this.estimatedNumRecords >= 0) {
			this.estimatedOutputSize = (long) (this.estimatedNumRecords * hints.getAvgOutputRecordSize());
		}
	}
}
 
Example #3
Source File: OptimizerNode.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Causes this node to compute its output estimates (such as number of rows, size in bytes)
 * based on the inputs and the compiler hints. The compiler hints are instantiated with conservative
 * default values which are used if no other values are provided. Nodes may access the statistics to
 * determine relevant information.
 * 
 * @param statistics
 *        The statistics object which may be accessed to get statistical information.
 *        The parameter may be null, if no statistics are available.
 */
public void computeOutputEstimates(DataStatistics statistics) {
	// sanity checking
	for (DagConnection c : getIncomingConnections()) {
		if (c.getSource() == null) {
			throw new CompilerException("Bug: Estimate computation called before inputs have been set.");
		}
	}
	
	// let every operator do its computation
	computeOperatorSpecificDefaultEstimates(statistics);
	
	if (this.estimatedOutputSize < 0) {
		this.estimatedOutputSize = -1;
	}
	if (this.estimatedNumRecords < 0) {
		this.estimatedNumRecords = -1;
	}
	
	// overwrite default estimates with hints, if given
	if (getOperator() == null || getOperator().getCompilerHints() == null) {
		return ;
	}
	
	CompilerHints hints = getOperator().getCompilerHints();
	if (hints.getOutputSize() >= 0) {
		this.estimatedOutputSize = hints.getOutputSize();
	}
	
	if (hints.getOutputCardinality() >= 0) {
		this.estimatedNumRecords = hints.getOutputCardinality();
	}
	
	if (hints.getFilterFactor() >= 0.0f) {
		if (this.estimatedNumRecords >= 0) {
			this.estimatedNumRecords = (long) (this.estimatedNumRecords * hints.getFilterFactor());
			
			if (this.estimatedOutputSize >= 0) {
				this.estimatedOutputSize = (long) (this.estimatedOutputSize * hints.getFilterFactor());
			}
		}
		else if (this instanceof SingleInputNode) {
			OptimizerNode pred = ((SingleInputNode) this).getPredecessorNode();
			if (pred != null && pred.getEstimatedNumRecords() >= 0) {
				this.estimatedNumRecords = (long) (pred.getEstimatedNumRecords() * hints.getFilterFactor());
			}
		}
	}
	
	// use the width to infer the cardinality (given size) and vice versa
	if (hints.getAvgOutputRecordSize() >= 1) {
		// the estimated number of rows based on size
		if (this.estimatedNumRecords == -1 && this.estimatedOutputSize >= 0) {
			this.estimatedNumRecords = (long) (this.estimatedOutputSize / hints.getAvgOutputRecordSize());
		}
		else if (this.estimatedOutputSize == -1 && this.estimatedNumRecords >= 0) {
			this.estimatedOutputSize = (long) (this.estimatedNumRecords * hints.getAvgOutputRecordSize());
		}
	}
}