dacort / metabase-athena-driver

An Amazon Athena driver for Metabase 0.32 and later
Apache License 2.0
225 stars 32 forks source link

Metabase in Athena: The Percentile function doesn't work. #102

Closed maxreis86 closed 2 years ago

maxreis86 commented 2 years ago

Hi dear all,

When I try to use the Percentile function in metabase, the metabase-athena-driver create a wrong SQL script.

I tried the function Percentile([Max Salary Expected], 0.25)` and the driver send to Athena the follow SQL:

select PERCENTILE_CONT(0.25) within group (order by a.max_salary_expected) FROM "prod-lakehouse-mirror"."applications" as a

However the right code should be:

select approx_percentile(a.max_salary_expected, 0.25) FROM "prod-lakehouse-mirror"."applications" as a

Thank you in advance.

dacort commented 2 years ago

Hi @maxreis86 - Thanks for opening a new issue!

I assume when the above SQL tries to run, Athena returns an error. Is that correct?

dacort commented 2 years ago

The Presto driver has mappings for both median and percentile that I probably need to incorporate.

maxreis86 commented 2 years ago

Hi @dacort,

Yes. Exactly. Athena returns the error: [Simba][AthenaJDBC](100071) An error has been thrown from the AWS Athena client. line 2:43: mismatched input '('. Expecting: 'BY' [Execution ID not available]

Thank you for your help!