flinksql怎么将数据写入到文件中
发表于:2025-12-03 作者:千家信息网编辑
千家信息网最后更新 2025年12月03日,本篇内容主要讲解"flinksql怎么将数据写入到文件中",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"flinksql怎么将数据写入到文件中"吧!pack
千家信息网最后更新 2025年12月03日flinksql怎么将数据写入到文件中
本篇内容主要讲解"flinksql怎么将数据写入到文件中",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"flinksql怎么将数据写入到文件中"吧!
package com.jd.dataoutput;import com.jd.data.SensorReading;import org.apache.flink.api.common.functions.MapFunction;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.DataTypes;import org.apache.flink.table.api.Table;import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;import org.apache.flink.table.descriptors.FileSystem;import org.apache.flink.table.descriptors.OldCsv;import org.apache.flink.table.descriptors.Schema;public class FlinkSqlOutputFile { 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);// 使用 table api Table table = tableEnv.fromDataStream(map);// table.printSchema(); Table select = table.select("a,b");// select.printSchema();// 使用 sql api// tableEnv.createTemporaryView("test", map);// Table select = tableEnv.sqlQuery(" select a, b from test");// select.printSchema();// 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;// }// });// tableEnv.connect(new FileSystem().path("/Users/liuhaijing/IdeaProjects/haijing3/spark/flinksqldemo/output/out.txt"))// .withFormat(new Csv())// .withSchema(// new Schema()// .field("a", DataTypes.STRING())// .field("b", DataTypes.STRING()))// .inAppendMode()// .createTemporaryTable("outputTable");// select.insertInto("outputTable"); tableEnv.connect(new FileSystem().path("/Users/liuhaijing/IdeaProjects/haijing3/spark/flinksqldemo/output/out.txt")) .withFormat(new OldCsv()) .withSchema(new Schema() .field("a", DataTypes.STRING()) ).inAppendMode() .createTemporaryTable("outputTable"); select.insertInto("outputTable"); env.execute(); }} 到此,相信大家对"flinksql怎么将数据写入到文件中"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
数据
文件
内容
学习
实用
更深
兴趣
实用性
实际
操作简单
方法
更多
朋友
网站
频道
查询
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络安全用网图画
高州数据库恢复
为啥使用服务器
运用gis技术建数据库
首届网络安全日在哪年
本科毕业软件开发工程师简历
数据库原理思维导图简单又漂亮
软件开发校招题目
山西党员教育软件开发哪儿好
政府招商投资平台软件开发商
搭建小程序需要多大服务器
软件开发技术工程师能干啥
网络安全专业工作与前景
在服务器里面怎么获得管理员
电商网络技术靠谱吗
购买软件开发集成材料怎么入账
城市建设数据库
网络安全架构有用吗
网络技术法原则
数据库备份工具 nav
怎么打开虚拟服务器
神通数据库好用么
软件开发笔记本电脑配置
数据库左外部连接
计算机网络技术升本什么专业
面对网络安全的想法和做法
山西服务器机柜厂家
工程软件开发专升本试卷
城市建设数据库
生手几天可以学会数据库