Java Code Examples for org.apache.flink.types.BooleanValue

The following examples show how to use org.apache.flink.types.BooleanValue. These examples are extracted from open source projects. 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
@Test
public void testCreate() throws Exception {
	// supported primitive types
	Assert.assertEquals(StringSummaryAggregator.class, SummaryAggregatorFactory.create(String.class).getClass());
	Assert.assertEquals(ShortSummaryAggregator.class, SummaryAggregatorFactory.create(Short.class).getClass());
	Assert.assertEquals(IntegerSummaryAggregator.class, SummaryAggregatorFactory.create(Integer.class).getClass());
	Assert.assertEquals(LongSummaryAggregator.class, SummaryAggregatorFactory.create(Long.class).getClass());
	Assert.assertEquals(FloatSummaryAggregator.class, SummaryAggregatorFactory.create(Float.class).getClass());
	Assert.assertEquals(DoubleSummaryAggregator.class, SummaryAggregatorFactory.create(Double.class).getClass());
	Assert.assertEquals(BooleanSummaryAggregator.class, SummaryAggregatorFactory.create(Boolean.class).getClass());

	// supported value types
	Assert.assertEquals(ValueSummaryAggregator.StringValueSummaryAggregator.class, SummaryAggregatorFactory.create(StringValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.ShortValueSummaryAggregator.class, SummaryAggregatorFactory.create(ShortValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.IntegerValueSummaryAggregator.class, SummaryAggregatorFactory.create(IntValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.LongValueSummaryAggregator.class, SummaryAggregatorFactory.create(LongValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.FloatValueSummaryAggregator.class, SummaryAggregatorFactory.create(FloatValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.DoubleValueSummaryAggregator.class, SummaryAggregatorFactory.create(DoubleValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.BooleanValueSummaryAggregator.class, SummaryAggregatorFactory.create(BooleanValue.class).getClass());

	// some not well supported types - these fallback to ObjectSummaryAggregator
	Assert.assertEquals(ObjectSummaryAggregator.class, SummaryAggregatorFactory.create(Object.class).getClass());
	Assert.assertEquals(ObjectSummaryAggregator.class, SummaryAggregatorFactory.create(List.class).getClass());
}
 
Example 2
Source Project: flink   Source File: BooleanValueSummaryAggregatorTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Helper method for summarizing a list of values.
 *
 * <p>This method breaks the rule of "testing only one thing" by aggregating and combining
 * a bunch of different ways.
 */
protected BooleanColumnSummary summarize(Boolean... values) {

	BooleanValue[] booleanValues = new BooleanValue[values.length];
	for (int i = 0; i < values.length; i++) {
		if (values[i] != null) {
			booleanValues[i] = new BooleanValue(values[i]);
		}
	}

	return new AggregateCombineHarness<BooleanValue, BooleanColumnSummary, ValueSummaryAggregator.BooleanValueSummaryAggregator>() {
		@Override
		protected void compareResults(BooleanColumnSummary result1, BooleanColumnSummary result2) {
			Assert.assertEquals(result1.getNullCount(), result2.getNullCount());
			Assert.assertEquals(result1.getNonNullCount(), result2.getNonNullCount());
			Assert.assertEquals(result1.getTrueCount(), result2.getTrueCount());
			Assert.assertEquals(result1.getFalseCount(), result2.getFalseCount());
		}
	}.summarize(booleanValues);
}
 
Example 3
Source Project: Flink-CEPplus   Source File: CsvReaderITCase.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testValueTypes() throws Exception {
	final String inputData = "ABC,true,1,2,3,4,5.0,6.0\nBCD,false,1,2,3,4,5.0,6.0";
	final String dataPath = createInputData(inputData);
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<Tuple8<StringValue, BooleanValue, ByteValue, ShortValue, IntValue, LongValue, FloatValue, DoubleValue>> data =
			env.readCsvFile(dataPath).types(StringValue.class, BooleanValue.class, ByteValue.class, ShortValue.class, IntValue.class, LongValue.class, FloatValue.class, DoubleValue.class);
	List<Tuple8<StringValue, BooleanValue, ByteValue, ShortValue, IntValue, LongValue, FloatValue, DoubleValue>> result = data.collect();

	expected = inputData;
	compareResultAsTuples(result, expected);
}
 
Example 4
Source Project: Flink-CEPplus   Source File: CSVReaderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWithValueType() throws Exception {
	CsvReader reader = getCsvReader();
	DataSource<Tuple8<StringValue, BooleanValue, ByteValue, ShortValue, IntValue, LongValue, FloatValue, DoubleValue>> items =
			reader.types(StringValue.class, BooleanValue.class, ByteValue.class, ShortValue.class, IntValue.class, LongValue.class, FloatValue.class, DoubleValue.class);
	TypeInformation<?> info = items.getType();

	Assert.assertEquals(true, info.isTupleType());
	Assert.assertEquals(Tuple8.class, info.getTypeClass());
}
 
Example 5
Source Project: flink   Source File: BooleanValueSerializerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected BooleanValue[] getTestData() {
	Random rnd = new Random(874597969123412341L);
	
	return new BooleanValue[] {new BooleanValue(true), new BooleanValue(false),
							new BooleanValue(rnd.nextBoolean()),
							new BooleanValue(rnd.nextBoolean()),
							new BooleanValue(rnd.nextBoolean())};
}
 
Example 6
Source Project: Flink-CEPplus   Source File: BooleanValueParser.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int parseField(byte[] bytes, int startPos, int limit, byte[] delim, BooleanValue reuse) {
	int returnValue = parser.parseField(bytes, startPos, limit, delim, reuse.getValue());
	setErrorState(parser.getErrorState());
	reuse.setValue(parser.getLastResult());
	result = reuse;
	return returnValue;
}
 
Example 7
Source Project: flink   Source File: BooleanValueParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public BooleanValue[] getValidTestResults() {
	return new BooleanValue[] {
			new BooleanValue(true), new BooleanValue(false), new BooleanValue(false), new BooleanValue(true),
			new BooleanValue(true), new BooleanValue(false), new BooleanValue(true), new BooleanValue(false)
	};
}
 
Example 8
Source Project: Flink-CEPplus   Source File: BooleanValueParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public BooleanValue[] getValidTestResults() {
	return new BooleanValue[] {
			new BooleanValue(true), new BooleanValue(false), new BooleanValue(false), new BooleanValue(true),
			new BooleanValue(true), new BooleanValue(false), new BooleanValue(true), new BooleanValue(false)
	};
}
 
Example 9
Source Project: flink   Source File: CSVReaderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWithValueType() throws Exception {
	CsvReader reader = getCsvReader();
	DataSource<Tuple8<StringValue, BooleanValue, ByteValue, ShortValue, IntValue, LongValue, FloatValue, DoubleValue>> items =
			reader.types(StringValue.class, BooleanValue.class, ByteValue.class, ShortValue.class, IntValue.class, LongValue.class, FloatValue.class, DoubleValue.class);
	TypeInformation<?> info = items.getType();

	Assert.assertEquals(true, info.isTupleType());
	Assert.assertEquals(Tuple8.class, info.getTypeClass());
}
 
Example 10
Source Project: flink   Source File: BooleanValueParser.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int parseField(byte[] bytes, int startPos, int limit, byte[] delim, BooleanValue reuse) {
	int returnValue = parser.parseField(bytes, startPos, limit, delim, reuse.getValue());
	setErrorState(parser.getErrorState());
	reuse.setValue(parser.getLastResult());
	result = reuse;
	return returnValue;
}
 
Example 11
Source Project: flink   Source File: BooleanValueSerializerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected BooleanValue[] getTestData() {
	Random rnd = new Random(874597969123412341L);
	
	return new BooleanValue[] {new BooleanValue(true), new BooleanValue(false),
							new BooleanValue(rnd.nextBoolean()),
							new BooleanValue(rnd.nextBoolean()),
							new BooleanValue(rnd.nextBoolean())};
}
 
Example 12
Source Project: flink   Source File: BooleanValueParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public BooleanValue[] getValidTestResults() {
	return new BooleanValue[] {
			new BooleanValue(true), new BooleanValue(false), new BooleanValue(false), new BooleanValue(true),
			new BooleanValue(true), new BooleanValue(false), new BooleanValue(true), new BooleanValue(false)
	};
}
 
Example 13
Source Project: flink   Source File: BooleanValueParser.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int parseField(byte[] bytes, int startPos, int limit, byte[] delim, BooleanValue reuse) {
	int returnValue = parser.parseField(bytes, startPos, limit, delim, reuse.getValue());
	setErrorState(parser.getErrorState());
	reuse.setValue(parser.getLastResult());
	result = reuse;
	return returnValue;
}
 
Example 14
Source Project: flink   Source File: CSVReaderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWithValueType() throws Exception {
	CsvReader reader = getCsvReader();
	DataSource<Tuple8<StringValue, BooleanValue, ByteValue, ShortValue, IntValue, LongValue, FloatValue, DoubleValue>> items =
			reader.types(StringValue.class, BooleanValue.class, ByteValue.class, ShortValue.class, IntValue.class, LongValue.class, FloatValue.class, DoubleValue.class);
	TypeInformation<?> info = items.getType();

	Assert.assertEquals(true, info.isTupleType());
	Assert.assertEquals(Tuple8.class, info.getTypeClass());
}
 
Example 15
Source Project: Flink-CEPplus   Source File: ValueSummaryAggregator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Boolean getValue(BooleanValue value) {
	return value.getValue();
}
 
Example 16
Source Project: Flink-CEPplus   Source File: SummaryAggregatorFactory.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Create a SummaryAggregator for the supplied type.
 * @param <T> the type to aggregate
 * @param <R> the result type of the aggregation
 */
@SuppressWarnings("unchecked")
public static <T, R> Aggregator<T, R> create(Class<T> type) {
	if (type == Long.class) {
		return (Aggregator<T, R>) new LongSummaryAggregator();
	}
	else if (type == LongValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.LongValueSummaryAggregator();
	}
	else if (type == Integer.class) {
		return (Aggregator<T, R>) new IntegerSummaryAggregator();
	}
	else if (type == IntValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.IntegerValueSummaryAggregator();
	}
	else if (type == Double.class) {
		return (Aggregator<T, R>) new DoubleSummaryAggregator();
	}
	else if (type == DoubleValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.DoubleValueSummaryAggregator();
	}
	else if (type == Float.class) {
		return (Aggregator<T, R>) new FloatSummaryAggregator();
	}
	else if (type == FloatValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.FloatValueSummaryAggregator();
	}
	else if (type == Short.class) {
		return (Aggregator<T, R>) new ShortSummaryAggregator();
	}
	else if (type == ShortValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.ShortValueSummaryAggregator();
	}
	else if (type == Boolean.class) {
		return (Aggregator<T, R>) new BooleanSummaryAggregator();
	}
	else if (type == BooleanValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.BooleanValueSummaryAggregator();
	}
	else if (type == String.class) {
		return (Aggregator<T, R>) new StringSummaryAggregator();
	}
	else if (type == StringValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.StringValueSummaryAggregator();
	}
	else {
		// rather than error for unsupported types do something very generic
		return (Aggregator<T, R>) new ObjectSummaryAggregator();
	}
}
 
Example 17
Source Project: flink   Source File: BooleanValueSerializer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public BooleanValue deserialize(BooleanValue reuse, DataInputView source) throws IOException {
	reuse.read(source);
	return reuse;
}
 
Example 18
Source Project: flink   Source File: BooleanValueComparator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setReference(BooleanValue toCompare) {
	toCompare.copyTo(reference);
}
 
Example 19
Source Project: Flink-CEPplus   Source File: ValueTypeInfo.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
@PublicEvolving
public TypeComparator<T> createComparator(boolean sortOrderAscending, ExecutionConfig executionConfig) {
	if (!isKeyType()) {
		throw new RuntimeException("The type " + type.getName() + " is not Comparable.");
	}

	if (BooleanValue.class.isAssignableFrom(type)) {
		return (TypeComparator<T>) new BooleanValueComparator(sortOrderAscending);
	}
	else if (ByteValue.class.isAssignableFrom(type)) {
		return (TypeComparator<T>) new ByteValueComparator(sortOrderAscending);
	}
	else if (CharValue.class.isAssignableFrom(type)) {
		return (TypeComparator<T>) new CharValueComparator(sortOrderAscending);
	}
	else if (DoubleValue.class.isAssignableFrom(type)) {
		return (TypeComparator<T>) new DoubleValueComparator(sortOrderAscending);
	}
	else if (FloatValue.class.isAssignableFrom(type)) {
		return (TypeComparator<T>) new FloatValueComparator(sortOrderAscending);
	}
	else if (IntValue.class.isAssignableFrom(type)) {
		return (TypeComparator<T>) new IntValueComparator(sortOrderAscending);
	}
	else if (LongValue.class.isAssignableFrom(type)) {
		return (TypeComparator<T>) new LongValueComparator(sortOrderAscending);
	}
	else if (NullValue.class.isAssignableFrom(type)) {
		return (TypeComparator<T>) NullValueComparator.getInstance();
	}
	else if (ShortValue.class.isAssignableFrom(type)) {
		return (TypeComparator<T>) new ShortValueComparator(sortOrderAscending);
	}
	else if (StringValue.class.isAssignableFrom(type)) {
		return (TypeComparator<T>) new StringValueComparator(sortOrderAscending);
	}
	else if (CopyableValue.class.isAssignableFrom(type)) {
		return (TypeComparator<T>) new CopyableValueComparator(sortOrderAscending, type);
	}
	else {
		return (TypeComparator<T>) new ValueComparator(sortOrderAscending, type);
	}
}
 
Example 20
Source Project: flink   Source File: SummaryAggregatorFactory.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Create a SummaryAggregator for the supplied type.
 * @param <T> the type to aggregate
 * @param <R> the result type of the aggregation
 */
@SuppressWarnings("unchecked")
public static <T, R> Aggregator<T, R> create(Class<T> type) {
	if (type == Long.class) {
		return (Aggregator<T, R>) new LongSummaryAggregator();
	}
	else if (type == LongValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.LongValueSummaryAggregator();
	}
	else if (type == Integer.class) {
		return (Aggregator<T, R>) new IntegerSummaryAggregator();
	}
	else if (type == IntValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.IntegerValueSummaryAggregator();
	}
	else if (type == Double.class) {
		return (Aggregator<T, R>) new DoubleSummaryAggregator();
	}
	else if (type == DoubleValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.DoubleValueSummaryAggregator();
	}
	else if (type == Float.class) {
		return (Aggregator<T, R>) new FloatSummaryAggregator();
	}
	else if (type == FloatValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.FloatValueSummaryAggregator();
	}
	else if (type == Short.class) {
		return (Aggregator<T, R>) new ShortSummaryAggregator();
	}
	else if (type == ShortValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.ShortValueSummaryAggregator();
	}
	else if (type == Boolean.class) {
		return (Aggregator<T, R>) new BooleanSummaryAggregator();
	}
	else if (type == BooleanValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.BooleanValueSummaryAggregator();
	}
	else if (type == String.class) {
		return (Aggregator<T, R>) new StringSummaryAggregator();
	}
	else if (type == StringValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.StringValueSummaryAggregator();
	}
	else {
		// rather than error for unsupported types do something very generic
		return (Aggregator<T, R>) new ObjectSummaryAggregator();
	}
}
 
Example 21
Source Project: Flink-CEPplus   Source File: BooleanValueComparator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setReference(BooleanValue toCompare) {
	toCompare.copyTo(reference);
}
 
Example 22
Source Project: Flink-CEPplus   Source File: BooleanValueComparator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean equalToReference(BooleanValue candidate) {
	return candidate.equals(this.reference);
}
 
Example 23
Source Project: Flink-CEPplus   Source File: BooleanValueComparator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public int compareToReference(TypeComparator<BooleanValue> referencedComparator) {
	BooleanValue otherRef = ((BooleanValueComparator) referencedComparator).reference;
	int comp = otherRef.compareTo(reference);
	return ascendingComparison ? comp : -comp;
}
 
Example 24
Source Project: Flink-CEPplus   Source File: BooleanValueComparator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public int compare(BooleanValue first, BooleanValue second) {
	int comp = first.compareTo(second);
	return ascendingComparison ? comp : -comp;
}
 
Example 25
Source Project: Flink-CEPplus   Source File: BooleanValueComparator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsNormalizedKey() {
	return NormalizableKey.class.isAssignableFrom(BooleanValue.class);
}
 
Example 26
Source Project: Flink-CEPplus   Source File: BooleanValueComparator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void putNormalizedKey(BooleanValue record, MemorySegment target, int offset, int numBytes) {
	record.copyNormalizedKey(target, offset, numBytes);
}
 
Example 27
Source Project: Flink-CEPplus   Source File: BooleanValueComparator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public TypeComparator<BooleanValue> duplicate() {
	return new BooleanValueComparator(ascendingComparison);
}
 
Example 28
Source Project: flink   Source File: BooleanValueComparatorTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected TypeSerializer<BooleanValue> createSerializer() {
	return new BooleanValueSerializer();
}
 
Example 29
Source Project: Flink-CEPplus   Source File: BooleanValueComparator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public BooleanValue readWithKeyDenormalization(BooleanValue reuse, DataInputView source) throws IOException {
	throw new UnsupportedOperationException();
}
 
Example 30
Source Project: Flink-CEPplus   Source File: BooleanValueSerializer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public BooleanValue createInstance() {
	return new BooleanValue();
}