apache / druid

Apache Druid: a high performance real-time analytics database.
https://druid.apache.org/
Apache License 2.0
13.46k stars 3.7k forks source link

SQL: Inconsistent behavior when using LIKE operator with a string function #17174

Open DominicRicardAdgear opened 3 weeks ago

DominicRicardAdgear commented 3 weeks ago

Affected Version

Druid V.30.0.0

Description

Running the following query yields an error:

with t as (select 'a string' as col) 
select 
  col, 
  upper(col)
from t
where 
UPPER(t.col) LIKE UPPER('a%')

Result:

Error: UNCATEGORIZED (ADMIN)

Function[like] pattern argument must be a literal

Running the same comparator against a table does not result in an error. When doing explain plan for on the table query, the filter value is shown as being uppercased, which suggest druid is executing the UPPER function before building the plan.

explain plan for select count(1) from INFORMATION_SCHEMA.TABLES where upper(TABLE_NAME) like upper('%a%')

Result:

BindableAggregate(group=[{}], EXPR$0=[COUNT()])
  BindableFilter(condition=[LIKE(UPPER($2), '%A%')])
    BindableTableScan(table=[[INFORMATION_SCHEMA, TABLES]])
data-wild commented 1 week ago

I was curious about this and see that the query works fine so long as you wrap it in an additional CTE. For example, this works:

with t as (select 'a string' as col) 
, aa as (select 
  col, 
  upper(col)
from t)
select * from aa
where 
upper(col) like UPPER('a%')