Skip to content

Commit

Permalink
version 0.29.1
Browse files Browse the repository at this point in the history
  • Loading branch information
xnuinside committed Jan 7, 2023
1 parent 8dd488a commit 5b140ae
Show file tree
Hide file tree
Showing 9 changed files with 411 additions and 288 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
**v0.29.1**
### Important updates:
1. Python 3.6 is deprecated in tests and by default, try to move to Python3.7, but better to 3.8, because 3.7 will be deprecated in 2023.

### Fixes
1. Fix for https://github.com/xnuinside/simple-ddl-parser/issues/177

### Imporvements
1. Added support for Oracle 2 component size for types, like '30 CHAR'. From https://github.com/xnuinside/simple-ddl-parser/issues/176


**v0.29.0**

Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,17 @@ https://github.com/swiatek25


## Changelog
**v0.29.1**
### Important updates:
1. Python 3.6 is deprecated in tests and by default, try to move to Python3.7, but better to 3.8, because 3.7 will be deprecated in 2023.

### Fixes
1. Fix for https://github.com/xnuinside/simple-ddl-parser/issues/177

### Imporvements
1. Added support for Oracle 2 component size for types, like '30 CHAR'. From https://github.com/xnuinside/simple-ddl-parser/issues/176


**v0.29.0**

### Fixes
Expand Down
20 changes: 20 additions & 0 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,26 @@ https://github.com/swiatek25
Changelog
---------

**v0.29.1**

Important updates:
^^^^^^^^^^^^^^^^^^


#. Python 3.6 is deprecated in tests and by default, try to move to Python3.7, but better to 3.8, because 3.7 will be deprecated in 2023.

Fixes
^^^^^


#. Fix for https://github.com/xnuinside/simple-ddl-parser/issues/177

Imporvements
^^^^^^^^^^^^


#. Added support for Oracle 2 component size for types, like '30 CHAR'. From https://github.com/xnuinside/simple-ddl-parser/issues/176

**v0.29.0**

Fixes
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "simple-ddl-parser"
version = "0.29.0"
version = "0.29.1"
description = "Simple DDL Parser to parse SQL & dialects like HQL, TSQL (MSSQL), Oracle, AWS Redshift, Snowflake, MySQL, PostgreSQL, etc ddl files to json/python dict with full information about columns: types, defaults, primary keys, etc.; sequences, alters, custom types & other entities from ddl."
authors = ["Iuliia Volkova <[email protected]>"]
license = "MIT"
Expand Down
5 changes: 5 additions & 0 deletions simple_ddl_parser/ddl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ def p_id(self, p):
if p[0].startswith(symbol) and p[0].endswith(delimeters_to_end[num]):
p[0] = p[0][1:-1]

def p_id_or_string(self, p):
"""id_or_string : id
| STRING"""
p[0] = p[1]

def t_error(self, t: LexToken):
raise DDLParserError("Unknown symbol %r" % (t.value[0],))

Expand Down
22 changes: 18 additions & 4 deletions simple_ddl_parser/dialects/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,30 @@ def check_type_parameter(size: Union[tuple, int]) -> bool:
return True
return False

@staticmethod
def process_oracle_type_size(p_list):
if p_list[-1] == ')' and p_list[-4] == '(':
# for Oracle sizes like 30 CHAR
p_list[-3] += f" {p_list[-2]}"
del p_list[-2]
return p_list

def p_column(self, p: List) -> None:
"""column : id c_type
| column comment
| column LP id RP
| column LP id id RP
| column LP id RP c_type
| column LP id COMMA id RP
| column LP id COMMA id RP c_type
"""
p[0] = self.set_base_column_propery(p)
p_list = remove_par(list(p))
p_list = list(p)

p_list = self.process_oracle_type_size(p_list)

p_list = remove_par(p_list)

if isinstance(p_list[-1], dict) and "type" in p_list[-1] and len(p_list) <= 3:
p[0]["type"] = p_list[-1]["type"]
if p_list[-1].get("property"):
Expand Down Expand Up @@ -696,10 +710,10 @@ def get_property(self, p_list: List) -> Dict:
return _property

def p_id_equals(self, p: List) -> None:
"""id_equals : id id id
| id id
"""id_equals : id id id_or_string
| id id_or_string
| id_equals COMMA
| id_equals COMMA id id id
| id_equals COMMA id id id_or_string
| id
| id_equals LP pid RP
| id_equals LP pid RP id
Expand Down
567 changes: 285 additions & 282 deletions simple_ddl_parser/parsetab.py

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions tests/dialects/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,3 +825,35 @@ def test_multiple_options_statements():
"types": [],
}
assert expected == result

def test_bigquery_options_string():

result = DDLParser("""
CREATE TABLE data.test ( col STRING OPTIONS(description='test') ) OPTIONS(description='test');
""", normalize_names=True).run(group_by_type=True)

expected = {'ddl_properties': [],
'domains': [],
'schemas': [],
'sequences': [],
'tables': [{'alter': {},
'checks': [],
'columns': [{'check': None,
'default': None,
'name': 'col',
'nullable': True,
'options': [{'description': "'test'"}],
'references': None,
'size': None,
'type': 'STRING',
'unique': False}],
'index': [],
'options': [{'description': "'test'"}],
'partitioned_by': [],
'primary_key': [],
'schema': 'data',
'table_name': 'test',
'tablespace': None}],
'types': []}
assert result == expected
33 changes: 32 additions & 1 deletion tests/dialects/test_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,4 +713,35 @@ def test_organization_index():
"""
result = DDLParser(ddl).run(group_by_type=True)

assert result == expected
assert result == expected



def test_oracle_sizes():
result = DDLParser("""
create table test (
col varchar2(30 char) default user not null
);
""", normalize_names=True).run(group_by_type=True)
expected = {'ddl_properties': [],
'domains': [],
'schemas': [],
'sequences': [],
'tables': [{'alter': {},
'checks': [],
'columns': [{'check': None,
'default': 'user',
'name': 'col',
'nullable': False,
'references': None,
'size': '30 char',
'type': 'varchar2',
'unique': False}],
'index': [],
'partitioned_by': [],
'primary_key': [],
'schema': None,
'table_name': 'test',
'tablespace': None}],
'types': []}
assert result == expected

0 comments on commit 5b140ae

Please sign in to comment.