Extracting, Converting, and Querying Data in Local Files using clickhouse-local
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.
Related posts
- An Introduction to Data Formats in ClickHouse
ClickHouse mediumAdept
ClickHouse can import and export a wide range of formats through the FORMAT clause and related settings. Covered here: CSV and TSV with custom delimiters, CustomSeparated for broken CSVs, JSONEachRow for NDJSON, Regexp and Template for custom text, Native and RowBinary for efficient transfer between servers, Parquet and other Apache formats, and SQLInsert/MySQLDump for SQL dumps. Two practical tricks: the Null format benchmarks queries without printing output, and Pretty* variants control how CLI results are displayed. clickhouse-local with the file() function lets you inspect local files before loading them.
- A Deep Dive into Apache Parquet with ClickHouse - Part 1
ClickHouse mediumAdept
ClickHouse can read and write Apache Parquet through its file and s3 table functions, using the same Parquet code in ClickHouse Local and ClickHouse Server. Examples on a 28M-row UK house price dataset show schema inspection with DESCRIBE and aggregation queries over local files, S3 objects and glob-matched file sets. Writes can go through INSERT INTO FUNCTION, INTO OUTFILE or FORMAT Parquet redirection, and PARTITION BY splits output into one file per year. INSERT INTO FUNCTION produces smaller files (243MB vs 291MB) than the client-side approaches, so it is recommended where possible.
- Getting Data Into ClickHouse - Part 1
ClickHouse mediumAdept
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.
- Getting Data Into ClickHouse - Part 3 - Using S3
ClickHouse mediumAdept
ClickHouse can both query data in place on Amazon S3 and ingest it, shown here on an 11.5-billion-row, ~600GB forex tick dataset stored as zstd CSV and Parquet. The s3 table function supports glob patterns and schema inference for ad-hoc queries. A full-dataset aggregation over all 66 pairs took about 583s on one node, about 435s with max_download_threads=12, and about 226s when distributed across the cluster with s3Cluster (roughly 50M rows/s). The examples also use window functions to find the largest daily spread changes and note that Parquet files parse less parallelly than CSV.
- Loading Parquet data into MySQL with ClickHouse
ClickHouse mediumAdept
MySQL has no native Parquet import, but clickhouse-local can read a Parquet file over HTTP with the `url` table function and write it straight into a MySQL table via `INSERT INTO FUNCTION mysql(...)`. In the walkthrough, 2.3M StackOverflow vote rows load in about 16.6 seconds using roughly 227 MiB of memory. The same `mysql` table function can query MySQL back. An inline subquery is written in ClickHouse SQL and rewritten into MySQL syntax, while the `query()` form is sent to MySQL verbatim, so ClickHouse-only functions like `tuple` fail there. Credentials can be kept in config-defined named collections instead of being passed on every call.