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:
-
MERGEstatement is not supported yet -
CREATE [TEMPORARY] FUNCTIONis not supported yet -
Function call without
()is not supported.For instance:
TIMESTAMP '2021-01-01'can not be parsed, expectedTIMESTAMP('2021-01-01') -
DECLAREstatement is not supported yet
Limitations of the sql_refactor:
- Has been tested on non-scripting SQL, and it works fine.
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99c30dd7f717df30de7e0c70741fba964f5ab6a51ffd44f8f0593bc42a6de1ad
|
|
| MD5 |
ef904b27eca661cd06cefacbf5ef029e
|
|
| BLAKE2b-256 |
524196609abd6b5d4d19f1f0a628165d309c0d9e0b61c623afc8a9163ffcc7f6
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6577aecd6b97fa77fbe41b3dc5f90752d2b3d98a94c74de556fcb77fea135a28
|
|
| MD5 |
13bb92d5577c69609175ad2cd07beb5b
|
|
| BLAKE2b-256 |
40c3e1bdf0241a95b668b88da5b4f20a164bca89eb43d190cf328c0f0825e8b0
|