org.apache.flink.api.common.typeinfo.TypeHint Java Examples
The following examples show how to use
org.apache.flink.api.common.typeinfo.TypeHint.
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
Source File: QsStateProducer.java From flink with Apache License 2.0 | 7 votes |
@Override public void open(Configuration parameters) { MapStateDescriptor<EmailId, EmailInformation> stateDescriptor = new MapStateDescriptor<>( QsConstants.STATE_NAME, TypeInformation.of(new TypeHint<EmailId>() { }), TypeInformation.of(new TypeHint<EmailInformation>() { }) ); stateDescriptor.setQueryable(QsConstants.QUERY_NAME); state = getRuntimeContext().getMapState(stateDescriptor); count = -1; }
Example #2
Source File: TypeExtractorTest.java From flink with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testSameGenericVariable() {
RichMapFunction<?, ?> function = new RichMapFunction<SameTypeVariable<String>, SameTypeVariable<String>>() {
private static final long serialVersionUID = 1L;
@Override
public SameTypeVariable<String> map(SameTypeVariable<String> value) throws Exception {
return null;
}
};
TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint<Tuple2<String, String>>(){}));
Assert.assertTrue(ti.isTupleType());
Assert.assertEquals(2, ti.getArity());
TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti;
Assert.assertEquals(SameTypeVariable.class, tti.getTypeClass());
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0));
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(1));
}
Example #3
Source File: TypeExtractorTest.java From flink with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGenericsInDirectSuperclass() {
// use TypeExtractor
RichMapFunction<?, ?> function = new RichMapFunction<ChainedThree, ChainedThree>() {
private static final long serialVersionUID = 1L;
@Override
public ChainedThree map(ChainedThree value) throws Exception {
return null;
}
};
TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint<Tuple3<String, Long, String>>(){}));
Assert.assertTrue(ti.isTupleType());
Assert.assertEquals(3, ti.getArity());
TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti;
Assert.assertEquals(ChainedThree.class, tti.getTypeClass());
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0));
Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, tti.getTypeAt(1));
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(2));
}
Example #4
Source File: PojoTypeExtractionTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test
public void testGenericPojoTypeInference1() {
MyMapper<String> function = new MyMapper<>();
TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(
function,
TypeInformation.of(new TypeHint<PojoWithGenerics<Long, String>>(){}));
Assert.assertTrue(ti instanceof PojoTypeInfo<?>);
PojoTypeInfo<?> pti = (PojoTypeInfo<?>) ti;
for(int i = 0; i < pti.getArity(); i++) {
PojoField field = pti.getPojoFieldAt(i);
String name = field.getField().getName();
if(name.equals("field1")) {
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, field.getTypeInformation());
} else if (name.equals("field2")) {
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, field.getTypeInformation());
} else if (name.equals("key")) {
Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, field.getTypeInformation());
} else {
Assert.fail("Unexpected field "+field);
}
}
}
Example #5
Source File: QsStateProducer.java From flink with Apache License 2.0 | 6 votes |
@Override public void open(Configuration parameters) { MapStateDescriptor<EmailId, EmailInformation> stateDescriptor = new MapStateDescriptor<>( QsConstants.STATE_NAME, TypeInformation.of(new TypeHint<EmailId>() { }), TypeInformation.of(new TypeHint<EmailInformation>() { }) ); stateDescriptor.setQueryable(QsConstants.QUERY_NAME); state = getRuntimeContext().getMapState(stateDescriptor); count = -1; }
Example #6
Source File: TypeExtractorTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGenericsNotInSuperclass() {
// use getMapReturnTypes()
RichMapFunction<?, ?> function = new RichMapFunction<LongKeyValue<String>, LongKeyValue<String>>() {
private static final long serialVersionUID = 1L;
@Override
public LongKeyValue<String> map(LongKeyValue<String> value) throws Exception {
return null;
}
};
TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint<Tuple2<Long, String>>(){}));
Assert.assertTrue(ti.isTupleType());
Assert.assertEquals(2, ti.getArity());
TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti;
Assert.assertEquals(LongKeyValue.class, tti.getTypeClass());
Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, tti.getTypeAt(0));
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(1));
}
Example #7
Source File: QsStateProducer.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public void open(Configuration parameters) { MapStateDescriptor<EmailId, EmailInformation> stateDescriptor = new MapStateDescriptor<>( QsConstants.STATE_NAME, TypeInformation.of(new TypeHint<EmailId>() { }), TypeInformation.of(new TypeHint<EmailInformation>() { }) ); stateDescriptor.setQueryable(QsConstants.QUERY_NAME); state = getRuntimeContext().getMapState(stateDescriptor); count = -1; }
Example #8
Source File: TypeExtractorTest.java From flink with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGenericsNotInSuperclassWithNonGenericClassAtEnd() {
// use TypeExtractor
RichMapFunction<?, ?> function = new RichMapFunction<ChainedFour, ChainedFour>() {
private static final long serialVersionUID = 1L;
@Override
public ChainedFour map(ChainedFour value) throws Exception {
return null;
}
};
TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint<Tuple3<String, Long, String>>(){}));
Assert.assertTrue(ti.isTupleType());
Assert.assertEquals(3, ti.getArity());
TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti;
Assert.assertEquals(ChainedFour.class, tti.getTypeClass());
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0));
Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, tti.getTypeAt(1));
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(2));
}
Example #9
Source File: TypeExtractorTest.java From flink with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testTuple0() {
// use getFlatMapReturnTypes()
RichFlatMapFunction<?, ?> function = new RichFlatMapFunction<Tuple0, Tuple0>() {
private static final long serialVersionUID = 1L;
@Override
public void flatMap(Tuple0 value, Collector<Tuple0> out) throws Exception {
// nothing to do
}
};
TypeInformation<?> ti = TypeExtractor.getFlatMapReturnTypes(function,
(TypeInformation) TypeInformation.of(new TypeHint<Tuple0>(){}));
Assert.assertTrue(ti.isTupleType());
Assert.assertEquals(0, ti.getArity());
Assert.assertTrue(ti instanceof TupleTypeInfo);
}
Example #10
Source File: TypeExtractorTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testTupleArray() {
RichMapFunction<?, ?> function = new RichMapFunction<Tuple2<String, String>[], Tuple2<String, String>[]>() {
private static final long serialVersionUID = 1L;
@Override
public Tuple2<String, String>[] map(Tuple2<String, String>[] value) throws Exception {
return null;
}
};
TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint<Tuple2<String, String>[]>(){}));
Assert.assertTrue(ti instanceof ObjectArrayTypeInfo<?, ?>);
ObjectArrayTypeInfo<?, ?> oati = (ObjectArrayTypeInfo<?, ?>) ti;
Assert.assertTrue(oati.getComponentInfo().isTupleType());
TupleTypeInfo<?> tti = (TupleTypeInfo<?>) oati.getComponentInfo();
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0));
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(1));
}
Example #11
Source File: TypeExtractorTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testInputInferenceWithCustomTupleAndRichFunction() { JoinFunction<CustomTuple2WithArray<Long>, CustomTuple2WithArray<Long>, CustomTuple2WithArray<Long>> function = new JoinWithCustomTuple2WithArray<>(); TypeInformation<?> ti = TypeExtractor.getJoinReturnTypes( function, new TypeHint<CustomTuple2WithArray<Long>>(){}.getTypeInfo(), new TypeHint<CustomTuple2WithArray<Long>>(){}.getTypeInfo()); Assert.assertTrue(ti.isTupleType()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, tti.getTypeAt(1)); Assert.assertTrue(tti.getTypeAt(0) instanceof ObjectArrayTypeInfo<?, ?>); ObjectArrayTypeInfo<?, ?> oati = (ObjectArrayTypeInfo<?, ?>) tti.getTypeAt(0); Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, oati.getComponentInfo()); }
Example #12
Source File: CommunityDetectionTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testWithRMatGraph() throws Exception { Graph<LongValue, Long, Double> result = undirectedRMatGraph(8, 4) .mapVertices(v -> v.getId().getValue(), new TypeHint<Vertex<LongValue, Long>>(){}.getTypeInfo()) .mapEdges(e -> (double) e.getTarget().getValue() - e.getSource().getValue(), new TypeHint<Edge<LongValue, Double>>(){}.getTypeInfo()) .run(new CommunityDetection<>(10, 0.5)); Checksum checksum = new ChecksumHashCode<Vertex<LongValue, Long>>() .run(result.getVertices()) .execute(); assertEquals(184, checksum.getCount()); assertEquals(0x00000000000cdc96L, checksum.getChecksum()); }
Example #13
Source File: CommunityDetectionTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testWithSimpleGraph() throws Exception { Graph<IntValue, Long, Double> result = undirectedSimpleGraph .mapVertices(v -> (long) v.getId().getValue(), new TypeHint<Vertex<IntValue, Long>>(){}.getTypeInfo()) .mapEdges(e -> (double) e.getTarget().getValue() + e.getSource().getValue(), new TypeHint<Edge<IntValue, Double>>(){}.getTypeInfo()) .run(new CommunityDetection<>(10, 0.5)); String expectedResult = "(0,3)\n" + "(1,5)\n" + "(2,5)\n" + "(3,3)\n" + "(4,5)\n" + "(5,5)\n"; TestBaseUtils.compareResultAsText(result.getVertices().collect(), expectedResult); }
Example #14
Source File: TypeExtractorTest.java From flink with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testTypeErasure() { TypeInformation<?> ti = TypeExtractor.getFlatMapReturnTypes(new DummyFlatMapFunction<String, Integer, String, Boolean>(), (TypeInformation) TypeInformation.of(new TypeHint<Tuple2<String, Integer>>(){}), "name", true); Assert.assertTrue(ti instanceof MissingTypeInfo); try { TypeExtractor.getFlatMapReturnTypes(new DummyFlatMapFunction<String, Integer, String, Boolean>(), (TypeInformation) TypeInformation.of(new TypeHint<Tuple2<String, Integer>>(){})); Assert.fail("Expected an exception"); } catch (InvalidTypesException e) { // expected } }
Example #15
Source File: TypeExtractorTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testFunctionDependingPartialOnInput() {
RichMapFunction<?, ?> function = new OneAppender<DoubleValue>() {
private static final long serialVersionUID = 1L;
};
TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint<DoubleValue>(){}));
Assert.assertTrue(ti.isTupleType());
Assert.assertEquals(2, ti.getArity());
TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti;
Assert.assertTrue(tti.getTypeAt(0) instanceof ValueTypeInfo<?>);
ValueTypeInfo<?> vti = (ValueTypeInfo<?>) tti.getTypeAt(0);
Assert.assertEquals(DoubleValue.class, vti.getTypeClass());
Assert.assertTrue(tti.getTypeAt(1).isBasicType());
Assert.assertEquals(Integer.class , tti.getTypeAt(1).getTypeClass());
}
Example #16
Source File: KeyedStateDeduplication.java From flink-learning with Apache License 2.0 | 6 votes |
@Override
public void open(Configuration parameters) throws Exception {
super.open(parameters);
ValueStateDescriptor<Boolean> keyedStateDuplicated =
new ValueStateDescriptor<>("KeyedStateDeduplication",
TypeInformation.of(new TypeHint<Boolean>() {}));
// 状态 TTL 相关配置,过期时间设定为 36 小时
StateTtlConfig ttlConfig = StateTtlConfig
.newBuilder(Time.hours(36))
.setUpdateType(StateTtlConfig.UpdateType.OnCreateAndWrite)
.setStateVisibility(
StateTtlConfig.StateVisibility.NeverReturnExpired)
.cleanupInRocksdbCompactFilter(50000000L)
.build();
// 开启 TTL
keyedStateDuplicated.enableTimeToLive(ttlConfig);
// 从状态后端恢复状态
isExist = getRuntimeContext().getState(keyedStateDuplicated);
}
Example #17
Source File: TypeExtractorTest.java From flink with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testChainedGenericsNotInSuperclass() {
// use TypeExtractor
RichMapFunction<?, ?> function = new RichMapFunction<ChainedTwo<Integer>, ChainedTwo<Integer>>() {
private static final long serialVersionUID = 1L;
@Override
public ChainedTwo<Integer> map(ChainedTwo<Integer> value) throws Exception {
return null;
}
};
TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint<Tuple3<String, Long, Integer>>(){}));
Assert.assertTrue(ti.isTupleType());
Assert.assertEquals(3, ti.getArity());
TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti;
Assert.assertEquals(ChainedTwo.class, tti.getTypeClass());
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0));
Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, tti.getTypeAt(1));
Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, tti.getTypeAt(2));
}
Example #18
Source File: TypeExtractorTest.java From flink with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testTupleArray() {
RichMapFunction<?, ?> function = new RichMapFunction<Tuple2<String, String>[], Tuple2<String, String>[]>() {
private static final long serialVersionUID = 1L;
@Override
public Tuple2<String, String>[] map(Tuple2<String, String>[] value) throws Exception {
return null;
}
};
TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint<Tuple2<String, String>[]>(){}));
Assert.assertTrue(ti instanceof ObjectArrayTypeInfo<?, ?>);
ObjectArrayTypeInfo<?, ?> oati = (ObjectArrayTypeInfo<?, ?>) ti;
Assert.assertTrue(oati.getComponentInfo().isTupleType());
TupleTypeInfo<?> tti = (TupleTypeInfo<?>) oati.getComponentInfo();
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0));
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(1));
}
Example #19
Source File: EmptyGraph.java From flink with Apache License 2.0 | 6 votes |
@Override
public Graph<LongValue, NullValue, NullValue> generate() {
Preconditions.checkState(vertexCount >= 0);
// Vertices
DataSet<Vertex<LongValue, NullValue>> vertices = GraphGeneratorUtils.vertexSequence(env, parallelism, vertexCount);
// Edges
DataSource<Edge<LongValue, NullValue>> edges = env
.fromCollection(Collections.<Edge<LongValue, NullValue>>emptyList(), TypeInformation.of(new TypeHint<Edge<LongValue, NullValue>>(){}))
.setParallelism(parallelism)
.name("Empty edge set");
// Graph
return Graph.fromDataSet(vertices, edges, env);
}
Example #20
Source File: TypeExtractorTest.java From flink with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testInputInference4() {
EdgeMapper4<Boolean, String> em = new EdgeMapper4<Boolean, String>();
TypeInformation<?> ti = TypeExtractor.getMapReturnTypes((MapFunction) em, TypeInformation.of(new TypeHint<Tuple3<Boolean,Boolean,String>[]>(){}));
Assert.assertTrue(ti.isBasicType());
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, ti);
}
Example #21
Source File: TypeExtractorTest.java From flink with Apache License 2.0 | 5 votes |
@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());
}
Example #22
Source File: QueryableStateClient.java From flink with Apache License 2.0 | 5 votes |
/** * Returns a future holding the request result. * @param jobId JobID of the job the queryable state belongs to. * @param queryableStateName Name under which the state is queryable. * @param key The key we are interested in. * @param keyTypeHint A {@link TypeHint} used to extract the type of the key. * @param stateDescriptor The {@link StateDescriptor} of the state we want to query. * @return Future holding the immutable {@link State} object containing the result. */ @PublicEvolving public <K, S extends State, V> CompletableFuture<S> getKvState( final JobID jobId, final String queryableStateName, final K key, final TypeHint<K> keyTypeHint, final StateDescriptor<S, V> stateDescriptor) { Preconditions.checkNotNull(keyTypeHint); TypeInformation<K> keyTypeInfo = keyTypeHint.getTypeInfo(); return getKvState(jobId, queryableStateName, key, keyTypeInfo, stateDescriptor); }
Example #23
Source File: OutageProcessFunction.java From flink-learning with Apache License 2.0 | 5 votes |
@Override public void open(Configuration parameters) throws Exception { TypeInformation<OutageMetricEvent> outageInfo = TypeInformation.of(new TypeHint<OutageMetricEvent>() { }); TypeInformation<Boolean> recoverInfo = TypeInformation.of(new TypeHint<Boolean>() { }); outageMetricState = getRuntimeContext().getState(new ValueStateDescriptor<>("outage_zhisheng", outageInfo)); recover = getRuntimeContext().getState(new ValueStateDescriptor<>("recover_zhisheng", recoverInfo)); }
Example #24
Source File: TypeExtractorTest.java From flink with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testFunctionDependingOnInputWithCustomTupleInput() {
IdentityMapper<SameTypeVariable<String>> function = new IdentityMapper<SameTypeVariable<String>>();
TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint<Tuple2<String, String>>(){}));
Assert.assertTrue(ti.isTupleType());
Assert.assertEquals(2, ti.getArity());
TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti;
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0));
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(1));
}
Example #25
Source File: CoGroupOperatorCollectionTest.java From flink with Apache License 2.0 | 5 votes |
private CoGroupOperatorBase<Tuple2<String, Integer>, Tuple2<String, Integer>,
Tuple2<String, Integer>, CoGroupFunction<Tuple2<String, Integer>, Tuple2<String, Integer>,
Tuple2<String, Integer>>> getCoGroupOperator(
RichCoGroupFunction<Tuple2<String, Integer>, Tuple2<String, Integer>, Tuple2<String, Integer>> udf) {
TypeInformation<Tuple2<String, Integer>> tuple2Info = TypeInformation.of(new TypeHint<Tuple2<String, Integer>>(){});
return new CoGroupOperatorBase<>(
udf,
new BinaryOperatorInformation<>(tuple2Info, tuple2Info, tuple2Info),
new int[]{0},
new int[]{0},
"coGroup on Collections"
);
}
Example #26
Source File: UdfAnalyzerTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testForwardWithBranchingReduce() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(ReduceFunction.class, Reduce2.class, TypeInformation.of(new TypeHint<MyPojo>(){}), TypeInformation.of(new TypeHint<MyPojo>(){}), new String[] { "field" }); }
Example #27
Source File: PojoTypeExtractionTest.java From flink with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGenericPojoTypeInference2() {
MyMapper2<Boolean, Character> function = new MyMapper2<>();
TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(
function,
TypeInformation.of(new TypeHint<Tuple2<Character,Boolean>>(){}));
Assert.assertTrue(ti instanceof PojoTypeInfo<?>);
PojoTypeInfo<?> pti = (PojoTypeInfo<?>) ti;
for(int i = 0; i < pti.getArity(); i++) {
PojoField field = pti.getPojoFieldAt(i);
String name = field.getField().getName();
if(name.equals("extraField")) {
Assert.assertEquals(BasicTypeInfo.CHAR_TYPE_INFO, field.getTypeInformation());
} else if (name.equals("f0")) {
Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, field.getTypeInformation());
} else if (name.equals("f1")) {
Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, field.getTypeInformation());
} else if (name.equals("f2")) {
Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, field.getTypeInformation());
} else {
Assert.fail("Unexpected field "+field);
}
}
}
Example #28
Source File: TypeExtractorTest.java From flink with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testCustomArrayWithTypeVariable() {
RichMapFunction<CustomArrayObject2<Boolean>[], ?> function = new IdentityMapper<CustomArrayObject2<Boolean>[]>();
TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint<Tuple1<Boolean>[]>(){}));
Assert.assertTrue(ti instanceof ObjectArrayTypeInfo<?, ?>);
ObjectArrayTypeInfo<?, ?> oati = (ObjectArrayTypeInfo<?, ?>) ti;
Assert.assertTrue(oati.getComponentInfo().isTupleType());
TupleTypeInfo<?> tti = (TupleTypeInfo<?>) oati.getComponentInfo();
Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, tti.getTypeAt(0));
}
Example #29
Source File: TypeExtractorTest.java From flink with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testInputInference3() {
EdgeMapper3<Boolean, String> em = new EdgeMapper3<Boolean, String>();
TypeInformation<?> ti = TypeExtractor.getMapReturnTypes((MapFunction) em, TypeInformation.of(new TypeHint<Tuple3<Boolean,Boolean,String>>(){}));
Assert.assertTrue(ti.isBasicType());
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, ti);
}
Example #30
Source File: SequenceStreamingFileSinkITCase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test
public void testWriteSequenceFile() throws Exception {
final File folder = TEMPORARY_FOLDER.newFolder();
final Path testPath = Path.fromLocalFile(folder);
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(1);
env.enableCheckpointing(100);
DataStream<Tuple2<Long, String>> stream = env.addSource(
new FiniteTestSource<>(testData),
TypeInformation.of(new TypeHint<Tuple2<Long, String>>() {
})
);
stream.map(new MapFunction<Tuple2<Long, String>, Tuple2<LongWritable, Text>>() {
@Override
public Tuple2<LongWritable, Text> map(Tuple2<Long, String> value) throws Exception {
return new Tuple2<>(new LongWritable(value.f0), new Text(value.f1));
}
}).addSink(
StreamingFileSink.forBulkFormat(
testPath,
new SequenceFileWriterFactory<>(configuration, LongWritable.class, Text.class, "BZip2")
).build());
env.execute();
validateResults(folder, testData);
}