flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mjsax <...@git.apache.org>
Subject [GitHub] flink pull request: [FLINK-2457] Integrate Tuple0
Date Tue, 04 Aug 2015 13:19:06 GMT
Github user mjsax commented on the pull request:

    https://github.com/apache/flink/pull/983#issuecomment-127605738
  
    I used different dop for source/consumer and double check that multiple TMs are involved
to make sure data is really going over the network...
    
    Batch example:
    ```
    public class TestEmptyTupleBatch {
    
    	public static void main(String[] args) throws Exception {
    		final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    
    		DataSource<Tuple0> input = env.fromElements(
    				new Tuple0(), new Tuple0(), new Tuple0(), new Tuple0(), new Tuple0(),
    				new Tuple0(), new Tuple0(), new Tuple0(), new Tuple0(), new Tuple0(),
    				new Tuple0(), new Tuple0(), new Tuple0(), new Tuple0(), new Tuple0(),
    				new Tuple0(), new Tuple0(), new Tuple0(), new Tuple0(), new Tuple0());
    
    		input.map(new Counter()).setParallelism(4).print();
    	}
    
    	public static class Counter implements MapFunction<Tuple0, Integer> {
    		private static final long serialVersionUID = 5518823010274195186L;
    
    		int counter = 0;
    		@Override
    		public Integer map(Tuple0 value) throws Exception {
    			System.out.println("mjsax: " + (++counter) + " " + value.getField(0));
    			return new Integer(value.getArity());
    		}
    	}
    }
    ```
    
    Streaming Example:
    ```
    public class TestEmptyTuple {
    
    	public static void main(String[] args) throws Exception {
    		final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    
    		DataStream<Tuple0> input = env.addSource(new Empty()).setParallelism(4);
    		input.shuffle().transform("verify", null, new Counter()).setParallelism(1);
    
    		env.execute();
    	}
    
    	public static class Empty implements ParallelSourceFunction<Tuple0> {
    		private static final long serialVersionUID = 1350902748274781033L;
    		private volatile boolean isRunning = true;
    
    		@Override
    		public void run(org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext<Tuple0>
ctx)
    						throws Exception {
    			while (this.isRunning) {
    				Thread.sleep(1000);
    				ctx.collect(new Tuple0());
    			}
    		}
    
    		@Override
    		public void cancel() {
    			this.isRunning = false;
    		}
    	}
    
    	public static class Counter implements OneInputStreamOperator<Tuple0,Object> {
    		private static final long serialVersionUID = 5518823010274195186L;
    
    		private int counter = 0;
    		@Override
    		public void processElement(StreamRecord<Tuple0> element) throws Exception {
    			System.out.println("Tuple0: " + (++counter));
    		}
    
    		// 
    	}
    
    }
    ```
    



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message