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 date, -- Oracle 'DATE' -> BigQuery 'DATETIME'
  UNIQUE (NAME)
);
"""


# parse pattern (1-1)
table = DdlParse().parse(sample_ddl)

# parse pattern (1-2) : Specify source database
table = DdlParse().parse(ddl=sample_ddl, source_database=DdlParse.DATABASE.oracle)


# parse pattern (2-1)
parser = DdlParse(sample_ddl)
table = parser.parse()

# parse pattern (2-2) : Specify source database
parser = DdlParse(ddl=sample_ddl, source_database=DdlParse.DATABASE.oracle)
table = parser.parse()


# parse pattern (3-1)
parser = DdlParse()
parser.ddl = sample_ddl
table = parser.parse()

# parse pattern (3-2) : Specify source database
parser = DdlParse()
parser.source_database = DdlParse.DATABASE.oracle
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

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.1.1.tar.gz (10.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.1.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ddlparse-1.1.1.tar.gz
Algorithm Hash digest
SHA256 a77dc948ee29bfe8fdd990a2b1d7c768f34848bf5181dd797f0c36e1606cc5cb
MD5 d68fe7f58abd2a3ffcf70b3b2857fb3b
BLAKE2b-256 8aa1e2192968c1bac935bcce767a414382ec5ae981570a1e367905db8d5ad516

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ddlparse-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 70db297665950fd882944f59e3fb5633c9f9d2540ece58e411f1ef15ac64d202
MD5 b961bc6105e11b92734bf0a803697e36
BLAKE2b-256 50dd6b4fba55fa984259d49bd2df2976b6343231784a64e4b59640254e7efccc

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