Repository: tobymao/sqlglot

Issue:
Parsing of ClickHouse multi-level quantiles fails
The ClickHouse SQL expression `quantiles(level1, level2, …)(x)` cannot be parsed if there are more than 2 levels:

```python
>>> sqlglot.parse("SELECT quantiles(0.1, 0.2, 0.3)(a)", read="clickhouse")
sqlglot.errors.ParseError: The number of provided arguments (3) is greater than the maximum number of supported arguments (2). Line 1, Col: 34.
  SELECT quantiles(0.1, 0.2, 0.3)(a)
```

while `SELECT quantiles(0.1)(a)` and `SELECT quantiles(0.1, 0.2)(a)` can be parsed just fine.

Discussion:

Patch:
diff --git a/sqlglot/expressions.py b/sqlglot/expressions.py
index 3123fb42..37c64a94 100644
--- a/sqlglot/expressions.py
+++ b/sqlglot/expressions.py
@@ -3681,6 +3681,7 @@ class Quantile(AggFunc):
 # https://clickhouse.com/docs/en/sql-reference/aggregate-functions/reference/quantiles/#quantiles
 class Quantiles(AggFunc):
     arg_types = {"parameters": True, "expressions": True}
+    is_var_len_args = True
 
 
 class QuantileIf(AggFunc):


Test patch:
diff --git a/tests/dialects/test_clickhouse.py b/tests/dialects/test_clickhouse.py
index 905e1f4b..24539cb5 100644
--- a/tests/dialects/test_clickhouse.py
+++ b/tests/dialects/test_clickhouse.py
@@ -16,6 +16,7 @@ class TestClickhouse(Validator):
         self.validate_identity("SELECT * FROM foo ANY JOIN bla")
         self.validate_identity("SELECT quantile(0.5)(a)")
         self.validate_identity("SELECT quantiles(0.5)(a) AS x FROM t")
+        self.validate_identity("SELECT quantiles(0.1, 0.2, 0.3)(a)")
         self.validate_identity("SELECT * FROM foo WHERE x GLOBAL IN (SELECT * FROM bar)")
         self.validate_identity("position(haystack, needle)")
         self.validate_identity("position(haystack, needle, position)")