Skip to main content

Library for read and write Native format between Clickhouse and file.

Project description

NativeDumper

Library for read and write Native format between Clickhouse and file

Examples

Initialization

from native_dumper import (
    CompressionMethod,
    CHConnector,
    NativeDumper,
)

connector = CHConnector(
    host = <your host>,
    dbname = <your database>,
    user = <your username>,
    password = <your password>,
    port = 8123,
)

dumper = NativeDumper(
    connector=connector,
    compression_method=CompressionMethod.ZSTD,  # or CompressionMethod.LZ4 or CompressionMethod.NONE
)

Read dump from Clickhouse into file

file_name = "native.zstd"
# you need define one of parameter query or table_name
query = "select ..."  # some sql query
table_name = "default.test_table"  # or some table

with open(file_name, "wb") as fileobj:
    dumper.read_dump(
        fileobj,
        query,
        table_name,
    )

Write dump from file into Clickhouse

file_name = "native.zstd"
# you need define one of parameter table_name
table_name = "default.test_table"  # some table

with open(file_name, "rb") as fileobj:
    dumper.write_dump(
        fileobj,
        table_name,
    )

Write from Clickhouse into Clickhouse

Same server

table_dest = "default.test_table_write"  # some table for write
table_src = "default.test_table_read"  # some table for read
query_src = "select ..."  # or some sql query for read

dumper.write_between(
    table_dest,
    table_src,
    query_src,
)

Different servers

connector_src = CHConnector(
    host = <host src>,
    dbname = <database src>,
    user = <username src>,
    password = <password src>,
    port = 8123,
)

dumper_src = NativeDumper(connector=connector_src)

table_dest = "default.test_table_write"  # some table for write
table_src = "default.test_table_read"  # some table for read
query_src = "select ..."  # or some sql query for read

dumper.write_between(
    table_dest,
    table_src,
    query_src,
    dumper_src.cursor,
)

Get NativeReader object from stream

table_name = "default.test_table_read"  # some table for read
query = "select ..."  # or some sql query for read

reader = dumper.to_reader(
    query=query,
    table_name=table_name,
)

Write from python lists

dtype_data = Iterable[Any] | list[list[Any]] # some python data
table_name = "default.test_table_write"  # some table for write

dumper.from_rows(
    dtype_data=dtype_data,
    table_name=table_name,
)

Write from pandas.DataFrame

data_frame = pandas.DataFrame({<some data>})
table_name = "default.test_table_write"  # some table for write

dumper.from_pandas(
    data_frame=data_frame,
    table_name=table_name,
)

Write from polars.DataFrame

data_frame = polars.DataFrame({<some data>})
table_name = "default.test_table_write"  # some table for write

dumper.from_polars(
    data_frame=data_frame,
    table_name=table_name,
)

Open Native file format

Get info from my another repository https://github.com/0xMihalich/nativelib

Installation

From pip

pip install native_dumper

From local directory

pip install .

From git

pip install git+https://github.com/0xMihalich/native_dumper

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

native_dumper-0.2.0.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

native_dumper-0.2.0.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file native_dumper-0.2.0.0.tar.gz.

File metadata

  • Download URL: native_dumper-0.2.0.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for native_dumper-0.2.0.0.tar.gz
Algorithm Hash digest
SHA256 e7b921278b61ee6278437f3bf6475e5e48b7d335324cebecaadb91f1ffd088e6
MD5 60c9f8aa75ef3f4777e4854b9100205c
BLAKE2b-256 5524539b74a274e812eb5a2dcda7f19a371c9ac3a26b2517d429c540bbe7a773

See more details on using hashes here.

File details

Details for the file native_dumper-0.2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for native_dumper-0.2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7081df4d9773456cecd8567db7eb8e316c9ac86db1b65ead3cba602c47fc8bb7
MD5 bdd939f8ba41f2fb72cec55ce9049a0a
BLAKE2b-256 1fe4393fe27159e9e83cb209f2c796aeac561aa6414a982f6cbc4fafec756f0b

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