阿帕契熊蟒蛇变形系列

beam-nuggets的Python项目详细描述


PyPIPyPI - Downloads

关于

Apache beampython sdk的随机转换集合。很多是 简单的变换。最有用的是那些 从关系数据库读/写。

安装

  • 使用pip
pip install beam-nuggets
  • 来源
git clone git@github.com:mohaseeb/beam-nuggets.git
cd beam-nuggets
pip install .

支持的转换

IO

其他

文档

here

用法

使用beam nugget将数据写入sqlite表 relational_db.Write转换。

# write_sqlite.py contentsimportapache_beamasbeamfromapache_beam.options.pipeline_optionsimportPipelineOptionsfrombeam_nuggets.ioimportrelational_dbrecords=[{'name':'Jan','num':1},{'name':'Feb','num':2}]source_config=relational_db.SourceConfiguration(drivername='sqlite',database='/tmp/months_db.sqlite',create_if_missing=True# create the database if not there )table_config=relational_db.TableConfiguration(name='months',create_if_missing=True,# automatically create the table if not thereprimary_key_columns=['num']# and use 'num' column as primary key)withbeam.Pipeline(options=PipelineOptions())asp:# Will use local runnermonths=p|"Reading month records">>beam.Create(records)months|'Writing to DB'>>relational_db.Write(source_config=source_config,table_config=table_config)

执行管道

python write_sqlite.py 

检查内容

sqlite3 /tmp/months_db.sqlite 'select * from months'# output:# 1.0|Jan# 2.0|Feb

要将相同的数据写入postgresql表,只需创建一个合适的 relational_db.SourceConfiguration如下。

source_config=relational_db.SourceConfiguration(drivername='postgresql+pg8000',host='localhost',port=5432,username='postgres',password='password',database='calendar',create_if_missing=True# create the database if not there )

单击here 更多示例,包括在google云平台中编写postgresql 使用DataFlowRunner。

演示如何使用束核relational_db.ReadFromDB的示例 转换为从PostgreSQL数据库表中读取。

from__future__importprint_functionimportapache_beamasbeamfromapache_beam.options.pipeline_optionsimportPipelineOptionsfrombeam_nuggets.ioimportrelational_dbwithbeam.Pipeline(options=PipelineOptions())asp:source_config=relational_db.SourceConfiguration(drivername='postgresql+pg8000',host='localhost',port=5432,username='postgres',password='password',database='calendar',)records=p|"Reading records from db">>relational_db.ReadFromDB(source_config=source_config,table_name='months',query='select num, name from months'# optional. When omitted, all table records are returned. )records|'Writing to stdout'>>beam.Map(print)

有关更多示例,请参见here

开发

  • 安装
git clone git@github.com:mohaseeb/beam-nuggets.git
cd beam-nuggets
exportBEAM_NUGGETS_ROOT=`pwd`
pip install -e .[dev]
  • 在专用开发分支上进行更改
  • 运行测试
cd$BEAM_NUGGETS_ROOT
python -m unittest discover -v
  • 生成文档
cd$BEAM_NUGGETS_ROOT
docs/generate_docs.sh
  • 创建一个针对master的pr。
  • 合并已接受的PR并更新本地主机后,上载新的 建立到Pypi。
cd$BEAM_NUGGETS_ROOT
scripts/build_test_deploy.sh

积压工作

  • 版本化文档?
  • 总结使用源/汇与pardo(和groupby)进行io的研究
  • 更多掘金:writetocsv
  • 调查sdf pardo的就绪性,以及是否可以用于relational数据库。readfromdb
  • 集成测试
  • 在IO转换上处理DB转换失败
  • 更多掘金:ElasticSearch,Mongo
  • 写入关系数据库,记录

出资人

mohaseebastrocox2514millerj

许可证

麻省理工学院

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java本机方法的源代码可用吗?   java如何使父方法抛出异常?   java Android以编程方式设置不同屏幕大小/密度的布局   java如何使用一个变量来管理所有客户端请求   java输入一个txt文件,每行有一组数字   json java从jsonobject获取jsonarray错误   java将一个(WAV)写入一个文件只会说一个单词(最后一个单词)   java Telnet忽略原始字节   proguard java。运行桌面应用程序时出现lang.VerifyError   java用左键移动JLabel?   java如何在jText区域验证选项卡?   文件服务器客户端Javasocket编程中的字符串搜索   java省略了JSTL中的最后一个逗号<c:out>   java如何找到if或else代码已执行的次数?   java JavaScript WebSocket send()方法未执行   浮点数声明上的java标识符预期错误   java这是指二进制搜索算法吗?   编译mod at:reobfJar java时的minecraft问题。util。拉链ZipException:重复条目   java检测特定的震动运动(如图所示:D)