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
Metadata
Release files for sql-refactor 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sql-refactor-0.0.6.tar.gz | 41.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sql_refactor-0.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 100.2 kB
Release files / sql-refactor-0.0.6.tar.gz
| Download URL | sql-refactor-0.0.6.tar.gz |
|---|---|
| Size | 41.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
99c30dd7f717df30de7e0c70741fba964f5ab6a51ffd44f8f0593bc42a6de1ad
|
|
BLAKE2b-256 checksum How to use checksums |
524196609abd6b5d4d19f1f0a628165d309c0d9e0b61c623afc8a9163ffcc7f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / sql_refactor-0.0.6-py3-none-any.whl
| Download URL | sql_refactor-0.0.6-py3-none-any.whl |
|---|---|
| Size | 59.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6577aecd6b97fa77fbe41b3dc5f90752d2b3d98a94c74de556fcb77fea135a28
|
|
BLAKE2b-256 checksum How to use checksums |
40c3e1bdf0241a95b668b88da5b4f20a164bca89eb43d190cf328c0f0825e8b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|