{"id":15041244,"url":"https://github.com/zbrookle/sql_to_ibis","last_synced_at":"2025-04-14T06:42:31.293Z","repository":{"id":40580465,"uuid":"267915008","full_name":"zbrookle/sql_to_ibis","owner":"zbrookle","description":"A Python package that parses sql and converts it to ibis expressions","archived":false,"fork":false,"pushed_at":"2023-11-17T21:47:44.000Z","size":511,"stargazers_count":54,"open_issues_count":12,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-27T20:22:58.480Z","etag":null,"topics":["data","databases","dataframes","etl","hacktoberfest","ibis","sql"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zbrookle.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-29T17:20:06.000Z","updated_at":"2025-03-03T15:23:43.000Z","dependencies_parsed_at":"2024-09-25T01:45:02.789Z","dependency_job_id":null,"html_url":"https://github.com/zbrookle/sql_to_ibis","commit_stats":{"total_commits":273,"total_committers":2,"mean_commits":136.5,"dds":0.00366300366300365,"last_synced_commit":"8908bcd468e843c5c467d01c50d1ac5c7004ea6f"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbrookle%2Fsql_to_ibis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbrookle%2Fsql_to_ibis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbrookle%2Fsql_to_ibis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbrookle%2Fsql_to_ibis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zbrookle","download_url":"https://codeload.github.com/zbrookle/sql_to_ibis/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248837260,"owners_count":21169373,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data","databases","dataframes","etl","hacktoberfest","ibis","sql"],"created_at":"2024-09-24T20:45:48.351Z","updated_at":"2025-04-14T06:42:31.245Z","avatar_url":"https://github.com/zbrookle.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"sql_to_ibis\n===========\n\n.. image:: https://github.com/zbrookle/sql_to_ibis/workflows/CI/badge.svg?branch=master\n    :target: https://github.com/zbrookle/sql_to_ibis/actions?query=workflow\n\n.. image:: https://pepy.tech/badge/sql-to-ibis\n    :target: https://pepy.tech/project/sql-to-ibis\n\n.. image:: https://img.shields.io/pypi/l/sql_to_ibis.svg\n    :target: https://github.com/zbrookle/sql_to_ibis/blob/master/LICENSE.txt\n\n.. image:: https://img.shields.io/pypi/status/sql_to_ibis.svg\n    :target: https://pypi.python.org/pypi/sql_to_ibis/\n\n.. image:: https://img.shields.io/pypi/v/sql_to_ibis.svg\n    :target: https://pypi.python.org/pypi/sql_to_ibis/\n\n.. image:: https://codecov.io/gh/zbrookle/sql_to_ibis/branch/master/graph/badge.svg?\n    :target: https://codecov.io/gh/zbrookle/sql_to_ibis\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/psf/black\n\n``sql_to_ibis`` is a Python_ package that translates SQL syntax into ibis_ expressions.\nThis provides the capability of using only one SQL dialect to target many different\nbackends\n\n.. _Python: https://www.python.org/\n.. _ibis: https://github.com/ibis-project/ibis\n\nInstallation\n------------\n\n.. code-block:: bash\n\n    pip install sql_to_ibis\n\nUsage\n-----\n\nRegistering and removing temp tables\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nTo use an ibis table in sql_to_ibis you must register it. Note that for joins or\nqueries that involve more than one table you must use the same ibis client when\ncreating both ibis tables. Once the table is registered you can query it using SQL\nwith the *query* function. In the example below, we create and query a pandas DataFrame\n\n.. code-block:: python\n\n    import ibis.pandas\n    import pandas\n    import sql_to_ibis\n\n    df = pandas.DataFrame({\"column1\": [1, 2, 3], \"column2\": [\"4\", \"5\", \"6\"]})\n    ibis_table = ibis.pandas.Backend().from_dataframe(\n        df, name=\"my_table\", client=ibis.pandas.connect({})\n    )\n    sql_to_ibis.register_temp_table(ibis_table, \"my_table\")\n    sql_to_ibis.query(\n        \"select column1, cast(column2 as integer) + 1 as my_col2 from my_table\"\n    ).execute()\n\nThis would output a DataFrame that looks like:\n\n+---------+---------+\n| column1 | my_col2 |\n+=========+=========+\n| 1       | 5       |\n+---------+---------+\n| 2       | 6       |\n+---------+---------+\n| 3       | 7       |\n+---------+---------+\n\n\nSQL Syntax\n----------\nThe sql syntax for sql_to_ibis is as follows (Note that all syntax is case insensitive):\n\nSelect statement\n~~~~~~~~~~~~~~~~\n\n.. code-block:: SQL\n\n    SELECT [{ ALL | DISTINCT }]\n        { [ \u003cexpression\u003e ] | \u003cexpression\u003e [ [ AS ] \u003calias\u003e ] } [, ...]\n    [ FROM \u003cfrom_item\u003e  [, ...] ]\n    [ WHERE \u003cbool_expression\u003e ]\n    [ GROUP BY { \u003cexpression\u003e [, ...] } ]\n    [ HAVING \u003cbool_expression\u003e ]\n\n\nExample:\n\n.. code-block:: SQL\n\n    SELECT\n        column4,\n        Sum(column1)\n    FROM\n        my_table\n    WHERE\n        column3 = 'yes'\n        AND column2 = 'no'\n    GROUP BY\n        column4\n\nNote that columns with spaces in them can be expressed using double quotes. For example:\n\n.. code-block:: SQL\n\n    SELECT\n        \"my column 1\",\n        column2 as \"the second column\"\n    FROM\n        my_table\n\n\nSet operations\n~~~~~~~~~~~~~~\n\n.. code-block:: SQL\n\n    \u003cselect_statement1\u003e\n    {UNION [DISTINCT] | UNION ALL | INTERSECT [DISTINCT] | EXCEPT [DISTINCT] | EXCEPT ALL}\n    \u003cselect_statment2\u003e\n\n\nExample:\n\n.. code-block:: SQL\n\n    SELECT\n        *\n    FROM\n        table1\n    UNION\n    SELECT\n        *\n    FROM\n        table2\n\n\nJoins\n~~~~~\n\n.. code-block:: SQL\n\n    INNER, CROSS, FULL OUTER, LEFT OUTER, RIGHT OUTER, FULL, LEFT, RIGHT\n\n\n.. code-block:: SQL\n\n    SELECT\n       *\n    FROM\n       table1\n       CROSS JOIN\n          table2\n\n\n.. code-block:: SQL\n\n    SELECT\n        *\n    FROM\n        table1\n    JOIN\n        table2\n            ON table1.column1 = table2.column1\n\n\nOrder by and limit\n~~~~~~~~~~~~~~~~~~\n\n.. code-block:: SQL\n\n    \u003cset\u003e\n    [ORDER BY \u003cexpression\u003e]\n    [LIMIT \u003cnumber\u003e]\n\n\nExample:\n\n.. code-block:: SQL\n\n    SELECT\n       *\n    FROM\n       table1\n    ORDER BY\n       column1\n    LIMIT 5\n\nWindowed aggregation\n~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: SQL\n\n    \u003caggregate\u003e() OVER(\n            [PARTITION BY (\u003cexpresssion\u003e [, \u003cexpression\u003e...)]\n            [ORDER_BY (\u003cexpresssion\u003e [, \u003cexpression\u003e...)]\n            [ ( ROWS | RANGE ) ( \u003cpreceding\u003e | BETWEEN \u003cpreceding\u003e AND \u003cfollowing\u003e ) ]\n           )\n\n    \u003cpreceding\u003e: UNBOUNDED PRECEDING | \u003cunsigned_integer\u003e PRECEDING | CURRENT ROW\n    \u003cfollowing\u003e: UNBOUNDED FOLLOWING | \u003cunsigned_integer\u003e FOLLOWING | CURRENT ROW\n\n\nSupported expressions and functions\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n.. code-block:: SQL\n\n    +, -, *, /\n\n.. code-block:: SQL\n\n    CASE WHEN \u003ccondition\u003e THEN \u003cresult\u003e [WHEN ...] ELSE \u003cresult\u003e END\n\n.. code-block:: SQL\n\n    SUM, AVG, MIN, MAX\n\n.. code-block:: SQL\n\n    {RANK | DENSE_RANK} OVER([PARTITION BY (\u003cexpresssion\u003e [, \u003cexpression\u003e...])])\n\n.. code-block:: SQL\n\n    CAST (\u003cexpression\u003e AS \u003cdata_type\u003e)\n\n.. code-block:: SQL\n\n    \u003cexpression\u003e is null\n\n.. code-block:: SQL\n\n    \u003cexpression\u003e is not null\n\n.. code-block:: SQL\n\n    COALESCE(\u003cexpresssion\u003e [, \u003cexpression\u003e...])\n\n* Anything in \u003c\u003e is meant to be some string\n* Anything in [] is optional\n* Anything in {} is grouped together\n\nSupported Data Types for cast expressions include:\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n* VARCHAR, STRING\n* INT16, SMALLINT\n* INT32, INT, INTEGER\n* INT64, BIGINT\n* FLOAT16\n* FLOAT32\n* FLOAT, FLOAT64\n* BOOL\n* DATETIME64, TIMESTAMP\n* CATEGORY\n* OBJECT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbrookle%2Fsql_to_ibis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzbrookle%2Fsql_to_ibis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbrookle%2Fsql_to_ibis/lists"}