DDL parase and Convert to BigQuery JSON schema
Project description
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.
Requirement
Python >= 3.4
Installation
Install
pip install:
$ pip install ddlparse
command install:
$ python setup.py install
Update
pip update:
$ pip install ddlparse --upgrade
Usage
Example
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)
);
"""
# 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 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():
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 (case insensitive) *")
print(table.columns["total"])
License
Links
Repository : https://github.com/shinichi-takii/ddlparse
PyPI Package : https://pypi.python.org/pypi/ddlparse
Special Thanks
pyparsing : http://pyparsing.wikispaces.com/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ddlparse-1.0.2.tar.gz.
File metadata
- Download URL: ddlparse-1.0.2.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc36b9bbadd1eefb82b378b1f3e863861ed3159cf29806012b9a48b8f6e2a5ca
|
|
| MD5 |
ba1753d65890ef1aecf247e88398adae
|
|
| BLAKE2b-256 |
4298dd306a2e2a6774a4fa4dc73176ae9552673ecac4404f72c3166726098c43
|
File details
Details for the file ddlparse-1.0.2-py3-none-any.whl.
File metadata
- Download URL: ddlparse-1.0.2-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79eab7c610f3634f862d166936aec353a44b83257ffd9d00a3bb475e67d5d7b5
|
|
| MD5 |
861e7f1a0e48d24a2a719e06d31c49eb
|
|
| BLAKE2b-256 |
780bdd4f74caffd0f59a8ac6e913a1f2e42595db29eb0a857a6b5b808cc12eab
|