Skip to main content

YAML based query language

Project description

YQML

YAML based query language.

This library will help you convert a YAML into a Query script.

Why using YAML for the query?

The query is purely text, hard to parse and convert into any form that we want. Also programming language can't read query text properly. But YAML does.

If you have a query that become a source of truth in your service, and need to be convertible or extract to every form let say json/yaml/erd/schema/others then this is the answer.

By using YQML, you write the Query in YAML format and it's transformable into SQL syntax.

Advantage

  • Your query will be easy to read by your programming language, since its YAML
  • Your query is not isolated with Query engine (say Postgres, MySQL, Bigquery), when you're doing some migration, your query is safe.
  • you can use sharing function / available yqml library around the world to get you covered, say for building SCD table, Fact accumulated, etc
  • You can apply any templating/function before render into some query

Sample

SQL YQML
-- simple syntax
SELECT
  id, 
  name,
  address
FROM 
  persons
select:
  - id
  - name
  - address
from: persons
-- syntax with CTE
WITH
raw_data AS (
SELECT
  id, 
  name as person_name,
  left(address,10) as address
FROM 
  persons
WHERE
  id > 1213
)
SELECT
  address, 
  count(*) total_person
FROM raw_data
GROUP BY 1
with:
  raw_data:
    select:
      - name: id
      - name: person_name
        source: name
      - aname: address
        source: left(address,10)
    from: persons
    where: >
      id > 1213

  select: 
    - name: address
    - name: total_persons
      source: count(*)
  from: raw_data
  group_by:
    - address
-- syntax with complex templating/function
WITH
scd_type2_raw AS (
SELECT
  id, 
  name as person_name,
  left(address,10) as address
FROM 
  persons
)
-- ..... 1000lines more here
SELECT
  person_id, 
  person_name,
  person_address
FROM semi_final_raw
function:
  - log_to_scd_type2

log_to_scd_type2:
  select: 
    - name: person_id
      source: id
    - name: person_name
      source: name
    - name: person_address
      source: address
  from:
    persons

Installation

Use the package manager pip to install yqml.

pip install yqml

Usage

from yqml.yqml import YQML

import yaml

content = yaml.safe_load(file)
engine = YQML(content, engine='bigquery')

sql = engine.to_sql()
print(sql)

What's supported now

  • Supporting simple SQL (Select, From, Where, Join)

TODO

  • Supporting CTE
  • Supporting MERGE
  • Supporting Scripting
  • Better to handling multiple JOIN statement
  • Supporting function import / tmplating

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yqml-0.0.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

yqml-0.0.2-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file yqml-0.0.2.tar.gz.

File metadata

  • Download URL: yqml-0.0.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.8

File hashes

Hashes for yqml-0.0.2.tar.gz
Algorithm Hash digest
SHA256 fde609ef64b8213af3a72de871d89a09aac76cdc0ab602732464a33958115dcb
MD5 1f0f1d4e9c660fe16f7cae8db9f3502c
BLAKE2b-256 fc828d80adeb7fa333d577820981bbc8aeee4d38430701c8a4713000bb01c1fc

See more details on using hashes here.

File details

Details for the file yqml-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: yqml-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.8

File hashes

Hashes for yqml-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 62b6d3631062ae4f04cfdd053c9f25e99727e5ae988a158a5e8a48f99cd44e88
MD5 df6048a50d4e1bb6b3b608cf1033de78
BLAKE2b-256 96eaed31e476f1198917984534ed2bef4f5fc859d150e630edaeb95cfe56946d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page