BigQuery的jxbigquery JSON表达式
jx-bigquer的Python项目详细描述
jx大查询
BigQuery的JSON表达式
状态
2020年6月-可以在管理模式时将JSON文档插入到BigQuery中。尚不支持查询。在
概述
该库旨在管理多个BigQuery表,以提供一个表具有动态管理模式的假象。在
定义
partition
-大数据根据时间被分成不同的容器。这使得对最近数据的查询使用更少的资源,并允许快速删除旧数据cluster
-分区中数据排序顺序的另一个名称。按最常用的查找进行排序将使查询更快id
-标识文档的一组列
配置
table
-你想给这个表系列起什么名字top_level_fields
-BigQuery要求控制列是顶级的。在这里定义它们。在partition
-field
-用于对表进行分区的点分隔字段(必须是time
数据类型)expire
-当BigQuery自动删除数据时。在
id
-文件的标识field
-唯一标识此文档的列集version
-用于确定文档期限的列;用旧的替换较新的
cluster
-用于对分区进行排序的列schema
-{name:type}dictionary-没有数据时需要;BigQuery需要列定义sharded
-boolean-如果允许此库跟踪多个表,则设置为true
。它允许模式迁移(仅限于扩展),并允许从多台计算机中更快地插入account_info
-BigQuery为connect提供的信息
示例
这是一个复杂的例子。请参见tests/config.json以获取最小的示例。在
{"table":"my_table_name","top_level_fields":{},"partition":{"field":"submit_time","expire":"2year"},"id":{"field":"id","version":"last_modified"},"cluster":["id","last_modified"],"schema":{"id":"integer","submit_time":"time","last_modified":"time"},"sharded":true,"account_info":{"private_key_id":{"$ref":"env://BIGQUERY_PRIVATE_KEY_ID"},"private_key":{"$ref":"env://BIGQUERY_PRIVATE_KEY"},"type":"service_account","project_id":"my-project-id","client_email":"me@my_project.iam.gserviceaccount.com","client_id":"12345","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_x509_cert_url":"https://www.googleapis.com/robot/v1/metadata/x509/my-project.iam.gserviceaccount.com"}}
使用
使用应用程序名设置Dataset
创建表
destination=dataset.get_or_create_table(settings.destination)
请插入文档
destination.extend(documents)
完成后请求合并
destination.merge()
运行测试
派生并克隆此回购。在
git clone https://github.com/klahnakoski/jx-bigquery.git
cd jx-bigquery
pip install -r requirements.txt
您将需要一个googleapi密钥来运行测试。该网站将允许您生成一个并下载一个带有密钥的JSON文件。更新tests/config.json以指向该文件:
# contents of tests/config.json
{
"destination": {
"account_info": {
"$ref": "file:///e:/moz-fx-dev-ekyle-treeherder-a838a7718652.json"
}
},
"constants": {},
"debug": {
"trace": true
}
}
然后你就可以运行测试了
python -m unittest discover tests
NOTE - the tests will create a
testing
dataset and generate/drop tables
- 项目
标签: