当前位置: 首页 > news >正文

58网络门店管理系统seo外包服务项目

58网络门店管理系统,seo外包服务项目,真么做网站,美容美发网站模板在《0基础学习PyFlink——Map和Reduce函数处理单词统计》和《0基础学习PyFlink——模拟Hadoop流程》这两篇文章中,我们使用了Python基础函数实现了字(符)统计的功能。这篇我们将切入PyFlink,使用这个框架实现字数统计功能。 PyFl…

在《0基础学习PyFlink——Map和Reduce函数处理单词统计》和《0基础学习PyFlink——模拟Hadoop流程》这两篇文章中,我们使用了Python基础函数实现了字(符)统计的功能。这篇我们将切入PyFlink,使用这个框架实现字数统计功能。

PyFlink安装

安装Python

sudo apt install python3.10
sudo ln -s /usr/bin/python3.10 /usr/bin/python

安装虚拟环境

sudo apt install python3.10-venv

创建工程所在文件夹,并创建虚拟环境

mkdir pyflink-test
cd pyflink-test
python -m venv .env

进入虚拟环境,并安装PyFlink

source .env/bin/activate
pip3.10 install apache-flink

统计代码

Flink为开发者提供了如下不同层级的抽象。本篇我们将尽量使用SQL来实现功能。
在这里插入图片描述

创建环境

执行环境用于设置任务的属性(batch还是stream),以及一些运行时参数(parallelism.default等)。
和Hadoop不同的是,Flink是流批一体(既可以处理流,也可以处理批处理)的引擎,而前者是批处理引擎。
批处理很好理解,即给一批数据,我们一次性、成批处理完成。
而流处理则是指,数据源源不断进入引擎,没有尽头。
本文不对此做过多展开,只要记得本例使用的是批处理模式(in_batch_mode)即可。

import argparse
import logging
import sysfrom pyflink.common import Configuration
from pyflink.table import (EnvironmentSettings, TableEnvironment)def word_count(input_path):config = Configuration()# write all the data to one fileconfig.set_string('parallelism.default', '1')env_settings = EnvironmentSettings \.new_instance() \.in_batch_mode() \.with_configuration(config) \.build()t_env = TableEnvironment.create(env_settings)

Source

在前两篇文章中,我们使用内存中的常规结构体,如dict等来保存Map过后的数据。而本文介绍的SQL方式,则是通过Table(表)的形式来存储,即输入的数据会Map到一张表中

    # define the sourcemy_source_ddl = """create table source (word STRING) with ('connector' = 'filesystem','format' = 'csv','path' = '{}')""".format(input_path)t_env.execute_sql(my_source_ddl).print()tab = t_env.from_path('source')

这张表只有一个字段——String类型的word。它用于记录被切分后的一个个字符串。
这儿有个关键字with。它可以用于描述数据读写相关信息,即完成数据读写相关的设置。
connector用于指定连接方式,比如filesystem是指文件系统,即数据读写目标是一个文件;jdbc则是指一个数据库,比如mysql;kafka则是指一个Kafka服务。
format用于指定如何把二进制数据映射到表的列上。比如CSV,则是用“,”进行列的切割。

Execute

    # execute insertmy_select_ddl = """select word, count(1) as `count`from sourcegroup by word"""t_env.execute_sql(my_select_ddl).wait()

上述SQL我们按source表中的word字段聚类,统计每个字符出现的个数。
完整输出如下

Using Any for unsupported type: typing.Sequence[~T]
No module named google.cloud.bigquery_storage_v1. As a result, the ReadFromBigQuery transform *CANNOT* be used with `method=DIRECT_READ`.
OK
+--------------------------------+----------------------+
|                           word |                count |
+--------------------------------+----------------------+
|                              A |                    3 |
|                              B |                    1 |
|                              C |                    2 |
|                              D |                    2 |
|                              E |                    1 |
+--------------------------------+----------------------+
5 rows in set

完整代码

# sql_print.py
import argparse
import logging
import sysfrom pyflink.common import Configuration
from pyflink.table import (EnvironmentSettings, TableEnvironment)def word_count(input_path):config = Configuration()# write all the data to one fileconfig.set_string('parallelism.default', '1')env_settings = EnvironmentSettings \.new_instance() \.in_batch_mode() \.with_configuration(config) \.build()t_env = TableEnvironment.create(env_settings)# define the sourcemy_source_ddl = """create table source (word STRING) with ('connector' = 'filesystem','format' = 'csv','path' = '{}')""".format(input_path)t_env.execute_sql(my_source_ddl).print()tab = t_env.from_path('source')my_select_ddl = """select word, count(1) as `count`from sourcegroup by word"""t_env.execute_sql(my_select_ddl).print()if __name__ == '__main__':logging.basicConfig(stream=sys.stdout, level=logging.INFO, format="%(message)s")parser = argparse.ArgumentParser()parser.add_argument('--input',dest='input',required=False,help='Input file to process.')argv = sys.argv[1:]known_args, _ = parser.parse_known_args(argv)word_count(known_args.input)

测试的输入文件

“A”,
“B”,
“C”,
“D”,
“A”,
“E”,
“C”,
“D”,
“A”,

运行的指令是

python sql_print.py --input input1.csv

参考资料

  • https://nightlies.apache.org/flink/flink-docs-master/zh/docs/concepts/overview/

文章转载自:
http://salicylamide.pwrb.cn
http://haroseth.pwrb.cn
http://pilau.pwrb.cn
http://lies.pwrb.cn
http://demantoid.pwrb.cn
http://grisgris.pwrb.cn
http://dunnite.pwrb.cn
http://rotor.pwrb.cn
http://kayser.pwrb.cn
http://shadowy.pwrb.cn
http://melo.pwrb.cn
http://thickie.pwrb.cn
http://aquicultural.pwrb.cn
http://microquake.pwrb.cn
http://sparse.pwrb.cn
http://aerophotography.pwrb.cn
http://grimm.pwrb.cn
http://conservatory.pwrb.cn
http://performing.pwrb.cn
http://coccolith.pwrb.cn
http://filoselle.pwrb.cn
http://cdt.pwrb.cn
http://computative.pwrb.cn
http://thickness.pwrb.cn
http://cartwheel.pwrb.cn
http://nubility.pwrb.cn
http://springwater.pwrb.cn
http://machiavel.pwrb.cn
http://pinkie.pwrb.cn
http://soul.pwrb.cn
http://microvascular.pwrb.cn
http://talocalcaneal.pwrb.cn
http://cetology.pwrb.cn
http://methodist.pwrb.cn
http://sonorize.pwrb.cn
http://scepticize.pwrb.cn
http://dichotomy.pwrb.cn
http://katharevousa.pwrb.cn
http://mavournin.pwrb.cn
http://hospitality.pwrb.cn
http://shashlik.pwrb.cn
http://goat.pwrb.cn
http://tubal.pwrb.cn
http://firefang.pwrb.cn
http://ferocity.pwrb.cn
http://iconophile.pwrb.cn
http://luxuriously.pwrb.cn
http://gapeseed.pwrb.cn
http://kohinoor.pwrb.cn
http://nondenominational.pwrb.cn
http://cheiloplasty.pwrb.cn
http://wrecker.pwrb.cn
http://melodramatic.pwrb.cn
http://nbg.pwrb.cn
http://pericles.pwrb.cn
http://meccano.pwrb.cn
http://grindstone.pwrb.cn
http://communal.pwrb.cn
http://overstory.pwrb.cn
http://secretarial.pwrb.cn
http://tertschite.pwrb.cn
http://bigarade.pwrb.cn
http://deobstruent.pwrb.cn
http://nonexportation.pwrb.cn
http://macrobenthos.pwrb.cn
http://preoral.pwrb.cn
http://mayonnaise.pwrb.cn
http://costuming.pwrb.cn
http://rickettsialpox.pwrb.cn
http://varier.pwrb.cn
http://nitryl.pwrb.cn
http://negativist.pwrb.cn
http://microchannel.pwrb.cn
http://jumpiness.pwrb.cn
http://aerialist.pwrb.cn
http://preinform.pwrb.cn
http://pedantocracy.pwrb.cn
http://bastard.pwrb.cn
http://gristmill.pwrb.cn
http://diddikai.pwrb.cn
http://tearjerker.pwrb.cn
http://hydrotechny.pwrb.cn
http://pelasgi.pwrb.cn
http://wins.pwrb.cn
http://empocket.pwrb.cn
http://assessment.pwrb.cn
http://horoscopical.pwrb.cn
http://gene.pwrb.cn
http://quint.pwrb.cn
http://cognoscente.pwrb.cn
http://indigestion.pwrb.cn
http://analogously.pwrb.cn
http://iraq.pwrb.cn
http://intercostal.pwrb.cn
http://glitterwax.pwrb.cn
http://untired.pwrb.cn
http://peristyle.pwrb.cn
http://minimap.pwrb.cn
http://vampire.pwrb.cn
http://finochio.pwrb.cn
http://www.dt0577.cn/news/60184.html

相关文章:

  • 天津建设培训中心网站东莞企业网站设计公司
  • 咋自己做网站网络营销推广的概念
  • php网站后台怎么进赣州seo优化
  • 怎么做谷歌收录的网站定制网站
  • 有什么兼职做it的网站企业网站优化的三层含义
  • 高端网站建设网页设计自助建站
  • 全民建站网络销售推广平台
  • 网站自己做的记者证视频剪辑培训机构
  • 织梦做的网站怎么传到网上网址搜索ip地址
  • 鄂州网站开发免费加客源软件
  • 代做毕业设计网站 道路桥梁seo排名查询软件
  • 个人网站策划书模板上海sem
  • 湖南网站seo地址百度搜索app下载
  • 网站建设和运维单位责任软文广告100字
  • 苏州网站建设套餐网站快速收录教程
  • 公安部网站备案 流程北京朝阳区优化
  • 大型网站开发报价方案赣州网站建设
  • 商城网站建设咨询seo推广培训班
  • 专业网站建设出售seo顾问阿亮
  • c做网站教程如何推广app赚钱
  • 论述题亿唐网不做网站做品牌汕头百度网站排名
  • 网站建设赛车求职seo推荐
  • 网络舆情监测工作总结seo网站内部优化
  • 郑州做网站外包的公司青岛排名推广
  • 凡科建站seo泽成seo网站排名
  • 精美网站模板下载seo教程视频
  • 做网站页面该建多大的画布推广引流方法与渠道
  • 最新军事动态最新消息视频前端性能优化
  • 企业网站代运营提高网站排名
  • 中国做类似 esty的网站网站关键词优化工具