Skip to main content

Add your description here

Project description

SQL Complexity Estimator

This package provides a simple algorithm to calculate complexity of SQL expressions.

It's based on SQLGlot abstract syntax tree, so the provided SQL must be compatible with SQLGlot engines.

The rules are the following:

  • +1 per join expression
  • +1 per predicate after WHERE or HAVING
  • +1 per CTE
  • +1 per GROUP BY expression
  • +1 per UNION or INTERSECT
  • +1 per function call
  • +1 per CASE expression

This package is inspired on the comments of this stack overflow thread.

Install

python -m pip install sql-complexity
poetry add sql-complexity
uv add sql-complexity

Run with uvx

uvx --refresh sql-complexity

Run from the CLI

sql-complexity some.sql
cat myfile.sql | sql-complexity

Using it in your code

from sql_complexity import SQLComplexityAssessment

assessor = SQLComplexityAssessment()
score = assessor.assess(contents)
print(score)
print(score.total)

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

sql_complexity-0.1.4.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sql_complexity-0.1.4-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file sql_complexity-0.1.4.tar.gz.

File metadata

  • Download URL: sql_complexity-0.1.4.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for sql_complexity-0.1.4.tar.gz
Algorithm Hash digest
SHA256 27f12e6c5b2d0ffb15f5f3160af1e4b33140a197579f9b0fa0bff79ac9374b80
MD5 dd8d2a8c5488366aacf42377a97fb95a
BLAKE2b-256 77a56fb993170709accc369eb9c804e212eb3bc1f25c025c055be20aff8a3a3e

See more details on using hashes here.

File details

Details for the file sql_complexity-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for sql_complexity-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ba74be09be0af2e09b4945ecbafcaff7662dbd07c632339820c59fe989b7e4ca
MD5 e1fbc5239ca02e06a364a29c64a95f71
BLAKE2b-256 0da86d4bd23061241dfc90cce64fdda906f605016153f42d315c2d003ac44ac8

See more details on using hashes here.

Supported by

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