Java Code Examples for org.apache.flink.api.common.typeinfo.TypeHint
The following examples show how to use
org.apache.flink.api.common.typeinfo.TypeHint. These examples are extracted from open source projects.
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 Project: flink Source File: QsStateProducer.java License: 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 Project: Flink-CEPplus Source File: TypeExtractorTest.java License: 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 3
Source Project: flink Source File: TypeExtractorTest.java License: 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 Project: Flink-CEPplus Source File: PojoTypeExtractionTest.java License: 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 Project: flink Source File: QsStateProducer.java License: 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 Project: flink Source File: TypeExtractorTest.java License: 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 7
Source Project: Flink-CEPplus Source File: QsStateProducer.java License: 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 Project: flink Source File: TypeExtractorTest.java License: 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 Project: flink Source File: TypeExtractorTest.java License: 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 Project: Flink-CEPplus Source File: TypeExtractorTest.java License: 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 Project: flink Source File: TypeExtractorTest.java License: 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 12
Source Project: flink Source File: TypeExtractorTest.java License: 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 13
Source Project: flink Source File: CommunityDetectionTest.java License: 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 14
Source Project: Flink-CEPplus Source File: CommunityDetectionTest.java License: 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 15
Source Project: flink Source File: TypeExtractorTest.java License: 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 16
Source Project: Flink-CEPplus Source File: TypeExtractorTest.java License: 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 17
Source Project: flink-learning Source File: KeyedStateDeduplication.java License: 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 18
Source Project: flink Source File: EmptyGraph.java License: 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 19
Source Project: flink Source File: TypeExtractorTest.java License: 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 20
Source Project: flink Source File: LambdaExtractionTest.java License: Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") @Test public void testLambdaTypeErasure() { MapFunction<Tuple1<Integer>, Tuple1> f = (i) -> null; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(f, new TypeHint<Tuple1<Integer>>(){}.getTypeInfo(), null, true); assertTrue(ti instanceof MissingTypeInfo); }
Example 21
Source Project: flink Source File: TypeExtractorTest.java License: 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 Project: Flink-CEPplus Source File: JavaTableEnvironmentITCase.java License: Apache License 2.0 | 5 votes |
@Test public void testFromNonAtomicAndNonComposite() throws Exception { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); BatchTableEnvironment tableEnv = BatchTableEnvironment.create(env, config()); List<Either<String, Integer>> data = new ArrayList<>(); data.add(new Either.Left<>("Hello")); data.add(new Either.Right<>(42)); data.add(new Either.Left<>("World")); Table table = tableEnv .fromDataSet( env.fromCollection( data, TypeInformation.of(new TypeHint<Either<String, Integer>>() { }) ), "either") .select("either"); DataSet<Row> ds = tableEnv.toDataSet(table, Row.class); List<Row> results = ds.collect(); String expected = "Left(Hello)\n" + "Left(World)\n" + "Right(42)\n"; compareResultAsText(results, expected); }
Example 23
Source Project: Flink-CEPplus Source File: SequenceStreamingFileSinkITCase.java License: 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); }
Example 24
Source Project: Flink-CEPplus Source File: UdfAnalyzerExamplesTest.java License: Apache License 2.0 | 5 votes |
@Test public void testEnumTrianglesBasicExamplesTriadBuilder() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(GroupReduceFunction.class, TriadBuilder.class, TypeInformation.of(new TypeHint<Tuple2<Integer, Integer>>(){}), TypeInformation.of(new TypeHint<Tuple3<Integer, Integer, Integer>>(){}), new String[] { "0" }); }
Example 25
Source Project: bravo Source File: RocksDBCheckpointReadingTest.java License: Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void validateCheckpointedStateReading() throws IOException, Exception { ExecutionEnvironment environment = ExecutionEnvironment.createLocalEnvironment(); Savepoint savepoint = getLastCheckpoint(); OperatorStateReader reader = new OperatorStateReader(environment, savepoint, "hello"); DataSet<Tuple2<Integer, Integer>> countState = reader.readKeyedStates( KeyedStateReader.forValueStateKVPairs("Count", new TypeHint<Tuple2<Integer, Integer>>() {})); assertEquals(Sets.newHashSet(Tuple2.of(1, 2), Tuple2.of(2, 1)), new HashSet<>(countState.collect())); }
Example 26
Source Project: flink-connectors Source File: EventTimeOrderingOperatorTest.java License: Apache License 2.0 | 5 votes |
@Before public void before() throws Exception { operator = new EventTimeOrderingOperator<>(); operator.setInputType(TypeInformation.of(new TypeHint<Tuple2<String, Long>>() { }), new ExecutionConfig()); testHarness = new KeyedOneInputStreamOperatorTestHarness<>( operator, in -> in.f0, TypeInformation.of(String.class)); testHarness.setTimeCharacteristic(TimeCharacteristic.EventTime); testHarness.open(); }
Example 27
Source Project: flink Source File: TypeExtractorTest.java License: Apache License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testNestedTupleGenerics() { RichMapFunction<?, ?> function = new RichMapFunction<Nested<String, Integer>, Nested<String, Integer>>() { private static final long serialVersionUID = 1L; @Override public Nested<String, Integer> map(Nested<String, Integer> value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint<Tuple2<String, Tuple2<Integer, Integer>>>(){})); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(Nested.class, tti.getTypeClass()); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0)); Assert.assertTrue(tti.getTypeAt(1).isTupleType()); Assert.assertEquals(2, tti.getTypeAt(1).getArity()); // Nested TupleTypeInfo<?> tti2 = (TupleTypeInfo<?>) tti.getTypeAt(1); Assert.assertEquals(Tuple2.class, tti2.getTypeClass()); Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, tti2.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, tti2.getTypeAt(1)); }
Example 28
Source Project: flink Source File: TypeExtractorTest.java License: Apache License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testInputInference1() { EdgeMapper<String, Double> em = new EdgeMapper<String, Double>(); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes((MapFunction) em, TypeInformation.of(new TypeHint<Tuple3<String, String, Double>>(){})); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(3, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(1)); Assert.assertEquals(BasicTypeInfo.DOUBLE_TYPE_INFO, tti.getTypeAt(2)); }
Example 29
Source Project: Flink-CEPplus Source File: UdfAnalyzerExamplesTest.java License: Apache License 2.0 | 5 votes |
@Test public void testLogisticRegressionExamplesSumGradient() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(ReduceFunction.class, SumGradient.class, TypeInformation.of(new TypeHint<Tuple1<Double>>(){}), TypeInformation.of(new TypeHint<Tuple1<Double>>(){}), new String[] { "0" }); }
Example 30
Source Project: Flink-CEPplus Source File: UdfAnalyzerExamplesTest.java License: Apache License 2.0 | 5 votes |
@Test public void testCanopyExamplesDocumentReducer() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(GroupReduceFunction.class, DocumentReducer.class, TypeInformation.of(new TypeHint<Tuple2<Integer, String>>(){}), TypeInformation.of(new TypeHint<Tuple5<Integer, Boolean, Boolean, String, String>>(){}), new String[] { "0" }); }