use of org.apache.flink.types.StringValue 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.StringValue in project flink by apache.
the class LongValueToStringValueTest method testTranslation.
@Test
public void testTranslation() throws Exception {
StringValue reuse = new StringValue();
assertEquals(new StringValue("-9223372036854775808"), translator.translate(new LongValue(Long.MIN_VALUE), reuse));
assertEquals(new StringValue("0"), translator.translate(new LongValue(0), reuse));
assertEquals(new StringValue("9223372036854775807"), translator.translate(new LongValue(Long.MAX_VALUE), reuse));
}
use of org.apache.flink.types.StringValue in project flink by apache.
the class TranslateTest method testTranslateGraphIds.
@Test
public void testTranslateGraphIds() throws Exception {
Graph<StringValue, LongValue, LongValue> stringIdGraph = graph.translateGraphIds(new LongValueToStringValue());
for (Vertex<StringValue, LongValue> vertex : stringIdGraph.getVertices().collect()) {
assertEquals(StringValue.class, vertex.f0.getClass());
assertEquals(LongValue.class, vertex.f1.getClass());
}
for (Edge<StringValue, LongValue> edge : stringIdGraph.getEdges().collect()) {
assertEquals(StringValue.class, edge.f0.getClass());
assertEquals(StringValue.class, edge.f1.getClass());
assertEquals(LongValue.class, edge.f2.getClass());
}
TestBaseUtils.compareResultAsText(stringIdGraph.getVertices().collect(), expectedVertexResult);
TestBaseUtils.compareResultAsText(stringIdGraph.getEdges().collect(), expectedEdgeResult);
}
use of org.apache.flink.types.StringValue in project flink by apache.
the class StringValueUtilsTest method testReplaceNonWordChars.
@Test
public void testReplaceNonWordChars() {
StringValue testString = new StringValue("TEST123_@");
StringValueUtils.replaceNonWordChars(testString, '!');
assertEquals(new StringValue("TEST123_!"), testString);
}
use of org.apache.flink.types.StringValue in project flink by apache.
the class StringValueUtilsTest method testTokenizerOnStringWithNexToken.
@Test
public void testTokenizerOnStringWithNexToken() {
StringValue testString = new StringValue("test test");
StringValueUtils.WhitespaceTokenizer tokenizer = new WhitespaceTokenizer();
tokenizer.setStringToTokenize(testString);
assertTrue(tokenizer.next(testString));
}
Aggregations