clickhouse
Version, currently 0.1.117 versions
- 0.6.2latestFeb 13, 2021
- 0.6.1not indexedFeb 13, 2021
- 0.5.6not indexedFeb 13, 2021
- 0.5.5not indexedFeb 13, 2021
- 0.5.4not indexedFeb 13, 2021
- 0.5.3not indexedFeb 13, 2021
- 0.5.2not indexedFeb 13, 2021
- 0.5.1not indexedFeb 13, 2021
- 0.5.0not indexedFeb 13, 2021
- 0.4.2not indexedFeb 13, 2021
- 0.4.1not indexedFeb 13, 2021
- 0.4.0not indexedFeb 13, 2021
- 0.3.0not indexedFeb 13, 2021
- 0.2.1not indexedFeb 13, 2021
- 0.2.0not indexedFeb 13, 2021
- 0.1.1not indexedFeb 13, 2021
- 0.1.0not indexedFeb 13, 2021
github.com/confact/clickhouse.cr
ClickHouse client for Crystal
Nothing has been indexed for 0.1.1 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
clickhouse:
github: confact/clickhouse.cr
version: ~> 0.1.1Then run:
shards installshard.yml
No shard.yml has been indexed for 0.1.1. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
clickhouse.cr 
ClickHouse client for Crystal.
- crystal: 0.27.2 0.31.1 0.32.1 0.33.0
Usage
Clickhouse#execute returns a Clickhouse::Response which includes Enumerable(Array(Type)).
require "clickhouse"
client = Clickhouse.new(host: "localhost", port: 8123)
res = client.execute <<-SQL
SELECT database, count(*)
FROM system.tables
GROUP BY database
SQL
res.rows # => 2
res.to_a # => [["system", 35], ["test", 9], ...
res.map(String, UInt64).each do |(name, cnt)|
p [name, cnt]
client.databases # => ["default", "system", ...
API
Clickhouse
def self.new(host = "localhost", port = 8123, database = nil, ...)
def execute(sql : String) : Response
# reflection
def databases : Array(Database)
def database(name : String) : Database
def tables(database : String) : Array(Table)
def table(database : String, name : String) : Table
Clickhouse::Response
def each
def each_hash
def records : Array(Record)
def map(*types : *T) forall T
def map(**types : **T) forall T
def success? : Response?
def success! : Response
def to_json : String
Clickhouse::Database
def name : String
def tables : Array(Table)
Clickhouse::Table
def name : String
def columns : Array(Column)
def count : UInt64
Clickhouse::Column
def name : String
def type : String
Response
records
res.each do |ary|
ary.class # => Array(Clickhouse::Type)
ary[0] # => "system"
ary[1] # => 35
res.each_hash do |hash|
hash.class # => Hash(String, Clickhouse::Type))
hash["database"] # => "system"
hash["count(*)"] # => 35
res.records.each do |hash|
hash.class # => Hash(String, Clickhouse::Type))
hash["database"] # => "system"
hash["count(*)"] # => 35
res.map(String, UInt64).each do |(name, cnt)|
name.class # => String
name # => "system"
cnt # => 35
res.map(name: String, cnt: UInt64).each do |r|
r.class # => NamedTuple(name: String, cnt: UInt64)
r["name"] # => "system"
r["cnt"] # => 35
statistics
res.statistics.elapsed # => 0.000671276
res.statistics.rows_read # => 1
res.statistics.bytes_read # => 1
Supported Data types
- [x] Array(T)
- [x] Nullable(T)
- [x] Boolean (as UInt8)
- [x] Date
- [x] DateTime
- [ ] Time zones
- [ ] Enum
- [ ] FixedString(N)
- [x] Float32, Float64
- [x] UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64
- [ ] Int ranges
- [ ] Uint ranges
- [x] String
- [ ] Tuple(T1, T2, ...)
- [ ] Nested data structures
- [ ] Special data types
See src/clickhouse/cast.cr for more details
Schema
provides reflecting database objects.
client = Clickhouse.new
client.databases.map(&.name)
# => ["default", "system", ...
system = client.database("system")
system.tables.map(&.name)
# => ["aggregate_function_combinators", "asynchronous_metrics", ...
table = client.table("system", "parts")
table.columns.map(&.name)
# => ["partition", "name", ...
table.columns.select(&.type.=~(/DateTime/)).map(&.name)
# => ["modification_time", "remove_time", "min_time", "max_time"]
Create Schema
buf = <<-SQL
CREATE TABLE logs (
`d` Date,
`k` UInt64
)
ENGINE = MergeTree(d, k, 8192)
SQL
create = Clickhouse::Schema::Create.parse(buf)
create.table # => "logs"
create.column("d").type # => "Date"
create.engine # => "MergeTree(d, k, 8192)"
create.to_sql # should be `buf`
QueryTokenizer
This provides general purpose query tokenizer like well-known advanced search.
string = %( foo from:user1 "a:b" -bar -"-x:-y" )
tokens = Clickhouse::QueryTokenizer.tokenize(string)
puts tokens.map(&.inspect)
# [Included("foo"), Modified("user1"), Exactly("a:b"), -Included("bar"), -Exactly("-x:-y")]
puts tokens.map(&.to_s)
# ["foo", "from:user1", "\"a:b\"", "-bar", "-\"-x:-y\""]
Installation
- Add the dependency to your
shard.yml:
dependencies:
var:
github: maiha/clickhouse.cr
version: 0.5.6
- Run
shards install
Development
make test
Add a new DataType
- src/clickhouse/data_type.cr Define ClickHouse DataType
- src/clickhouse.cr Add corresponding Crystal class into
Clickhouse::Type - src/clickhouse/cast.cr Add logic to combine them
Roadmap
- Core
- [x] all primitive DataType
- Request
- [ ] output format
- Response
- [x] statistics methods
- [ ] fetch value by field name
BREAKING CHANGES
- 0.3.0:
Column#typeis nowStringbecauseenumcan't handleArray(Int32)as its value.
Contributing
- Fork it (https://github.com/maiha/clickhouse.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- maiha - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.1- Tagged
- Feb 13, 2021
- Commit
8843eb531fac- Indexed
- not yet
Dependents
No indexed shard depends on this one yet.
Repository
github.com/confact/clickhouse.cr
Metadata
- Created
- Aug 16, 2026
- Updated
- Aug 16, 2026
- Synced
- Aug 16, 2026
- Versions
- 17