-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mateusz #1
Open
mateum97
wants to merge
21
commits into
main
Choose a base branch
from
mateusz
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mateusz #1
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e0dfd6f
Update README.md
arianeziehn 0fc477f
init
mateum97 60f1aa5
Merge branch 'master' of https://github.com/arianeziehn/CEP2ASP into …
mateum97 ee67755
Merge branch 'main' of https://github.com/arianeziehn/CEP2ASP into ma…
mateum97 e57ffdb
pulling changes from main
mateum97 597ec4e
Merge branch 'main' of https://github.com/arianeziehn/CEP2ASP into ma…
mateum97 2a59b9f
Merge branch 'main' of https://github.com/arianeziehn/CEP2ASP into ma…
mateum97 7c0075f
coding assignment done
mateum97 0a53371
thank you git very nice
mateum97 c01528f
added Q8 and Q9 logger,hashset,intervaljoin
mateum97 41085ec
Q5IJ
mateum97 2c0b6d0
Merge branch 'main' of https://github.com/arianeziehn/CEP2ASP into ma…
mateum97 5ec64e2
commits from main
mateum97 c07bfd3
wrong package small fix
mateum97 c2baf94
removed target
mateum97 a13bcbc
updated gitignore
mateum97 276fbff
added lower/upper bound exclusive and changed key assignment
mateum97 f7843f0
Merge branch 'main' of https://github.com/arianeziehn/CEP2ASP into ma…
mateum97 210156e
Merge branch 'main' of https://github.com/arianeziehn/CEP2ASP into ma…
mateum97 a137d15
1v3 input files seqlength 8 10 12 experiment
mateum97 436456e
q6iterquery length 12
mateum97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import org.apache.flink.api.common.JobExecutionResult; | ||
import org.apache.flink.api.common.functions.FlatJoinFunction; | ||
import org.apache.flink.api.java.tuple.*; | ||
import org.apache.flink.api.java.utils.ParameterTool; | ||
import org.apache.flink.core.fs.FileSystem; | ||
import org.apache.flink.streaming.api.TimeCharacteristic; | ||
import org.apache.flink.streaming.api.datastream.DataStream; | ||
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; | ||
import org.apache.flink.streaming.api.windowing.assigners.SlidingEventTimeWindows; | ||
import org.apache.flink.streaming.api.windowing.time.Time; | ||
import org.apache.flink.util.Collector; | ||
import util.*; | ||
|
||
import java.util.HashSet; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Run with these parameters | ||
* --input ./src/main/resources/QnV.csv | ||
*/ | ||
|
||
public class Q6_ITERQueryI1T3 { | ||
public static void main(String[] args) throws Exception { | ||
|
||
final ParameterTool parameters = ParameterTool.fromArgs(args); | ||
// Checking input parameters | ||
if (!parameters.has("input")) { | ||
throw new Exception("Input Data is not specified"); | ||
} | ||
|
||
String file = parameters.get("input"); | ||
String outputPath; | ||
long throughput = parameters.getLong("tput", 0); | ||
int times = parameters.getInt("times", 3); | ||
Integer velFilter = parameters.getInt("vel", 205); | ||
Integer windowSize = parameters.getInt("wsize", 15); | ||
|
||
if (!parameters.has("output")) { | ||
outputPath = file.replace(".csv", "_resultQ6_I1T3_ASP.csv"); | ||
} else { | ||
outputPath = parameters.get("output"); | ||
} | ||
|
||
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); | ||
env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime); | ||
|
||
DataStream<KeyedDataPointGeneral> input = env.addSource(new KeyedDataPointSourceFunction(file, throughput)) | ||
.assignTimestampsAndWatermarks(new UDFs.ExtractTimestamp(60000)); | ||
|
||
input.flatMap(new ThroughputLogger<KeyedDataPointGeneral>(KeyedDataPointSourceFunction.RECORD_SIZE_IN_BYTE, throughput)); | ||
|
||
DataStream<Tuple2<KeyedDataPointGeneral, Integer>> velStream = input | ||
.filter(t -> ((Double) t.getValue()) >= velFilter && (t instanceof VelocityEvent)) | ||
.map(new UDFs.MapKey()); | ||
|
||
// iter2 | ||
DataStream<Tuple4<KeyedDataPointGeneral, KeyedDataPointGeneral, Long, Integer>> it2 = velStream.join(velStream) | ||
.where(new UDFs.getArtificalKey()) | ||
.equalTo(new UDFs.getArtificalKey()) | ||
.window(SlidingEventTimeWindows.of(Time.minutes(windowSize), Time.minutes(1))) | ||
.apply(new FlatJoinFunction<Tuple2<KeyedDataPointGeneral, Integer>, Tuple2<KeyedDataPointGeneral, Integer>, Tuple4<KeyedDataPointGeneral, KeyedDataPointGeneral, Long, Integer>>() { | ||
final HashSet<Tuple4<KeyedDataPointGeneral, KeyedDataPointGeneral, Long, Integer>> set = new HashSet<Tuple4<KeyedDataPointGeneral, KeyedDataPointGeneral, Long, Integer>>(1000); | ||
@Override | ||
public void join(Tuple2<KeyedDataPointGeneral, Integer> d1, Tuple2<KeyedDataPointGeneral, Integer> d2, Collector<Tuple4<KeyedDataPointGeneral, KeyedDataPointGeneral, Long, Integer>> collector) throws Exception { | ||
if (d1.f0.getTimeStampMs() < d2.f0.getTimeStampMs() && (Double) d1.f0.getValue() < (Double) d2.f0.getValue()) { | ||
collector.collect(new Tuple4<>(d1.f0, d2.f0, d1.f0.getTimeStampMs(), 1)); | ||
Tuple4<KeyedDataPointGeneral, KeyedDataPointGeneral, Long, Integer> result = new Tuple4<>(d1.f0, d2.f0, d1.f0.getTimeStampMs(), 1); | ||
if (!set.contains(result)) { | ||
if (set.size() == 1000) { | ||
set.removeAll(set); | ||
// to maintain the HashSet Size we flush after 1000 entries | ||
} | ||
collector.collect(result); | ||
set.add(result); | ||
|
||
} | ||
} | ||
} | ||
}).assignTimestampsAndWatermarks(new UDFs.ExtractTimestamp2KeyedDataPointGeneralLongInt(60000)); | ||
|
||
DataStream<Tuple3<KeyedDataPointGeneral, KeyedDataPointGeneral, KeyedDataPointGeneral>> it3 = it2.join(velStream) | ||
.where(new UDFs.getArtificalKeyT4()) | ||
.equalTo(new UDFs.getArtificalKey()) | ||
.window(SlidingEventTimeWindows.of(Time.minutes(windowSize), Time.minutes(1))) | ||
.apply(new FlatJoinFunction<Tuple4<KeyedDataPointGeneral, KeyedDataPointGeneral, Long, Integer>, Tuple2<KeyedDataPointGeneral, Integer>, Tuple3<KeyedDataPointGeneral, KeyedDataPointGeneral, KeyedDataPointGeneral>>() { | ||
final HashSet<Tuple3<KeyedDataPointGeneral, KeyedDataPointGeneral, KeyedDataPointGeneral>> set = new HashSet<Tuple3<KeyedDataPointGeneral, KeyedDataPointGeneral, KeyedDataPointGeneral>>(1000); | ||
@Override | ||
public void join(Tuple4<KeyedDataPointGeneral, KeyedDataPointGeneral, Long, Integer> d1, Tuple2<KeyedDataPointGeneral, Integer> d2, Collector<Tuple3<KeyedDataPointGeneral, KeyedDataPointGeneral, KeyedDataPointGeneral>> collector) throws Exception { | ||
if (d1.f1.getTimeStampMs() < d2.f0.getTimeStampMs() && (Double) d1.f1.getValue() < (Double) d2.f0.getValue()) { | ||
Tuple3<KeyedDataPointGeneral, KeyedDataPointGeneral, KeyedDataPointGeneral> result = new Tuple3<>(d1.f0, d1.f1, d2.f0); | ||
if (!set.contains(result)) { | ||
if (set.size() == 1000) { | ||
set.removeAll(set); | ||
// to maintain the HashSet Size we flush after 1000 entries | ||
} | ||
collector.collect(result); | ||
set.add(result); | ||
|
||
} | ||
} | ||
} | ||
}); | ||
|
||
it3.flatMap(new LatencyLoggerT3()); | ||
it3//.print(); | ||
.writeAsText(outputPath, FileSystem.WriteMode.OVERWRITE); | ||
|
||
JobExecutionResult executionResult = env.execute("My FlinkASP Job"); | ||
System.out.println("The job took " + executionResult.getNetRuntime(TimeUnit.MILLISECONDS) + "ms to execute"); | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import org.apache.flink.api.common.JobExecutionResult; | ||
import org.apache.flink.api.common.functions.FlatJoinFunction; | ||
import org.apache.flink.api.java.tuple.*; | ||
import org.apache.flink.api.java.utils.ParameterTool; | ||
import org.apache.flink.core.fs.FileSystem; | ||
import org.apache.flink.streaming.api.TimeCharacteristic; | ||
import org.apache.flink.streaming.api.datastream.DataStream; | ||
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; | ||
import org.apache.flink.streaming.api.functions.co.ProcessJoinFunction; | ||
import org.apache.flink.streaming.api.windowing.assigners.SlidingEventTimeWindows; | ||
import org.apache.flink.streaming.api.windowing.time.Time; | ||
import org.apache.flink.util.Collector; | ||
import util.*; | ||
|
||
import java.util.HashSet; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Run with these parameters | ||
* --input ./src/main/resources/QnV.csv | ||
*/ | ||
|
||
public class Q6_ITERQueryI1T3_IntervalJoin { | ||
public static void main(String[] args) throws Exception { | ||
|
||
final ParameterTool parameters = ParameterTool.fromArgs(args); | ||
// Checking input parameters | ||
if (!parameters.has("input")) { | ||
throw new Exception("Input Data is not specified"); | ||
} | ||
|
||
String file = parameters.get("input"); | ||
String outputPath; | ||
long throughput = parameters.getLong("tput", 0); | ||
int times = parameters.getInt("times", 3); | ||
Integer velFilter = parameters.getInt("vel", 205); | ||
Integer windowSize = parameters.getInt("wsize", 15); | ||
|
||
if (!parameters.has("output")) { | ||
outputPath = file.replace(".csv", "_resultQ6_I1T3_ASP.csv"); | ||
} else { | ||
outputPath = parameters.get("output"); | ||
} | ||
|
||
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); | ||
env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime); | ||
|
||
DataStream<KeyedDataPointGeneral> input = env.addSource(new KeyedDataPointSourceFunction(file, throughput)) | ||
.assignTimestampsAndWatermarks(new UDFs.ExtractTimestamp(60000)); | ||
|
||
input.flatMap(new ThroughputLogger<KeyedDataPointGeneral>(KeyedDataPointSourceFunction.RECORD_SIZE_IN_BYTE, throughput)); | ||
|
||
DataStream<KeyedDataPointGeneral> velStream = input | ||
.filter(t -> ((Double) t.getValue()) >= velFilter && (t instanceof VelocityEvent)); | ||
|
||
// iter2 | ||
DataStream<Tuple3<KeyedDataPointGeneral, KeyedDataPointGeneral, Long>> it2 = velStream.keyBy(KeyedDataPointGeneral::getKey) | ||
.intervalJoin(velStream.keyBy(KeyedDataPointGeneral::getKey)) | ||
.between(Time.seconds(1), Time.seconds((windowSize*60)-1)) | ||
.process(new ProcessJoinFunction<KeyedDataPointGeneral, KeyedDataPointGeneral, Tuple3<KeyedDataPointGeneral, KeyedDataPointGeneral, Long>>() { | ||
@Override | ||
public void processElement(KeyedDataPointGeneral d1, KeyedDataPointGeneral d2, ProcessJoinFunction<KeyedDataPointGeneral, KeyedDataPointGeneral, Tuple3<KeyedDataPointGeneral, KeyedDataPointGeneral, Long>>.Context context, Collector<Tuple3<KeyedDataPointGeneral, KeyedDataPointGeneral, Long>> collector) throws Exception { | ||
if (d1.getTimeStampMs() < d2.getTimeStampMs() && (Double) d1.getValue() < (Double) d2.getValue()) { | ||
collector.collect(new Tuple3<>(d1, d2, d1.getTimeStampMs())); | ||
} | ||
} | ||
}).assignTimestampsAndWatermarks(new UDFs.ExtractTimestamp2KeyedDataPointGeneralLong(60000)); | ||
|
||
DataStream<Tuple3<KeyedDataPointGeneral, KeyedDataPointGeneral, KeyedDataPointGeneral>> it3 = it2.keyBy(new UDFs.getKeyT3()) | ||
.intervalJoin(velStream.keyBy(KeyedDataPointGeneral::getKey)) | ||
.between(Time.seconds(1), Time.seconds((windowSize*60)-1)) | ||
.process(new ProcessJoinFunction<Tuple3<KeyedDataPointGeneral, KeyedDataPointGeneral, Long>, KeyedDataPointGeneral, Tuple3<KeyedDataPointGeneral, KeyedDataPointGeneral, KeyedDataPointGeneral>>() { | ||
@Override | ||
public void processElement(Tuple3<KeyedDataPointGeneral, KeyedDataPointGeneral, Long> d1, KeyedDataPointGeneral d2, ProcessJoinFunction<Tuple3<KeyedDataPointGeneral, KeyedDataPointGeneral, Long>, KeyedDataPointGeneral, Tuple3<KeyedDataPointGeneral, KeyedDataPointGeneral, KeyedDataPointGeneral>>.Context context, Collector<Tuple3<KeyedDataPointGeneral, KeyedDataPointGeneral, KeyedDataPointGeneral>> collector) throws Exception { | ||
if (d1.f1.getTimeStampMs() < d2.getTimeStampMs() && (Double) d1.f1.getValue() < (Double) d2.getValue()) { | ||
collector.collect(new Tuple3<>(d1.f0, d1.f1, d2)); | ||
} | ||
} | ||
}); | ||
|
||
it3.flatMap(new LatencyLoggerT3()); | ||
it3//.print(); | ||
.writeAsText(outputPath, FileSystem.WriteMode.OVERWRITE); | ||
|
||
JobExecutionResult executionResult = env.execute("My FlinkASP Job"); | ||
System.out.println("The job took " + executionResult.getNetRuntime(TimeUnit.MILLISECONDS) + "ms to execute"); | ||
|
||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q6 is also already there but has other names and I took your Q8 classes, so in essence all should be there now and we can close this PR