apache / apache/druid

Check the types of given parameters matches the types of SQL function declared parameters

Open
#18,010 4 comments 3 reactions 0 assignees View on GitHub
Area - SQL Contributions Welcome
Dominant language
Java
Stars
14.1k
Forks
3.8k
Avg merge
2d 58m
Merged PRs (30d)
233

Description

### Affected Version

ALL

### Description

For APPROX_QUANTILE and related functions, the first parameter MUST be numeric column. however, currently the SQL planner does not check if the given expression is type of number, even a STRING is accepted.
If users accidentally use single quote instead of double quote for a column, an hard to understand exception is thrown as follows>

```sql
SELECT channel,
APPROX_QUANTILE('r1', 0.990000, 100) AS "p99"
FROM "wikipedia"
GROUP BY channel
```

```bash
Error: RUNTIME_FAILURE (OPERATOR)
java.util.concurrent.ExecutionException: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Number (java.lang.String and java.lang.Number are in module java.base of loader 'bootstrap')
java.lang.RuntimeException
```

This makes people think that there's an internal error at the engine side not at the SQL side.
 
So, for these functions, a type check at SQL layer is needed to give a clear information instead of throwing an exception which makes people think there's internal error from the engine.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the APPROX_QUANTILE query in the issue and trace how the SQL planner handles its first parameter. The work is done when a nonnumeric expression is rejected at the SQL layer with a clear error instead of a runtime ClassCastException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
backend-api-design, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.