Skip to content

Commit

Permalink
Merge pull request #3 from shinichi-takii/feature/miner_enhancement
Browse files Browse the repository at this point in the history
miner enhancement
  • Loading branch information
Shinichi Takii authored Jan 14, 2018
2 parents 9099bb3 + 71d3fe0 commit b64e29d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ exclude README.md
include requirements.txt
include test-requirements.txt
include setup.cfg
include tox.ini
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand Down Expand Up @@ -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():
Expand All @@ -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

Expand Down
17 changes: 12 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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 <LICENSE>`__
`BSD 3-Clause License <LICENSE.md>`__

Author
------
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion ddlparse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = '[email protected]'
Expand Down
3 changes: 1 addition & 2 deletions ddlparse/ddlparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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")
Expand Down
11 changes: 7 additions & 4 deletions example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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():
Expand All @@ -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"])

0 comments on commit b64e29d

Please sign in to comment.