You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by ka...@apache.org on 2022/06/27 03:08:45 UTC
[rocketmq-streams] branch main updated: An example of real-time score statistics, counting information for students with scores greater than 90
This is an automated email from the ASF dual-hosted git repository.
karp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/rocketmq-streams.git
The following commit(s) were added to refs/heads/main by this push:
new b965a779 An example of real-time score statistics, counting information for students with scores greater than 90
new b44bc6aa Merge pull request #171 from 123liuziming/main
b965a779 is described below
commit b965a7795715876e14c53d1d672da5021e92cc3e
Author: musi <li...@alibaba-inc.com>
AuthorDate: Thu Jun 23 23:49:08 2022 +0800
An example of real-time score statistics, counting information for students with scores greater than 90
---
.../examples/source/FileSourceExample1.java | 32 ++++++++++++++++++++++
.../src/main/resources/score.txt | 18 ++++++++++++
2 files changed, 50 insertions(+)
diff --git a/rocketmq-streams-examples/src/main/java/org/apache/rocketmq/streams/examples/source/FileSourceExample1.java b/rocketmq-streams-examples/src/main/java/org/apache/rocketmq/streams/examples/source/FileSourceExample1.java
new file mode 100644
index 00000000..1254f7ca
--- /dev/null
+++ b/rocketmq-streams-examples/src/main/java/org/apache/rocketmq/streams/examples/source/FileSourceExample1.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rocketmq.streams.examples.source;
+
+import com.alibaba.fastjson.JSONObject;
+import org.apache.rocketmq.streams.client.StreamBuilder;
+import org.apache.rocketmq.streams.client.source.DataStreamSource;
+
+public class FileSourceExample1 {
+ public static void main(String[] args) {
+ DataStreamSource source = StreamBuilder.dataStream("namespace", "pipeline");
+ source.fromFile("score.txt", true)
+ .filter(message -> ((JSONObject)message).getInteger("score") > 90)
+ .selectFields("name", "class", "subject")
+ .toPrint()
+ .start();
+ }
+}
diff --git a/rocketmq-streams-examples/src/main/resources/score.txt b/rocketmq-streams-examples/src/main/resources/score.txt
new file mode 100644
index 00000000..b2e90a11
--- /dev/null
+++ b/rocketmq-streams-examples/src/main/resources/score.txt
@@ -0,0 +1,18 @@
+{"name":"zhangsan","class":"3","subject":"math","score":90}
+{"name":"zhangsan","class":"3","subject":"history","score":81}
+{"name":"zhangsan","class":"3","subject":"english","score":91}
+{"name":"zhangsan","class":"3","subject":"chinese","score":70}
+{"name":"zhangsan","class":"3","subject":"political","score":84}
+{"name":"zhangsan","class":"3","subject":"geographic","score":99}
+{"name":"lisi","class":"3","subject":"math","score":76}
+{"name":"lisi","class":"3","subject":"history","score":83}
+{"name":"lisi","class":"3","subject":"english","score":82}
+{"name":"lisi","class":"3","subject":"chinese","score":92}
+{"name":"lisi","class":"3","subject":"political","score":97}
+{"name":"lisi","class":"3","subject":"geographic","score":89}
+{"name":"wangwu","class":"3","subject":"math","score":86}
+{"name":"wangwu","class":"3","subject":"history","score":88}
+{"name":"wangwu","class":"3","subject":"english","score":86}
+{"name":"wangwu","class":"3","subject":"chinese","score":93}
+{"name":"wangwu","class":"3","subject":"political","score":99}
+{"name":"wangwu","class":"3","subject":"geographic","score":88}
\ No newline at end of file