ClickHouse: quantile is read as the exact Quantile, though ClickHouse's quantile is approximate

Open Beginner friendly
#9,476 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python, sql

Research direction

Start by reading the ClickHouse dialect’s function mappings and the expression classes for Quantile, ApproxQuantile, and ParameterizedAgg. Trace how the parser handles quantile and quantileExact, then add or update focused parser tests for both calls. Done means the parsed expressions match the expected classes in the issue.

Written by the indexing model from the issue text.

Description

ClickHouse's quantile is approximate, but the ClickHouse dialect reads it into exp.Quantile, SQLGlot's exact quantile:

import sqlglot

type(sqlglot.parse_one("SELECT quantile(0.9)(x)", read="clickhouse").expressions[0]).__name__
# 'Quantile'
type(sqlglot.parse_one("SELECT quantileExact(0.9)(x)", read="clickhouse").expressions[0]).__name__
# 'ParameterizedAgg'

ClickHouse documents quantile as approximate ("Computes an approximate quantile of a numeric data sequence"; it uses reservoir sampling) and quantileExact as the exact one. So the exact class ends up on the approximate function and not on the exact one.

Expected: quantile reads as exp.ApproxQuantile (and quantileExact as exp.Quantile), so that what the tree says about the computation matches ClickHouse's.

Docs: https://clickhouse.com/docs/reference/functions/aggregate-functions/quantile

Checked on main (c321d9f). I used an LLM (Claude) to help narrow this down and write it up.

Dominant language
Python
Stars
9.8k
Forks
1.5k
Avg merge
10h 54m
Merged PRs (30d)
310

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tobymao/sqlglot

All issues in tobymao/sqlglot

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.