public StreamsPlanCreator(Map<String, ISqlStreamsDataSource> sources, RexBuilder rexBuilder) { this.sources = sources; this.rexCompiler = new RexNodeToJavaCodeCompiler(rexBuilder); this.typeFactory = (JavaTypeFactory) rexBuilder.getTypeFactory(); this.streamBuilder = new StreamBuilder(); this.dataContext = new StormDataContext(); }
@Before public void setUp() throws Exception { streamBuilder = new StreamBuilder(); UniqueIdGen.getInstance().reset(); }
@SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { StreamBuilder builder = new StreamBuilder(); Stream<Integer>[] evenAndOdd = builder /* * Create a stream of random numbers from a spout that * emits random integers by extracting the tuple value at index 0. */ .newStream(new RandomIntegerSpout(), new ValueMapper<Integer>(0)) /* * Split the stream of numbers into streams of * even and odd numbers. The first stream contains even * and the second contains odd numbers. */ .branch(x -> (x % 2) == 0, x -> (x % 2) == 1); evenAndOdd[0].forEach(x -> LOG.info("EVEN> " + x)); evenAndOdd[1].forEach(x -> LOG.info("ODD > " + x)); Config config = new Config(); String topoName = "branchExample"; if (args.length > 0) { topoName = args[0]; } config.setNumWorkers(1); StormSubmitter.submitTopologyWithProgressBar(topoName, config, builder.build()); }
public static void main(String[] args) throws Exception { StreamBuilder builder = new StreamBuilder();
public static void main(String[] args) throws Exception { StreamBuilder builder = new StreamBuilder(); // a stream of (number, square) pairs PairStream<Integer, Integer> squares = builder .newStream(new NumberSpout(x -> x * x), new PairValueMapper<>(0, 1)); // a stream of (number, cube) pairs PairStream<Integer, Integer> cubes = builder .newStream(new NumberSpout(x -> x * x * x), new PairValueMapper<>(0, 1)); // create a windowed stream of five seconds duration squares.window(TumblingWindows.of(Duration.seconds(5))) /* * Join the squares and the cubes stream within the window. * The values in the squares stream having the same key as that * of the cubes stream within the window will be joined together. */ .join(cubes) /** * The results should be of the form (number, (square, cube)) */ .print(); Config config = new Config(); String topoName = JoinExample.class.getName(); if (args.length > 0) { topoName = args[0]; } config.setNumWorkers(1); StormSubmitter.submitTopologyWithProgressBar(topoName, config, builder.build()); }
public static void main(String[] args) throws Exception { StreamBuilder builder = new StreamBuilder(); /** * The spout emits sequences of (Integer, Long, Long). TupleValueMapper can be used to extract fields * from the values and produce a stream of typed tuple (Tuple3<Integer, Long, Long> in this case. */ Stream<Tuple3<Integer, Long, Long>> stream = builder.newStream(new RandomIntegerSpout(), TupleValueMappers.of(0, 1, 2)); PairStream<Long, Integer> pairs = stream.mapToPair(t -> Pair.of(t._2 / 10000, t._1)); pairs.window(TumblingWindows.of(Count.of(10))).groupByKey().print(); String topoName = "test"; if (args.length > 0) { topoName = args[0]; } Config config = new Config(); config.setNumWorkers(1); StormSubmitter.submitTopologyWithProgressBar(topoName, config, builder.build()); } }
@SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { StreamBuilder builder = new StreamBuilder(); /** * Computes average of the stream of numbers emitted by the spout. Internally the per-partition * sum and counts are accumulated and emitted to a downstream task where the partially accumulated * results are merged and the final result is emitted. */ builder.newStream(new RandomIntegerSpout(), new ValueMapper<Integer>(0), 2) .window(TumblingWindows.of(BaseWindowedBolt.Duration.seconds(5))) .filter(x -> x > 0 && x < 500) .aggregate(new Avg()) .print(); Config config = new Config(); String topoName = "AGG_EXAMPLE"; if (args.length > 0) { topoName = args[0]; } config.setNumWorkers(1); StormSubmitter.submitTopologyWithProgressBar(topoName, config, builder.build()); }
public static void main(String[] args) throws Exception { StreamBuilder builder = new StreamBuilder();
public static void main(String[] args) throws Exception { StreamBuilder builder = new StreamBuilder(); StreamState<String, Long> ss = builder.newStream(new TestWordSpout(), new ValueMapper<String>(0), 2)
public static void main(String[] args) throws Exception { StreamBuilder builder = new StreamBuilder();
public static void main(String[] args) throws Exception { StreamBuilder builder = new StreamBuilder();
StreamFactory factory = StreamFactory.newInstance(); StreamBuilder builder = new StreamBuilder("") // Your file .format("delimited") .parser(new DelimitedParserBuilder(',')) // Sign to use as a delimiter .addRecord(Yourclass.class); // class to be mapped factory.define(builder);
new StreamBuilder("s1").format("fixedlength").addRecord(MyRecord.class);
@Test public void test(){ StringTypeHandler nullableStringTypeHandler = new StringTypeHandler(); nullableStringTypeHandler.setNullIfEmpty(true); nullableStringTypeHandler.setTrim(true); StreamFactory factory = StreamFactory.newInstance(); factory.define(new StreamBuilder("pojo") .format("fixedlength") .addRecord(Pojo.class) .addTypeHandler(String.class, nullableStringTypeHandler) ); Unmarshaller unmarshaller = factory.createUnmarshaller("pojo"); Pojo pojo = (Pojo) unmarshaller.unmarshal(" "); assertNull(pojo.field); }
public static void main(String[] args) throws IOException { StreamFactory factory = StreamFactory.newInstance(); StreamBuilder builderCSV = new StreamBuilder("Tm") .format("fixedlength") .parser(new FixedLengthParserBuilder()) .addRecord(com.mycompany.bio.Team.class) .addRecord(com.mycompany.bio.Employee.class); factory.define(builderCSV); BeanWriter out = factory.createWriter("Tm", new File("C:\\Users\\topSecretUsername\\Desktop\\tm.txt")); Employee e1 = new Employee("EmpF1", "EmpL1", "Developer", "1", new Date()); Employee e2 = new Employee("EmpF2", "EmpL2", "Developer", "2", new Date()); Team team = new Team(); team.setTeamName("Great Team"); team.getEmployees().add(e1); team.getEmployees().add(e2); out.write(team); for (Employee e : team.getEmployees()) { out.write(e); } out.flush(); out.close(); }