SQL2Arrow
This is a Python library that provides convenient and high-performance methods to parse INSERT SQL statements into Arrow arrays. It's very useful for analyzing data dumped by mysqldump or other tools.
How to use
Installation
Install the latest SQL2arrow version with:
pip install sql2arrow
Parsing SQL str
import sql2arrow
sql_str = '''
INSERT INTO `region` VALUES
('', '', '2023-01-31 18:00:48', '2023-01-31 18:00:48', ''),
('1541947646568607746', 'region name', '2022-06-29 08:52:21', '2022-06-29 08:52:21', 'D99'),
('1541947680890597378', 'region name1', '2022-06-29 08:52:29', '2022-06-29 08:52:29', 'D98'),
('620422117205', 'region name7', '2021-10-25 18:23:48', '2021-10-25 18:23:48', 'D620422117');
'''
columns = [
sql2arrow.Column("region_code", sql2arrow.ArrowTypes.utf8()),
sql2arrow.Column("region_name", sql2arrow.ArrowTypes.utf8()),
sql2arrow.Column("create_time", sql2arrow.ArrowTypes.utf8()),
sql2arrow.Column("update_time", sql2arrow.ArrowTypes.utf8()),
sql2arrow.Column("parent_region_code", sql2arrow.ArrowTypes.utf8())
]
arrow_data = sql2arrow.parse_sql(sql_str, columns)
Parsing sql files
import sql2arrow
sql_paths = [
"region.sql_0.gz", "region.sql_1.gz","region.sql_2.gz","region.sql_3.gz","region.sql_4.gz","region.sql_5.gz","region.sql_6.gz"
]
columns = [
sql2arrow.Column("region_code", sql2arrow.ArrowTypes.utf8()),
sql2arrow.Column("region_name", sql2arrow.ArrowTypes.utf8()),
sql2arrow.Column("create_time", sql2arrow.ArrowTypes.utf8()),
sql2arrow.Column("update_time", sql2arrow.ArrowTypes.utf8()),
sql2arrow.Column("parent_region_code", sql2arrow.ArrowTypes.utf8())
]
partition_func_spec = sql2arrow.partition.IcebergPartitionFuncSpec()
partition_func_spec.add_partition("region_code", sql2arrow.partition.IcebergTransforms.bucket(30))
it = sql2arrow.SQLFile2ArrowIter(
sql_paths,
columns,
4,
1000,
sql2arrow.CompressionType.SNAPPY,
sql2arrow.Dialect.MYSQL,
partition_func_spec
)
for arr in it:
print(arr)
arro3
SQL2Arrow uses arro3 as the default Python library for Apache Arrow. Thanks to the Arrow PyCapsule Interface, we can seamlessly pass Arro3's Array data to other libraries compatible with the Arrow PyCapsule Interface, including PyArrow, Polars (v1.2+), Pandas (v2.2+), NanoArrow, and more, all with zero-copy memory.
# some codes from above
import pyarrow as pa
tables = [pa.Table.from_arrays(a, names=names) for a in arrs]
Limitations
Dialect
It currently supports only MySQL and PostgreSQL INSERT statements.
Metadata
Release files for sql2arrow 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sql2arrow-0.1.3.tar.gz | 45.0 kB | Details |
Built distributions (wheels)
Total release size: 56.1 MB
Release files / sql2arrow-0.1.3.tar.gz
| Download URL | sql2arrow-0.1.3.tar.gz |
|---|---|
| Size | 45.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8887a606fc3e3548312e64a5e5b30036dd8a311edeb8634aca6c8f6026153b37
|
|
BLAKE2b-256 checksum How to use checksums |
7f64644b43ac087b388f3b104e689593a153b329742d1b878ce64bed74fc557e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.8.1
|
Release files / sql2arrow-0.1.3-cp38-abi3-win_amd64.whl
| Download URL | sql2arrow-0.1.3-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 4.5 MB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
bca05337fca332d04a2b381068f004dae3158fa2f2ecb870738b2b2cd6b8266b
|
|
BLAKE2b-256 checksum How to use checksums |
8ac77a0b8e91614b647e9b7792803e77f4a9b53a89d9cafc6e02de0018728f57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.8.1
|
Release files / sql2arrow-0.1.3-cp38-abi3-musllinux_1_2_x86_64.whl
| Download URL | sql2arrow-0.1.3-cp38-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 5.1 MB |
| Tags | CPython 3.8 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
87a1cc5ddc90c5e1702cbfc0d3f70a0313e1482105bccc8d51585fd9dd67de81
|
|
BLAKE2b-256 checksum How to use checksums |
beecd526b7296f942964dea1ad06912fb205633aa4b31cf327900a3477b71edb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.8.1
|
Release files / sql2arrow-0.1.3-cp38-abi3-musllinux_1_2_i686.whl
| Download URL | sql2arrow-0.1.3-cp38-abi3-musllinux_1_2_i686.whl |
|---|---|
| Size | 5.3 MB |
| Tags | CPython 3.8 Linux musl 1.2+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
0961fa3d017249a4f30546096185ca9f9ccc7a8c2027751838e7685e0e853a1c
|
|
BLAKE2b-256 checksum How to use checksums |
237f3485bab6df9c0c34cb33c154f2b43a7697d390f716a433c657b8209a196c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.8.1
|
Release files / sql2arrow-0.1.3-cp38-abi3-musllinux_1_2_armv7l.whl
| Download URL | sql2arrow-0.1.3-cp38-abi3-musllinux_1_2_armv7l.whl |
|---|---|
| Size | 5.2 MB |
| Tags | CPython 3.8 Linux musl 1.2+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
873f6d19d85d66e7deecb22a5996e423453b1a82973c746e140b884cc969340d
|
|
BLAKE2b-256 checksum How to use checksums |
3c0b2b4f15fe60c084007bbb241753cf1daa88ad8feb4b8e3c98d07320c7c374
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.8.1
|
Release files / sql2arrow-0.1.3-cp38-abi3-musllinux_1_2_aarch64.whl
| Download URL | sql2arrow-0.1.3-cp38-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.8 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
61fbdde2a5dcd1be4ce98e420735faad67cae40f4446806ec34ad8b59c71e309
|
|
BLAKE2b-256 checksum How to use checksums |
ef0405e62dc983f84c61f0ea5f6983b75355773cc8b0777a33081bbdc4d095f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.8.1
|
Release files / sql2arrow-0.1.3-cp38-abi3-manylinux_2_28_x86_64.whl
| Download URL | sql2arrow-0.1.3-cp38-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.8 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
8d560cca8ef61e434cf6bc5506720ad41bb618c835a3746719116e84a720dddb
|
|
BLAKE2b-256 checksum How to use checksums |
3d392e99494c1a7c3e716c25a5b89787e23a6bb2af681bca324301cda66e637d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.8.1
|
Release files / sql2arrow-0.1.3-cp38-abi3-manylinux_2_28_s390x.whl
| Download URL | sql2arrow-0.1.3-cp38-abi3-manylinux_2_28_s390x.whl |
|---|---|
| Size | 5.8 MB |
| Tags | CPython 3.8 Linux glibc 2.28+ IBM System/390x abi3 |
|
SHA-256 checksum How to use checksums |
b4e72daecf028f8842d77ea6d84eac0cd537badc5a8a6433594187f23f15e406
|
|
BLAKE2b-256 checksum How to use checksums |
94ad56ec5de96386f650f37e0298d1569e4a31a7905c49b4f54f82e72ccca5cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.8.1
|
Release files / sql2arrow-0.1.3-cp38-abi3-manylinux_2_28_ppc64le.whl
| Download URL | sql2arrow-0.1.3-cp38-abi3-manylinux_2_28_ppc64le.whl |
|---|---|
| Size | 6.5 MB |
| Tags | CPython 3.8 Linux glibc 2.28+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
3c3a1f03f90ab6bca6fe9cbee73f44c8e833c62256eaede2d53c95730ab5aa4a
|
|
BLAKE2b-256 checksum How to use checksums |
9ed704daeedc1103be7ac30fd6ba4c522a4bcc4c65447f4f961f34f115245811
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.8.1
|
Release files / sql2arrow-0.1.3-cp38-abi3-manylinux_2_28_armv7l.whl
| Download URL | sql2arrow-0.1.3-cp38-abi3-manylinux_2_28_armv7l.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.8 Linux glibc 2.28+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
cd5a69b2794f6c5c51cdac77efabd34e9070adc8e939d37e068e713d33937a0f
|
|
BLAKE2b-256 checksum How to use checksums |
d301d732b0acaef000b58faed4666046a8401019c01dee09c9db5a072db4c3b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.8.1
|
Release files / sql2arrow-0.1.3-cp38-abi3-manylinux_2_28_aarch64.whl
| Download URL | sql2arrow-0.1.3-cp38-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 4.7 MB |
| Tags | CPython 3.8 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
d4cbda4e80e26248a0d798c37d979c93e2f2caea62be275ff1f25b096f2bc953
|
|
BLAKE2b-256 checksum How to use checksums |
698c8a9f83f26b30e2231a70f692558a392178968129acc3522342e8691b3cab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.8.1
|
Release files / sql2arrow-0.1.3-cp38-abi3-macosx_11_0_arm64.whl
| Download URL | sql2arrow-0.1.3-cp38-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.2 MB |
| Tags | CPython 3.8 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5f025f334293dee107ea301110374ead232e7d8fac0b5f4d514aee28a7be5eeb
|
|
BLAKE2b-256 checksum How to use checksums |
c2610a72f670a33026b26860d7635f963fa43b5216469fe34ea67e755556647b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.8.1
|