11package com .spbsu .flamestream .example .nexmark ;
22
3+ import com .github .nexmark .flink .model .Auction ;
4+ import com .github .nexmark .flink .model .Person ;
35import com .spbsu .flamestream .core .graph .SerializableBiFunction ;
46import com .spbsu .flamestream .core .graph .SerializableFunction ;
57import com .spbsu .flamestream .example .labels .Flow ;
1012import scala .runtime .AbstractFunction1 ;
1113import scala .util .Either ;
1214
15+ import java .time .Instant ;
1316import java .util .ArrayList ;
1417import java .util .Collections ;
1518import java .util .Objects ;
1619import java .util .function .ToLongFunction ;
1720import java .util .stream .Stream ;
1821
1922public class Query8 {
20- public static class Input {
21- private Input () {
22- }
23-
24- public static class Auction extends Input {
25- public final String seller ;
26- public final long dateTime ;
27-
28- public Auction (String seller , long dateTime ) {
29- this .seller = seller ;
30- this .dateTime = dateTime ;
31- }
32- }
33-
34- public static class Person extends Input {
35- public final String id ;
36- public final String name ;
37- public final long dateTime ;
38-
39- public Person (String id , String name , long dateTime ) {
40- this .id = id ;
41- this .name = name ;
42- this .dateTime = dateTime ;
43- }
44- }
45- }
46-
4723 public static final class PersonGroupingKey {
48- public final String id ;
24+ public final long id ;
4925 public final String name ;
5026 public final long startTime ;
5127
52- private PersonGroupingKey (String id , String name , long startTime ) {
28+ private PersonGroupingKey (long id , String name , long startTime ) {
5329 this .id = id ;
5430 this .name = name ;
5531 this .startTime = startTime ;
@@ -79,10 +55,10 @@ public String toString() {
7955 }
8056
8157 private static final class AuctionGroupingKey {
82- public final String seller ;
58+ public final long seller ;
8359 public final long startTime ;
8460
85- private AuctionGroupingKey (String seller , long startTime ) {
61+ private AuctionGroupingKey (long seller , long startTime ) {
8662 this .seller = seller ;
8763 this .startTime = startTime ;
8864 }
@@ -99,7 +75,7 @@ public boolean equals(Object obj) {
9975 }
10076 if (obj instanceof AuctionGroupingKey ) {
10177 final var that = (AuctionGroupingKey ) obj ;
102- return Objects . equals ( seller , that .seller ) && startTime == that .startTime ;
78+ return seller == that .seller && startTime == that .startTime ;
10379 }
10480 return false ;
10581 }
@@ -110,21 +86,21 @@ public String toString() {
11086 }
11187 }
11288
113- public static Flow <Input , PersonGroupingKey > create (long timeWindow ) {
114- final var inputs = new Operator .Input <>(Input .class );
89+ public static Flow <Object , PersonGroupingKey > create () {
90+ final var inputs = new Operator .Input <>(Object .class );
11591 return new Flow <>(inputs , selectJoinOn (
11692 PersonGroupingKey .class ,
11793 (p , a ) -> p ,
11894 selectGroupBy (
11995 PersonGroupingKey .class ,
120- person -> new PersonGroupingKey (person .id , person .name , tumbleStart (person .dateTime , timeWindow )),
121- filterType (inputs , Input . Person .class ),
96+ person -> new PersonGroupingKey (person .id , person .name , tumbleStart (person .dateTime , 10 )),
97+ filterType (inputs , Person .class ),
12298 person -> person .startTime
12399 ),
124100 selectGroupBy (
125101 AuctionGroupingKey .class ,
126- auction -> new AuctionGroupingKey (auction .seller , tumbleStart (auction .dateTime , timeWindow )),
127- filterType (inputs , Input . Auction .class ),
102+ auction -> new AuctionGroupingKey (auction .seller , tumbleStart (auction .dateTime , 10 )),
103+ filterType (inputs , Auction .class ),
128104 auction -> auction .startTime
129105 ),
130106 p -> p .id , a -> a .seller , p -> p .startTime , a -> a .startTime
@@ -237,7 +213,7 @@ public Output apply(Right right) {
237213 );
238214 }
239215
240- private static long tumbleStart (long dateTime , long interval ) {
241- return (dateTime / interval + 1 ) * interval ;
216+ private static long tumbleStart (Instant dateTime , long interval ) {
217+ return (dateTime . getEpochSecond () / interval + 1 ) * interval ;
242218 }
243219}
0 commit comments