Skip to main content

DDL parase and Convert to BigQuery JSON schema

Project description

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.

Requirement

  1. Python >= 3.4

  2. pyparsing

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)
);
"""

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

Author

Shinichi Takii shinichi.takii@gmail.com

Special Thanks

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ddlparse-1.0.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ddlparse-1.0.1-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file ddlparse-1.0.1.tar.gz.

File metadata

  • Download URL: ddlparse-1.0.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ddlparse-1.0.1.tar.gz
Algorithm Hash digest
SHA256 2b8c9f10a7c3864a3e59e5c4c7b27d5ad693774e96476aad8214fcf648be21e1
MD5 8fcf99c73f2954a0c2484b156ebfc224
BLAKE2b-256 b7d23daf1cd6f074d12d563172d2e54e440cc4576ef2a4ef9666b3012f0ec2de

See more details on using hashes here.

File details

Details for the file ddlparse-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ddlparse-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b2b5f4c4914bf94d9c11dd8a0519bbf78a9922f633d5d4049df43eaca4dc8cab
MD5 b16f075767553ec5b97a22147870f684
BLAKE2b-256 7c69c74c26198ee12bd0b3988c656a80759c4e4380271877f3f9b5fc7ac67e19

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page