Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinichi Takii committed Jan 5, 2018
1 parent 2a8144f commit fe031b3
Show file tree
Hide file tree
Showing 18 changed files with 1,164 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Changes
- fix # : summary...
51 changes: 4 additions & 47 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# General
.DS_Store
*~

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -25,16 +29,6 @@ wheels/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
Expand All @@ -46,39 +40,9 @@ coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

Expand All @@ -87,13 +51,6 @@ celerybeat-schedule
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

Expand Down
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
language: python

python:
- "3.4"
- "3.5"
- "3.6"

# command to install dependencies
install:
- pip install -r requirements.txt
- pip install -r test-requirements.txt

# command to run tests
script:
- pytest

after_success:
- coveralls
- codecov
- codeclimate-test-reporter
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changelog

## 1.0.0
First released
2 changes: 1 addition & 1 deletion LICENSE → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2018, Shinichi Takii
Copyright (c) 2018, Shinichi Takii
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include README.md
include requirements.txt
include test-requirements.txt
include setup.cfg
include tox.ini
113 changes: 111 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,111 @@
# ddlparse
DDL parase and Convert to BigQuery JSON schema
# DDL Parse

[![PyPI version](https://img.shields.io/pypi/v/ddlparse.svg)](https://pypi.python.org/pypi/ddlparse)
[![Python version](https://img.shields.io/pypi/pyversions/ddlparse.svg)](https://pypi.python.org/pypi/ddlparse)
[![Travis CI Build Status](https://travis-ci.org/shinichi-takii/ddlparse.svg?branch=master)](https://travis-ci.org/shinichi-takii/ddlparse)
[![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)

*DDL parase and Convert to BigQuery JSON schema module, available in Python.*

----

## Features

- DDL parse and get table schema information.
- Currently, only the `CREATE TABLE` statement is supported.
- Supported databases are MySQL, PostgreSQL, Oracle, Redshift.
- Convert to [BigQuery JSON schema](https://cloud.google.com/bigquery/docs/schemas#creating_a_json_schema_file).

## Requirement

1. Python >= 3.4
1. [pyparsing](http://pyparsing.wikispaces.com/)

## Installation

### Install

pip install:
```bash
$ pip install ddlparse
```

command install:
```bash
$ python setup.py install
```

### Update

pip update:
```bash
$ pip install ddlparse --upgrade
```

## Usage

### Example

```python
from ddlparse import DdlParse

sample_ddl = """
CREATE TABLE My_Schema.Sample_Table (
ID integer PRIMARY KEY,
NAME varchar(100) NOT NULL,
TOTAL bigint NOT NULL,
AVG decimal(5,1) NOT NULL,
CREATED_AT timestamp,
UNIQUE (NAME)
);
"""

table = DdlParse().parse(sample_ddl)

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(table.to_bigquery_fields(DdlParse.NAME_CASE.lower))

print("* COLUMN *")
for col in table.columns.values():
print("name = {} : data_type = {} : length = {} : precision(=length) = {} : scale = {} : constraint = {} : not_null = {} : PK = {} : unique = {} : BQ {}".format(
col.name,
col.data_type,
col.length,
col.precision,
col.scale,
col.constraint,
col.not_null,
col.primary_key,
col.unique,
col.to_bigquery_field()
))

print("* Get Column object *")
print(table.columns["Name"])
```

## License

[BSD 3-Clause License](LICENSE)

## Author

Shinichi Takii <shinichi.takii@gmail.com>

## Links

- Repository : https://github.com/shinichi-takii/ddlparse
- PyPI Package : https://pypi.python.org/pypi/ddlparse

## Special Thanks

- pyparsing : http://pyparsing.wikispaces.com/
139 changes: 139 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
DDL Parse
=========

|PyPI version| |Python version| |Travis CI Build Status| |Coveralls
Coverage Status| |codecov Coverage Status| |Requirements Status|
|License|

*DDL parase and Convert to BigQuery JSON schema module, available in
Python.*

--------------

Features
--------

- DDL parse and get table schema information.
- Currently, only the ``CREATE TABLE`` statement is supported.
- Supported databases are MySQL, PostgreSQL, Oracle, Redshift.
- Convert to `BigQuery JSON
schema <https://cloud.google.com/bigquery/docs/schemas#creating_a_json_schema_file>`__.

Requirement
-----------

1. Python >= 3.4
2. `pyparsing <http://pyparsing.wikispaces.com/>`__

Installation
------------

Install
~~~~~~~

pip install:

.. code:: bash
$ pip install ddlparse
command install:

.. code:: bash
$ python setup.py install
Update
~~~~~~

pip update:

.. code:: bash
$ pip install ddlparse --upgrade
Usage
-----

Example
~~~~~~~

.. code:: python
from ddlparse import DdlParse
sample_ddl = """
CREATE TABLE My_Schema.Sample_Table (
ID integer PRIMARY KEY,
NAME varchar(100) NOT NULL,
TOTAL bigint NOT NULL,
AVG decimal(5,1) NOT NULL,
CREATED_AT timestamp,
UNIQUE (NAME)
);
"""
table = DdlParse().parse(sample_ddl)
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(table.to_bigquery_fields(DdlParse.NAME_CASE.lower))
print("* COLUMN *")
for col in table.columns.values():
print("name = {} : data_type = {} : length = {} : precision(=length) = {} : scale = {} : constraint = {} : not_null = {} : PK = {} : unique = {} : BQ {}".format(
col.name,
col.data_type,
col.length,
col.precision,
col.scale,
col.constraint,
col.not_null,
col.primary_key,
col.unique,
col.to_bigquery_field()
))
print("* Get Column object *")
print(table.columns["Name"])
License
-------

`BSD 3-Clause License <LICENSE>`__

Author
------

Shinichi Takii shinichi.takii@gmail.com

Links
-----

- Repository : https://github.com/shinichi-takii/ddlparse
- PyPI Package : https://pypi.python.org/pypi/ddlparse

Special Thanks
--------------

- pyparsing : http://pyparsing.wikispaces.com/

.. |PyPI version| image:: https://img.shields.io/pypi/v/ddlparse.svg
:target: https://pypi.python.org/pypi/ddlparse
.. |Python version| image:: https://img.shields.io/pypi/pyversions/ddlparse.svg
:target: https://pypi.python.org/pypi/ddlparse
.. |Travis CI Build Status| image:: https://travis-ci.org/shinichi-takii/ddlparse.svg?branch=master
:target: https://travis-ci.org/shinichi-takii/ddlparse
.. |Coveralls Coverage Status| image:: https://coveralls.io/repos/github/shinichi-takii/ddlparse/badge.svg?branch=master
:target: https://coveralls.io/github/shinichi-takii/ddlparse?branch=master
.. |codecov Coverage Status| image:: https://codecov.io/gh/shinichi-takii/ddlparse/branch/master/graph/badge.svg
:target: https://codecov.io/gh/shinichi-takii/ddlparse
.. |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
17 changes: 17 additions & 0 deletions ddlparse/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 Shinichi Takii, shinichi.takii@gmail.com
#
# This module is part of python-ddlparse and is released under
# the BSD License: https://opensource.org/licenses/BSD-3-Clause

from .ddlparse import *

__copyright__ = 'Copyright (C) 2018 Shinichi Takii'
__version__ = '1.0.0'
__license__ = 'BSD-3-Clause'
__author__ = 'Shinichi Takii'
__author_email__ = 'shinichi.takii@gmail.com'
__url__ = 'http://github.com/shinichi-takii/ddlparse'

__all__ = ['DdlParse', 'DdlParseTable', 'DdlParseColumn', 'DdlParseColumnDict']

0 comments on commit fe031b3

Please sign in to comment.