Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement LZ4 transport compression #33

Merged
merged 19 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
docs/build
docs/Manifest.toml
Manifest.toml

# editor(s)
.vscode
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.2.2"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
CodecLz4 = "5ba52731-8f18-5e0d-9241-30f10d1ec561"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DecFP = "55939f99-70c6-5e9b-8bb0-5071ed7d61fd"
Expand Down
1 change: 0 additions & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Usage examples can be found on the [usage page](@ref Usage).

## Limitations

- Transfer compression is currently not implemented
- Timezone conversion of `DateTime` / `DateTime64` for columns that have a
timezone assigned in ClickHouse doesn't happen automatically. All DateTime
objects are naive, meaning they aren't timezone aware. For reasoning, see
Expand Down
4 changes: 4 additions & 0 deletions src/ClickHouse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ include("columns/columns.jl")
include("Connect.jl")
include("Query.jl")

export Compression
export COMPRESSION_NONE
export COMPRESSION_LZ4
export COMPRESSION_CHECKSUM_ONLY
export ClickHouseSock
export Block
export select
Expand Down
6 changes: 4 additions & 2 deletions src/Connect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ function connect(
password::AbstractString = "",
connection_timeout = DBMS_DEFAULT_CONNECT_TIMEOUT,
max_insert_block_size = DBMS_DEFAULT_MAX_INSERT_BLOCK,
send_buffer_size = DBMS_DEFAULT_BUFFER_SIZE
send_buffer_size = DBMS_DEFAULT_BUFFER_SIZE,
compression::Compression = COMPRESSION_NONE
)::ClickHouseSock
sock = ClickHouseSock(
nothing,
Expand All @@ -107,7 +108,8 @@ function connect(
password = password,
connection_timeout = connection_timeout,
max_insert_block_size = max_insert_block_size,
send_buffer_size = send_buffer_size
send_buffer_size = send_buffer_size,
compression = compression,
)
)

Expand Down
5 changes: 4 additions & 1 deletion src/Exceptions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ struct ClickHouseServerException <: Exception
code::Int
name::String
message::String
end
end

"""checksum (compressed block hash values) don't match"""
struct ChecksumError <: Exception end
3 changes: 2 additions & 1 deletion src/Query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import Sockets
# ============================================================================ #

function write_query(sock::ClickHouseSock, query::AbstractString)::Nothing
query = ClientQuery("", ClientInfo(), "", 2, 0, query)
compression = compression_enabled(sock.settings)
query = ClientQuery("", ClientInfo(), "", 2, compression, query)
write_packet(sock, query)
write_packet(sock, make_block())
nothing
Expand Down
13 changes: 12 additions & 1 deletion src/tcp/BasicIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,15 @@ chwrite(sock::ClickHouseSock, x::AbstractVector{T}) where T <: Number =
write(sock.io, x)

chwrite(sock::ClickHouseSock, x::AbstractVector{String}) =
foreach(x -> chwrite(sock, x), x)
foreach(x -> chwrite(sock, x), x)


# Compression bytes

function chwrite(sock::ClickHouseSock, compression::ClickHouse.Compression)
chwrite(sock, UInt8(compression))
end

function chread(sock::ClickHouseSock, ::Type{ClickHouse.Compression})
Compression(chread(sock, UInt8))
end
Loading