本文整理匯總了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();
}