use of org.apache.flink.types.StringValue in project flink by apache.
the class TypeExtractorTest method testTupleOfValues.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testTupleOfValues() {
// use getMapReturnTypes()
RichMapFunction<?, ?> function = new RichMapFunction<Tuple2<StringValue, IntValue>, Tuple2<StringValue, IntValue>>() {
private static final long serialVersionUID = 1L;
@Override
public Tuple2<StringValue, IntValue> map(Tuple2<StringValue, IntValue> value) throws Exception {
return null;
}
};
TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint<Tuple2<StringValue, IntValue>>() {
}));
Assert.assertFalse(ti.isBasicType());
Assert.assertTrue(ti.isTupleType());
Assert.assertEquals(StringValue.class, ((TupleTypeInfo<?>) ti).getTypeAt(0).getTypeClass());
Assert.assertEquals(IntValue.class, ((TupleTypeInfo<?>) ti).getTypeAt(1).getTypeClass());
// use getForObject()
Tuple2<StringValue, IntValue> t = new Tuple2<StringValue, IntValue>(new StringValue("x"), new IntValue(1));
TypeInformation<?> ti2 = TypeExtractor.getForObject(t);
Assert.assertFalse(ti2.isBasicType());
Assert.assertTrue(ti2.isTupleType());
Assert.assertEquals(((TupleTypeInfo<?>) ti2).getTypeAt(0).getTypeClass(), StringValue.class);
Assert.assertEquals(((TupleTypeInfo<?>) ti2).getTypeAt(1).getTypeClass(), IntValue.class);
}
use of org.apache.flink.types.StringValue in project flink by apache.
the class TypeExtractorTest method testValue.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testValue() {
// use getKeyExtractorType()
KeySelector<?, ?> function = new KeySelector<StringValue, StringValue>() {
private static final long serialVersionUID = 1L;
@Override
public StringValue getKey(StringValue value) {
return null;
}
};
TypeInformation<?> ti = TypeExtractor.getKeySelectorTypes(function, (TypeInformation) TypeInformation.of(new TypeHint<StringValue>() {
}));
Assert.assertFalse(ti.isBasicType());
Assert.assertFalse(ti.isTupleType());
Assert.assertTrue(ti instanceof ValueTypeInfo);
Assert.assertEquals(ti.getTypeClass(), StringValue.class);
// use getForClass()
Assert.assertTrue(TypeExtractor.getForClass(StringValue.class) instanceof ValueTypeInfo);
Assert.assertEquals(TypeExtractor.getForClass(StringValue.class).getTypeClass(), ti.getTypeClass());
// use getForObject()
StringValue v = new StringValue("Hello");
Assert.assertTrue(TypeExtractor.getForObject(v) instanceof ValueTypeInfo);
Assert.assertEquals(TypeExtractor.getForObject(v).getTypeClass(), ti.getTypeClass());
}
use of org.apache.flink.types.StringValue in project flink by apache.
the class StringValueComparator method compareToReference.
@Override
public int compareToReference(TypeComparator<StringValue> referencedComparator) {
StringValue otherRef = ((StringValueComparator) referencedComparator).reference;
int comp = otherRef.compareTo(reference);
return ascendingComparison ? comp : -comp;
}
use of org.apache.flink.types.StringValue in project flink by apache.
the class UnionTranslationTest method translateUnion2Group.
@Test
public void translateUnion2Group() {
try {
final int parallelism = 4;
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment(parallelism);
DataSet<Tuple3<Double, StringValue, LongValue>> dataset1 = getSourceDataSet(env, 3);
DataSet<Tuple3<Double, StringValue, LongValue>> dataset2 = getSourceDataSet(env, 2);
dataset1.union(dataset2).groupBy((KeySelector<Tuple3<Double, StringValue, LongValue>, String>) value -> "").reduceGroup((GroupReduceFunction<Tuple3<Double, StringValue, LongValue>, String>) (values, out) -> {
}).returns(String.class).output(new DiscardingOutputFormat<>());
Plan p = env.createProgramPlan();
// The plan should look like the following one.
//
// DataSet1(3) - MapOperator(3)-+
// |- Union(-1) - SingleInputOperator - Sink
// DataSet2(2) - MapOperator(2)-+
GenericDataSinkBase<?> sink = p.getDataSinks().iterator().next();
Union unionOperator = (Union) ((SingleInputOperator) sink.getInput()).getInput();
// The key mappers should be added to both of the two input streams for union.
assertTrue(unionOperator.getFirstInput() instanceof MapOperatorBase<?, ?, ?>);
assertTrue(unionOperator.getSecondInput() instanceof MapOperatorBase<?, ?, ?>);
// The parallelisms of the key mappers should be equal to those of their inputs.
assertEquals(unionOperator.getFirstInput().getParallelism(), 3);
assertEquals(unionOperator.getSecondInput().getParallelism(), 2);
// The union should always have the default parallelism.
assertEquals(unionOperator.getParallelism(), ExecutionConfig.PARALLELISM_DEFAULT);
} 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 DefaultChannelSelectorTest method channelSelect.
/**
* This test checks the channel selection.
*/
@Test
public void channelSelect() {
final StringValue dummyRecord = new StringValue("abc");
final RoundRobinChannelSelector<StringValue> selector = new RoundRobinChannelSelector<>();
selector.setup(2);
assertSelectedChannel(selector, dummyRecord, 0);
assertSelectedChannel(selector, dummyRecord, 1);
}
Aggregations