diff --git a/CHANGELOG.md b/CHANGELOG.md index 7190598..f26c257 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 1.0.2 +- Miner enhancement + - `ddlparse.py` : Exclude unused module. + - `example.py` : Modified comment. + - `README.md` : Miner fix. + ## 1.0.1 - Miner enhancement diff --git a/MANIFEST.in b/MANIFEST.in index 7728a0b..7f0b9c5 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,4 +4,3 @@ exclude README.md include requirements.txt include test-requirements.txt include setup.cfg -include tox.ini diff --git a/README.md b/README.md index 22e5abf..133fea6 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Coveralls Coverage Status](https://coveralls.io/repos/github/shinichi-takii/ddlparse/badge.svg?branch=master)](https://coveralls.io/github/shinichi-takii/ddlparse?branch=master) [![codecov Coverage Status](https://codecov.io/gh/shinichi-takii/ddlparse/branch/master/graph/badge.svg)](https://codecov.io/gh/shinichi-takii/ddlparse) [![Requirements Status](https://requires.io/github/shinichi-takii/ddlparse/requirements.svg?branch=master)](https://requires.io/github/shinichi-takii/ddlparse/requirements/?branch=master) -[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://github.com/shinichi-takii/ddlparse/blob/master/LICENSE) +[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://github.com/shinichi-takii/ddlparse/blob/master/LICENSE.md) *DDL parase and Convert to BigQuery JSON schema module, available in Python.* @@ -63,16 +63,23 @@ CREATE TABLE My_Schema.Sample_Table ( ); """ +# parse pattern (1) table = DdlParse().parse(sample_ddl) +# parse pattern (2) +parser = DdlParse() +parser.ddl = sample_ddl +table = parser.parse() + print("* TABLE *") print("schema = {} : name = {} : is_temp = {}".format(table.schema, table.name, table.is_temp)) print("* BigQuery Fields *") print(table.to_bigquery_fields()) -print("* BigQuery Fields - column name to lower *") +print("* BigQuery Fields - column name to lower case / upper case *") print(table.to_bigquery_fields(DdlParse.NAME_CASE.lower)) +print(table.to_bigquery_fields(DdlParse.NAME_CASE.upper)) print("* COLUMN *") for col in table.columns.values(): @@ -89,13 +96,13 @@ for col in table.columns.values(): col.to_bigquery_field() )) -print("* Get Column object *") -print(table.columns["Name"]) +print("* Get Column object (case insensitive) *") +print(table.columns["total"]) ``` ## License -[BSD 3-Clause License](LICENSE) +[BSD 3-Clause License](LICENSE.md) ## Author diff --git a/README.rst b/README.rst index ae17e41..ac0e35e 100644 --- a/README.rst +++ b/README.rst @@ -73,16 +73,23 @@ Example ); """ + # parse pattern (1) table = DdlParse().parse(sample_ddl) + # parse pattern (2) + parser = DdlParse() + parser.ddl = sample_ddl + table = parser.parse() + print("* TABLE *") print("schema = {} : name = {} : is_temp = {}".format(table.schema, table.name, table.is_temp)) print("* BigQuery Fields *") print(table.to_bigquery_fields()) - print("* BigQuery Fields - column name to lower *") + print("* BigQuery Fields - column name to lower case / upper case *") print(table.to_bigquery_fields(DdlParse.NAME_CASE.lower)) + print(table.to_bigquery_fields(DdlParse.NAME_CASE.upper)) print("* COLUMN *") for col in table.columns.values(): @@ -99,13 +106,13 @@ Example col.to_bigquery_field() )) - print("* Get Column object *") - print(table.columns["Name"]) + print("* Get Column object (case insensitive) *") + print(table.columns["total"]) License ------- -`BSD 3-Clause License `__ +`BSD 3-Clause License `__ Author ------ @@ -136,4 +143,4 @@ Special Thanks .. |Requirements Status| image:: https://requires.io/github/shinichi-takii/ddlparse/requirements.svg?branch=master :target: https://requires.io/github/shinichi-takii/ddlparse/requirements/?branch=master .. |License| image:: https://img.shields.io/badge/License-BSD%203--Clause-blue.svg - :target: https://github.com/shinichi-takii/ddlparse/blob/master/LICENSE + :target: https://github.com/shinichi-takii/ddlparse/blob/master/LICENSE.md diff --git a/ddlparse/__init__.py b/ddlparse/__init__.py index 34ce4aa..89cf20e 100644 --- a/ddlparse/__init__.py +++ b/ddlparse/__init__.py @@ -8,7 +8,7 @@ from .ddlparse import * __copyright__ = 'Copyright (C) 2018 Shinichi Takii' -__version__ = '1.0.1' +__version__ = '1.0.2' __license__ = 'BSD-3-Clause' __author__ = 'Shinichi Takii' __author_email__ = 'shinichi.takii@gmail.com' diff --git a/ddlparse/ddlparse.py b/ddlparse/ddlparse.py index 293153c..373295c 100644 --- a/ddlparse/ddlparse.py +++ b/ddlparse/ddlparse.py @@ -11,7 +11,7 @@ from collections import OrderedDict from enum import IntEnum -from pyparsing import CaselessKeyword, Forward, Word, Regex, alphanums, unicodeString, \ +from pyparsing import CaselessKeyword, Forward, Word, Regex, alphanums, \ delimitedList, Suppress, Optional, Group, OneOrMore @@ -284,7 +284,6 @@ class DdlParse(DdlParseBase): + Group( Word(alphanums+"_") + Optional(CaselessKeyword("WITHOUT TIME ZONE") ^ CaselessKeyword("WITH TIME ZONE") ^ CaselessKeyword("PRECISION")) - # + Optional(_LPAR + Word(nums+",") + _RPAR) + Optional(_LPAR + Regex(r"\d+\s*,*\s*\d*") + _RPAR) )("type") + Optional(Word(alphanums+"_' "))("constraint") diff --git a/example/example.py b/example/example.py index c2df444..263e34e 100644 --- a/example/example.py +++ b/example/example.py @@ -18,8 +18,10 @@ ); """ +# parse pattern (1) table = DdlParse().parse(sample_ddl) -# or this + +# parse pattern (2) parser = DdlParse() parser.ddl = sample_ddl table = parser.parse() @@ -30,8 +32,9 @@ print("* BigQuery Fields *") print(table.to_bigquery_fields()) -print("* BigQuery Fields - column name to lower *") +print("* BigQuery Fields - column name to lower case / upper case *") print(table.to_bigquery_fields(DdlParse.NAME_CASE.lower)) +print(table.to_bigquery_fields(DdlParse.NAME_CASE.upper)) print("* COLUMN *") for col in table.columns.values(): @@ -48,5 +51,5 @@ col.to_bigquery_field() )) -print("* Get Column object *") -print(table.columns["Name"]) +print("* Get Column object (case insensitive) *") +print(table.columns["total"])