Apache Flink Fundamentals: Using Table API for Programming

What Is Table API?

Overview of Flink APIs

Table API Features

Table API Programming

WordCount Example

import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.java.BatchTableEnvironment;
import org.apache.flink.table.descriptors.FileSystem;
import org.apache.flink.table.descriptors.OldCsv;
import org.apache.flink.table.descriptors.Schema;
import org.apache.flink.types.Row;
public class JavaBatchWordCount { // line:10 public static void main(String[] args) throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tEnv = BatchTableEnvironment.create(env);
String path = JavaBatchWordCount.class.getClassLoader().getResource("words.txt").getPath();
tEnv.connect(new FileSystem().path(path))
.withFormat(new OldCsv().field("word", Types.STRING).lineDelimiter("\n"))
.withSchema(new Schema().field("word", Types.STRING))
.registerTableSource("fileSource"); // line:20
Table result = tEnv.scan("fileSource")
.groupBy("word")
.select("word, count(1) as count");
tEnv.toDataSet(result, Row.class).print();
}
}
tEnv.connect(new FileSystem().path(path))
.withFormat(new OldCsv().field("word", Types.STRING).lineDelimiter("\n"))
.withSchema(new Schema().field("word", Types.STRING))
.registerTableSource("fileSource");
Table result = tEnv.scan("fileSource")
.groupBy("word")
.select("word, count(1) as count");
tEnv.toDataSet(result, Row.class).print();

Obtain a Table

How to Output a Table

How to Operate on a Table

Table Operation Overview

Operations to Improve the Usability

Operations to Enhance Functions

  • ScalarFunction
  • TableFunction
  • AggregateFunction

Table API Developments

Original Source:

--

--

--

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Map and a filter function in python

Concurrent Sudoku Solver: Part 1 - Single Candidate Technique + Domain Modelling

In the aftermath of the Canadian Revolution and the Reign of

At present, there are many Ido platforms in the market, and the competition is intense.

Solve the testability issue of legacy software projects (1)

Introduction to CI pipelines on Github

Two people looking at code on a Silver Macbook Pro https://www.pexels.com/@divinetechygirl?utm_content=attributionCopyText&utm_medium=referral&utm_source=pexels

Where do I start my RPA journey?

What I have learned In My First Week Undergoing IGHUBFellowship4.0 Program.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

More from Medium

What is Apache Kafka?

Apache Druid — Druid SQL in Java

Understanding Docker Architecture

Understanding Docker Architecture

Database consistency level