https://questdb.io logo
Title
n

Newskooler

02/03/2023, 2:00 PM
🤔 If I have a paragraph in QuestDB stored as a string, do you know how can I count the number of words inside this large string? E.g.
Hi, my name is Jon.
Should yield
5
j

Jaromir Hamala

02/03/2023, 2:12 PM
hi, I think you would have to implement a custom function for this. it should not be that hard, have a look at for https://github.com/questdb/questdb/blob/7e0207604f61faf641553064a2a646fa69ee4067/c[…]db/griffin/engine/functions/str/ToUppercaseFunctionFactory.java for inspiration.
n

Newskooler

02/03/2023, 2:12 PM
Thanks will check it out now 👍 🤘🏻
j

Jaromir Hamala

02/03/2023, 2:13 PM
WordCount is actually a very good example for a tutorial on how to extend QuestDB!
n

Newskooler

02/03/2023, 2:17 PM
By one of these custom functions, right?
j

Jaromir Hamala

02/03/2023, 2:18 PM
yes
hi, I prepared a simple demo project showing how to do that: https://github.com/jerrinot/questdb_ext_tutorial
m

Matt

02/03/2023, 7:26 PM
I confirm that the demo project is really easy to follow! Very nice. If you have already followed the Create my first dataset guide, then you can immediately use the function in queries like this:
select distinct
  city,
  wordcount(city) as word_count
from sensors
order by word_count, city;
j

Jaromir Hamala

02/06/2023, 9:22 AM
thanks Matt! after publishing the demo I realized there could be an issue in distributions where we
jlink
JDK and QuestDB into a single image. because there is no QuestDB JAR in the first place. So for now the demo will work in MacOS and no-RT distributions. but it might be more complicated in distributions where JDK (RT) is packaged together with QuestDB.