Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Flink DataSet programming in Apache Flink

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces to you what is Flink DataSet programming in Apache Flink, the content is very detailed, interested friends can refer to, hope to be helpful to you.

DataSet programming in Flink is very conventional programming, which only needs to implement the transformation of his dataset (such as filtering, mapping, joining, grouping). This dataset is originally created by a data source (for example, reading files, loading a local collection of local datasets), and the results of the transformation are returned to the local (or distributed) file system or terminal via sink. Flink programs can be run in a variety of environments, such as standalone, or embedded in other programs. The execution process can be in the local JVM or in the cluster.

Source = = > Flink (transformation) = > Sink

File based

ReadTextFile (path) / TextInputFormat-Reads files line wise and returns them as Strings.

ReadTextFileWithValue (path) / TextValueInputFormat-Reads files line wise and returns them as StringValues. StringValues are mutable strings.

ReadCsvFile (path) / CsvInputFormat-Parses files of comma (or another char) delimited fields. Returns a DataSet of tuples or POJOs. Supports the basic java types and their Value counterparts as field types.

ReadFileOfPrimitives (path, Class) / PrimitiveInputFormat-Parses files of new-line (or another char sequence) delimited primitive data types such as String or Integer.

ReadFileOfPrimitives (path, delimiter, Class) / PrimitiveInputFormat-Parses files of new-line (or another char sequence) delimited primitive data types such as String or Integer using the given delimiter.

Based on set

FromCollection (Collection)

FromCollection (Iterator, Class)

FromElements (T...)

FromParallelCollection (SplittableIterator, Class)

GenerateSequence (from, to)

Create a DataSet from a simple collection-based

Collection-based data sources are often used in the development environment or in programmers' learning, and we can create the data we need at will, because the way is simple. Let's use collections as data sources in both java and scala ways. The data source is simple from 1 to 10

Javaimport org.apache.flink.api.java.ExecutionEnvironment;import java.util.ArrayList;import java.util.List;public class JavaDataSetSourceApp {public static void main (String [] args) throws Exception {ExecutionEnvironment executionEnvironment = ExecutionEnvironment.getExecutionEnvironment (); fromCollection (executionEnvironment);} public static void fromCollection (ExecutionEnvironment env) throws Exception {List list = new ArrayList (); for (int I = 1; I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report