Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

1. How to use flink table and sql ​ to build pom files

Shulou Source: shulou.com Published: 2022-06-01 09:07:31 10月02日 Update

This article mainly explains the "1, how to use flink table and sql to build pom files", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "1, how to use flink table and sql to build pom files" it!

Build the pom file

4.0.0 org.example flinksqldemo 1.0-SNAPSHOT UTF-8 UTF-8 2.11 2.11.8 0.10.2.1 1.12.0 2.7.3 compile org.apache.maven.plugins maven- Compiler-plugin 8 8 org.apache.flink flink-table-planner-blink_2.11 1.12.0 org.apache.flink Flink-java ${flink.version} ${setting.scope} org.apache.flink flink-streaming-java_2.11 ${flink.version} ${setting.scope} org.apache.flink flink-clients_2.11 ${ Flink.version} ${setting.scope} org.apache.flink flink-connector-kafka-0.10_$ {scala.binary.version} ${flink.version} org.apache.flink flink-streaming-scala_$ {scala.binary.version} ${flink.version} ${setting.scope} org.apache.flink flink-connector-filesystem_$ {scala.binary.version} ${flink.version} org.apache.kafka kafka_$ {scala.binary.version} ${kafka.version} ${setting.scope} org.apache.hadoop hadoop-common ${hadoop.version} ${setting.scope} org.apache.hadoop hadoop-hdfs ${hadoop.version} ${setting.scope} Org.apache.hadoop hadoop-client ${hadoop.version} ${setting.scope} org.slf4j slf4j-api 1.7.25 com.alibaba fastjson 1.2. 72 redis.clients jedis 2.7.3 com.google.guava guava 29.0-jre

2. Write code

Package com.jd.data;import org.apache.flink.api.common.functions.MapFunction;import org.apache.flink.streaming.api.datastream.DataStream;import org.apache.flink.streaming.api.datastream.DataStreamSource;import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;import org.apache.flink.table.api.Table;import org.apache.flink.table.api.bridge.java.StreamTableEnvironment Public class test {public static void main (String [] args) throws Exception {StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment (); env.setParallelism (1); DataStreamSource stream = env.readTextFile ("/ Users/liuhaijing/Desktop/flinktestword/aaa.txt"); / / DataStreamSource stream = env.socketTextStream ("localhost", 8888) SingleOutputStreamOperator map = stream.map (new MapFunction () {public SensorReading map (String s) throws Exception {String [] split = s.split (","); return new SensorReading (split [0], split [1], split [2]);}}); StreamTableEnvironment tableEnv = StreamTableEnvironment.create (env) / / use table api// Table table = tableEnv.fromDataStream (map); / / table.printSchema (); / / Table select = table.select ("test b"); / / use sql api tableEnv.createTemporaryView ("test", map); Table select = tableEnv.sqlQuery ("select ameme b from test"); DataStream sensorReading2DataStream = tableEnv.toAppendStream (select, SensorReading2.class) SensorReading2DataStream.map (new MapFunction () {@ Override public Object map (SensorReading2 value) throws Exception {System.out.println (value.a+ "" + value.b); return null;}}); env.execute ();}} package com.jd.data;public class SensorReading {public String public String b; public String c Public SensorReading () {} public SensorReading (String a, String b, String c) {this.a = a; this.b = b; this.c = c;} public String getA () {return a;} public void setA (String a) {this.a = a;} public String getB () {return b } public void setB (String b) {this.b = b;} public String getC () {return c;} public void setC (String c) {this.c = c;}} package com.jd.data;public class SensorReading2 {public String a public String public String b; public SensorReading2 () {} public SensorReading2 (String a, String b) {this.a = a This.b = b;} public String getA () {return a;} public void setA (String a) {this.a = a;} public String getB () {return b;} public void setB (String b) {this.b = b;}}

Note: attributes in pojo must be public, including no-parameter constructor

Thank you for reading, the above is "1, how to use flink table and sql to build pom file" content, after the study of this article, I believe you on 1, how to use flink table and sql to build pom file this problem has a deeper understanding, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Files learning content UTF-8 code that is attributes ideas situations articles more knowledge knowledge points articles followers questions constructors practice push research Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information Microsoft macOS Shulou Technology