Skip to main content

Utility functions for DuckDB to BigQuery data type mapping and other database operations

Project description

Airbook DuckDB Utils

A Python package providing utility functions for DuckDB to BigQuery data type mapping and other database operations.

Installation

From Private PyPI (Recommended)

pip install airbook-duckdb-utils --extra-index-url https://your-private-pypi-server.com/simple/ --trusted-host your-private-pypi-server.com

From Source

git clone https://github.com/airbook/airbook-duckdb-utils.git
cd airbook-duckdb-utils
pip install -e .

Usage

Basic Type Mapping

from airbook_duckdb_utils import map_duckdb_data_type

# Map individual types
bigquery_type = map_duckdb_data_type('INTEGER')
print(bigquery_type)  # Output: NUMERIC

bigquery_type = map_duckdb_data_type('VARCHAR')
print(bigquery_type)  # Output: STRING

bigquery_type = map_duckdb_data_type('DECIMAL(18,3)')
print(bigquery_type)  # Output: NUMERIC

Advanced Usage

from airbook_duckdb_utils.type_mapping import (
    map_duckdb_data_type,
    get_type_mapping_dict,
    is_supported_type
)

# Check if a type is supported
if is_supported_type('TIMESTAMP'):
    mapped_type = map_duckdb_data_type('TIMESTAMP')
    print(f"TIMESTAMP maps to {mapped_type}")

# Get all supported mappings
all_mappings = get_type_mapping_dict()
print(f"Total supported types: {len(all_mappings)}")

# Example: Process a schema
schema = [
    ('id', 'BIGINT'),
    ('name', 'VARCHAR'),
    ('created_at', 'TIMESTAMP'),
    ('metadata', 'JSON'),
    ('score', 'DECIMAL(10,2)')
]

bigquery_schema = []
for column_name, duckdb_type in schema:
    bq_type = map_duckdb_data_type(duckdb_type)
    bigquery_schema.append((column_name, bq_type))
    
print("BigQuery Schema:")
for col_name, col_type in bigquery_schema:
    print(f"  {col_name}: {col_type}")

Supported Type Mappings

DuckDB Type BigQuery Type Notes
INTEGER, BIGINT, etc. NUMERIC All integer variants
FLOAT, DOUBLE FLOAT64 Floating point numbers
VARCHAR, TEXT STRING Text data
BOOLEAN BOOLEAN Boolean values
DATE DATE Date values
TIMESTAMP DATETIME Timestamp without timezone
TIMESTAMPTZ TIMESTAMP Timestamp with timezone
JSON JSON JSON data
ARRAY, LIST JSON Arrays stored as JSON
STRUCT JSON Structured data as JSON
BLOB BYTES Binary data

Development

Setup Development Environment

git clone https://github.com/airbook/airbook-duckdb-utils.git
cd airbook-duckdb-utils
pip install -e .[dev]

Running Tests

pytest tests/

Code Formatting

black airbook_duckdb_utils/
flake8 airbook_duckdb_utils/
mypy airbook_duckdb_utils/

Publishing to Private PyPI

Build the Package

python setup.py sdist bdist_wheel

Upload to Private PyPI

twine upload --repository-url https://your-private-pypi-server.com/legacy/ dist/*

Authentication

For private PyPI access, configure your ~/.pypirc:

[distutils]
index-servers = 
    private-pypi

[private-pypi]
repository: https://your-private-pypi-server.com/legacy/
username: your-username
password: your-password

Or use environment variables:

export TWINE_USERNAME=your-username
export TWINE_PASSWORD=your-password
export TWINE_REPOSITORY_URL=https://your-private-pypi-server.com/legacy/

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite
  6. Submit a pull request

Changelog

v1.0.0

  • Initial release
  • DuckDB to BigQuery type mapping functionality
  • Support for all major DuckDB data types
  • Comprehensive test coverage

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

airbook_duckdb_utils_vb-1.0.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

airbook_duckdb_utils_vb-1.0.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file airbook_duckdb_utils_vb-1.0.0.tar.gz.

File metadata

  • Download URL: airbook_duckdb_utils_vb-1.0.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.19

File hashes

Hashes for airbook_duckdb_utils_vb-1.0.0.tar.gz
Algorithm Hash digest
SHA256 25e97f52c4cdafa7ef677d4453d80cb00b1ec33492858836db99c2fc9d3cfd05
MD5 b858a97e6d3f965d15f9bb666f72413e
BLAKE2b-256 a27abdfed77f37e7d7a1fcb2a3f66c4fc6e3884b4f22855efd2361403a2ccdf2

See more details on using hashes here.

File details

Details for the file airbook_duckdb_utils_vb-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for airbook_duckdb_utils_vb-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e6ee32162100ce02c24a78fc4aaa2c717730a9543f04a14cb48f0d30322e3fd
MD5 389ff037bef883a95f95dc5e652ffae7
BLAKE2b-256 042a652f2037c611f5cbda88d70076acd9e38f015fd300a52d4d6a3d32624ca8

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