Slackbot
12/04/2022, 10:25 AMtilak chowdary
12/04/2022, 10:35 AMSELECT
CONCAT(tags, '-', count(*)) as tag_count
FROM inline_data
where tags like 't3'
group by tags
having tag_count like 't3%'
One issue with using this hack is it might break in future because of delimiter we use to add tags to countVadim
12/04/2022, 4:19 PMMV_CONTAINS(tags, 't3') is probably the true way of representing the filter that you want. tags = 't3' semi-works for strange back compat reasons but it can lead to bad things since the SQL planner can simplify it incorrectly. It plans to the same native construct (selector) but plays nicer with the SQL side of the world.Vadim
12/04/2022, 4:22 PMGROUP BY tags + HAVING tags = 't3' does not work as you want... this is because the SQL planner is trying to be too cool and push the HAVING into a WHEREVadim
12/04/2022, 4:23 PMtagsVadim
12/04/2022, 4:29 PMtags ? well you see tags is not an array, it is a multi-value string (thus MV_). I always imagine MV strings as being in super-position with themselves. Like a single tags can be both t1 and t2 and t3. Hence tags = 't1' and tags = 't2' can both be true for the same row. This is a concept of Druid that was inherited from the native system but it does not translate to SQL as there is no SQL equivalent. SQL has `ARRAY`s but they have different semantics so Druid can not just pretend that tags is an Array as its storage format for MV columns is different.Vadim
12/04/2022, 4:31 PMMV_FILTER_ONLY(tags, ARRAY ['t3']) will restrict what values tags can be (think of it like Array#filter in JS).Vadim
12/04/2022, 4:32 PMVadim
12/04/2022, 4:33 PMVadim
12/04/2022, 4:42 PMMV_* functions https://druid.apache.org/docs/latest/querying/sql-multivalue-string-functions.html the 8th one will blow your mind!tilak chowdary
12/05/2022, 1:30 AMSELECT tags, count(*)
FROM inline_data
where tags like 't3%'
group by tags
having tags like 't3%
. In native query this can be done using
"dimensions": [
{
"type": "prefixFiltered",
"delegate": {
"type": "default",
"dimension": "tags",
"outputName": "tags"
},
"prefix": "t3%"
}
],Gian Merlino
12/06/2022, 8:34 AMtilak chowdary
12/06/2022, 5:19 PMtilak chowdary
12/06/2022, 5:20 PM