Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
f0d39267
F
flink
项目概览
doujutun3207
/
flink
与 Fork 源项目一致
从无法访问的项目Fork
通知
24
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
flink
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f0d39267
编写于
5月 20, 2014
作者:
R
Robert Metzger
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added links to programming guide / examples
remove reading from files from WC
上级
65602201
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
82 deletion
+23
-82
stratosphere-quickstart/quickstart-java/src/main/resources/archetype-resources/src/main/java/Job.java
...main/resources/archetype-resources/src/main/java/Job.java
+7
-16
stratosphere-quickstart/quickstart-java/src/main/resources/archetype-resources/src/main/java/WordCountJob.java
...urces/archetype-resources/src/main/java/WordCountJob.java
+16
-66
未找到文件。
stratosphere-quickstart/quickstart-java/src/main/resources/archetype-resources/src/main/java/Job.java
浏览文件 @
f0d39267
package
${
package
};
import
eu.stratosphere.api.common.Plan
;
import
eu.stratosphere.api.common.Program
;
import
eu.stratosphere.api.common.operators.FileDataSink
;
import
eu.stratosphere.api.common.operators.GenericDataSink
;
import
eu.stratosphere.api.java.DataSet
;
import
eu.stratosphere.api.java.ExecutionEnvironment
;
import
eu.stratosphere.api.java.aggregation.Aggregations
;
import
eu.stratosphere.api.java.functions.FlatMapFunction
;
import
eu.stratosphere.api.java.record.io.DelimitedOutputFormat
;
import
eu.stratosphere.api.java.tuple.Tuple2
;
import
eu.stratosphere.client.LocalExecutor
;
import
eu.stratosphere.util.Collector
;
/**
* Skeleton for a Stratosphere Job.
...
...
@@ -30,7 +17,6 @@ import eu.stratosphere.util.Collector;
* target/stratosphere-quickstart-0.1-SNAPSHOT-Sample.jar
*
*/
@SuppressWarnings
(
"serial"
)
public
class
Job
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
...
...
@@ -51,12 +37,17 @@ public class Job {
* .join()
* .group()
* and many more.
* Have a look at the programming guide for the Java API:
*
* http://stratosphere.eu/docs/0.5/programming_guides/java.html
*
* and the examples
*
*
Run it!
*
http://stratosphere.eu/docs/0.5/programming_guides/examples.html
*
*/
// execute program
env
.
execute
(
"
Example
"
);
env
.
execute
(
"
Stratosphere Java API Skeleton
"
);
}
}
\ No newline at end of file
stratosphere-quickstart/quickstart-java/src/main/resources/archetype-resources/src/main/java/WordCountJob.java
浏览文件 @
f0d39267
...
...
@@ -9,10 +9,7 @@ import eu.stratosphere.util.Collector;
/**
* Implements the "WordCount" program that computes a simple word occurrence histogram
* over text files.
*
* <p>
* The input is a plain text file with lines separated by newline characters.
* over some sample data
*
* <p>
* This example shows how to:
...
...
@@ -26,48 +23,47 @@ import eu.stratosphere.util.Collector;
@SuppressWarnings
(
"serial"
)
public
class
WordCountJob
{
//
*************************************************************************
//
PROGRAM
//
*************************************************************************
//
//
Program.
//
public
static
void
main
(
String
[]
args
)
throws
Exception
{
parseParameters
(
args
);
// set up the execution environment
final
ExecutionEnvironment
env
=
ExecutionEnvironment
.
getExecutionEnvironment
();
// get input data
DataSet
<
String
>
text
=
getTextDataSet
(
env
);
DataSet
<
String
>
text
=
env
.
fromElements
(
"To be, or not to be,--that is the question:--"
,
"Whether 'tis nobler in the mind to suffer"
,
"The slings and arrows of outrageous fortune"
,
"Or to take arms against a sea of troubles,"
);
DataSet
<
Tuple2
<
String
,
Integer
>>
counts
=
// split up the lines in pairs (2-tuples) containing: (word,1)
text
.
flatMap
(
new
Tokeniz
er
())
text
.
flatMap
(
new
LineSplitt
er
())
// group by the tuple field "0" and sum up tuple field "1"
.
groupBy
(
0
)
.
aggregate
(
Aggregations
.
SUM
,
1
);
// emit result
if
(
fileOutput
)
{
counts
.
writeAsCsv
(
outputPath
,
"\n"
,
" "
);
}
else
{
counts
.
print
();
}
counts
.
print
();
// execute program
env
.
execute
(
"WordCount Example"
);
}
//
*************************************************************************
//
USER FUNCTIONS
//
*************************************************************************
//
//
User Functions
//
/**
* Implements the string tokenizer that splits sentences into words as a user-defined
* FlatMapFunction. The function takes a line (String) and splits it into
* multiple pairs in the form of "(word,1)" (Tuple2<String, Integer>).
*/
public
static
final
class
Tokeniz
er
extends
FlatMapFunction
<
String
,
Tuple2
<
String
,
Integer
>>
{
public
static
final
class
LineSplitt
er
extends
FlatMapFunction
<
String
,
Tuple2
<
String
,
Integer
>>
{
@Override
public
void
flatMap
(
String
value
,
Collector
<
Tuple2
<
String
,
Integer
>>
out
)
{
...
...
@@ -82,50 +78,4 @@ public class WordCountJob {
}
}
}
// *************************************************************************
// UTIL METHODS
// *************************************************************************
private
static
boolean
fileOutput
=
false
;
private
static
String
textPath
;
private
static
String
outputPath
;
private
static
void
parseParameters
(
String
[]
args
)
{
if
(
args
.
length
>
0
)
{
// parse input arguments
fileOutput
=
true
;
if
(
args
.
length
==
2
)
{
textPath
=
args
[
0
];
outputPath
=
args
[
1
];
}
else
{
System
.
err
.
println
(
"Usage: WordCount <text path> <result path>"
);
System
.
exit
(
1
);
}
}
else
{
System
.
out
.
println
(
"Executing WordCount example with built-in default data."
);
System
.
out
.
println
(
" Provide parameters to read input data from a file."
);
System
.
out
.
println
(
" Usage: WordCount <text path> <result path>"
);
}
}
private
static
DataSet
<
String
>
getTextDataSet
(
ExecutionEnvironment
env
)
{
if
(
fileOutput
)
{
// read the text file from given input path
return
env
.
readTextFile
(
textPath
);
}
else
{
// get default test text data
return
getDefaultTextLineDataSet
(
env
);
}
}
public
static
DataSet
<
String
>
getDefaultTextLineDataSet
(
ExecutionEnvironment
env
)
{
return
env
.
fromElements
(
"To be, or not to be,--that is the question:--"
,
"Whether 'tis nobler in the mind to suffer"
,
"The slings and arrows of outrageous fortune"
,
"Or to take arms against a sea of troubles,"
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录