Skip to content

Commit 61d72a8

Browse files
committed
release 1.4.0 temp + is_global for oracle
1 parent d1c0a63 commit 61d72a8

File tree

11 files changed

+18240
-18069
lines changed

11 files changed

+18240
-18069
lines changed

CHANGELOG.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
**v1.4.0**
2+
3+
### Fixes
4+
#### BigQuery:
5+
1. Indexes without schema causes issues in BigQuery dialect - fixed.
6+
7+
### Improvements
8+
#### Oracle:
9+
1. Added new output keywords in table definition - `temp` & `is_global`. Added support for create global temporary table - https://github.com/xnuinside/simple-ddl-parser/issues/182
10+
11+
112
**v1.3.0**
213

314
### Fixes

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,17 @@ for help with debugging & testing support for BigQuery dialect DDLs:
486486

487487

488488
## Changelog
489+
**v1.4.0**
490+
491+
### Fixes
492+
#### BigQuery:
493+
1. Indexes without schema causes issues in BigQuery dialect - fixed.
494+
495+
### Improvements
496+
#### Oracle:
497+
1. Added new output keywords in table definition - `temp` & `is_global`. Added support for create global temporary table - https://github.com/xnuinside/simple-ddl-parser/issues/182
498+
499+
489500
**v1.3.0**
490501

491502
### Fixes

docs/README.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,26 @@ for help with debugging & testing support for BigQuery dialect DDLs:
549549
Changelog
550550
---------
551551

552+
**v1.4.0**
553+
554+
Fixes
555+
^^^^^
556+
557+
BigQuery:
558+
~~~~~~~~~
559+
560+
561+
#. Indexes without schema causes issues in BigQuery dialect - fixed.
562+
563+
Improvements
564+
^^^^^^^^^^^^
565+
566+
Oracle:
567+
~~~~~~~
568+
569+
570+
#. Added new output keywords in table definition - ``temp`` & ``is_global``. Added support for create global temporary table - https://github.com/xnuinside/simple-ddl-parser/issues/182
571+
552572
**v1.3.0**
553573

554574
Fixes

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "simple-ddl-parser"
3-
version = "1.3.0"
3+
version = "1.4.0"
44
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."
55
authors = ["Iuliia Volkova <[email protected]>"]
66
license = "MIT"

simple_ddl_parser/dialects/sql.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def p_create_table(self, p: List):
161161
| CREATE OR REPLACE TABLE
162162
| CREATE id TABLE IF NOT EXISTS
163163
| CREATE id TABLE
164+
| CREATE id id TABLE
164165
| CREATE OR REPLACE id TABLE IF NOT EXISTS
165166
| CREATE OR REPLACE id TABLE
166167
@@ -173,14 +174,21 @@ def p_create_table(self, p: List):
173174

174175
if "REPLACE" in p_list:
175176
p[0]["replace"] = True
176-
177-
id_key = p_list[4] if "REPLACE" in p_list else p_list[2]
177+
if "REPLACE" in p_list:
178+
id_key = p_list[4]
179+
elif len(p_list) == 5:
180+
id_key = p_list[3]
181+
else:
182+
id_key = p_list[2]
178183
id_key = id_key.upper()
179-
180184
if id_key in ["EXTERNAL", "TRANSIENT"]:
181185
p[0][id_key.lower()] = True
186+
elif id_key in ["GLOBAL"]:
187+
p[0]["is_global"] = True
182188
elif id_key in ["TEMP", "TEMPORARY"]:
183189
p[0]["temp"] = True
190+
if len(p_list) == 5 and p_list[2].upper() == "GLOBAL":
191+
p[0]["is_global"] = True
184192

185193

186194
class Column:

simple_ddl_parser/output/core.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,21 @@ def get_table_from_tables_data(self, schema: str, table_name: str) -> Dict:
3838
return target_table
3939

4040
def clean_up_index_statement(self, statement: Dict) -> None:
41-
del statement[self.schema_key]
41+
try:
42+
del statement[self.schema_key]
43+
except KeyError:
44+
del statement["schema"]
4245
del statement["table_name"]
4346

4447
if self.output_mode != "mssql":
4548
del statement["clustered"]
4649

4750
def add_index_to_table(self, statement: Dict) -> None:
4851
"""populate 'index' key in output data"""
52+
4953
target_table = self.get_table_from_tables_data(
50-
statement[self.schema_key], statement["table_name"]
54+
statement.get(self.schema_key) or statement.get("schema"),
55+
statement["table_name"],
5156
)
5257
self.clean_up_index_statement(statement)
5358
target_table.index.append(statement)

simple_ddl_parser/output/dialects.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class MySSQL(Dialect):
101101
@dataclass
102102
@dialect(name="bigquery")
103103
class BigQuery(Dialect):
104-
dataset: Optional[str] = field(default=False)
104+
dataset: Optional[str] = field(default=None)
105105
project: Optional[str] = field(
106106
default=None, metadata={"exclude_if_not_provided": True}
107107
)
@@ -186,6 +186,7 @@ class PostgreSQL(Dialect):
186186
class Oracle(Dialect):
187187
# https://oracle-base.com/articles/8i/index-organized-tables
188188

189+
is_global: Optional[bool] = field(default=False)
189190
organization_index: Optional[bool] = field(
190191
default=False, metadata={"exclude_if_not_provided": True}
191192
)
@@ -253,7 +254,7 @@ class CommonDialectsFieldsMixin(Dialect):
253254
"""base fields & mixed between dialects"""
254255

255256
temp: Optional[bool] = field(
256-
default=False, metadata={"output_modes": add_dialects([HQL, Redshift])}
257+
default=False, metadata={"output_modes": add_dialects([HQL, Redshift, Oracle])}
257258
)
258259
tblproperties: Optional[dict] = field(
259260
default_factory=dict,

simple_ddl_parser/output/table_data.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def pre_load_mods(cls, main_cls, kwargs):
6363
table_properties = {
6464
k.lower(): v for k, v in kwargs.items() if k.lower() not in table_main_args
6565
}
66-
6766
init_data = {}
6867
init_data.update(table_main_args)
6968
init_data.update(table_properties)

simple_ddl_parser/parsetab.py

Lines changed: 18074 additions & 18060 deletions
Large diffs are not rendered by default.

tests/dialects/test_bigquery.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,3 +994,46 @@ def test_date_trunc():
994994
]
995995

996996
assert result == expected
997+
998+
999+
def test_index_without_schema():
1000+
ddl = """CREATE TABLE t1 (
1001+
val INT,
1002+
);
1003+
CREATE INDEX idx1 ON t1(val);"""
1004+
1005+
result = DDLParser(ddl).run(output_mode="bigquery")
1006+
expected = [
1007+
{
1008+
"alter": {},
1009+
"checks": [],
1010+
"columns": [
1011+
{
1012+
"check": None,
1013+
"default": None,
1014+
"name": "val",
1015+
"nullable": True,
1016+
"references": None,
1017+
"size": None,
1018+
"type": "INT",
1019+
"unique": False,
1020+
}
1021+
],
1022+
"dataset": None,
1023+
"index": [
1024+
{
1025+
"columns": ["val"],
1026+
"detailed_columns": [
1027+
{"name": "val", "nulls": "LAST", "order": "ASC"}
1028+
],
1029+
"index_name": "idx1",
1030+
"unique": False,
1031+
}
1032+
],
1033+
"partitioned_by": [],
1034+
"primary_key": [],
1035+
"table_name": "t1",
1036+
"tablespace": None,
1037+
}
1038+
]
1039+
assert expected == result

0 commit comments

Comments
 (0)