Getting Data Into ClickHouse - Part 1
ClickHouse can load a 28.7M-row, 4.6GB gzipped Hacker News CSV with a single command, using schema inference via clickhouse-local's file() and the url() table function. Inferred schemas are best-effort, with Nullable Float64 and String types everywhere. Defining explicit types (UInt32, Enum, LowCardinality, DateTime) with ORDER BY id improves the result: loading from a local file with INFILE took about 94s versus 204s streaming from the URL. Sample analytical queries then scan the full table in under 2 seconds, even with ILIKE text filters.
Related posts
- Extracting, Converting, and Querying Data in Local Files using clickhouse-local
ClickHouse mediumAdept
clickhouse-local runs ClickHouse's SQL engine as a standalone CLI, so you can query, transform and convert local, piped, HTTP, S3, MySQL or Postgres data without deploying a server. Worked examples cover querying CSVs with or without headers via the file() function, schema inference with DESCRIBE, and writing results with INTO OUTFILE in formats such as SQLInsert and Parquet. They also show globbing and joining multiple files, the virtual _file/_path columns, and stdin piping with --structure. Compressed multi-gigabyte files are handled with automatic compression detection, and a 826K CSV shrinks to 432K as Parquet.
- Getting Data Into ClickHouse - Part 2 - A JSON detour
ClickHouse mediumAdept
ClickHouse's experimental JSON (Object('json')) type, introduced around 22.8, stores semi-structured rows by automatically inferring sub-columns and representing them internally as Tuples with minimal-width numeric types. It is demonstrated on the 28M-row Hacker News dataset via the JSONAsObject and JSONAsString formats. Because JSON sub-columns cannot serve as primary keys or carry codecs, the recommended pattern is a hybrid schema: declare stable fields like time and type explicitly so they can be used in ORDER BY, and keep the rest in a JSON column. That change cut a sample query from 2.6s to 0.74s. Inferred types widen transparently as new values arrive, but a single string value can silently convert a numeric column to String, so clean the data or declare critical columns explicitly.
- What’s New in ClickHouse 22.1
ClickHouse mediumAdept
ClickHouse 22.1 adds schema inference for table functions like url, s3, file and hdfs, detecting format and compression from the file extension and reading column types from self-describing formats such as Native, Parquet, Avro and ORC. For Parquet it uses range requests to fetch only the footer metadata. Other additions include experimental parallel query processing across replicas with dynamic work distribution, ZooKeeper-path-based cluster service discovery, and automatic sparse column serialization for mostly-default columns, selected from statistics gathered on insert and merge. The release also brings live CPU/memory usage in clickhouse-client, Hive and Azure Blob Storage integrations, and Cramér's V and Theil's U functions.
- Optimizing ClickHouse with Schemas and Codecs
ClickHouse mediumAdept
Tightening a ClickHouse schema with strict types cuts a 1B-row NOAA weather dataset from 131.58 GiB to 71.38 GiB uncompressed. The changes are right-sized integers instead of Int64, Int16 elevation, an Enum8 for weather type, LowCardinality for ~100k-value strings, and Float32 lat/lon in place of a Point. Compressed size moves less, from 4.07 GiB to 3.83 GiB, but smaller uncompressed data lowers RAM use and improves CPU cache efficiency at query time. Each step is checked against per-column system.columns stats and a benchmark query, before moving on to tuning column codecs for the largest columns such as date and temperatures.
- The world’s fastest tool for querying JSON files
ClickHouse easyNovice
clickhouse-local, a single-binary SQL engine for local and remote files, outperforms SPySQL, jq, trdsql, Miller, OctoSQL, spark-sql, Pandas and DSQ when querying large JSON files in the SPySQL benchmark on Amazon book reviews data. The benchmark covers map (computed column over all rows), aggregation (column average) and filter (first 100 matching rows) tasks, and OctoSQL is faster on smaller files. Schema inference and semi-structured data support make the queries simple to write. Caveats: each query runs only once, results vary by hardware, and the filter test favors tools that stop early on LIMIT without loading the whole file.