Skip to main content

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

Metadata

Release files for yqml 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yqml 0.0.2
File Size Uploaded
yqml-0.0.2.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yqml 0.0.2
File Interpreter ABI Platform
yqml-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.9 kB

Release files / yqml-0.0.2.tar.gz

Download URL yqml-0.0.2.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fde609ef64b8213af3a72de871d89a09aac76cdc0ab602732464a33958115dcb
BLAKE2b-256 checksum
How to use checksums
fc828d80adeb7fa333d577820981bbc8aeee4d38430701c8a4713000bb01c1fc
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / yqml-0.0.2-py3-none-any.whl

Download URL yqml-0.0.2-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62b6d3631062ae4f04cfdd053c9f25e99727e5ae988a158a5e8a48f99cd44e88
BLAKE2b-256 checksum
How to use checksums
96eaed31e476f1198917984534ed2bef4f5fc859d150e630edaeb95cfe56946d
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page