基于json表模式描述符生成bigquery表,加载和提取数据。
jsontableschema-bigquer的Python项目详细描述
基于json表模式生成和加载bigquery表 描述符。
Version ^{tt1}$ contains breaking changes:
- 将Storage.tables重命名为Storage.buckets
- 将Storage.read更改为读入内存
- 添加了Storage.iter以逐行生成
开始
安装
pip install jsontableschema-bigquery
储存
包实现Tabular Storage 接口。
开始使用google bigquery服务:
我们可以通过这种方式获得存储空间:
importioimportosimportjsonfromapiclient.discoveryimportbuildfromoauth2client.clientimportGoogleCredentialsfromjsontableschema_bigqueryimportStorageos.environ['GOOGLE_APPLICATION_CREDENTIALS']='.credentials.json'credentials=GoogleCredentials.get_application_default()service=build('bigquery','v2',credentials=credentials)project=json.load(io.open('.credentials.json',encoding='utf-8'))['project_id']storage=Storage(service,project,'dataset',prefix='prefix')
然后我们可以与存储交互:
storage.bucketsstorage.create('bucket',descriptor)storage.delete('bucket')storage.describe('bucket')# return descriptorstorage.iter('bucket')# yields rowsstorage.read('bucket')# return rowsstorage.write('bucket',rows)
映射
schema.json -> bigquery table schema data.csv -> bigquery talbe data
司机
使用默认的google bigquery客户端- docs。