Skip to main content

Transform column and table name to desired one

Project description

SQL Refactor

This library contains a class, Refactor, for refactoring a SQL with a given knowledge of tables and column names mapping.

Structur of the knowledge

The knowledge is a dictionary containing the mapping of old_table-new_table and corresponding old_column-new_column.

The structure of the knowledge:

{
    "old_table_name":
    {
        "new_table": "new_table_name",
        "column_knowledge":
        {
            "column_1" : "new_column_1",
            "column_2" : "new_column_2",

        }
        "preserved" : boolean
    },
    .
    .
    .
}

How to use

Code sample:

from sql_refactor import Refactor

# refer to Structure of Knowledge
knowledge = KNOWLEDGE

refactor = Refactor(knowledge)
refactor.refactor('''SELECT column_1, column_2 FROM old_table_name''')

new_query = refactor.result()

Result:

SELECT
  new_column_1 AS column_1,
  new_column_2 AS column_2
FROM
  `new_table_name`

Limitation

This repo is under development which contains some limitations.

Limitations of the sql_parser:

  1. MERGE statement is not supported yet

  2. CREATE [TEMPORARY] FUNCTION is not supported yet

  3. Function call without () is not supported.

    For instance: TIMESTAMP '2021-01-01' can not be parsed, expected TIMESTAMP('2021-01-01')

  4. DECLARE statement is not supported yet

Limitations of the sql_refactor:

  1. Has been tested on non-scripting SQL, and it works fine.
  2. For the scripting SQL, only works if the query only contains CREATE TEMP TABLE + main select

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-refactor-0.0.6.tar.gz (41.3 kB view details)

Uploaded Source

Built Distribution

sql_refactor-0.0.6-py3-none-any.whl (59.0 kB view details)

Uploaded Python 3

File details

Details for the file sql-refactor-0.0.6.tar.gz.

File metadata

  • Download URL: sql-refactor-0.0.6.tar.gz
  • Upload date:
  • Size: 41.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for sql-refactor-0.0.6.tar.gz
Algorithm Hash digest
SHA256 99c30dd7f717df30de7e0c70741fba964f5ab6a51ffd44f8f0593bc42a6de1ad
MD5 ef904b27eca661cd06cefacbf5ef029e
BLAKE2b-256 524196609abd6b5d4d19f1f0a628165d309c0d9e0b61c623afc8a9163ffcc7f6

See more details on using hashes here.

File details

Details for the file sql_refactor-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: sql_refactor-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 59.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for sql_refactor-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 6577aecd6b97fa77fbe41b3dc5f90752d2b3d98a94c74de556fcb77fea135a28
MD5 13bb92d5577c69609175ad2cd07beb5b
BLAKE2b-256 40c3e1bdf0241a95b668b88da5b4f20a164bca89eb43d190cf328c0f0825e8b0

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