Giter Site home page Giter Site logo

big-orm's Introduction

BigOrm

本 package 真正處理 orm 的部份由 ibis 處理,目前主要在處理:

  1. query code 跟 bigquery 的連接,方便使用
  2. 把 impala 轉成 bigquery 吃的 SQL 2011 standard

兩個部分的功能。


安裝方式

pip install big-orm



使用方式,建構 big-orm object

from big_orm import bq, orm

bqh = bq.BQHandler(project_id='{{ project_id }}', credential_path="{{ credential_path }}")
bqorm = orm.BQOrm(bq_handler=bqh)



然後就可以開始使用了,假設我要從一個 Table [IntegratedTable.Info_Content] 裡面,特別找出三年級的數學練習題的資訊

# 列出對象 table 的 bigquery 位置
info_content_addr = "IntegratedTable.Info_Content"

# 建構該 Table
info_content = bqorm.build_ibis_tb(info_content_addr)

# 針對該 Table 做處理
exercise_in_grade3 = info_content[(info_content.content_kind == "Exercise") & (info_content.level1_name == "數學(年級式)") & ((info_content.level2_name == "數學 小三"))]



基本上在使用 bqorm 建構完 ibis_table 之後(在上面的例子中為 info_content),之後的處理都是依循 ibis 的 document

處理完的結果,可以再藉由 bqorm 直接獲得結果,並轉為 pandas dataframe

df = bqorm.get_df(exercise_in_grade3)
df.head()

exercise_in_grade3_output



如果你想看到產生的 query,可以使用 get_sql function

sql= bqorm.get_sql(exercise_in_grade3)
print sql

這樣就可以看到 sql code

#standardSQL
SELECT *
FROM IntegratedTable.Info_Content
WHERE ((`content_kind` = 'Exercise') AND (`level1_name` = '數學(年級式)')) AND (`level2_name` = '數學 小三')

祝您使用愉快

big-orm's People

Contributors

fonyou avatar

Stargazers

Delphi Kuo avatar pcboy avatar young_tsai avatar

Watchers

James Cloos avatar Shinjou avatar  avatar 呂冠緯 avatar young_tsai avatar  avatar pcboy avatar junyisupport avatar

big-orm's Issues

bq.py 的 query_to_table() fail

目前bigorm 這隻 bq.py 的 query_to_table() 會爆掉

self.check_bq_job_status(job['id'].replace(job_id_start_with, ""))

因為 job[‘id’] 格式有變(多了US.) 像是這樣

"id": "junyiacademy:US.job_-gpIPTLpwcM8B5tOJnGNJmpOUido",

建議換成
self.check_bq_job_status(job['jobReference']['jobId'])
就可以了!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.