org.apache.flink.api.common.accumulators.DoubleCounter Java Examples

The following examples show how to use org.apache.flink.api.common.accumulators.DoubleCounter. 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: AccumulatorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open(Configuration parameters) {

	// Add counters using convenience functions
	this.cntNumLines = getRuntimeContext().getIntCounter("num-lines");
	this.wordsPerLineDistribution = getRuntimeContext().getHistogram("words-per-line");

	// Add built-in accumulator without convenience function
	getRuntimeContext().addAccumulator("open-close-counter", this.openCloseCounter);

	// Add custom counter
	this.distinctWords = new SetAccumulator<>();
	this.getRuntimeContext().addAccumulator("distinct-words", distinctWords);

	// Create counter and test increment
	IntCounter simpleCounter = getRuntimeContext().getIntCounter("simple-counter");
	simpleCounter.add(1);
	Assert.assertEquals(simpleCounter.getLocalValue().intValue(), 1);

	// Test if we get the same counter
	IntCounter simpleCounter2 = getRuntimeContext().getIntCounter("simple-counter");
	Assert.assertEquals(simpleCounter.getLocalValue(), simpleCounter2.getLocalValue());

	// Should fail if we request it with different type
	try {
		@SuppressWarnings("unused")
		DoubleCounter simpleCounter3 = getRuntimeContext().getDoubleCounter("simple-counter");
		// DoubleSumAggregator longAggregator3 = (DoubleSumAggregator)
		// getRuntimeContext().getAggregator("custom",
		// DoubleSumAggregator.class);
		Assert.fail("Should not be able to obtain previously created counter with different type");
	}
	catch (UnsupportedOperationException ex) {
		// expected!
	}

	// Test counter used in open() and closed()
	this.openCloseCounter.add(0.5);
}
 
Example #2
Source File: AccumulatorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open(Configuration parameters) {

	// Add counters using convenience functions
	this.cntNumLines = getRuntimeContext().getIntCounter("num-lines");
	this.wordsPerLineDistribution = getRuntimeContext().getHistogram("words-per-line");

	// Add built-in accumulator without convenience function
	getRuntimeContext().addAccumulator("open-close-counter", this.openCloseCounter);

	// Add custom counter
	this.distinctWords = new SetAccumulator<>();
	this.getRuntimeContext().addAccumulator("distinct-words", distinctWords);

	// Create counter and test increment
	IntCounter simpleCounter = getRuntimeContext().getIntCounter("simple-counter");
	simpleCounter.add(1);
	Assert.assertEquals(simpleCounter.getLocalValue().intValue(), 1);

	// Test if we get the same counter
	IntCounter simpleCounter2 = getRuntimeContext().getIntCounter("simple-counter");
	Assert.assertEquals(simpleCounter.getLocalValue(), simpleCounter2.getLocalValue());

	// Should fail if we request it with different type
	try {
		@SuppressWarnings("unused")
		DoubleCounter simpleCounter3 = getRuntimeContext().getDoubleCounter("simple-counter");
		// DoubleSumAggregator longAggregator3 = (DoubleSumAggregator)
		// getRuntimeContext().getAggregator("custom",
		// DoubleSumAggregator.class);
		Assert.fail("Should not be able to obtain previously created counter with different type");
	}
	catch (UnsupportedOperationException ex) {
		// expected!
	}

	// Test counter used in open() and closed()
	this.openCloseCounter.add(0.5);
}
 
Example #3
Source File: AccumulatorITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void open(Configuration parameters) {

	// Add counters using convenience functions
	this.cntNumLines = getRuntimeContext().getIntCounter("num-lines");
	this.wordsPerLineDistribution = getRuntimeContext().getHistogram("words-per-line");

	// Add built-in accumulator without convenience function
	getRuntimeContext().addAccumulator("open-close-counter", this.openCloseCounter);

	// Add custom counter
	this.distinctWords = new SetAccumulator<>();
	this.getRuntimeContext().addAccumulator("distinct-words", distinctWords);

	// Create counter and test increment
	IntCounter simpleCounter = getRuntimeContext().getIntCounter("simple-counter");
	simpleCounter.add(1);
	Assert.assertEquals(simpleCounter.getLocalValue().intValue(), 1);

	// Test if we get the same counter
	IntCounter simpleCounter2 = getRuntimeContext().getIntCounter("simple-counter");
	Assert.assertEquals(simpleCounter.getLocalValue(), simpleCounter2.getLocalValue());

	// Should fail if we request it with different type
	try {
		@SuppressWarnings("unused")
		DoubleCounter simpleCounter3 = getRuntimeContext().getDoubleCounter("simple-counter");
		// DoubleSumAggregator longAggregator3 = (DoubleSumAggregator)
		// getRuntimeContext().getAggregator("custom",
		// DoubleSumAggregator.class);
		Assert.fail("Should not be able to obtain previously created counter with different type");
	}
	catch (UnsupportedOperationException ex) {
		// expected!
	}

	// Test counter used in open() and closed()
	this.openCloseCounter.add(0.5);
}
 
Example #4
Source File: AverageClusteringCoefficient.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws IOException {
	addAccumulator(VERTEX_COUNT, new LongCounter(vertexCount));
	addAccumulator(SUM_OF_LOCAL_CLUSTERING_COEFFICIENT, new DoubleCounter(sumOfLocalClusteringCoefficient));
}
 
Example #5
Source File: RichAsyncFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DoubleCounter getDoubleCounter(String name) {
	throw new UnsupportedOperationException("Long counters are not supported in rich async functions.");
}
 
Example #6
Source File: SavepointRuntimeContext.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DoubleCounter getDoubleCounter(String name) {
	return ctx.getDoubleCounter(name);
}
 
Example #7
Source File: AverageClusteringCoefficient.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws IOException {
	addAccumulator(VERTEX_COUNT, new LongCounter(vertexCount));
	addAccumulator(SUM_OF_LOCAL_CLUSTERING_COEFFICIENT, new DoubleCounter(sumOfLocalClusteringCoefficient));
}
 
Example #8
Source File: AverageClusteringCoefficient.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws IOException {
	addAccumulator(VERTEX_COUNT, new LongCounter(vertexCount));
	addAccumulator(SUM_OF_LOCAL_CLUSTERING_COEFFICIENT, new DoubleCounter(sumOfLocalClusteringCoefficient));
}
 
Example #9
Source File: CepRuntimeContext.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DoubleCounter getDoubleCounter(final String name) {
	throw new UnsupportedOperationException("Double counters are not supported.");
}
 
Example #10
Source File: AbstractRuntimeUDFContext.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DoubleCounter getDoubleCounter(String name) {
	return (DoubleCounter) getAccumulator(name, DoubleCounter.class);
}
 
Example #11
Source File: AccumulatorErrorITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void open(Configuration parameters) throws Exception {
	getRuntimeContext().addAccumulator(INCOMPATIBLE_ACCUMULATORS_NAME, new DoubleCounter());
}
 
Example #12
Source File: ReductionsTest.java    From flink-statefun with Apache License 2.0 4 votes vote down vote up
@Override
public DoubleCounter getDoubleCounter(String name) {
  throw new UnsupportedOperationException();
}
 
Example #13
Source File: ReductionsTest.java    From stateful-functions with Apache License 2.0 4 votes vote down vote up
@Override
public DoubleCounter getDoubleCounter(String name) {
  throw new UnsupportedOperationException();
}
 
Example #14
Source File: RichAsyncFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DoubleCounter getDoubleCounter(String name) {
	throw new UnsupportedOperationException("Long counters are not supported in rich async functions.");
}
 
Example #15
Source File: SavepointRuntimeContext.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DoubleCounter getDoubleCounter(String name) {
	return ctx.getDoubleCounter(name);
}
 
Example #16
Source File: AverageClusteringCoefficient.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws IOException {
	addAccumulator(VERTEX_COUNT, new LongCounter(vertexCount));
	addAccumulator(SUM_OF_LOCAL_CLUSTERING_COEFFICIENT, new DoubleCounter(sumOfLocalClusteringCoefficient));
}
 
Example #17
Source File: CepRuntimeContext.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DoubleCounter getDoubleCounter(final String name) {
	throw new UnsupportedOperationException("Double counters are not supported.");
}
 
Example #18
Source File: AbstractRuntimeUDFContext.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DoubleCounter getDoubleCounter(String name) {
	return (DoubleCounter) getAccumulator(name, DoubleCounter.class);
}
 
Example #19
Source File: AccumulatorErrorITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void open(Configuration parameters) throws Exception {
	getRuntimeContext().addAccumulator(INCOMPATIBLE_ACCUMULATORS_NAME, new DoubleCounter());
}
 
Example #20
Source File: RichAsyncFunction.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public DoubleCounter getDoubleCounter(String name) {
	throw new UnsupportedOperationException("Long counters are not supported in rich async functions.");
}
 
Example #21
Source File: AverageClusteringCoefficient.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws IOException {
	addAccumulator(VERTEX_COUNT, new LongCounter(vertexCount));
	addAccumulator(SUM_OF_LOCAL_CLUSTERING_COEFFICIENT, new DoubleCounter(sumOfLocalClusteringCoefficient));
}
 
Example #22
Source File: AverageClusteringCoefficient.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws IOException {
	addAccumulator(VERTEX_COUNT, new LongCounter(vertexCount));
	addAccumulator(SUM_OF_LOCAL_CLUSTERING_COEFFICIENT, new DoubleCounter(sumOfLocalClusteringCoefficient));
}
 
Example #23
Source File: CepRuntimeContext.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public DoubleCounter getDoubleCounter(final String name) {
	throw new UnsupportedOperationException("Double counters are not supported.");
}
 
Example #24
Source File: AbstractRuntimeUDFContext.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public DoubleCounter getDoubleCounter(String name) {
	return (DoubleCounter) getAccumulator(name, DoubleCounter.class);
}
 
Example #25
Source File: AccumulatorErrorITCase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void open(Configuration parameters) throws Exception {
	getRuntimeContext().addAccumulator(INCOMPATIBLE_ACCUMULATORS_NAME, new DoubleCounter());
}
 
Example #26
Source File: RuntimeContext.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Convenience function to create a counter object for doubles.
 */
@PublicEvolving
DoubleCounter getDoubleCounter(String name);
 
Example #27
Source File: RuntimeContext.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Convenience function to create a counter object for doubles.
 */
@PublicEvolving
DoubleCounter getDoubleCounter(String name);
 
Example #28
Source File: RuntimeContext.java    From Flink-CEPplus with Apache License 2.0 2 votes vote down vote up
/**
 * Convenience function to create a counter object for doubles.
 */
@PublicEvolving
DoubleCounter getDoubleCounter(String name);