use of org.apache.flink.types.LongValue in project flink by apache.
the class ReduceTranslationTests method translateNonGroupedReduce.
@Test
public void translateNonGroupedReduce() {
try {
final int parallelism = 8;
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment(parallelism);
DataSet<Tuple3<Double, StringValue, LongValue>> initialData = getSourceDataSet(env);
initialData.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());
// check keys
assertTrue(reducer.getKeyColumns(0) == null || reducer.getKeyColumns(0).length == 0);
// parallelism was not configured on the operator
assertTrue(reducer.getParallelism() == 1 || reducer.getParallelism() == ExecutionConfig.PARALLELISM_DEFAULT);
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.LongValue in project flink by apache.
the class ReduceTranslationTests method translateGroupedReduceWithkeyExtractor.
@Test
public void translateGroupedReduceWithkeyExtractor() {
try {
final int parallelism = 8;
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment(parallelism);
DataSet<Tuple3<Double, StringValue, LongValue>> initialData = getSourceDataSet(env);
initialData.groupBy(new KeySelector<Tuple3<Double, StringValue, LongValue>, StringValue>() {
public StringValue getKey(Tuple3<Double, StringValue, LongValue> value) {
return value.f1;
}
}).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;
}
}).setParallelism(4).output(new DiscardingOutputFormat<Tuple3<Double, StringValue, LongValue>>());
Plan p = env.createProgramPlan();
GenericDataSinkBase<?> sink = p.getDataSinks().iterator().next();
MapOperatorBase<?, ?, ?> keyProjector = (MapOperatorBase<?, ?, ?>) sink.getInput();
PlanUnwrappingReduceOperator<?, ?> reducer = (PlanUnwrappingReduceOperator<?, ?>) keyProjector.getInput();
MapOperatorBase<?, ?, ?> keyExtractor = (MapOperatorBase<?, ?, ?>) reducer.getInput();
// check the parallelisms
assertEquals(1, keyExtractor.getParallelism());
assertEquals(4, reducer.getParallelism());
assertEquals(4, keyProjector.getParallelism());
// check types
TypeInformation<?> keyValueInfo = new TupleTypeInfo<Tuple2<StringValue, Tuple3<Double, StringValue, LongValue>>>(new ValueTypeInfo<StringValue>(StringValue.class), initialData.getType());
assertEquals(initialData.getType(), keyExtractor.getOperatorInfo().getInputType());
assertEquals(keyValueInfo, keyExtractor.getOperatorInfo().getOutputType());
assertEquals(keyValueInfo, reducer.getOperatorInfo().getInputType());
assertEquals(keyValueInfo, reducer.getOperatorInfo().getOutputType());
assertEquals(keyValueInfo, keyProjector.getOperatorInfo().getInputType());
assertEquals(initialData.getType(), keyProjector.getOperatorInfo().getOutputType());
// check keys
assertEquals(KeyExtractingMapper.class, keyExtractor.getUserCodeWrapper().getUserCodeClass());
assertTrue(keyExtractor.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.LongValue in project flink by apache.
the class LongValueComparatorTest method getSortedTestData.
@Override
protected LongValue[] getSortedTestData() {
Random rnd = new Random(874597969123412338L);
long rndLong = rnd.nextLong();
if (rndLong < 0) {
rndLong = -rndLong;
}
if (rndLong == Long.MAX_VALUE) {
rndLong -= 3;
}
if (rndLong <= 2) {
rndLong += 3;
}
return new LongValue[] { new LongValue(Long.MIN_VALUE), new LongValue(-rndLong), new LongValue(-1L), new LongValue(0L), new LongValue(1L), new LongValue(2L), new LongValue(rndLong), new LongValue(Long.MAX_VALUE) };
}
use of org.apache.flink.types.LongValue in project flink by apache.
the class LongValueComparator method compareToReference.
@Override
public int compareToReference(TypeComparator<LongValue> referencedComparator) {
LongValue otherRef = ((LongValueComparator) referencedComparator).reference;
int comp = otherRef.compareTo(reference);
return ascendingComparison ? comp : -comp;
}
use of org.apache.flink.types.LongValue in project flink by apache.
the class GenericCsvInputFormatTest method testLongLongLong.
@Test
public void testLongLongLong() {
try {
final String fileContent = "1,2,3\n3,2,1";
final FileInputSplit split = createTempFile(fileContent);
final Configuration parameters = new Configuration();
format.setFieldDelimiter(",");
format.setFieldTypesGeneric(LongValue.class, LongValue.class, LongValue.class);
format.configure(parameters);
format.open(split);
Value[] values = createLongValues(3);
values = format.nextRecord(values);
assertNotNull(values);
assertEquals(1L, ((LongValue) values[0]).getValue());
assertEquals(2L, ((LongValue) values[1]).getValue());
assertEquals(3L, ((LongValue) values[2]).getValue());
values = format.nextRecord(values);
assertNotNull(values);
assertEquals(3L, ((LongValue) values[0]).getValue());
assertEquals(2L, ((LongValue) values[1]).getValue());
assertEquals(1L, ((LongValue) values[2]).getValue());
assertNull(format.nextRecord(values));
assertTrue(format.reachedEnd());
} catch (Exception ex) {
System.err.println(ex.getMessage());
ex.printStackTrace();
fail("Test erroneous");
}
}
Aggregations