/** * Shallow tuple copy. * @return A new Tuple with the same fields as this. */ @Override @SuppressWarnings("unchecked") public Tuple4<T0, T1, T2, T3> copy() { return new Tuple4<>(this.f0, this.f1, this.f2, this.f3); }
@Override public Tuple4<Integer, Long, Integer, String> map(Tuple3<Integer, Long, String> value) throws IOException { // update counter Integer counterValue = counter.value(); if (counterValue == null) { counterValue = 0; } counter.update(counterValue + 1); // save last value Long lastValue = last.value(); if (lastValue == null) { lastValue = initialValue; } last.update(value.f1); return Tuple4.of(value.f0, value.f1 - lastValue, counterValue, value.f2); } }
@Override public Tuple4<Integer, Integer, Integer, Integer> map(Tuple4<Integer, Integer, Integer, Integer> value) throws Exception { Tuple4<Integer, Integer, Integer, Integer> t = new Tuple4<Integer, Integer, Integer, Integer>(); t.f0 = value.getField(0); t.f1 = value.getField((int) 1L); return t; } }
/** * Creates a new tuple and assigns the given values to the tuple's fields. * This is more convenient than using the constructor, because the compiler can * infer the generic type arguments implicitly. For example: * {@code Tuple3.of(n, x, s)} * instead of * {@code new Tuple3<Integer, Double, String>(n, x, s)} */ public static <T0, T1, T2, T3> Tuple4<T0, T1, T2, T3> of(T0 value0, T1 value1, T2 value2, T3 value3) { return new Tuple4<>(value0, value1, value2, value3); } }
.map(x -> Tuple4.of("0-0", 0L, 1, x.f0)) .returns(Types.TUPLE(Types.STRING, Types.LONG, Types.INT, Types.STRING))
public Tuple4Builder<T0, T1, T2, T3> add(T0 value0, T1 value1, T2 value2, T3 value3){ tuples.add(new Tuple4<>(value0, value1, value2, value3)); return this; }
@Override public void run(SourceContext<Tuple4<Integer, String, Double, Long>> ctx) throws Exception { while (isRunning) { long timestamp = initialTimestamp + 1000 * number.get(); ctx.collectWithTimestamp(Tuple4.of(number.get(), "test_tuple", random.nextDouble(), timestamp), timestamp); if (number.incrementAndGet() >= this.count) { cancel(); } } }
@Override public Tuple4<Integer, Integer, Double, Long> map(String record) { String rawData = record.substring(1, record.length() - 1); String[] data = rawData.split(","); return new Tuple4<>(Integer.valueOf(data[0]), Integer.valueOf(data[1]), Double.valueOf(data[2]), Long.valueOf(data[3])); } }
Tuple4.of(restoreStateMetaInfoSnapshot.getKeySerializer(), UnloadableDummyTypeSerializer.class, restoreStateMetaInfoSnapshot.getKeySerializerConfigSnapshot(), newKeySerializer), Tuple4.of(restoreStateMetaInfoSnapshot.getValueSerializer(), UnloadableDummyTypeSerializer.class, restoreStateMetaInfoSnapshot.getValueSerializerConfigSnapshot(), newValueSerializer), Tuple4.of(restoreStateMetaInfoSnapshot.getNamespaceSerializer(), null, restoreStateMetaInfoSnapshot.getNamespaceSerializerConfigSnapshot(),
@Override public void run(SourceContext<Tuple4<Integer, Integer, Double, Long>> ctx) throws Exception { while (isRunning) { Thread.sleep(100); for (int carId = 0; carId < speeds.length; carId++) { if (rand.nextBoolean()) { speeds[carId] = Math.min(100, speeds[carId] + 5); } else { speeds[carId] = Math.max(0, speeds[carId] - 5); } distances[carId] += speeds[carId] / 3.6d; Tuple4<Integer, Integer, Double, Long> record = new Tuple4<>(carId, speeds[carId], distances[carId], System.currentTimeMillis()); ctx.collect(record); } } }
public static RegisteredStateMetaInfo resolveStateCompatibility( StateMetaInfoSnapshot restoreStateMetaInfoSnapshot, KeyedStateDescriptor newKeyedStateDescriptor) throws StateMigrationException { if (!VoidNamespaceSerializer.INSTANCE.equals(restoreStateMetaInfoSnapshot.getNamespaceSerializer())) { throw new IllegalStateException("Expected Keyed state's meta info snapshot."); } Preconditions.checkState( Objects.equals(newKeyedStateDescriptor.getName(), restoreStateMetaInfoSnapshot.getName()), "Incompatible state names. " + "Was [" + restoreStateMetaInfoSnapshot.getName() + "], " + "registered with [" + newKeyedStateDescriptor.getName() + "]."); TypeSerializer newKeySerializer = newKeyedStateDescriptor.getKeySerializer(); TypeSerializer newValueSerializer = newKeyedStateDescriptor.getValueSerializer(); checkRequireMigration(Arrays.asList( Tuple4.of(restoreStateMetaInfoSnapshot.getKeySerializer(), UnloadableDummyTypeSerializer.class, restoreStateMetaInfoSnapshot.getKeySerializerConfigSnapshot(), newKeySerializer), Tuple4.of(restoreStateMetaInfoSnapshot.getValueSerializer(), UnloadableDummyTypeSerializer.class, restoreStateMetaInfoSnapshot.getValueSerializerConfigSnapshot(), newValueSerializer))); return new RegisteredStateMetaInfo( newKeyedStateDescriptor.getStateType(), newKeyedStateDescriptor.getName(), newKeySerializer, newValueSerializer); }
return new Tuple4<>( normalizedKeyLengths, numLeadingNormalizableKeys, if (normalizableKeyPrefixLen < 0) { return new Tuple4<>( normalizedKeyLengths, numLeadingNormalizableKeys, return new Tuple4<>( normalizedKeyLengths, numLeadingNormalizableKeys, return new Tuple4<>( normalizedKeyLengths, numLeadingNormalizableKeys,
@Override public void join(Vertex<K, VV> vertex, Edge<K, EV> edge, Collector<Tuple4<K, K, VV, EV>> collector) throws Exception { collector.collect(new Tuple4<>(edge.getSource(), edge.getTarget(), vertex.getValue(), edge.getValue())); } }
@Override public void invoke( T value, Context context) throws Exception { Long timestamp = context.timestamp(); if (timestamp != null) { data.add( new Tuple4<>( context.currentWatermark(), context.currentProcessingTime(), context.timestamp(), value)); } else { data.add( new Tuple4<>( context.currentWatermark(), context.currentProcessingTime(), null, value)); } } }
@Ignore @Test public void testAsFromTupleToPojo() throws Exception { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config()); List<Tuple4<String, Integer, Double, String>> data = new ArrayList<>(); data.add(new Tuple4<>("Rofl", 1, 1.0, "Hi")); data.add(new Tuple4<>("lol", 2, 1.0, "Hi")); data.add(new Tuple4<>("Test me", 4, 3.33, "Hello world")); Table table = tableEnv .fromDataSet(env.fromCollection(data), "q, w, e, r") .select("q as a, w as b, e as c, r as d"); DataSet<SmallPojo2> ds = tableEnv.toDataSet(table, SmallPojo2.class); List<SmallPojo2> results = ds.collect(); String expected = "Rofl,1,1.0,Hi\n" + "lol,2,1.0,Hi\n" + "Test me,4,3.33,Hello world\n"; compareResultAsText(results, expected); }
@Override public void apply( TimeWindow window, Iterable<Tuple2<Long, IntType>> input, Collector<Tuple4<Long, Long, Long, IntType>> out) { // validate that the function has been opened properly assertTrue(open); for (Tuple2<Long, IntType> in: input) { out.collect(new Tuple4<>(in.f0, window.getStart(), window.getEnd(), in.f1)); } } })
@Override public void apply( TimeWindow window, Iterable<Tuple4<Long, Long, Long, IntType>> input, Collector<Tuple4<Long, Long, Long, IntType>> out) { // validate that the function has been opened properly assertTrue(open); for (Tuple4<Long, Long, Long, IntType> in: input) { out.collect(new Tuple4<>(in.f0, window.getStart(), window.getEnd(), in.f3)); } } })
@Override public void apply( TimeWindow window, Iterable<Tuple2<Long, IntType>> input, Collector<Tuple4<Long, Long, Long, IntType>> out) { // validate that the function has been opened properly assertTrue(open); for (Tuple2<Long, IntType> in: input) { out.collect(new Tuple4<>(in.f0, window.getStart(), window.getEnd(), in.f1)); } } })
@Override public void apply( Tuple tuple, TimeWindow window, Iterable<Tuple2<Long, IntType>> input, Collector<Tuple4<Long, Long, Long, IntType>> out) { // validate that the function has been opened properly assertTrue(open); for (Tuple2<Long, IntType> in: input) { out.collect(new Tuple4<>(in.f0, window.getStart(), window.getEnd(), in.f1)); } } })
@Override public void apply( Tuple tuple, TimeWindow window, Iterable<Tuple2<Long, IntType>> input, Collector<Tuple4<Long, Long, Long, IntType>> out) { // validate that the function has been opened properly assertTrue(open); for (Tuple2<Long, IntType> in: input) { final Tuple4<Long, Long, Long, IntType> output = new Tuple4<>(in.f0, window.getStart(), window.getEnd(), in.f1); out.collect(output); } } })