本文整理汇总了Java中org.apache.flink.examples.java.wordcount.util.WordCountData类的典型用法代码示例。如果您正苦于以下问题:Java WordCountData类的具体用法?Java WordCountData怎么用?Java WordCountData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WordCountData类属于org.apache.flink.examples.java.wordcount.util包,在下文中一共展示了WordCountData类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTextDataSet
import org.apache.flink.examples.java.wordcount.util.WordCountData; //导入依赖的package包/类
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 WordCountData.getDefaultTextLineDataSet(env);
}
}
示例2: getTextDataStream
import org.apache.flink.examples.java.wordcount.util.WordCountData; //导入依赖的package包/类
private static DataStream<String> getTextDataStream(StreamExecutionEnvironment env) {
if (fileOutput) {
// read the text file from given input path
return env.readTextFile(textPath);
} else {
// get default test text data
return env.fromElements(WordCountData.WORDS);
}
}
示例3: main
import org.apache.flink.examples.java.wordcount.util.WordCountData; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
final ParameterTool params = ParameterTool.fromArgs(args);
// set up the execution environment
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
// make parameters available in the web interface
env.getConfig().setGlobalJobParameters(params);
// get input data
DataSet<String> text;
if (params.has("input")) {
// read the text file from given input path
text = env.readTextFile(params.get("input"));
} else {
// get default test text data
System.out.println("Executing WordCount example with default input data set.");
System.out.println("Use --input to specify file input.");
text = WordCountData.getDefaultTextLineDataSet(env);
}
DataSet<Tuple2<String, Integer>> counts =
// split up the lines in pairs (2-tuples) containing: (word,1)
text.flatMap(new Tokenizer())
// group by the tuple field "0" and sum up tuple field "1"
.groupBy(0)
.sum(1);
// emit result
if (params.has("output")) {
counts.writeAsCsv(params.get("output"), "\n", " ");
// execute program
env.execute("WordCount Example");
} else {
System.out.println("Printing result to stdout. Use --output to specify output path.");
counts.print();
}
}
示例4: getTextDataSet
import org.apache.flink.examples.java.wordcount.util.WordCountData; //导入依赖的package包/类
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 WordCountData.getDefaultTextLineDataSet(env);
}
}
示例5: main
import org.apache.flink.examples.java.wordcount.util.WordCountData; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
final ParameterTool params = ParameterTool.fromArgs(args);
// set up the execution environment
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
// make parameters available in the web interface
env.getConfig().setGlobalJobParameters(params);
// get input data
DataSet<String> text;
if (params.has("input")) {
// read the text file from given input path
text = env.readTextFile(params.get("input"));
} else {
// get default test text data
System.out.println("Executing WordCount example with default input data set.");
System.out.println("Use --input to specify file input.");
text = WordCountData.getDefaultTextLineDataSet(env);
}
DataSet<Word> counts =
// split up the lines into Word objects (with frequency = 1)
text.flatMap(new Tokenizer())
// group by the field word and sum up the frequency
.groupBy("word")
.reduce(new ReduceFunction<Word>() {
@Override
public Word reduce(Word value1, Word value2) throws Exception {
return new Word(value1.word, value1.frequency + value2.frequency);
}
});
if (params.has("output")) {
counts.writeAsText(params.get("output"), WriteMode.OVERWRITE);
// execute program
env.execute("WordCount-Pojo Example");
} else {
System.out.println("Printing result to stdout. Use --output to specify output path.");
counts.print();
}
}
示例6: main
import org.apache.flink.examples.java.wordcount.util.WordCountData; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment
.createLocalEnvironment(PARALLELISM);
DataStream<String> stream = env.fromElements(WordCountData.WORDS).map(new IdentityMap());
stream.print();
env.execute();
}