simple-ddl-parser
simple-ddl-parser copied to clipboard
Snowflake exotism support
Hi,
there is CREATE TABLE statement in Snowflake, created by Matillion where the cluster by property precedes the table column definition, I have no idea where to start the change.
here the acceptance test :
def test_table_inverse_clusterby_and_column_def(): ddl = """CREATE TABLE ${database_name}.MySchemaName."MyTableName" cluster by ("DocProv") (ID NUMBER(38,0) NOT NULL, "DocProv" VARCHAR(2));"""
result = DDLParser(ddl, normalize_names=True, debug=True).run(output_mode="snowflake")
expected = [{'table_name': 'MyTableName',
'schema': 'MySchemaName',
'primary_key': [],
'columns': [{
'name': 'ID',
'size' : (38,0),
'type': 'NUMBER',
'references': None,
'unique': False,
'nullable': False,
'default': None,
'check': None,
},
{
'name': 'DocProv',
'size' : 2,
'type': 'VARCHAR',
'references': None,
'unique': False,
'nullable': True,
'default': None,
'check': None,
}],
'alter': {},
'checks': [],
'index': [],
'partitioned_by': [],
'cluster_by' : ['DocProv'],
'tablespace': None,
'external' : False,
'primary_key_enforced' : None,
'table_properties': {'project': '${database_name}'},
'clone' : None
}]
assert result == expected
@dmaresma you need to add case where cluster by statement can be before columns defenitions. There is main 'table' expression https://github.com/xnuinside/simple-ddl-parser/blob/main/simple_ddl_parser/dialects/sql.py#L1016 it is expect that after table_name should be LP and defcolumn (column description), so you should add here cluster_by statement as a possible variant like table_name cluster_by (or how this statement should be named)
I can add it on weekends
I released in version 1.1.0. Have no idea why I'm writing about weekends, when I didn't have any time( Tests added in PR: https://github.com/xnuinside/simple-ddl-parser/pull/246/files. If will be needed anything - open new issue.