use of org.apache.flink.types.StringValue in project flink by apache.
the class ReduceTranslationTests method translateGroupedReduceNoMapper.
@Test
public void translateGroupedReduceNoMapper() {
try {
final int parallelism = 8;
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment(parallelism);
DataSet<Tuple3<Double, StringValue, LongValue>> initialData = getSourceDataSet(env);
initialData.groupBy(2).reduce(new RichReduceFunction<Tuple3<Double, StringValue, LongValue>>() {
public Tuple3<Double, StringValue, LongValue> reduce(Tuple3<Double, StringValue, LongValue> value1, Tuple3<Double, StringValue, LongValue> value2) {
return value1;
}
}).output(new DiscardingOutputFormat<Tuple3<Double, StringValue, LongValue>>());
Plan p = env.createProgramPlan();
GenericDataSinkBase<?> sink = p.getDataSinks().iterator().next();
ReduceOperatorBase<?, ?> reducer = (ReduceOperatorBase<?, ?>) sink.getInput();
// check types
assertEquals(initialData.getType(), reducer.getOperatorInfo().getInputType());
assertEquals(initialData.getType(), reducer.getOperatorInfo().getOutputType());
// parallelism was not configured on the operator
assertTrue(reducer.getParallelism() == parallelism || reducer.getParallelism() == ExecutionConfig.PARALLELISM_DEFAULT);
// check keys
assertArrayEquals(new int[] { 2 }, reducer.getKeyColumns(0));
assertTrue(reducer.getInput() instanceof GenericDataSourceBase<?, ?>);
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
fail("Test caused an error: " + e.getMessage());
}
}
use of org.apache.flink.types.StringValue in project flink by apache.
the class StringValueArray method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder("[");
String separator = "";
for (StringValue sv : this) {
sb.append(sv.getValue()).append(separator);
separator = ",";
}
sb.append("]");
return sb.toString();
}
use of org.apache.flink.types.StringValue in project flink by apache.
the class StringValueArrayComparatorTest method getSortedTestData.
@Override
protected StringValueArray[] getSortedTestData() {
StringValueArray sva0 = new StringValueArray();
StringValueArray sva1 = new StringValueArray();
sva1.add(new StringValue("abc"));
StringValueArray sva2 = new StringValueArray();
sva2.add(new StringValue("qrs"));
sva2.add(new StringValue("xyz"));
return new StringValueArray[] { sva0, sva1, sva2 };
}
use of org.apache.flink.types.StringValue in project flink by apache.
the class StringValueArrayTest method testBoundedArray.
@Test
public void testBoundedArray() {
// one byte for length and one byte for character
int count = StringValueArray.DEFAULT_CAPACITY_IN_BYTES / 2;
ValueArray<StringValue> sva = new StringValueArray(StringValueArray.DEFAULT_CAPACITY_IN_BYTES);
// fill the array
for (int i = 0; i < count; i++) {
assertFalse(sva.isFull());
assertEquals(i, sva.size());
assertTrue(sva.add(new StringValue(Character.toString((char) (i & 0x7F)))));
assertEquals(i + 1, sva.size());
}
// array is now full
assertTrue(sva.isFull());
assertEquals(count, sva.size());
// verify the array values
int idx = 0;
for (StringValue sv : sva) {
assertEquals((idx++) & 0x7F, sv.getValue().charAt(0));
}
// add element past end of array
assertFalse(sva.add(new StringValue(String.valueOf((char) count))));
assertFalse(sva.addAll(sva));
// test copy
assertEquals(sva, sva.copy());
// test copyTo
StringValueArray svaTo = new StringValueArray();
sva.copyTo(svaTo);
assertEquals(sva, svaTo);
// test clear
sva.clear();
assertEquals(0, sva.size());
}
use of org.apache.flink.types.StringValue in project flink by apache.
the class EitherSerializerTest method testStringValueDoubleValueEither.
@Test
public void testStringValueDoubleValueEither() {
@SuppressWarnings("unchecked") Either<StringValue, DoubleValue>[] testData = new Either[] { Left(new StringValue("banana")), Left.of(new StringValue("apple")), new Left(new StringValue("")), Right(new DoubleValue(32.0)), Right.of(new DoubleValue(Double.MIN_VALUE)), new Right(new DoubleValue(Double.MAX_VALUE)) };
EitherTypeInfo<StringValue, DoubleValue> eitherTypeInfo = new EitherTypeInfo<>(ValueTypeInfo.STRING_VALUE_TYPE_INFO, ValueTypeInfo.DOUBLE_VALUE_TYPE_INFO);
EitherSerializer<StringValue, DoubleValue> eitherSerializer = (EitherSerializer<StringValue, DoubleValue>) eitherTypeInfo.createSerializer(new ExecutionConfig());
SerializerTestInstance<Either<StringValue, DoubleValue>> testInstance = new EitherSerializerTestInstance<>(eitherSerializer, eitherTypeInfo.getTypeClass(), -1, testData);
testInstance.testAll();
}
Aggregations